dragAndDrop.cc
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055 #include "CoreWidget.hh"
00056
00057 #include <OpenFlipper/BasePlugin/PluginFunctions.hh>
00058 #include <OpenFlipper/common/GlobalOptions.hh>
00059
00060
00061
00062
00063
00064
00065 static const char VIEW_MAGIC[] = "ACG::QtWidgets::QGLViewerWidget encoded view";
00066
00067
00068
00069 void CoreWidget::startDrag ( QMouseEvent* _event )
00070 {
00071 QObject* senderPointer = sender();
00072 int examinerId = -1;
00073
00074 if ( senderPointer != 0 ) {
00075 for ( unsigned int i = 0 ; i < OpenFlipper::Options::examinerWidgets(); ++i ) {
00076 if ( senderPointer == examiner_widgets_[i] ) {
00077 examinerId = i;
00078 break;
00079 }
00080 }
00081
00082 }
00083
00084 if ( examinerId == -1 ) {
00085 emit log(LOGERR , tr("startDrag in Core called by non examiner, stopping here"));
00086 return;
00087 }
00088
00089 PluginFunctions::setActiveExaminer(examinerId);
00090
00091
00092 QPoint position = _event->pos();
00093
00094
00095
00096 int objectId = -1;
00097
00098
00099 unsigned int node_idx, target_idx;
00100 ACG::Vec3d hit_point;
00101 BaseObjectData* object;
00102 if ( PluginFunctions::scenegraphPick ( ACG::SceneGraph::PICK_ANYTHING,
00103 position,
00104 node_idx,
00105 target_idx,
00106 &hit_point ) ) {
00107 if ( PluginFunctions::getPickedObject ( node_idx, object ) )
00108 objectId = object->id();
00109 }
00110
00111 if ( objectId != -1 ) {
00112 emit log(LOGERR , tr("dragEvent Picked Object"));
00113 }
00114
00115
00116
00117
00118 QString view;
00119 examiner_widgets_[PluginFunctions::activeExaminer()]->encodeView ( view );
00120
00121 QDrag * drag = new QDrag ( this );
00122 QMimeData * mime_data = new QMimeData;
00123
00124 mime_data->setText ( view );
00125 drag->setMimeData ( mime_data );
00126 drag->start();
00127
00128 }
00129
00130 void CoreWidget::dragEnterEvent ( QDragEnterEvent* _event ) {
00131
00132 if ( _event->mimeData()->hasFormat ( "text/plain" ) ) {
00133 QString view ( _event->mimeData()->text() );
00134
00135
00136 if ( view.left ( sizeof ( VIEW_MAGIC ) - 1 ) == QString ( VIEW_MAGIC ) ) {
00137 _event->acceptProposedAction();
00138 }
00139
00140 }
00141
00142 }
00143
00144 void CoreWidget::dropEvent ( QDropEvent* _event ) {
00145 QObject* senderPointer = sender();
00146 int examinerId = -1;
00147
00148 if ( senderPointer != 0 ) {
00149 for ( unsigned int i = 0 ; i < OpenFlipper::Options::examinerWidgets(); ++i ) {
00150 if ( senderPointer == examiner_widgets_[i] ) {
00151 examinerId = i;
00152 break;
00153 }
00154 }
00155 }
00156
00157 if ( examinerId == -1 ) {
00158 emit log(LOGERR , tr("startDrag in Core called by non examiner, stopping here"));
00159 return;
00160 }
00161
00162 PluginFunctions::setActiveExaminer(examinerId);
00163
00164 if ( _event->mimeData()->hasUrls() ) {
00165 QList<QUrl> urls = _event->mimeData()->urls();
00166 for ( int j = 0 ; j < urls.size() ; ++j ) {
00167 emit log(LOGWARN , tr("Dropped URL: %1").arg(urls[j].toLocalFile()));
00168 emit dragOpenFile(urls[j].toLocalFile());
00169 }
00170
00171 return;
00172 }
00173
00174 if ( _event->mimeData()->hasFormat ( "text/plain" ) ) {
00175
00176 QString view ( _event->mimeData()->text() );
00177
00178
00179 if ( view.left ( sizeof ( VIEW_MAGIC ) - 1 ) == QString ( VIEW_MAGIC ) ) {
00180 examiner_widgets_[PluginFunctions::activeExaminer()]->decodeView ( view );
00181 _event->acceptProposedAction();
00182 return;
00183 }
00184
00186
00187 if ( view.left ( 7 ) == QString("file://") ) {
00188 _event->acceptProposedAction();
00189 emit dragOpenFile(view.remove(0,7));
00190
00191 return;
00192 }
00193
00194 emit log(LOGERR , tr("Unknown drop event! Unable to handle the dropped data! Received data: %1").arg(view));
00195 }
00196
00197 emit log(LOGERR , tr("Unknown drop event!"));
00198
00199
00200 }
00201
00202