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

[FIX #241] title bars now scale down and replace the tool buttons on demand...

[FIX #241] title bars now scale down and replace the tool buttons on demand with some kind of "more-menu".
parent a65a3063
......@@ -28,7 +28,7 @@
#define WGLOBAL_MARGIN 0
#define WGLOBAL_SPACING 0
#define WMIN_LABEL_LENGTH 20
#define WPREFERRED_LABEL_LENGTH 15
#define WMIN_SLIDER_WIDTH 60
......
......@@ -22,13 +22,17 @@
//
//---------------------------------------------------------------------------
#include <iostream>
#include <QtGui/QAction>
#include <QtGui/QWidgetAction>
#include <QtGui/QDockWidget>
#include <QtGui/QVBoxLayout>
#include <QtGui/QHBoxLayout>
#include <QtGui/QToolButton>
#include <QtGui/QToolBar>
#include "guiElements/WScaleLabel.h"
#include "WQt4Gui.h"
#include "WMainWindow.h"
......@@ -114,74 +118,138 @@ void setupButton( QToolButton* btn )
{
btn->setToolButtonStyle( Qt::ToolButtonIconOnly );
btn->setContentsMargins( 0, 0, 0, 0 );
//btn->setFixedWidth( 24 );
btn->setFixedHeight( 24 );
btn->setAutoRaise( true );
}
WQtGLDockWidgetTitle::WQtGLDockWidgetTitle( WQtGLDockWidget* parent, const QString& dockTitle ):
QWidget( parent )
void WQtGLDockWidgetTitle::fillToolLayout( QWidget* parent, QBoxLayout* layout, QMenu* screenShotConfigMenu )
{
QFrame* line = new QFrame();
line->setFrameShape( QFrame::VLine );
line->setFrameShadow( QFrame::Sunken );
// screen capture trigger
QToolButton* screenShotBtn = new QToolButton( this );
screenShotBtn->setDefaultAction( parent->getScreenCapture()->getScreenshotTrigger() );
QToolButton* screenShotBtn = new QToolButton( parent );
screenShotBtn->setDefaultAction( m_dock->getScreenCapture()->getScreenshotTrigger() );
setupButton( screenShotBtn );
QMenu* m = new QMenu();
QWidgetAction* a = new QWidgetAction( this );
a->setDefaultWidget( parent->getScreenCapture() );
m->addAction( a );
screenShotBtn->setMenu( m );
screenShotBtn->setPopupMode( QToolButton::MenuButtonPopup );
screenShotBtn->setMenu( screenShotConfigMenu );
// camera presets
QToolButton* presetBtn = new QToolButton( this );
presetBtn->setDefaultAction( parent->getGLWidget()->getCameraResetAction() );
presetBtn->setMenu( parent->getGLWidget()->getCameraPresetsMenu() );
QToolButton* presetBtn = new QToolButton( parent );
presetBtn->setDefaultAction( m_dock->getGLWidget()->getCameraResetAction() );
presetBtn->setMenu( m_dock->getGLWidget()->getCameraPresetsMenu() );
presetBtn->setPopupMode( QToolButton::MenuButtonPopup );
setupButton( presetBtn );
QToolButton* settingsBtn = new QToolButton( this );
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( this );
QMenu* settingsMenu = new QMenu( parent );
settingsBtn->setMenu( settingsMenu );
// throwing
settingsMenu->addAction( parent->getGLWidget()->getThrowingSetting() );
settingsMenu->addAction( m_dock->getGLWidget()->getThrowingSetting() );
// change background color
settingsMenu->addAction( parent->getGLWidget()->getBackgroundColorAction() );
settingsMenu->addAction( m_dock->getGLWidget()->getBackgroundColorAction() );
// add all the tool buttons to the tool widget
layout->addWidget( screenShotBtn );
layout->addWidget( presetBtn );
layout->addWidget( line );
layout->addWidget( settingsBtn );
}
WQtGLDockWidgetTitle::WQtGLDockWidgetTitle( WQtGLDockWidget* parent, const QString& dockTitle ):
QWidget( parent ),
m_dock( parent )
{
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
QToolButton* closeBtn = new QToolButton( this );
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() ) );
closeBtn->setDefaultAction( act );
setupButton( closeBtn );
m_closeBtn->setDefaultAction( act );
setupButton( m_closeBtn );
m_closeBtn->setMinimumSize( 12, 12 );
m_moreBtn->setMinimumSize( 12, 12 );
// title
QLabel* title = new QLabel( " " + dockTitle, this );
m_title = new WScaleLabel( " " + dockTitle, 3, this );
m_title->setTextInteractionFlags( Qt::NoTextInteraction );
// build layout
QHBoxLayout* layout = new QHBoxLayout( this );
layout->setMargin( 0 );
layout->setSpacing( 0 );
layout->addWidget( title );
layout->addWidget( m_title );
layout->addStretch( 100000 );
layout->addWidget( screenShotBtn );
layout->addWidget( presetBtn );
layout->addWidget( line );
layout->addWidget( settingsBtn );
layout->addWidget( closeBtn );
layout->addWidget( m_tools );
layout->addWidget( m_moreBtn );
layout->addWidget( m_closeBtn );
setSizePolicy( QSizePolicy( QSizePolicy::Ignored, QSizePolicy::Fixed ) );
}
setSizePolicy( QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Fixed ) );
void WQtGLDockWidgetTitle::resizeEvent( QResizeEvent* event )
{
int required = m_title->minimumSizeHint().width() + 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 );
}
}
WQtGLScreenCapture* WQtGLDockWidget::getScreenCapture()
......
......@@ -27,6 +27,11 @@
#include <QtGui/QDockWidget>
#include <QtGui/QVBoxLayout>
#include <QtGui/QHBoxLayout>
#include <QtGui/QToolButton>
#include <QtGui/QLabel>
#include <QtGui/QResizeEvent>
#include <QtGui/QWidgetAction>
#include "core/graphicsEngine/WGECamera.h"
......@@ -163,7 +168,71 @@ public:
*/
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
*/
QLabel* 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
......@@ -31,9 +31,9 @@
WPropertyTriggerWidget::WPropertyTriggerWidget( WPropTrigger property, QGridLayout* propertyGrid, QWidget* parent ):
WPropertyWidget( property, propertyGrid, parent ),
m_triggerProperty( property ),
m_button( &m_parameterWidgets ),
m_button( WPREFERRED_LABEL_LENGTH, &m_parameterWidgets ),
m_layout( &m_parameterWidgets ),
m_asText( &m_informationWidgets ),
m_asText( WPREFERRED_LABEL_LENGTH, &m_informationWidgets ),
m_infoLayout( &m_informationWidgets )
{
// initialize members
......
......@@ -203,7 +203,7 @@ QWidget* WQtPropertyGroupWidget::createPropertyGroupBox( WQtPropertyGroupWidget*
box->setLayout( boxLayout );
// create a button as title
WScaleToolButton* boxTitle = new WScaleToolButton( box );
WScaleToolButton* boxTitle = new WScaleToolButton( WPREFERRED_LABEL_LENGTH , box );
QString titleText = ( title == "" ) ? widget->getName() : title;
boxTitle->setText( titleText );
boxTitle->setToolTip( titleText );
......
......@@ -27,22 +27,43 @@
#include "WScaleLabel.h"
#include "WScaleLabel.moc"
WScaleLabel::WScaleLabel( QWidget *parent /*= NULL */ ):
WScaleLabel::WScaleLabel( size_t length, QWidget* parent ):
QLabel( parent ),
m_additionalWidth( 0 )
m_additionalWidth( 0 ),
m_minLength( length )
{
setMinimumWidth( fontMetrics().width( m_orgText.left( WMIN_LABEL_LENGTH ) + tr( ".." ) ) + m_additionalWidth );
setSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::Maximum );
setMargin( WGLOBAL_MARGIN );
setTextInteractionFlags( Qt::TextSelectableByMouse );
construct();
}
WScaleLabel::WScaleLabel( const QString &text, QWidget *parent /*= NULL */ ) :
WScaleLabel::WScaleLabel( const QString &text, size_t length, QWidget* parent ) :
QLabel( text, parent ),
m_orgText( text ),
m_additionalWidth( 0 )
m_additionalWidth( 0 ),
m_minLength( length )
{
setMinimumWidth( fontMetrics().width( m_orgText.left( WMIN_LABEL_LENGTH ) + tr( ".." ) ) + m_additionalWidth );
construct();
}
WScaleLabel::WScaleLabel( QWidget* parent ):
QLabel( parent ),
m_additionalWidth( 0 ),
m_minLength( WPREFERRED_LABEL_LENGTH )
{
construct();
}
WScaleLabel::WScaleLabel( const QString &text, QWidget* parent ):
QLabel( text, parent ),
m_orgText( text ),
m_additionalWidth( 0 ),
m_minLength( WPREFERRED_LABEL_LENGTH )
{
construct();
}
void WScaleLabel::construct()
{
setMinimumWidth( fontMetrics().width( m_orgText.left( m_minLength ) + tr( ".." ) ) + m_additionalWidth );
setSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::Maximum );
setMargin( WGLOBAL_MARGIN );
setTextInteractionFlags( Qt::TextSelectableByMouse );
......@@ -61,14 +82,14 @@ QSize WScaleLabel::sizeHint() const
QSize WScaleLabel::minimumSizeHint() const
{
return QSize( fontMetrics().width( m_orgText.left( WMIN_LABEL_LENGTH ) + tr( ".." ) ) + 2 * margin() + m_additionalWidth,
return QSize( fontMetrics().width( m_orgText.left( m_minLength ) + tr( ".." ) ) + 2 * margin() + m_additionalWidth,
QLabel::minimumSizeHint().height() );
}
void WScaleLabel::setText( const QString &text )
{
m_orgText = text;
setMinimumWidth( fontMetrics().width( m_orgText.left( WMIN_LABEL_LENGTH ) + tr( ".." ) ) + 2 * margin() + m_additionalWidth );
setMinimumWidth( fontMetrics().width( m_orgText.left( m_minLength ) + tr( ".." ) ) + 2 * margin() + m_additionalWidth );
fitTextToSize();
}
......@@ -95,3 +116,14 @@ void WScaleLabel::addAdditionalWidth( int w )
{
m_additionalWidth = w;
}
void WScaleLabel::setMinimalLength( size_t chars )
{
setText( m_orgText );
m_minLength = chars;
}
size_t WScaleLabel::getMinimalLength() const
{
return m_minLength;
}
......@@ -28,6 +28,8 @@
#include <QtGui/QLabel>
#include <QtCore/QString>
#include "../WGuiConsts.h"
/**
* Special Label that can shrink and expand in a layout
*/
......@@ -35,12 +37,29 @@ class WScaleLabel: public QLabel
{
Q_OBJECT
public:
/**
* Constructor
*
* \param parent the widgets parent
* \param length the minimal number of characters visible.
*/
WScaleLabel( size_t length = WPREFERRED_LABEL_LENGTH, QWidget* parent = NULL );
/**
* Constructor. Creates the label with its original text
*
* \param text text of the label
* \param parent the widgets parent
* \param length the minimal number of characters visible.
*/
WScaleLabel( const QString &text, size_t length = WPREFERRED_LABEL_LENGTH, QWidget* parent = NULL );
/**
* Constructor
*
* \param parent the widgets parent
*/
explicit WScaleLabel( QWidget *parent = NULL );
explicit WScaleLabel( QWidget* parent );
/**
* Constructor. Creates the label with its original text
......@@ -48,7 +67,7 @@ public:
* \param text text of the label
* \param parent the widgets parent
*/
WScaleLabel( const QString &text, QWidget *parent = NULL );
WScaleLabel( const QString &text, QWidget* parent );
/**
* overwritten from QLabel, returning the widgets prefered size
......@@ -78,6 +97,20 @@ public:
* \param margin the margin to keep in mind for size calculations
*/
virtual void addAdditionalWidth( int margin );
/**
* How many characters should be visible all the time?
*
* \param chars the number of chars
*/
virtual void setMinimalLength( size_t chars );
/**
* Get the current minimal number of characters
*
* \return the number of chars visible all the time
*/
virtual size_t getMinimalLength() const;
protected:
/**
* custom implementation of the resize event
......@@ -87,6 +120,11 @@ protected:
*/
virtual void resizeEvent( QResizeEvent * event );
private:
/**
* Deferred construction.
*/
void construct();
/**
* set the actual text which is shown on the QLabel
*/
......@@ -101,6 +139,11 @@ private:
* The additional width we need to reserver (like for margins).
*/
int m_additionalWidth;
/**
* Minimal character number
*/
size_t m_minLength;
};
#endif // WSCALELABEL_H
......@@ -22,26 +22,26 @@
//
//---------------------------------------------------------------------------
#include "../WGuiConsts.h"
#include "WScaleToolButton.h"
#include "WScaleToolButton.moc"
WScaleToolButton::WScaleToolButton( QWidget *parent /*= NULL */ ):
WScaleToolButton::WScaleToolButton( size_t length, QWidget *parent /*= NULL */ ):
QToolButton( parent ),
m_additionalWidth( 0 )
m_additionalWidth( 0 ),
m_minLength( length )
{
setMinimumWidth( fontMetrics().width( m_orgText.left( WMIN_LABEL_LENGTH ) + tr( ".." ) ) + m_additionalWidth );
setMinimumWidth( fontMetrics().width( m_orgText.left( m_minLength ) + tr( ".." ) ) + m_additionalWidth );
setSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::Maximum );
}
WScaleToolButton::WScaleToolButton( const QString &text, QWidget *parent /*= NULL */ ) :
WScaleToolButton::WScaleToolButton( const QString &text, size_t length, QWidget *parent /*= NULL */ ) :
QToolButton( parent ),
m_orgText( text ),
m_additionalWidth( 0 )
m_additionalWidth( 0 ),
m_minLength( length )
{
setText( text );
setMinimumWidth( fontMetrics().width( m_orgText.left( WMIN_LABEL_LENGTH ) + tr( ".." ) ) + m_additionalWidth );
setMinimumWidth( fontMetrics().width( m_orgText.left( m_minLength ) + tr( ".." ) ) + m_additionalWidth );
setSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::Maximum );
}
......@@ -58,14 +58,14 @@ QSize WScaleToolButton::sizeHint() const
QSize WScaleToolButton::minimumSizeHint() const
{
return QSize( fontMetrics().width( m_orgText.left( WMIN_LABEL_LENGTH ) + tr( ".." ) ) + m_additionalWidth,
return QSize( fontMetrics().width( m_orgText.left( m_minLength ) + tr( ".." ) ) + m_additionalWidth,
QToolButton::minimumSizeHint().height() );
}
void WScaleToolButton::setText( const QString &text )
{
m_orgText = text;
setMinimumWidth( fontMetrics().width( m_orgText.left( WMIN_LABEL_LENGTH ) + tr( ".." ) ) + m_additionalWidth );
setMinimumWidth( fontMetrics().width( m_orgText.left( m_minLength ) + tr( ".." ) ) + m_additionalWidth );
fitTextToSize();
}
......@@ -92,3 +92,14 @@ void WScaleToolButton::addAdditionalWidth( int w )
{
m_additionalWidth = w;
}
void WScaleToolButton::setMinimalLength( size_t chars )
{
setText( m_orgText );
m_minLength = chars;
}
size_t WScaleToolButton::getMinimalLength() const
{
return m_minLength;
}
......@@ -28,6 +28,8 @@
#include <QtGui/QToolButton>
#include <QtCore/QString>
#include "../WGuiConsts.h"
/**
* Special Button that can shrink and expand in a layout
*/
......@@ -39,16 +41,18 @@ public:
* Constructor
*
* \param parent the widgets parent
* \param length the minimal number of characters visible
*/
explicit WScaleToolButton( QWidget *parent = NULL );
WScaleToolButton( size_t length = WPREFERRED_LABEL_LENGTH, QWidget *parent = NULL );
/**
* Constructor. Creates the button with its original text
*
* \param text text of the button
* \param parent the widgets parent
* \param length the minimal number of characters
*/
WScaleToolButton( const QString &text, QWidget *parent = NULL );
WScaleToolButton( const QString &text, size_t length = WPREFERRED_LABEL_LENGTH, QWidget *parent = NULL );
/**
* overwritten from QToolButton, returning the widgets prefered size
......@@ -78,6 +82,20 @@ public:
* \param margin the margin to keep in mind for size calculations
*/
virtual void addAdditionalWidth( int margin );
/**
* How many characters should be visible all the time?
*
* \param chars the number of chars
*/
virtual void setMinimalLength( size_t chars );
/**
* Get the current minimal number of characters
*
* \return the number of chars visible all the time
*/
virtual size_t getMinimalLength() const;
protected:
/**
* custom implementation of the resize event
......@@ -101,6 +119,11 @@ private:
* The additional width we need to reserver (like for margins).
*/
int m_additionalWidth;
/**
* Minimal character number
*/
size_t m_minLength;
};
#endif // WSCALETOOLBUTTON_H
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