Commit 1d67c11f authored by Sebastian Eichelbaum's avatar Sebastian Eichelbaum
Browse files

[CHANGE] dock widget help button only appears if help is available

parent 5f084028
...@@ -25,10 +25,11 @@ ...@@ -25,10 +25,11 @@
#include "../WQt4Gui.h" #include "../WQt4Gui.h"
#include "../WMainWindow.h" #include "../WMainWindow.h"
#include "WQtDockWidget.h"
#include "WQtDockTitleWidget.h" #include "WQtDockTitleWidget.h"
#include "WQtDockTitleWidget.moc" #include "WQtDockTitleWidget.moc"
WQtDockTitleWidget::WQtDockTitleWidget( QDockWidget* parent ): WQtDockTitleWidget::WQtDockTitleWidget( WQtDockWidget* parent ):
QWidget( parent ), QWidget( parent ),
dockParent( parent ) dockParent( parent )
{ {
...@@ -111,6 +112,7 @@ void WQtDockTitleWidget::construct() ...@@ -111,6 +112,7 @@ void WQtDockTitleWidget::construct()
setupSizeConstraints( m_helpBtn ); setupSizeConstraints( m_helpBtn );
m_helpBtn->setMinimumSize( 24, 24 ); m_helpBtn->setMinimumSize( 24, 24 );
m_helpBtn->setMaximumSize( 24, 24 ); m_helpBtn->setMaximumSize( 24, 24 );
m_helpBtn->setVisible( false );
// fill layout // fill layout
titleWidgetLayout->addWidget( m_title ); titleWidgetLayout->addWidget( m_title );
...@@ -204,7 +206,7 @@ void WQtDockTitleWidget::addTitleSeperator() ...@@ -204,7 +206,7 @@ void WQtDockTitleWidget::addTitleSeperator()
void WQtDockTitleWidget::updateLayouts( int width ) void WQtDockTitleWidget::updateLayouts( int width )
{ {
// calc the size of widgets and the title and the mandatory close button // calculate the size of widgets and the title and the mandatory close button
int minRequired = m_title->calculateSize( m_title->text().length() ) + int minRequired = m_title->calculateSize( m_title->text().length() ) +
m_moreBtn->sizeHint().width() + m_moreBtn->sizeHint().width() +
m_helpBtn->isVisible() * m_helpBtn->sizeHint().width() + m_helpBtn->isVisible() * m_helpBtn->sizeHint().width() +
...@@ -240,6 +242,17 @@ void WQtDockTitleWidget::updateLayouts( int width ) ...@@ -240,6 +242,17 @@ void WQtDockTitleWidget::updateLayouts( int width )
m_toolsMenuLayout->addWidget( *i ); m_toolsMenuLayout->addWidget( *i );
} }
// hide more button if nothing needs to be hiden // hide more button if nothing needs to be hidden
m_moreBtn->setHidden( !( hidden.size() ) ); m_moreBtn->setHidden( !( hidden.size() ) );
} }
void WQtDockTitleWidget::updateHelp()
{
// hide button if no help is available.
if( dockParent->getHelpContext() == "" )
{
m_helpBtn->setVisible( false );
return;
}
m_helpBtn->setVisible( true );
}
...@@ -35,6 +35,11 @@ ...@@ -35,6 +35,11 @@
#include "WScaleLabel.h" #include "WScaleLabel.h"
/**
* We need the dock widget class.
*/
class WQtDockWidget;
/** /**
* Class for managing dock widget title bars. * Class for managing dock widget title bars.
*/ */
...@@ -47,7 +52,7 @@ public: ...@@ -47,7 +52,7 @@ public:
* *
* \param parent the parent * \param parent the parent
*/ */
explicit WQtDockTitleWidget( QDockWidget* parent ); explicit WQtDockTitleWidget( WQtDockWidget* parent );
/** /**
* Add the given action to the titlebar. It gets added after the previously added ones. * Add the given action to the titlebar. It gets added after the previously added ones.
...@@ -90,6 +95,10 @@ public: ...@@ -90,6 +95,10 @@ public:
*/ */
virtual void removeTitleWidget( QWidget* widget ); virtual void removeTitleWidget( QWidget* widget );
/**
* Update help button.
*/
virtual void updateHelp();
protected: protected:
/** /**
* Called upon resize. Used to switch between the more menu and the tools widget * Called upon resize. Used to switch between the more menu and the tools widget
...@@ -167,7 +176,7 @@ private: ...@@ -167,7 +176,7 @@ private:
/** /**
* The parent as dock pointer * The parent as dock pointer
*/ */
QDockWidget* dockParent; WQtDockWidget* dockParent;
/** /**
* We keep track of the widgets that we add * We keep track of the widgets that we add
......
...@@ -36,6 +36,7 @@ WQtDockWidget::WQtDockWidget( const QString& title, QWidget* parent, Qt::WindowF ...@@ -36,6 +36,7 @@ WQtDockWidget::WQtDockWidget( const QString& title, QWidget* parent, Qt::WindowF
// thats it. we now have the title bar // thats it. we now have the title bar
m_titleBar = new WQtDockTitleWidget( this ); m_titleBar = new WQtDockTitleWidget( this );
setTitleBarWidget( m_titleBar ); setTitleBarWidget( m_titleBar );
m_titleBar->updateHelp();
// some standard dock features // some standard dock features
setAllowedAreas( Qt::AllDockWidgetAreas ); setAllowedAreas( Qt::AllDockWidgetAreas );
...@@ -48,6 +49,7 @@ WQtDockWidget::WQtDockWidget( QWidget* parent, Qt::WindowFlags flags ): ...@@ -48,6 +49,7 @@ WQtDockWidget::WQtDockWidget( QWidget* parent, Qt::WindowFlags flags ):
// thats it. we now have the title bar // thats it. we now have the title bar
m_titleBar = new WQtDockTitleWidget( this ); m_titleBar = new WQtDockTitleWidget( this );
setTitleBarWidget( m_titleBar ); setTitleBarWidget( m_titleBar );
m_titleBar->updateHelp();
// some standard dock features // some standard dock features
setAllowedAreas( Qt::AllDockWidgetAreas ); setAllowedAreas( Qt::AllDockWidgetAreas );
...@@ -92,6 +94,7 @@ void WQtDockWidget::removeTitleWidget( QWidget* widget ) ...@@ -92,6 +94,7 @@ void WQtDockWidget::removeTitleWidget( QWidget* widget )
void WQtDockWidget::setHelpContext( const QString& id ) void WQtDockWidget::setHelpContext( const QString& id )
{ {
m_helpContextId = id; m_helpContextId = id;
m_titleBar->updateHelp();
} }
const QString& WQtDockWidget::getHelpContext() const QString& WQtDockWidget::getHelpContext()
......
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