Commit e1f67bf3 authored by Jan Möbius's avatar Jan Möbius

Make Context Menus more usable

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@5213 383ad7c9-94d9-4d36-a494-682f7c89f535
parent da41025c
...@@ -51,81 +51,144 @@ ...@@ -51,81 +51,144 @@
void CoreWidget::slotCustomContextMenu( const QPoint& _point ) { void CoreWidget::slotCustomContextMenu( const QPoint& _point ) {
// QObject* senderPointer = sender();
QPoint popupPosition; QPoint popupPosition;
QPoint scenePos; QPoint scenePos;
// if ( senderPointer == 0 ) { // Calculate popup position. Use the position from the viewer which was clicked on.
// std::cerr << "Error : slotCustomContextMenu directly called! This should only be called by an examiner" << std::endl; popupPosition = examiner_widgets_[PluginFunctions::activeExaminer()]->glMapToGlobal(_point);
// } else { QPointF f = examiner_widgets_[PluginFunctions::activeExaminer()]->mapToScene(QPointF(_point.x(), _point.y()));
// for ( unsigned int i = 0 ; i < OpenFlipper::Options::examinerWidgets(); ++i ) { scenePos = QPoint (f.x(), f.y());
// if ( senderPointer == examiner_widgets_[i] ) {
popupPosition = examiner_widgets_[PluginFunctions::activeExaminer()]->glMapToGlobal(_point); // Call function to adapt the menu to the currently used contex.
QPointF f = examiner_widgets_[PluginFunctions::activeExaminer()]->mapToScene(QPointF(_point.x(), _point.y()));
scenePos = QPoint (f.x(), f.y());
// break;
// }
// }
// }
updatePopupMenu(scenePos); updatePopupMenu(scenePos);
// If not initialized, dont show it!! // If the menu is not correctly initialized, dont try to show it.
if ( !contextMenu_->isEmpty () ) if ( !contextMenu_->isEmpty () )
contextMenu_->exec( popupPosition ); 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(); /** \brief Update context Menu an object has been clicked on.
contextSelectionMenu_->clear(); *
* 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; int objectId = -1;
enum CONTEXTTYPE {
COORDSYSCONTEXT ,BACKGROUNDCONTEXT ,OBJECTCONTEXT
} context = BACKGROUNDCONTEXT;
// Do picking in the gl area to find an object // Do picking in the gl area to find an object
unsigned int node_idx, target_idx; unsigned int node_idx, target_idx;
ACG::Vec3d hit_point; ACG::Vec3d hit_point;
BaseObjectData* object; BaseObjectData* object;
if (examiner_widgets_[PluginFunctions::activeExaminer()]->pick( ACG::SceneGraph::PICK_ANYTHING,_point,node_idx, target_idx, &hit_point ) ) { 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(); objectId = object->id();
context = OBJECTCONTEXT;
if ( objectId == -1 ) { } else {
std::cerr << "NodeIndex is : " << node_idx << std::endl;
ACG::SceneGraph::BaseNode* node = ACG::SceneGraph::find_node( PluginFunctions::getSceneGraphRootNode() , node_idx ); ACG::SceneGraph::BaseNode* node = ACG::SceneGraph::find_node( PluginFunctions::getSceneGraphRootNode() , node_idx );
if ( node != 0 && ( node->name() == "Core Coordsys Node") )
if ( node == 0 ) context = COORDSYSCONTEXT;
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;
}
} }
}
// =============================================================================
// 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; int topLevelAdded = 0;
...@@ -234,16 +297,6 @@ void CoreWidget::updatePopupMenu(const QPoint& _point) { ...@@ -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 = functionMenu_->addAction("Snapshot");
action->setToolTip("Make a snapshot"); action->setToolTip("Make a snapshot");
connect(action, SIGNAL(triggered()), this, SLOT( slotSnapshot() ) ); connect(action, SIGNAL(triggered()), this, SLOT( slotSnapshot() ) );
...@@ -334,36 +387,6 @@ void CoreWidget::slotSnapshotName() { ...@@ -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){ void CoreWidget::slotChangeAnimation(bool _animation){
if ( shiftPressed_ ){ if ( shiftPressed_ ){
for ( uint i = 0 ; i < OpenFlipper::Options::examinerWidgets() ; ++i ) for ( uint i = 0 ; i < OpenFlipper::Options::examinerWidgets() ; ++i )
......
...@@ -503,9 +503,6 @@ public: ...@@ -503,9 +503,6 @@ public:
/// called by plugins to add a real context menu depending on DataType /// called by plugins to add a real context menu depending on DataType
void slotAddContextMenu( QMenu* _menu , DataType _dataType ,ContextMenuType type_); void slotAddContextMenu( QMenu* _menu , DataType _dataType ,ContextMenuType type_);
/// change the background color
void changeBackgroundColor();
/// change the animation setting /// change the animation setting
void slotChangeAnimation(bool _animation); void slotChangeAnimation(bool _animation);
...@@ -534,9 +531,9 @@ public: ...@@ -534,9 +531,9 @@ public:
*/ */
void updatePopupMenu(const QPoint& _point); void updatePopupMenu(const QPoint& _point);
/** This function creates the PopupMenu Part when clicking on the Coordsys Node void updatePopupMenuCoordsysNode(QMenu* _menu , const int _part);
*/ void updatePopupMenuObject(QMenu* _menu , const int _objectId );
void updatePopupMenuCoordsysNode(QMenu* _menu , const QPoint& _point); void updatePopupMenuBackground(QMenu* _menu , const QPoint& _point);
private : private :
/// context Menu for the gl area /// context Menu for the gl area
...@@ -716,6 +713,12 @@ public: ...@@ -716,6 +713,12 @@ public:
/// Called when the functionMenu has to be updated /// Called when the functionMenu has to be updated
void slotFunctionMenuUpdate(); void slotFunctionMenuUpdate();
/// Set Background Color for all viewers at once.
void slotSetGlobalBackgroundColor();
/// Set Background Color for one viewer.
void slotSetLocalBackgroundColor();
private : private :
bool stereoActive_; bool stereoActive_;
......
...@@ -83,6 +83,17 @@ void CoreWidget::setupMenuBar() ...@@ -83,6 +83,17 @@ void CoreWidget::setupMenuBar()
viewMenu_ = new QMenu(tr("&View")); viewMenu_ = new QMenu(tr("&View"));
menuBar()->addMenu(viewMenu_ ); 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) { if (examiner_widgets_[0]->getDrawMenu() != NULL) {
...@@ -96,8 +107,6 @@ void CoreWidget::setupMenuBar() ...@@ -96,8 +107,6 @@ void CoreWidget::setupMenuBar()
examiner_widgets_[0]->getDrawMenu()->setTearOffEnabled(true); examiner_widgets_[0]->getDrawMenu()->setTearOffEnabled(true);
} }
QIcon icon;
//Clear all //Clear all
QAction* AC_clear_all = new QAction(tr("&Clear All"), this);; QAction* AC_clear_all = new QAction(tr("&Clear All"), this);;
AC_clear_all->setStatusTip(tr("Clear all Objects")); AC_clear_all->setStatusTip(tr("Clear all Objects"));
......
...@@ -131,5 +131,37 @@ void CoreWidget::slotFunctionMenuUpdate() { ...@@ -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));
}
//============================================================================= //=============================================================================
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