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

Create a global drawMode Menu

Remove DrawMode Menu handling from glViewer

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@5228 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 337d4d13
...@@ -57,6 +57,9 @@ void Core::resetScenegraph() { ...@@ -57,6 +57,9 @@ void Core::resetScenegraph() {
} }
} }
// Update the draw Modes Menu
coreWidget_->slotUpdateGlobalDrawMenu();
} }
//======================================================================================== //========================================================================================
......
...@@ -351,18 +351,6 @@ void CoreWidget::updatePopupMenu(const QPoint& _point) { ...@@ -351,18 +351,6 @@ void CoreWidget::updatePopupMenu(const QPoint& _point) {
} }
contextMenu_->addMenu(functionMenu_ ); contextMenu_->addMenu(functionMenu_ );
if ( ( examiner_widgets_[PluginFunctions::activeExaminer()]->getDrawMenu() != NULL ) && OpenFlipper::Options::drawModesInContextMenu() ) {
examiner_widgets_[PluginFunctions::activeExaminer()]->getDrawMenu()->setTitle("&DrawModes");
QAction* drawMenuAction = contextMenu_->addMenu(examiner_widgets_[PluginFunctions::activeExaminer()]->getDrawMenu() );
QIcon icon;
icon.addFile(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"drawModes.png");
drawMenuAction->setIcon(icon);
examiner_widgets_[PluginFunctions::activeExaminer()]->getDrawMenu()->setTearOffEnabled(true);
}
} }
void CoreWidget::slotSnapshotName() { void CoreWidget::slotSnapshotName() {
......
...@@ -69,22 +69,26 @@ CoreWidget( QVector<ViewMode*>& _viewModes, ...@@ -69,22 +69,26 @@ CoreWidget( QVector<ViewMode*>& _viewModes,
shiftPressed_(false), shiftPressed_(false),
viewModes_(_viewModes), viewModes_(_viewModes),
viewModeButton_(0), viewModeButton_(0),
viewModeMenu_(0), viewModeMenu_(0),
viewGroup_(0),
splitter_(0), splitter_(0),
logWidget_(0), logWidget_(0),
recentFilesMenu_(0), recentFilesMenu_(0),
helpMenu_(0), helpMenu_(0),
sceneGraphDialog_(0), sceneGraphDialog_(0),
fileMenu_(0), fileMenu_(0),
viewMenu_(0), viewMenu_(0),
fileMenuEnd_(0), fileMenuEnd_(0),
stereoButton_(0), stereoButton_(0),
projectionButton_(0), projectionButton_(0),
moveButton_(0), moveButton_(0),
lightButton_(0), lightButton_(0),
pickButton_(0), pickButton_(0),
questionButton_(0), questionButton_(0),
globalDrawMenu_(0),
drawGroup_(0),
viewGroup_(0),
activeDrawModes_(0),
availableDrawModes_(0),
contextMenu_(0), contextMenu_(0),
functionMenu_(0), functionMenu_(0),
contextSelectionMenu_(0), contextSelectionMenu_(0),
......
...@@ -270,7 +270,14 @@ public: ...@@ -270,7 +270,14 @@ public:
/// Setup the main menubar /// Setup the main menubar
void setupMenuBar(); void setupMenuBar();
/** @} */
//===========================================================================
/** @name Recent File Menu handling
* @{ */
//===========================================================================
/// Add a recent file and update menu /// Add a recent file and update menu
void addRecent(QString _filename, DataType _type); void addRecent(QString _filename, DataType _type);
...@@ -329,9 +336,6 @@ public: ...@@ -329,9 +336,6 @@ public:
/// Submenu holding all ViewMode actions /// Submenu holding all ViewMode actions
QMenu* viewModeMenu_; QMenu* viewModeMenu_;
/// Group for all menu items
QActionGroup* viewGroup_;
public slots: public slots:
/// init ViewModes that were loaded via ini-file /// init ViewModes that were loaded via ini-file
...@@ -486,9 +490,38 @@ public: ...@@ -486,9 +490,38 @@ public:
/** @} */ /** @} */
//=========================================================================== //===========================================================================
/** @name Context Menu /** @name View Menu
* @{ */ * @{ */
//=========================================================================== //===========================================================================
public slots:
/// Setup and update the global draw menu
void slotUpdateGlobalDrawMenu();
private slots:
/// Called when the global drawMode is selected
void slotGlobalDrawMenu(QAction * _action);
private:
/// This variable holds the global draw menu
QMenu* globalDrawMenu_;
QActionGroup * drawGroup_;
/// Group for all menu items
QActionGroup* viewGroup_;
int activeDrawModes_;
int availableDrawModes_;
/** @} */
//===========================================================================
/** @name Context Menu
* @{ */
//===========================================================================
signals : signals :
// tells the plugins to update their context menu // tells the plugins to update their context menu
void updateContextMenu(int) ; void updateContextMenu(int) ;
......
...@@ -44,6 +44,7 @@ ...@@ -44,6 +44,7 @@
// -------------------- mview // -------------------- mview
#include "CoreWidget.hh" #include "CoreWidget.hh"
#include <OpenFlipper/common/GlobalOptions.hh> #include <OpenFlipper/common/GlobalOptions.hh>
#include <OpenFlipper/BasePlugin/PluginFunctions.hh>
//== IMPLEMENTATION ========================================================== //== IMPLEMENTATION ==========================================================
...@@ -94,19 +95,8 @@ void CoreWidget::setupMenuBar() ...@@ -94,19 +95,8 @@ void CoreWidget::setupMenuBar()
connect(setGlobalBackgroundColor, SIGNAL(triggered()), this, SLOT(slotSetGlobalBackgroundColor())); connect(setGlobalBackgroundColor, SIGNAL(triggered()), this, SLOT(slotSetGlobalBackgroundColor()));
viewMenu_->addAction(setGlobalBackgroundColor); viewMenu_->addAction(setGlobalBackgroundColor);
slotUpdateGlobalDrawMenu();
if (examiner_widgets_[0]->getDrawMenu() != NULL) {
examiner_widgets_[0]->getDrawMenu()->setTitle("&DrawModes");
QAction* drawMenuAction = viewMenu_->addMenu(examiner_widgets_[0]->getDrawMenu() );
QIcon icon;
icon.addFile(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"drawModes.png");
drawMenuAction->setIcon(icon);
examiner_widgets_[0]->getDrawMenu()->setTearOffEnabled(true);
}
//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"));
...@@ -277,4 +267,92 @@ void CoreWidget::setupMenuBar() ...@@ -277,4 +267,92 @@ void CoreWidget::setupMenuBar()
} }
void CoreWidget::slotUpdateGlobalDrawMenu() {
if ( drawGroup_ ) {
disconnect( drawGroup_ , SIGNAL( triggered( QAction * ) ),
this , SLOT( slotGlobalDrawMenu( QAction * ) ) );
delete( drawGroup_ );
drawGroup_ = 0;
}
// Recreate drawGroup
drawGroup_ = new QActionGroup( this );
drawGroup_->setExclusive( false );
connect( drawGroup_ , SIGNAL( triggered( QAction * ) ),
this , SLOT( slotGlobalDrawMenu( QAction * ) ) );
if ( !globalDrawMenu_ ) {
QIcon icon;
icon.addFile(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"drawModes.png");
globalDrawMenu_ = new QMenu("Set Global DrawMode");
globalDrawMenu_->setTearOffEnabled(true);
globalDrawMenu_->setIcon(icon);
connect(globalDrawMenu_,SIGNAL(aboutToShow () ) , this, SLOT(slotUpdateGlobalDrawMenu() ) );
viewMenu_->addMenu(globalDrawMenu_);
}
// Collect available draw Modes
ACG::SceneGraph::CollectDrawModesAction actionAvailable;
ACG::SceneGraph::traverse( PluginFunctions::getRootNode() , actionAvailable);
availableDrawModes_ = actionAvailable.drawModes();
// Get currently active drawModes (first viewer only )
// TODO: create combination from all viewers!
activeDrawModes_ = INT_MAX;
for ( int i = 0 ; i < PluginFunctions::viewers(); ++i )
activeDrawModes_ &= PluginFunctions::drawMode(i);
// Convert to ids
std::vector< unsigned int > availDrawModeIds;
availDrawModeIds = ACG::SceneGraph::DrawModes::getDrawModeIDs( availableDrawModes_ );
globalDrawMenu_->clear();
for ( unsigned int i = 0; i < availDrawModeIds.size(); ++i )
{
unsigned int id = availDrawModeIds[i];
std::string descr = ACG::SceneGraph::DrawModes::description( id );
QAction * action = new QAction( descr.c_str(), drawGroup_ );
action->setCheckable( true );
action->setChecked( ACG::SceneGraph::DrawModes::containsId( activeDrawModes_, id ) );
}
globalDrawMenu_->addActions( drawGroup_->actions() );
}
void CoreWidget::slotGlobalDrawMenu(QAction * _action) {
//======================================================================================
// Get the mode toggled
//======================================================================================
unsigned int mode = 0;
std::vector< unsigned int > availDrawModeIds;
availDrawModeIds = ACG::SceneGraph::DrawModes::getDrawModeIDs( availableDrawModes_ );
for ( unsigned int i = 0; i < availDrawModeIds.size(); ++i )
{
QString descr = QString( ACG::SceneGraph::DrawModes::description( availDrawModeIds[i] ).c_str() );
if ( descr == _action->text() ) {
mode = availDrawModeIds[i];
break;
}
}
if ( qApp->keyboardModifiers() & Qt::ShiftModifier )
activeDrawModes_ = ( activeDrawModes_ ^ mode);
else
activeDrawModes_ = mode ;
PluginFunctions::setDrawMode( activeDrawModes_ );
slotUpdateGlobalDrawMenu();
}
//============================================================================= //=============================================================================
...@@ -151,7 +151,6 @@ glViewer::glViewer( QtGLGraphicsScene* _scene, ...@@ -151,7 +151,6 @@ glViewer::glViewer( QtGLGraphicsScene* _scene,
sceneGraphRoot_ = 0; sceneGraphRoot_ = 0;
curDrawMode_ = ACG::SceneGraph::DrawModes::NONE; curDrawMode_ = ACG::SceneGraph::DrawModes::NONE;
availDrawModes_ = ACG::SceneGraph::DrawModes::NONE;
normalsMode_ = DONT_TOUCH_NORMALS; normalsMode_ = DONT_TOUCH_NORMALS;
projectionMode_ = PERSPECTIVE_PROJECTION; projectionMode_ = PERSPECTIVE_PROJECTION;
...@@ -166,8 +165,6 @@ glViewer::glViewer( QtGLGraphicsScene* _scene, ...@@ -166,8 +165,6 @@ glViewer::glViewer( QtGLGraphicsScene* _scene,
pickMenu_ = 0; pickMenu_ = 0;
drawMenu_ = 0;
// Note: we start locked (initialization of updateLocked_) // Note: we start locked (initialization of updateLocked_)
// will be unlocked in initializeGL() // will be unlocked in initializeGL()
...@@ -251,12 +248,6 @@ void glViewer::sceneGraph(ACG::SceneGraph::BaseNode* _root) ...@@ -251,12 +248,6 @@ void glViewer::sceneGraph(ACG::SceneGraph::BaseNode* _root)
if (sceneGraphRoot_ ) if (sceneGraphRoot_ )
{ {
// get draw modes
ACG::SceneGraph::CollectDrawModesAction action;
ACG::SceneGraph::traverse(sceneGraphRoot_, action);
availDrawModes_ = action.drawModes();
updatePopupMenu();
// get scene size // get scene size
ACG::SceneGraph::BoundingBoxAction act; ACG::SceneGraph::BoundingBoxAction act;
ACG::SceneGraph::traverse(sceneGraphRoot_, act); ACG::SceneGraph::traverse(sceneGraphRoot_, act);
...@@ -1209,7 +1200,6 @@ void ...@@ -1209,7 +1200,6 @@ void
glViewer::createWidgets(QStatusBar* _sb) glViewer::createWidgets(QStatusBar* _sb)
{ {
setStatusBar(_sb); setStatusBar(_sb);
drawMenu_=0;
pickMenu_=0; pickMenu_=0;
// Construct GL context & widget // Construct GL context & widget
...@@ -1259,68 +1249,11 @@ glViewer::createWidgets(QStatusBar* _sb) ...@@ -1259,68 +1249,11 @@ glViewer::createWidgets(QStatusBar* _sb)
setLayout(glBaseLayout_); setLayout(glBaseLayout_);
} }
//-----------------------------------------------------------------------------
void glViewer::updatePopupMenu()
{
//
// Draw mode menu
//
if ( ! drawMenu_ )
{
drawMenu_ = new QMenu( scene()->views().first() );
connect( drawMenu_, SIGNAL( aboutToHide() ),
this, SLOT( hidePopupMenus() ) );
}
QActionGroup * drawGroup = new QActionGroup( this );
drawGroup->setExclusive( false );
connect( drawGroup, SIGNAL( triggered( QAction * ) ),
this, SLOT( actionDrawMenu( QAction * ) ) );
drawMenuActions_.clear();
std::vector< unsigned int > draw_mode_id;
draw_mode_id = ACG::SceneGraph::DrawModes::getDrawModeIDs( availDrawModes_ );
for ( unsigned int i = 0; i < draw_mode_id.size(); ++i )
{
unsigned int id = draw_mode_id[i];
std::string descr = ACG::SceneGraph::DrawModes::description( id );
QAction * action = new QAction( descr.c_str(), drawGroup );
action->setData( QVariant( id ) );
action->setCheckable( true );
action->setChecked( ACG::SceneGraph::DrawModes::containsId( curDrawMode_, id ) );
drawMenuActions_.push_back( action );
}
drawMenu_->clear();
drawMenu_->addActions( drawGroup->actions() );
}
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void glViewer::hidePopupMenus() void glViewer::hidePopupMenus()
{ {
if ( drawMenu_ )
{
drawMenu_->blockSignals(true);
drawMenu_->hide();
drawMenu_->blockSignals(false);
}
if ( pickMenu_ ) if ( pickMenu_ )
{ {
......
...@@ -263,8 +263,7 @@ public: ...@@ -263,8 +263,7 @@ public:
/// set draw mode (No test if this mode is available!) /// set draw mode (No test if this mode is available!)
void drawMode(unsigned int _mode) void drawMode(unsigned int _mode)
{ {
curDrawMode_=_mode; curDrawMode_ = _mode;
updatePopupMenu();
} }
/// get current draw mode /// get current draw mode
...@@ -302,7 +301,6 @@ public: ...@@ -302,7 +301,6 @@ public:
/// Get the menu pointers (required to add them to the menubar as a temp workaround for a qt 4.3 bug /// Get the menu pointers (required to add them to the menubar as a temp workaround for a qt 4.3 bug
QMenu * getPickMenu() { return pickMenu_; }; QMenu * getPickMenu() { return pickMenu_; };
QMenu * getDrawMenu() { return drawMenu_; };
//---------------------------------------------------------------- public slots //---------------------------------------------------------------- public slots
...@@ -483,10 +481,6 @@ private: ...@@ -483,10 +481,6 @@ private:
// helper called by drawScene() when stereo viewing is active. // helper called by drawScene() when stereo viewing is active.
void drawScene_stereo(); void drawScene_stereo();
// updates popup menu with the available draw modes
void updatePopupMenu();
//-------------------------------------------------------------- protected data //-------------------------------------------------------------- protected data
protected: protected:
...@@ -535,13 +529,11 @@ private: ...@@ -535,13 +529,11 @@ private:
QMenu * pickMenu_; QMenu * pickMenu_;
QMenu * drawMenu_;
// scenegraph stuff // scenegraph stuff
ACG::SceneGraph::BaseNode* sceneGraphRoot_; ACG::SceneGraph::BaseNode* sceneGraphRoot_;
unsigned int curDrawMode_, unsigned int curDrawMode_;
availDrawModes_;
bool projectionUpdateLocked_; bool projectionUpdateLocked_;
bool blending_; bool blending_;
......
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