Commit 239a54c9 authored by Jan Möbius's avatar Jan Möbius
Browse files

Update Drag and drop functions to support multiview

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@4295 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 31cdda26
...@@ -45,6 +45,7 @@ ...@@ -45,6 +45,7 @@
#include "CoreWidget.hh" #include "CoreWidget.hh"
#include <OpenFlipper/BasePlugin/PluginFunctions.hh> #include <OpenFlipper/BasePlugin/PluginFunctions.hh>
#include <OpenFlipper/common/GlobalOptions.hh>
...@@ -57,73 +58,113 @@ static const char VIEW_MAGIC[] = "ACG::QtWidgets::QGLViewerWidget encoded view"; ...@@ -57,73 +58,113 @@ static const char VIEW_MAGIC[] = "ACG::QtWidgets::QGLViewerWidget encoded view";
void CoreWidget::startDrag ( QMouseEvent* _event ) void CoreWidget::startDrag ( QMouseEvent* _event )
{ {
QObject* senderPointer = sender();
int examinerId = -1;
if ( senderPointer != 0 ) {
for ( unsigned int i = 0 ; i < OpenFlipper::Options::examinerWidgets(); ++i ) {
if ( senderPointer == examiner_widgets_[i] ) {
examinerId = i;
break;
}
}
// Get the correct position in the widget }
QPoint position = _event->pos();
// -1 if no object id found for the current picking position if ( examinerId == -1 ) {
// otherwise the id of the object std::cerr << "startDrag in Core called by non examiner, stopping here" << std::endl;
int objectId = -1; return;
}
// Do picking in the gl area to find an object PluginFunctions::setActiveExaminer(examinerId);
unsigned int node_idx, target_idx;
ACG::Vec3d hit_point;
BaseObjectData* object;
if ( PluginFunctions::scenegraph_pick ( ACG::SceneGraph::PICK_ANYTHING,
position,
node_idx,
target_idx,
&hit_point ) ) {
if ( PluginFunctions::get_picked_object ( node_idx, object ) )
objectId = object->id();
}
if ( objectId != -1 ) { // Get the correct position in the widget
std::cerr << "dragEvent Picked Object" << std::endl; QPoint position = _event->pos();
}
// -1 if no object id found for the current picking position
// otherwise the id of the object
int objectId = -1;
QString view; // Do picking in the gl area to find an object
examiner_widget_->encodeView ( view ); unsigned int node_idx, target_idx;
ACG::Vec3d hit_point;
BaseObjectData* object;
if ( PluginFunctions::scenegraph_pick ( ACG::SceneGraph::PICK_ANYTHING,
position,
node_idx,
target_idx,
&hit_point ) ) {
if ( PluginFunctions::get_picked_object ( node_idx, object ) )
objectId = object->id();
}
QDrag * drag = new QDrag ( examiner_widget_ ); if ( objectId != -1 ) {
QMimeData * mime_data = new QMimeData; std::cerr << "dragEvent Picked Object" << std::endl;
}
mime_data->setText ( view );
drag->setMimeData ( mime_data );
drag->start();
}
void CoreWidget::dragEnterEvent ( QDragEnterEvent* _event ) {
if ( _event->mimeData()->hasFormat ( "text/plain" ) ) {
QString view ( _event->mimeData()->text() );
// view information entering via drag QString view;
if ( view.left ( sizeof ( VIEW_MAGIC ) - 1 ) == QString ( VIEW_MAGIC ) ) { examiner_widgets_[PluginFunctions::activeExaminer()]->encodeView ( view );
_event->acceptProposedAction();
}
} QDrag * drag = new QDrag ( examiner_widgets_[PluginFunctions::activeExaminer()] );
} QMimeData * mime_data = new QMimeData;
mime_data->setText ( view );
drag->setMimeData ( mime_data );
drag->start();
void CoreWidget::dropEvent ( QDropEvent* _event ) { }
void CoreWidget::dragEnterEvent ( QDragEnterEvent* _event ) {
if ( _event->mimeData()->hasFormat ( "text/plain" ) ) {
QString view ( _event->mimeData()->text() );
// view information entering via drag
if ( view.left ( sizeof ( VIEW_MAGIC ) - 1 ) == QString ( VIEW_MAGIC ) ) {
_event->acceptProposedAction();
}
if ( _event->mimeData()->hasFormat ( "text/plain" ) ) { }
QString view ( _event->mimeData()->text() ); }
// Dropped view information void CoreWidget::dropEvent ( QDropEvent* _event ) {
if ( view.left ( sizeof ( VIEW_MAGIC ) - 1 ) == QString ( VIEW_MAGIC ) ) { QObject* senderPointer = sender();
examiner_widget_->decodeView ( view ); int examinerId = -1;
_event->acceptProposedAction();
return;
}
if ( senderPointer != 0 ) {
for ( unsigned int i = 0 ; i < OpenFlipper::Options::examinerWidgets(); ++i ) {
if ( senderPointer == examiner_widgets_[i] ) {
examinerId = i;
break;
} }
}
}
if ( examinerId == -1 ) {
std::cerr << "dropEvent in Core called by non examiner, stopping here" << std::endl;
return;
}
PluginFunctions::setActiveExaminer(examinerId);
if ( _event->mimeData()->hasFormat ( "text/plain" ) ) {
QString view ( _event->mimeData()->text() );
// Dropped view information
if ( view.left ( sizeof ( VIEW_MAGIC ) - 1 ) == QString ( VIEW_MAGIC ) ) {
examiner_widgets_[PluginFunctions::activeExaminer()]->decodeView ( view );
_event->acceptProposedAction();
return;
}
}
} }
//============================================================================= //=============================================================================
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment