Commit cb4d7dd6 authored by Sebastian Eichelbaum's avatar Sebastian Eichelbaum
Browse files

[CHANGE #255] the message dock now uses the title bar for its widgets.

parent 2a2601b4
......@@ -48,19 +48,13 @@ WQtMessageDock::WQtMessageDock( QString dockTitle, QWidget* parent ):
setAllowedAreas( Qt::AllDockWidgetAreas );
setFeatures( QDockWidget::AllDockWidgetFeatures );
QVBoxLayout* panelLayout = new QVBoxLayout();
QWidget* panel = new QWidget( this );
panel->setLayout( panelLayout );
setWidget( panel );
// fill the panel
// log messages
m_logList = new QListWidget( this );
setWidget( m_logList );
// filter list
QLabel* filterLabel = new QLabel( "Filter Messages" );
m_filterCombo = new QComboBox();
m_filterCombo->setToolTip( "Filter the messages by level. When choosing a level, all messages with this and an above level will be displayed." );
m_filterCombo->addItem( "Debug" );
m_filterCombo->addItem( "Info" );
m_filterCombo->addItem( "Warning" );
......@@ -69,24 +63,16 @@ WQtMessageDock::WQtMessageDock( QString dockTitle, QWidget* parent ):
WMainWindow::getSettings().value( "MessageDockFilterIndex", 2 ).toInt()
); // warning is the default
// the filter widgets reside in a common layout:
QHBoxLayout* filterLayout = new QHBoxLayout();
filterLayout->addWidget( filterLabel );
filterLayout->addWidget( m_filterCombo );
QWidget* filterWidget = new QWidget();
filterWidget->setLayout( filterLayout );
// compose them together into the panel
panelLayout->addWidget( filterWidget );
panelLayout->addWidget( m_logList );
panelLayout->setSpacing( 0 );
filterLayout->setSpacing( 0 );
panelLayout->setContentsMargins( 0, 0, 0, 0 );
filterLayout->setContentsMargins( 0, 0, 0, 2 );
// connect filter combo
connect( m_filterCombo, SIGNAL( currentIndexChanged( int ) ), this, SLOT( handleFilterUpdate() ) );
// clear list action
QAction* clearAction = new QAction( WQt4Gui::getMainWindow()->getIconManager()->getIcon( "clear" ), "Clear Messages", this );
connect( clearAction, SIGNAL( triggered() ), this, SLOT( clearMessages() ) );
// add everything too the title list
addTitleAction( clearAction );
addTitleWidget( m_filterCombo );
}
WQtMessageDock::~WQtMessageDock()
......@@ -159,3 +145,8 @@ void WQtMessageDock::handleFilterUpdate()
}
}
}
void WQtMessageDock::clearMessages()
{
m_logList->clear();
}
......@@ -84,6 +84,12 @@ public:
*/
void saveSettings();
public slots:
/**
* Clear the message list.
*/
void clearMessages();
protected slots:
/**
* Handles changes in the filter combo
......
......@@ -38,11 +38,15 @@ WQtDockTitleWidget::WQtDockTitleWidget( QDockWidget* parent ):
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 ) );
}
void WQtDockTitleWidget::setupSizeConstraints( QWidget* widget )
{
widget->setContentsMargins( 0, 0, 0, 0 );
widget->setFixedHeight( 24 );
widget->setMinimumSize( 24, 24 );
widget->setSizePolicy( QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Fixed ) );
}
void WQtDockTitleWidget::construct()
......@@ -63,6 +67,7 @@ void WQtDockTitleWidget::construct()
connect( closeAction, SIGNAL( triggered( bool ) ), dockParent, SLOT( close() ) );
m_closeBtn->setDefaultAction( closeAction );
setupButton( m_closeBtn );
setupSizeConstraints( m_closeBtn );
m_closeBtn->setMinimumSize( 24, 24 );
m_closeBtn->setMaximumSize( 24, 24 );
......@@ -87,6 +92,7 @@ void WQtDockTitleWidget::construct()
// create a button that shows the m_toolsMenu container widget
m_moreBtn = new QToolButton( this );
setupButton( m_moreBtn );
setupSizeConstraints( m_moreBtn );
m_moreBtn->setFixedWidth( 32 );
m_moreBtn->setPopupMode( QToolButton::InstantPopup );
m_moreBtn->setIcon( WQt4Gui::getMainWindow()->getIconManager()->getIcon( "popup_more" ) );
......@@ -114,6 +120,7 @@ void WQtDockTitleWidget::addTitleAction( QAction* action, bool instantPopup )
QToolButton* actionBtn = new QToolButton( this );
actionBtn->setDefaultAction( action );
setupButton( actionBtn );
setupSizeConstraints( actionBtn );
if( instantPopup )
{
......@@ -121,24 +128,40 @@ void WQtDockTitleWidget::addTitleAction( QAction* action, bool instantPopup )
actionBtn->setFixedWidth( 32 );
}
// we keep track of the widgets:
m_titleActionWidgets.push_back( actionBtn );
// update the layouts
updateLayouts( width() );
addTitleWidget( actionBtn );
}
void WQtDockTitleWidget::addTitleButton( QToolButton* button )
{
setupButton( button );
setupSizeConstraints( button );
addTitleWidget( button );
}
void WQtDockTitleWidget::addTitleWidget( QWidget* widget )
{
setupSizeConstraints( widget );
// we keep track of the widgets:
m_titleActionWidgets.push_back( button );
m_titleActionWidgets.push_back( widget );
// update the layouts
updateLayouts( width() );
}
void WQtDockTitleWidget::removeTitleWidget( QWidget* widget )
{
if( widget )
{
m_toolsLayout->removeWidget( widget );
m_toolsMenuLayout->removeWidget( widget );
m_titleActionWidgets.removeAll( widget );
// update the layouts
updateLayouts( width() );
}
}
void WQtDockTitleWidget::removeTitleAction( QAction* action )
{
// find the widget for this action
......@@ -152,15 +175,7 @@ void WQtDockTitleWidget::removeTitleAction( QAction* action )
}
}
// found?
if( btn )
{
m_toolsLayout->removeWidget( btn );
m_toolsMenuLayout->removeWidget( btn );
m_titleActionWidgets.removeAll( btn );
// update the layouts
updateLayouts( width() );
}
removeTitleWidget( btn );
}
void WQtDockTitleWidget::addTitleSeperator()
......
......@@ -76,6 +76,20 @@ public:
*/
virtual void addTitleSeperator();
/**
* Add an arbitrary widget. Please take care of its size! This method sets a size policy and a fixed height.
*
* \param widget the widget to add
*/
virtual void addTitleWidget( QWidget* widget );
/**
* Remove the specified widget from the title bar.
*
* \param widget the widget to remove
*/
virtual void removeTitleWidget( QWidget* widget );
protected:
/**
* Called upon resize. Used to switch between the more menu and the tools widget
......@@ -90,6 +104,13 @@ protected:
* \param btn the button to setup
*/
virtual void setupButton( QToolButton* btn );
/**
* Apply size setup to a given widget.
*
* \param widget the widget to setup
*/
virtual void setupSizeConstraints( QWidget* widget );
private:
/**
* Construct the title and configure the widget.
......
......@@ -78,3 +78,14 @@ void WQtDockWidget::addTitleSeperator()
{
m_titleBar->addTitleSeperator();
}
void WQtDockWidget::addTitleWidget( QWidget* widget )
{
m_titleBar->addTitleWidget( widget );
}
void WQtDockWidget::removeTitleWidget( QWidget* widget )
{
m_titleBar->removeTitleWidget( widget );
}
......@@ -95,6 +95,21 @@ public:
* Add a separator.
*/
virtual void addTitleSeperator();
/**
* Add an arbitrary widget. Please take care of its size! This method sets a size policy and a fixed height.
*
* \param widget the widget to add
*/
virtual void addTitleWidget( QWidget* widget );
/**
* Remove the specified widget from the title bar.
*
* \param widget the widget to remove
*/
virtual void removeTitleWidget( QWidget* widget );
protected:
private:
/**
......
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