dragAndDrop.cc

00001 /*===========================================================================*\
00002  *                                                                           *
00003  *                              OpenFlipper                                  *
00004  *      Copyright (C) 2001-2009 by Computer Graphics Group, RWTH Aachen      *
00005  *                           www.openflipper.org                             *
00006  *                                                                           *
00007  *---------------------------------------------------------------------------*
00008  *  This file is part of OpenFlipper.                                        *
00009  *                                                                           *
00010  *  OpenFlipper is free software: you can redistribute it and/or modify      *
00011  *  it under the terms of the GNU Lesser General Public License as           *
00012  *  published by the Free Software Foundation, either version 3 of           *
00013  *  the License, or (at your option) any later version with the              *
00014  *  following exceptions:                                                    *
00015  *                                                                           *
00016  *  If other files instantiate templates or use macros                       *
00017  *  or inline functions from this file, or you compile this file and         *
00018  *  link it with other files to produce an executable, this file does        *
00019  *  not by itself cause the resulting executable to be covered by the        *
00020  *  GNU Lesser General Public License. This exception does not however       *
00021  *  invalidate any other reasons why the executable file might be            *
00022  *  covered by the GNU Lesser General Public License.                        *
00023  *                                                                           *
00024  *  OpenFlipper is distributed in the hope that it will be useful,           *
00025  *  but WITHOUT ANY WARRANTY; without even the implied warranty of           *
00026  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            *
00027  *  GNU Lesser General Public License for more details.                      *
00028  *                                                                           *
00029  *  You should have received a copy of the GNU LesserGeneral Public          *
00030  *  License along with OpenFlipper. If not,                                  *
00031  *  see <http://www.gnu.org/licenses/>.                                      *
00032  *                                                                           *
00033 \*===========================================================================*/
00034 
00035 /*===========================================================================*\
00036  *                                                                           *
00037  *   $Revision: 8520 $                                                         *
00038  *   $Author: moebius $                                                      *
00039  *   $Date: 2010-02-10 15:56:59 +0100 (Mi, 10. Feb 2010) $                   *
00040  *                                                                           *
00041 \*===========================================================================*/
00042 
00043 
00044 
00045 //=============================================================================
00046 //
00047 //  CLASS CoreWidget - IMPLEMENTATION
00048 //
00049 //=============================================================================
00050 
00051 
00052 //== INCLUDES =================================================================
00053 
00054 // -------------------- mview
00055 #include "CoreWidget.hh"
00056 
00057 #include <OpenFlipper/BasePlugin/PluginFunctions.hh>
00058 #include <OpenFlipper/common/GlobalOptions.hh>
00059 
00060 
00061 
00062 //== IMPLEMENTATION ==========================================================
00063 
00064 // Drag evencts view Magic ( header for drag and drop of views )
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   // Get the correct position in the widget
00092   QPoint position = _event->pos();
00093 
00094   // -1 if no object id found for the current picking position
00095   // otherwise the id of the object
00096   int objectId = -1;
00097 
00098   // Do picking in the gl area to find an object
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       // view information entering via drag
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     // Dropped view information
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     // Dropped file information
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 //=============================================================================

acg pic Project OpenFlipper, ©  Computer Graphics Group, RWTH Aachen. Documentation generated using doxygen .