From e1f67bf363b85060490812c9ef82f3a267305450 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20M=C3=B6bius?= Date: Fri, 6 Mar 2009 08:55:46 +0000 Subject: [PATCH] Make Context Menus more usable git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@5213 383ad7c9-94d9-4d36-a494-682f7c89f535 --- widgets/coreWidget/ContextMenu.cc | 193 ++++++++++++++++------------ widgets/coreWidget/CoreWidget.hh | 15 ++- widgets/coreWidget/MenuBar.cc | 13 +- widgets/coreWidget/viewerControl.cc | 32 +++++ 4 files changed, 160 insertions(+), 93 deletions(-) diff --git a/widgets/coreWidget/ContextMenu.cc b/widgets/coreWidget/ContextMenu.cc index a709fd66..f9b6b837 100644 --- a/widgets/coreWidget/ContextMenu.cc +++ b/widgets/coreWidget/ContextMenu.cc @@ -51,81 +51,144 @@ void CoreWidget::slotCustomContextMenu( const QPoint& _point ) { -// QObject* senderPointer = sender(); QPoint popupPosition; QPoint scenePos; -// if ( senderPointer == 0 ) { -// std::cerr << "Error : slotCustomContextMenu directly called! This should only be called by an examiner" << std::endl; -// } else { -// for ( unsigned int i = 0 ; i < OpenFlipper::Options::examinerWidgets(); ++i ) { -// if ( senderPointer == examiner_widgets_[i] ) { - popupPosition = examiner_widgets_[PluginFunctions::activeExaminer()]->glMapToGlobal(_point); - QPointF f = examiner_widgets_[PluginFunctions::activeExaminer()]->mapToScene(QPointF(_point.x(), _point.y())); - scenePos = QPoint (f.x(), f.y()); -// break; -// } -// } - -// } - + // Calculate popup position. Use the position from the viewer which was clicked on. + popupPosition = examiner_widgets_[PluginFunctions::activeExaminer()]->glMapToGlobal(_point); + QPointF f = examiner_widgets_[PluginFunctions::activeExaminer()]->mapToScene(QPointF(_point.x(), _point.y())); + scenePos = QPoint (f.x(), f.y()); + + // Call function to adapt the menu to the currently used contex. updatePopupMenu(scenePos); - // If not initialized, dont show it!! + // If the menu is not correctly initialized, dont try to show it. if ( !contextMenu_->isEmpty () ) contextMenu_->exec( popupPosition ); } -void CoreWidget::updatePopupMenuCoordsysNode(QMenu* _menu , const QPoint& _point) { - +/** \brief Update context Menu when Coordsys node has been clicked on. + * + * This function is called when the coordinate system in a viewer has been clicked on. + * This context menu will show all function relevant for the current view like the + * projection/viewing direction... + * + * @param _menu Pointer to the context Menu + * @param _part id of the coordsys part which has been clicked on. + */ +void CoreWidget::updatePopupMenuCoordsysNode(QMenu* _menu , const int _part) { + std::cerr << "Coordsys part was : " << _part << std::endl; + QAction* typeEntry = new QAction("Viewer Settings",_menu); + _menu->addAction( typeEntry ); + + //==================================================================================================== + + } -void CoreWidget::updatePopupMenu(const QPoint& _point) { +/** \brief Update context Menu when background has been clicked on. + * + * This function is called when the background in a viewer has been clicked on. + * This context menu will show functions which are related to the background of the + * viewer. + * + * @param _menu Pointer to the context Menu + * @param _point position in the viewer where the user clicked. + */ +void CoreWidget::updatePopupMenuBackground(QMenu* _menu , const QPoint& _point) { + QAction* typeEntry = new QAction("Background",_menu); + _menu->addAction( typeEntry ); + + //==================================================================================================== + + QAction* action = _menu->addAction("Set Background Color"); + action->setToolTip("Set the background color for the current viewer"); + action->setStatusTip(tr("Set the background color for the current viewer")); + action->setWhatsThis(tr("Set the background color for the current viewer")); + connect(action, SIGNAL(triggered()), this, SLOT(slotSetLocalBackgroundColor()) ); + + //==================================================================================================== + +} - contextMenu_->clear(); - contextSelectionMenu_->clear(); +/** \brief Update context Menu an object has been clicked on. + * + * This function is called when an object has been clicked on. + * This context menu will show all properties for the given object. + * + * @param _menu Pointer to the context Menu + * @param _objectId Id of the object that has been clicked on. + */ +void CoreWidget::updatePopupMenuObject(QMenu* _menu , const int _objectId ) { + std::cerr << "Object Context Menu for id: " << _objectId << std::endl; +} - QIcon icon; - QAction* typeEntry = new QAction("Viewer",contextMenu_); - contextMenu_->addAction( typeEntry ); - QAction* entrySeparator = contextMenu_->addSeparator( ); +/** \brief check current context and initialize context menu according to this context. + * + * This function is called whenever a context menu for the corewidget is requested. + * It will decide about the current context, collect all menus for plugins and + * construct the final context menu. + */ +void CoreWidget::updatePopupMenu(const QPoint& _point) { - QAction* contextSelectionAction = contextMenu_->addMenu( contextSelectionMenu_ ); + // Clear the complete context menu. + contextMenu_->clear(); + + // Clear the selection context menu part. + contextSelectionMenu_->clear(); - // -1 if no object id found for the current picking position - // otherwise the id of the object + // ============================================================================= + // First do a picking on the current position to check which context we are in. + // ============================================================================= int objectId = -1; + + enum CONTEXTTYPE { + COORDSYSCONTEXT ,BACKGROUNDCONTEXT ,OBJECTCONTEXT + } context = BACKGROUNDCONTEXT; // Do picking in the gl area to find an object unsigned int node_idx, target_idx; ACG::Vec3d hit_point; BaseObjectData* object; + if (examiner_widgets_[PluginFunctions::activeExaminer()]->pick( ACG::SceneGraph::PICK_ANYTHING,_point,node_idx, target_idx, &hit_point ) ) { - if ( PluginFunctions::getPickedObject(node_idx, object) ) + if ( PluginFunctions::getPickedObject(node_idx, object) ) { objectId = object->id(); - - if ( objectId == -1 ) { - std::cerr << "NodeIndex is : " << node_idx << std::endl; - + context = OBJECTCONTEXT; + } else { ACG::SceneGraph::BaseNode* node = ACG::SceneGraph::find_node( PluginFunctions::getSceneGraphRootNode() , node_idx ); - - if ( node == 0 ) - std::cerr << "Node not found" << std::endl; - else { - if ( node->name() == "Core Coordsys Node") { - std::cerr << "Picked Coordsys Node" << std::endl; - typeEntry->setText( "Viewer Settings" ); - - } - std::cerr << "Picked Node with name" << node->name() << std::endl; - std::cerr << "Target index was : " << target_idx << std::endl; - } + if ( node != 0 && ( node->name() == "Core Coordsys Node") ) + context = COORDSYSCONTEXT; } + } + + // ============================================================================= + // Depending on the context create the basic context menu. + // ============================================================================= + + QIcon icon; + QAction* typeEntry = 0; + switch (context) { + case BACKGROUNDCONTEXT: + updatePopupMenuBackground(contextMenu_,_point); + break; + case OBJECTCONTEXT: + typeEntry = new QAction("Object",contextMenu_); + contextMenu_->addAction( typeEntry ); + break; + case COORDSYSCONTEXT: + updatePopupMenuCoordsysNode(contextMenu_,target_idx); + break; } + + // Add the global entry to the context menu. + QAction* entrySeparator = contextMenu_->addSeparator( ); + + QAction* contextSelectionAction = contextMenu_->addMenu( contextSelectionMenu_ ); int topLevelAdded = 0; @@ -234,16 +297,6 @@ void CoreWidget::updatePopupMenu(const QPoint& _point) { //==================================================================================================== - action = functionMenu_->addAction("Set Background Color"); - action->setToolTip("Set the background color for the viewer"); - connect(action, SIGNAL(triggered()), this, SLOT(changeBackgroundColor()) ); - - //==================================================================================================== - - functionMenu_->addSeparator(); - - //==================================================================================================== - action = functionMenu_->addAction("Snapshot"); action->setToolTip("Make a snapshot"); connect(action, SIGNAL(triggered()), this, SLOT( slotSnapshot() ) ); @@ -334,36 +387,6 @@ void CoreWidget::slotSnapshotName() { } -void CoreWidget::changeBackgroundColor(){ - - ACG::Vec4f bc = PluginFunctions::viewerProperties().backgroundColor() * 255.0; - - QColor backCol((int)bc[0], (int)bc[1], (int)bc[2], (int)bc[3]); - QColor c = QColorDialog::getColor(backCol,this); - - if (c != backCol && c.isValid()){ - - if ( shiftPressed_ ){ - //apply to all viewers - for ( uint i = 0 ; i < OpenFlipper::Options::examinerWidgets(); ++i ) { - PluginFunctions::viewerProperties(i).backgroundColor(ACG::Vec4f(((double) c.redF()) , - ((double) c.greenF()) , - ((double) c.blueF()) , - 1.0)); - } - - } else{ - //apply only to active viewer - PluginFunctions::viewerProperties().backgroundColor(ACG::Vec4f(((double) c.redF()) , - ((double) c.greenF()) , - ((double) c.blueF()) , - 1.0)); - } - - OpenFlipper::Options::defaultBackgroundColor( c ); - } -} - void CoreWidget::slotChangeAnimation(bool _animation){ if ( shiftPressed_ ){ for ( uint i = 0 ; i < OpenFlipper::Options::examinerWidgets() ; ++i ) diff --git a/widgets/coreWidget/CoreWidget.hh b/widgets/coreWidget/CoreWidget.hh index 29747289..0f882afe 100644 --- a/widgets/coreWidget/CoreWidget.hh +++ b/widgets/coreWidget/CoreWidget.hh @@ -503,9 +503,6 @@ public: /// called by plugins to add a real context menu depending on DataType void slotAddContextMenu( QMenu* _menu , DataType _dataType ,ContextMenuType type_); - /// change the background color - void changeBackgroundColor(); - /// change the animation setting void slotChangeAnimation(bool _animation); @@ -534,9 +531,9 @@ public: */ void updatePopupMenu(const QPoint& _point); - /** This function creates the PopupMenu Part when clicking on the Coordsys Node - */ - void updatePopupMenuCoordsysNode(QMenu* _menu , const QPoint& _point); + void updatePopupMenuCoordsysNode(QMenu* _menu , const int _part); + void updatePopupMenuObject(QMenu* _menu , const int _objectId ); + void updatePopupMenuBackground(QMenu* _menu , const QPoint& _point); private : /// context Menu for the gl area @@ -716,6 +713,12 @@ public: /// Called when the functionMenu has to be updated void slotFunctionMenuUpdate(); + + /// Set Background Color for all viewers at once. + void slotSetGlobalBackgroundColor(); + + /// Set Background Color for one viewer. + void slotSetLocalBackgroundColor(); private : bool stereoActive_; diff --git a/widgets/coreWidget/MenuBar.cc b/widgets/coreWidget/MenuBar.cc index a0c9c789..560ab3f0 100644 --- a/widgets/coreWidget/MenuBar.cc +++ b/widgets/coreWidget/MenuBar.cc @@ -83,6 +83,17 @@ void CoreWidget::setupMenuBar() viewMenu_ = new QMenu(tr("&View")); menuBar()->addMenu(viewMenu_ ); + + QIcon icon; + QAction* setGlobalBackgroundColor = new QAction(tr("&Background Color"), this);; + setGlobalBackgroundColor->setToolTip(tr("Set Background Color for all viewers")); + setGlobalBackgroundColor->setStatusTip(tr("Set Background Color for all viewers")); + setGlobalBackgroundColor->setWhatsThis("Set Background Color for all viewers"); + icon.addFile(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"bgColor.png"); + setGlobalBackgroundColor->setIcon(icon); + connect(setGlobalBackgroundColor, SIGNAL(triggered()), this, SLOT(slotSetGlobalBackgroundColor())); + viewMenu_->addAction(setGlobalBackgroundColor); + if (examiner_widgets_[0]->getDrawMenu() != NULL) { @@ -96,8 +107,6 @@ void CoreWidget::setupMenuBar() examiner_widgets_[0]->getDrawMenu()->setTearOffEnabled(true); } - QIcon icon; - //Clear all QAction* AC_clear_all = new QAction(tr("&Clear All"), this);; AC_clear_all->setStatusTip(tr("Clear all Objects")); diff --git a/widgets/coreWidget/viewerControl.cc b/widgets/coreWidget/viewerControl.cc index f6a13a6a..9399d559 100644 --- a/widgets/coreWidget/viewerControl.cc +++ b/widgets/coreWidget/viewerControl.cc @@ -131,5 +131,37 @@ void CoreWidget::slotFunctionMenuUpdate() { } +void CoreWidget::slotSetGlobalBackgroundColor() { + ACG::Vec4f bc = PluginFunctions::viewerProperties().backgroundColor() * 255.0; + + QColor backCol((int)bc[0], (int)bc[1], (int)bc[2], (int)bc[3]); + QColor c = QColorDialog::getColor(backCol,this); + + if (c != backCol && c.isValid()) + for ( uint i = 0 ; i < OpenFlipper::Options::examinerWidgets(); ++i ) + PluginFunctions::viewerProperties(i).backgroundColor(ACG::Vec4f(((double) c.redF()) , + ((double) c.greenF()) , + ((double) c.blueF()) , + 1.0)); + + OpenFlipper::Options::defaultBackgroundColor( c ); + +} + +void CoreWidget::slotSetLocalBackgroundColor() { + ACG::Vec4f bc = PluginFunctions::viewerProperties().backgroundColor() * 255.0; + + QColor backCol((int)bc[0], (int)bc[1], (int)bc[2], (int)bc[3]); + QColor c = QColorDialog::getColor(backCol,this); + + if (c != backCol && c.isValid()) + PluginFunctions::viewerProperties().backgroundColor(ACG::Vec4f(((double) c.redF()) , + ((double) c.greenF()) , + ((double) c.blueF()) , + 1.0)); +} + + + //============================================================================= -- GitLab