Developer Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
dragAndDrop.cc
1 /*===========================================================================*\
2 * *
3 * OpenFlipper *
4  * Copyright (c) 2001-2015, RWTH-Aachen University *
5  * Department of Computer Graphics and Multimedia *
6  * All rights reserved. *
7  * www.openflipper.org *
8  * *
9  *---------------------------------------------------------------------------*
10  * This file is part of OpenFlipper. *
11  *---------------------------------------------------------------------------*
12  * *
13  * Redistribution and use in source and binary forms, with or without *
14  * modification, are permitted provided that the following conditions *
15  * are met: *
16  * *
17  * 1. Redistributions of source code must retain the above copyright notice, *
18  * this list of conditions and the following disclaimer. *
19  * *
20  * 2. Redistributions in binary form must reproduce the above copyright *
21  * notice, this list of conditions and the following disclaimer in the *
22  * documentation and/or other materials provided with the distribution. *
23  * *
24  * 3. Neither the name of the copyright holder nor the names of its *
25  * contributors may be used to endorse or promote products derived from *
26  * this software without specific prior written permission. *
27  * *
28  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
29  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
30  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
31  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
32  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
33  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
34  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
35  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
36  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
37  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
38  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
39 * *
40 \*===========================================================================*/
41 
42 /*===========================================================================*\
43 * *
44 * $Revision$ *
45 * $LastChangedBy$ *
46 * $Date$ *
47 * *
48 \*===========================================================================*/
49 
50 
51 
52 //=============================================================================
53 //
54 // CLASS CoreWidget - IMPLEMENTATION
55 //
56 //=============================================================================
57 
58 
59 //== INCLUDES =================================================================
60 
61 // -------------------- mview
62 #include "CoreWidget.hh"
63 
64 
65 
66 //== IMPLEMENTATION ==========================================================
67 
68 // Drag evencts view Magic ( header for drag and drop of views )
69 static const char VIEW_MAGIC[] = "ACG::QtWidgets::QGLViewerWidget encoded view";
70 
71 //=============================================================================
72 
73 void CoreWidget::startDrag ( QMouseEvent* _event )
74 {
75  QObject* senderPointer = sender();
76  int examinerId = -1;
77 
78  if ( senderPointer != 0 ) {
79  for ( unsigned int i = 0 ; i < OpenFlipper::Options::examinerWidgets(); ++i ) {
80  if ( senderPointer == examiner_widgets_[i] ) {
81  examinerId = i;
82  break;
83  }
84  }
85 
86  }
87 
88  if ( examinerId == -1 ) {
89  emit log(LOGERR , tr("startDrag in Core called by non examiner, stopping here"));
90  return;
91  }
92 
94 
95  // Get the correct position in the widget
96  QPoint position = _event->pos();
97 
98  // -1 if no object id found for the current picking position
99  // otherwise the id of the object
100  int objectId = -1;
101 
102  // Do picking in the gl area to find an object
103  unsigned int node_idx, target_idx;
104  ACG::Vec3d hit_point;
105  BaseObjectData* object;
107  position,
108  node_idx,
109  target_idx,
110  &hit_point ) ) {
111  if ( PluginFunctions::getPickedObject ( node_idx, object ) )
112  objectId = object->id();
113  }
114 
115  if ( objectId != -1 ) {
116  emit log(LOGERR , tr("dragEvent Picked Object"));
117  }
118 
119 
120 
121 
122  QString view;
123  examiner_widgets_[PluginFunctions::activeExaminer()]->encodeView ( view );
124 
125  QDrag * drag = new QDrag ( this );
126  QMimeData * mime_data = new QMimeData;
127 
128  mime_data->setText ( view );
129  drag->setMimeData ( mime_data );
130  drag->start();
131 
132 }
133 
134 void CoreWidget::dragEnterEvent ( QDragEnterEvent* _event ) {
135 
136  if ( _event->mimeData()->hasFormat ( "text/plain" ) ) {
137  QString view ( _event->mimeData()->text() );
138 
139  // view information entering via drag
140  if ( view.left ( sizeof ( VIEW_MAGIC ) - 1 ) == QString ( VIEW_MAGIC ) ) {
141  _event->acceptProposedAction();
142  }
143 
144  }
145 
146 }
147 
148 void CoreWidget::dropEvent ( QDropEvent* _event ) {
149  QObject* senderPointer = sender();
150  int examinerId = -1;
151 
152  if ( senderPointer != 0 ) {
153  for ( unsigned int i = 0 ; i < OpenFlipper::Options::examinerWidgets(); ++i ) {
154  if ( senderPointer == examiner_widgets_[i] ) {
155  examinerId = i;
156  break;
157  }
158  }
159  }
160 
161  if ( examinerId == -1 ) {
162  emit log(LOGERR , tr("startDrag in Core called by non examiner, stopping here"));
163  return;
164  }
165 
167 
168  if ( _event->mimeData()->hasUrls() ) {
169  QList<QUrl> urls = _event->mimeData()->urls();
170  for ( int j = 0 ; j < urls.size() ; ++j ) {
171  emit log(LOGWARN , tr("Dropped URL: %1").arg(urls[j].toLocalFile()));
172  emit dragOpenFile(urls[j].toLocalFile());
173  }
174 
175  return;
176  }
177 
178  if ( _event->mimeData()->hasFormat ( "text/plain" ) ) {
179 
180  QString view ( _event->mimeData()->text() );
181 
182  // Dropped view information
183  if ( view.left ( sizeof ( VIEW_MAGIC ) - 1 ) == QString ( VIEW_MAGIC ) ) {
184  examiner_widgets_[PluginFunctions::activeExaminer()]->decodeView ( view );
185  _event->acceptProposedAction();
186  return;
187  }
188 
190  // Dropped file information
191  if ( view.left ( 7 ) == QString("file://") ) {
192  _event->acceptProposedAction();
193  emit dragOpenFile(view.remove(0,7));
194 
195  return;
196  }
197 
198  emit log(LOGERR , tr("Unknown drop event! Unable to handle the dropped data! Received data: %1").arg(view));
199  }
200 
201  emit log(LOGERR , tr("Unknown drop event!"));
202 
203 
204 }
205 
206 //=============================================================================
void dropEvent(QDropEvent *_event)
Definition: dragAndDrop.cc:148
pick any of the prior targets (should be implemented for all nodes)
Definition: BaseNode.hh:110
void dragEnterEvent(QDragEnterEvent *_event)
Definition: dragAndDrop.cc:134
void setActiveExaminer(const unsigned int _id)
Set the active id of the examiner which got the last mouse events.
void dragOpenFile(QString _filename)
void log(Logtype _type, QString _message)
Logg with OUT,WARN or ERR as type.
void startDrag(QMouseEvent *_event)
Definition: dragAndDrop.cc:73
bool scenegraphPick(ACG::SceneGraph::PickTarget _pickTarget, const QPoint &_mousePos, unsigned int &_nodeIdx, unsigned int &_targetIdx, ACG::Vec3d *_hitPointPtr=0)
Execute picking operation on scenegraph.
unsigned int activeExaminer()
Get the id of the examiner which got the last mouse events.
bool getPickedObject(const unsigned int _node_idx, BaseObjectData *&_object)
Get the picked mesh.
int id() const
Definition: BaseObject.cc:201
std::vector< glViewer * > examiner_widgets_
Examiner Widget.
Definition: CoreWidget.hh:669