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,82 +51,145 @@
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] ) {
// 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());
// break;
// }
// }
// }
// 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 );
contextMenu_->clear();
contextSelectionMenu_->clear();
//====================================================================================================
QIcon icon;
QAction* typeEntry = new QAction("Viewer",contextMenu_);
contextMenu_->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()) );
QAction* entrySeparator = contextMenu_->addSeparator( );
//====================================================================================================
}
QAction* contextSelectionAction = contextMenu_->addMenu( contextSelectionMenu_ );
/** \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;
}
// -1 if no object id found for the current picking position
// otherwise the id of the object
/** \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) {
// Clear the complete context menu.
contextMenu_->clear();
// Clear the selection context menu part.
contextSelectionMenu_->clear();
// =============================================================================
// 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;
if ( objectId != -1) {
......@@ -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 )
......
......@@ -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
......@@ -717,6 +714,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_;
......
......@@ -84,6 +84,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) {
examiner_widgets_[0]->getDrawMenu()->setTitle("&DrawModes");
......@@ -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"));
......
......@@ -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