Commit 273d5559 authored by Sebastian Eichelbaum's avatar Sebastian Eichelbaum
Browse files

[CHANGE #254] WQtGLDockWidget now uses unified title widget.

parent bd7ba5ab
......@@ -331,7 +331,7 @@ void WMainWindow::setupGUI()
// directly -> set shortcuts, and some further properties using QAction's interface
m_settingsAction = new QAction( "Settings", this );
m_settingsAction->setIcon( m_iconManager.getIcon( "preferences" ) );
m_settingsAction->setIcon( m_iconManager.getIcon( "configure" ) );
m_settingsMenu = m_menuBar->addMenu( "Settings" );
m_viewMenu = m_settingsMenu->addMenu( "View" );
m_viewMenu->addAction( hideMenuAction );
......@@ -366,6 +366,7 @@ void WMainWindow::setupGUI()
m_helpMenu->addAction( m_iconManager.getIcon( "logo" ), "About OpenWalnut", this, SLOT( openAboutDialog() ) );
m_helpMenu->addAction( m_iconManager.getIcon( "qt" ), "About Qt", this, SLOT( openAboutQtDialog() ) );
m_helpAction->setMenu( m_helpMenu );
connect( m_helpAction, SIGNAL( triggered( bool ) ), this, SLOT( openOpenWalnutHelpDialog() ) );
setMenuBar( m_menuBar );
......@@ -435,10 +436,6 @@ void WMainWindow::setupGUI()
m_networkEditor->addTitleAction( m_newAction );
m_networkEditor->addTitleAction( m_loadButton );
m_networkEditor->addTitleAction( m_saveAction );
m_networkEditor->addTitleSeperator();
m_networkEditor->addTitleAction( m_settingsAction, true );
m_networkEditor->addTitleSeperator();
m_networkEditor->addTitleAction( m_helpAction, true );
// allow the control panel to complete setup
m_controlPanel->completeGuiSetup();
......
......@@ -37,20 +37,19 @@
#include "WSettingAction.h"
#include "guiElements/WQtDockWidget.h"
#include "WQtGLDockWidget.h"
#include "WQtGLDockWidget.moc"
WQtGLDockWidget::WQtGLDockWidget( QString viewTitle, QString dockTitle, QWidget* parent, WGECamera::ProjectionMode projectionMode,
const QWidget* shareWidget )
: QDockWidget( dockTitle, parent ),
const QWidget* shareWidget ):
WQtDockWidget( viewTitle, parent ),
m_dockTitle( dockTitle )
{
setObjectName( QString( "GL - " ) + dockTitle );
setAllowedAreas( Qt::AllDockWidgetAreas );
setFeatures( QDockWidget::AllDockWidgetFeatures );
// the panel contains all other widgets, including the gl widget
// This allows adding other widgets to certain docks
m_panel = new QWidget( this );
......@@ -74,179 +73,67 @@ WQtGLDockWidget::WQtGLDockWidget( QString viewTitle, QString dockTitle, QWidget*
// all view docks have a screen capture object
m_screenCapture = new WQtGLScreenCapture( this );
// set custom title
setTitleBarWidget( new WQtGLDockWidgetTitle( this, dockTitle ) );
}
WQtGLDockWidget::~WQtGLDockWidget()
{
// cleanup
}
boost::shared_ptr<WQtGLWidget>WQtGLDockWidget::getGLWidget() const
{
return m_glWidget;
}
void WQtGLDockWidget::handleVisibilityChange( bool visible )
{
// this can help to reduce CPU load. Especially if multithreading viewers are used with cull thread per context.
m_glWidget->getViewer()->getView()->getScene()->getSceneData()->setNodeMask( visible * 0xFFFFFFFF );
}
void WQtGLDockWidget::closeEvent( QCloseEvent *event )
{
getGLWidget()->getViewer()->setClosed( true );
QDockWidget::closeEvent( event );
}
void WQtGLDockWidget::showEvent( QShowEvent* event )
{
getGLWidget()->getViewer()->setClosed( false );
QDockWidget::showEvent( event );
}
/**
* Apply default settings for dock widget title buttons
*
* \param btn the button to setup
*/
void setupButton( QToolButton* btn )
{
btn->setToolButtonStyle( Qt::ToolButtonIconOnly );
btn->setContentsMargins( 0, 0, 0, 0 );
btn->setFixedHeight( 24 );
btn->setAutoRaise( true );
}
void WQtGLDockWidgetTitle::fillToolLayout( QWidget* parent, QBoxLayout* layout, QMenu* screenShotConfigMenu )
{
QFrame* line = new QFrame();
line->setFrameShape( QFrame::VLine );
line->setFrameShadow( QFrame::Sunken );
// screen capture trigger
QWidgetAction* screenCaptureWidgetAction = new QWidgetAction( this );
screenCaptureWidgetAction->setDefaultWidget( m_screenCapture );
QMenu* screenCaptureMenu = new QMenu();
screenCaptureMenu->addAction( screenCaptureWidgetAction );
QToolButton* screenShotBtn = new QToolButton( parent );
screenShotBtn->setDefaultAction( m_dock->getScreenCapture()->getScreenshotTrigger() );
setupButton( screenShotBtn );
screenShotBtn->setDefaultAction( m_screenCapture->getScreenshotTrigger() );
screenShotBtn->setPopupMode( QToolButton::MenuButtonPopup );
screenShotBtn->setMenu( screenShotConfigMenu );
screenShotBtn->setMenu( screenCaptureMenu );
// camera presets
QToolButton* presetBtn = new QToolButton( parent );
presetBtn->setDefaultAction( m_dock->getGLWidget()->getCameraResetAction() );
presetBtn->setMenu( m_dock->getGLWidget()->getCameraPresetsMenu() );
presetBtn->setDefaultAction( getGLWidget()->getCameraResetAction() );
presetBtn->setMenu( getGLWidget()->getCameraPresetsMenu() );
presetBtn->setPopupMode( QToolButton::MenuButtonPopup );
setupButton( presetBtn );
QToolButton* settingsBtn = new QToolButton( parent );
settingsBtn->setPopupMode( QToolButton::InstantPopup );
settingsBtn->setIcon( WQt4Gui::getMainWindow()->getIconManager()->getIcon( "configure" ) );
setupButton( settingsBtn );
settingsBtn->setToolTip( "Settings" );
QMenu* settingsMenu = new QMenu( parent );
settingsBtn->setMenu( settingsMenu );
// throwing
settingsMenu->addAction( m_dock->getGLWidget()->getThrowingSetting() );
settingsMenu->addAction( getGLWidget()->getThrowingSetting() );
// change background color
settingsMenu->addAction( m_dock->getGLWidget()->getBackgroundColorAction() );
settingsMenu->addAction( getGLWidget()->getBackgroundColorAction() );
// add all the tool buttons to the tool widget
layout->addWidget( screenShotBtn );
layout->addWidget( presetBtn );
layout->addWidget( line );
layout->addWidget( settingsBtn );
// add them to the title
addTitleButton( screenShotBtn );
addTitleButton( presetBtn );
addTitleButton( settingsBtn );
}
WQtGLDockWidgetTitle::WQtGLDockWidgetTitle( WQtGLDockWidget* parent, const QString& dockTitle ):
QWidget( parent ),
m_dock( parent )
WQtGLDockWidget::~WQtGLDockWidget()
{
m_screenCaptureWidgetAction = new QWidgetAction( this );
m_screenCaptureWidgetAction->setDefaultWidget( m_dock->getScreenCapture() );
m_screenCaptureMenu1 = new QMenu();
m_screenCaptureMenu2 = new QMenu();
// all tool buttons go into this widget
m_tools = new QWidget( this );
m_toolsLayout = new QHBoxLayout( m_tools );
m_tools->setLayout( m_toolsLayout );
m_tools->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ) );
m_toolsLayout->setMargin( 0 );
m_toolsLayout->setSpacing( 0 );
m_tools->setContentsMargins( 0, 0, 0, 0 );
m_tools->setMinimumSize( 1, 24 );
m_toolsMenu = new QWidget( this );
QHBoxLayout* toolsMenuLayout = new QHBoxLayout( m_toolsMenu );
m_toolsMenu->setLayout( toolsMenuLayout );
toolsMenuLayout->setMargin( 0 );
toolsMenuLayout->setSpacing( 0 );
m_toolsMenu->setContentsMargins( 0, 0, 0, 0 );
m_moreBtn = new QToolButton( this );
m_moreBtn->setHidden( true );
m_moreBtn->setFixedWidth( 32 );
setupButton( m_moreBtn );
m_moreBtn->setPopupMode( QToolButton::InstantPopup );
m_moreBtn->setIcon( WQt4Gui::getMainWindow()->getIconManager()->getIcon( "popup_more" ) );
QMenu* moreMenu = new QMenu();
QWidgetAction* moreAction = new QWidgetAction( m_toolsMenu );
moreAction->setDefaultWidget( m_toolsMenu );
moreMenu->addAction( moreAction );
m_moreBtn->setMenu( moreMenu );
fillToolLayout( m_tools, m_toolsLayout, m_screenCaptureMenu1 );
fillToolLayout( m_toolsMenu, toolsMenuLayout, m_screenCaptureMenu2 );
// close Btn
m_closeBtn = new QToolButton( this );
QAction* act = new QAction( WQt4Gui::getMainWindow()->getIconManager()->getIcon( "popup_close" ), "Close", this );
connect( act, SIGNAL( triggered( bool ) ), parent, SLOT( close() ) );
m_closeBtn->setDefaultAction( act );
setupButton( m_closeBtn );
m_closeBtn->setMinimumSize( 12, 12 );
m_moreBtn->setMinimumSize( 12, 12 );
// title
m_title = new WScaleLabel( " " + dockTitle, 3, this );
m_title->setTextInteractionFlags( Qt::NoTextInteraction );
// cleanup
}
// build layout
QHBoxLayout* layout = new QHBoxLayout( this );
layout->setMargin( 0 );
layout->setSpacing( 0 );
boost::shared_ptr<WQtGLWidget>WQtGLDockWidget::getGLWidget() const
{
return m_glWidget;
}
layout->addWidget( m_title );
layout->addStretch( 100000 );
layout->addWidget( m_tools );
layout->addWidget( m_moreBtn );
layout->addWidget( m_closeBtn );
void WQtGLDockWidget::handleVisibilityChange( bool visible )
{
// this can help to reduce CPU load. Especially if multithreading viewers are used with cull thread per context.
m_glWidget->getViewer()->getView()->getScene()->getSceneData()->setNodeMask( visible * 0xFFFFFFFF );
}
setSizePolicy( QSizePolicy( QSizePolicy::Ignored, QSizePolicy::Fixed ) );
void WQtGLDockWidget::closeEvent( QCloseEvent *event )
{
getGLWidget()->getViewer()->setClosed( true );
QDockWidget::closeEvent( event );
}
void WQtGLDockWidgetTitle::resizeEvent( QResizeEvent* event )
void WQtGLDockWidget::showEvent( QShowEvent* event )
{
int required = m_title->calculateSize( m_title->text().length() ) + m_tools->sizeHint().width() + m_closeBtn->sizeHint().width();
if( event->size().width() < required )
{
m_tools->setHidden( true );
m_moreBtn->setHidden( false );
m_screenCaptureMenu1->clear();
m_screenCaptureMenu2->addAction( m_screenCaptureWidgetAction );
}
else
{
m_tools->setHidden( false );
m_moreBtn->setHidden( true );
m_screenCaptureMenu2->clear();
m_screenCaptureMenu1->addAction( m_screenCaptureWidgetAction );
}
getGLWidget()->getViewer()->setClosed( false );
QDockWidget::showEvent( event );
}
WQtGLScreenCapture* WQtGLDockWidget::getScreenCapture()
......
......@@ -36,17 +36,16 @@
#include "core/graphicsEngine/WGECamera.h"
#include "guiElements/WScaleLabel.h"
#include "guiElements/WQtDockWidget.h"
#include "WQtGLWidget.h"
/**
* Dock widget containing only a GLWidget.
*/
class WQtGLDockWidget: public QDockWidget
class WQtGLDockWidget: public WQtDockWidget
{
Q_OBJECT
friend class WQtGLDockWidgetTitle;
public:
/**
* default constructor
......@@ -155,86 +154,4 @@ private:
WQtGLScreenCapture* m_screenCapture;
};
/**
* Class for managing dock widget title bars.
*/
class WQtGLDockWidgetTitle: public QWidget
{
Q_OBJECT
public:
/**
* Constructor
*
* \param parent the parent
* \param dockTitle The title text
*/
WQtGLDockWidgetTitle( WQtGLDockWidget* parent, const QString& dockTitle );
protected:
/**
* Called upon resize. Used to switch between the more menu and the tools widget
*
* \param event the event
*/
virtual void resizeEvent( QResizeEvent* event );
private:
/**
* The tools buttons
*/
QWidget* m_tools;
/**
* The tool inside the menu
*/
QWidget* m_toolsMenu;
/**
* LAyout containing the tools
*/
QHBoxLayout* m_toolsLayout;
/**
* The tool button used when shrinking the title bar too much
*/
QToolButton* m_moreBtn;
/**
* Title label
*/
WScaleLabel* m_title;
/**
* Close button
*/
QToolButton* m_closeBtn;
/**
* Fill the layout with all the tool buttons
*
* \param parent the parent widget for the buttons
* \param layout the layout to fill
* \param screenShotConfigMenu the menu to add as screen shot config
*/
void fillToolLayout( QWidget* parent, QBoxLayout* layout, QMenu* screenShotConfigMenu );
/**
* The dock
*/
WQtGLDockWidget* m_dock;
/**
* Used to contain the screen capture dialog
*/
QWidgetAction* m_screenCaptureWidgetAction;
/**
* Menu 1, used to alternate the m_screenCaptureWidgetAction in the tools bar and the tools menu
*/
QMenu* m_screenCaptureMenu1;
/**
* Menu 2, used to alternate the m_screenCaptureWidgetAction in the tools bar and the tools menu
*/
QMenu* m_screenCaptureMenu2;
};
#endif // WQTGLDOCKWIDGET_H
......@@ -40,6 +40,7 @@ void WQtDockTitleWidget::setupButton( QToolButton* btn )
btn->setToolButtonStyle( Qt::ToolButtonIconOnly );
btn->setContentsMargins( 0, 0, 0, 0 );
btn->setFixedHeight( 24 );
btn->setMinimumSize( 24, 24 );
btn->setAutoRaise( true );
btn->setSizePolicy( QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Fixed ) );
}
......@@ -85,8 +86,8 @@ void WQtDockTitleWidget::construct()
// create a button that shows the m_toolsMenu container widget
m_moreBtn = new QToolButton( this );
m_moreBtn->setHidden( true );
setupButton( m_moreBtn );
m_moreBtn->setFixedWidth( 32 );
m_moreBtn->setPopupMode( QToolButton::InstantPopup );
m_moreBtn->setIcon( WQt4Gui::getMainWindow()->getIconManager()->getIcon( "popup_more" ) );
QMenu* moreMenu = new QMenu();
......@@ -117,7 +118,9 @@ void WQtDockTitleWidget::addTitleAction( QAction* action, bool instantPopup )
if( instantPopup )
{
actionBtn->setPopupMode( QToolButton::InstantPopup );
actionBtn->setFixedWidth( 32 );
}
// we keep track of the widgets:
m_titleActionWidgets.push_back( actionBtn );
......@@ -125,6 +128,17 @@ void WQtDockTitleWidget::addTitleAction( QAction* action, bool instantPopup )
updateLayouts( width() );
}
void WQtDockTitleWidget::addTitleButton( QToolButton* button )
{
setupButton( button );
// we keep track of the widgets:
m_titleActionWidgets.push_back( button );
// update the layouts
updateLayouts( width() );
}
void WQtDockTitleWidget::removeTitleAction( QAction* action )
{
// find the widget for this action
......
......@@ -57,6 +57,13 @@ public:
*/
virtual void addTitleAction( QAction* action, bool instantPopup = false );
/**
* Add the given tool button to the titlebar. It gets added after the previously added ones.
*
* \param button the action to add.
*/
virtual void addTitleButton( QToolButton* button );
/**
* Remove the given action from the list
*
......
......@@ -64,6 +64,11 @@ void WQtDockWidget::addTitleAction( QAction* action, bool instantPopup )
m_titleBar->addTitleAction( action, instantPopup );
}
void WQtDockWidget::addTitleButton( QToolButton* button )
{
m_titleBar->addTitleButton( button );
}
void WQtDockWidget::removeTitleAction( QAction* action )
{
m_titleBar->removeTitleAction( action );
......
......@@ -77,6 +77,13 @@ public:
*/
virtual void addTitleAction( QAction* action, bool instantPopup = false );
/**
* Add the given tool button to the titlebar. It gets added after the previously added ones.
*
* \param button the action to add.
*/
virtual void addTitleButton( QToolButton* button );
/**
* Remove the given action from the list
*
......
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