Developer Documentation
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
45
46//=============================================================================
47//
48// CLASS CoreWidget - IMPLEMENTATION
49//
50//=============================================================================
51
52
53//== INCLUDES =================================================================
54
55// -------------------- mview
56#include "CoreWidget.hh"
57
58
59
60//== IMPLEMENTATION ==========================================================
61
62// Drag evencts view Magic ( header for drag and drop of views )
63static const char VIEW_MAGIC[] = "ACG::QtWidgets::QGLViewerWidget encoded view";
64
65//=============================================================================
66
67void CoreWidget::startDrag ( QMouseEvent* _event )
68{
69 QObject* senderPointer = sender();
70 int examinerId = -1;
71
72 if ( senderPointer != 0 ) {
73 for ( unsigned int i = 0 ; i < OpenFlipper::Options::examinerWidgets(); ++i ) {
74 if ( senderPointer == examiner_widgets_[i] ) {
75 examinerId = i;
76 break;
77 }
78 }
79
80 }
81
82 if ( examinerId == -1 ) {
83 emit log(LOGERR , tr("startDrag in Core called by non examiner, stopping here"));
84 return;
85 }
86
88
89 // Get the correct position in the widget
90 QPoint position = _event->pos();
91
92 // -1 if no object id found for the current picking position
93 // otherwise the id of the object
94 int objectId = -1;
95
96 // Do picking in the gl area to find an object
97 size_t node_idx, target_idx;
98 ACG::Vec3d hit_point;
99 BaseObjectData* object;
101 position,
102 node_idx,
103 target_idx,
104 &hit_point ) ) {
105 if ( PluginFunctions::getPickedObject ( node_idx, object ) )
106 objectId = object->id();
107 }
108
109 if ( objectId != -1 ) {
110 emit log(LOGERR , tr("dragEvent Picked Object"));
111 }
112
113
114
115
116 QString view;
118
119 QDrag * drag = new QDrag ( this );
120 QMimeData * mime_data = new QMimeData;
121
122 mime_data->setText ( view );
123 drag->setMimeData ( mime_data );
124 drag->exec();
125
126}
127
128void CoreWidget::dragEnterEvent ( QDragEnterEvent* _event ) {
129
130 if ( _event->mimeData()->hasFormat ( "text/plain" ) ) {
131 QString view ( _event->mimeData()->text() );
132
133 // view information entering via drag
134 if ( view.left ( sizeof ( VIEW_MAGIC ) - 1 ) == QString ( VIEW_MAGIC ) ) {
135 _event->acceptProposedAction();
136 }
137
138 }
139
140}
141
142void CoreWidget::dropEvent ( QDropEvent* _event ) {
143 QObject* senderPointer = sender();
144 int examinerId = -1;
145
146 if ( senderPointer != 0 ) {
147 for ( unsigned int i = 0 ; i < OpenFlipper::Options::examinerWidgets(); ++i ) {
148 if ( senderPointer == examiner_widgets_[i] ) {
149 examinerId = i;
150 break;
151 }
152 }
153 }
154
155 if ( examinerId == -1 ) {
156 emit log(LOGERR , tr("startDrag in Core called by non examiner, stopping here"));
157 return;
158 }
159
161
162 if ( _event->mimeData()->hasUrls() ) {
163 QList<QUrl> urls = _event->mimeData()->urls();
164 for ( int j = 0 ; j < urls.size() ; ++j ) {
165 emit log(LOGWARN , tr("Dropped URL: %1").arg(urls[j].toLocalFile()));
166 emit dragOpenFile(urls[j].toLocalFile());
167 }
168
169 return;
170 }
171
172 if ( _event->mimeData()->hasFormat ( "text/plain" ) ) {
173
174 QString view ( _event->mimeData()->text() );
175
176 // Dropped view information
177 if ( view.left ( sizeof ( VIEW_MAGIC ) - 1 ) == QString ( VIEW_MAGIC ) ) {
179 _event->acceptProposedAction();
180 return;
181 }
182
184 // Dropped file information
185 if ( view.left ( 7 ) == QString("file://") ) {
186 _event->acceptProposedAction();
187 emit dragOpenFile(view.remove(0,7));
188
189 return;
190 }
191
192 emit log(LOGERR , tr("Unknown drop event! Unable to handle the dropped data! Received data: %1").arg(view));
193 }
194
195 emit log(LOGERR , tr("Unknown drop event!"));
196
197
198}
199
200//=============================================================================
@ LOGERR
@ LOGWARN
int id() const
Definition: BaseObject.cc:188
std::vector< glViewer * > examiner_widgets_
Examiner Widget.
Definition: CoreWidget.hh:684
void dragEnterEvent(QDragEnterEvent *_event)
Definition: dragAndDrop.cc:128
void dropEvent(QDropEvent *_event)
Definition: dragAndDrop.cc:142
void dragOpenFile(QString _filename)
void startDrag(QMouseEvent *_event)
Definition: dragAndDrop.cc:67
@ PICK_ANYTHING
pick any of the prior targets (should be implemented for all nodes)
Definition: PickTarget.hh:84
bool getPickedObject(const size_t _node_idx, BaseObjectData *&_object)
Get the picked mesh.
bool scenegraphPick(ACG::SceneGraph::PickTarget _pickTarget, const QPoint &_mousePos, size_t &_nodeIdx, size_t &_targetIdx, ACG::Vec3d *_hitPointPtr=0)
Execute picking operation on scenegraph.
void setActiveExaminer(const unsigned int _id)
Set the active id of the examiner which got the last mouse events.
unsigned int activeExaminer()
Get the id of the examiner which got the last mouse events.