Commit 0fa954b1 authored by Sebastian Eichelbaum's avatar Sebastian Eichelbaum
Browse files

[ADD] we now have nicely beutified property widgets with more compact layout...

[ADD] we now have nicely beutified property widgets with more compact layout and small but useful separators in between
parent 4944f988
......@@ -25,8 +25,8 @@
#ifndef WGUICONSTS_H
#define WGUICONSTS_H
#define WGLOBAL_MARGIN 1
#define WGLOBAL_SPACING 1
#define WGLOBAL_MARGIN 0
#define WGLOBAL_SPACING 0
#define WMIN_LABEL_LENGTH 20
......
......@@ -31,6 +31,8 @@
#include <QtGui/QAction>
#include <QtGui/QHBoxLayout>
#include "../guiElements/WScaleLabel.h"
#include "WPropertyWidget.h"
/**
......@@ -78,7 +80,7 @@ protected:
/**
* Used to show the property as text.
*/
QLabel m_asText;
WScaleLabel m_asText;
/**
* The layout used for the pure output (information properties)
......
......@@ -30,6 +30,8 @@
#include <QtGui/QPushButton>
#include <QtGui/QHBoxLayout>
#include "../guiElements/WScaleLabel.h"
#include "WPropertyWidget.h"
/**
......@@ -95,7 +97,7 @@ protected:
/**
* Used to show the property as text.
*/
QLabel m_asText;
WScaleLabel m_asText;
/**
* The layout used for the pure output (information properties)
......
......@@ -33,6 +33,8 @@
#include <QtGui/QToolButton>
#include "../guiElements/WQtIntervalEdit.h"
#include "../guiElements/WScaleLabel.h"
#include "WPropertyWidget.h"
/**
......@@ -118,7 +120,7 @@ protected:
/**
* Used to show the property as text.
*/
QLabel m_asText;
WScaleLabel m_asText;
/**
* The layout used for the pure output (information properties)
......
......@@ -30,6 +30,8 @@
#include <QtGui/QPushButton>
#include <QtGui/QHBoxLayout>
#include "../guiElements/WScaleLabel.h"
#include "WPropertyWidget.h"
/**
......@@ -77,7 +79,7 @@ protected:
/**
* Used to show the property as text.
*/
QLabel m_asText;
WScaleLabel m_asText;
/**
* The layout used for the pure output (information properties)
......
......@@ -33,6 +33,8 @@
#include <QtGui/QToolButton>
#include "../guiElements/WQtIntervalEdit.h"
#include "../guiElements/WScaleLabel.h"
#include "WPropertyWidget.h"
/**
......@@ -118,7 +120,7 @@ protected:
/**
* Used to show the property as text.
*/
QLabel m_asText;
WScaleLabel m_asText;
/**
* The layout used for the pure output (information properties)
......
......@@ -33,6 +33,8 @@
#include <QtGui/QToolButton>
#include "../guiElements/WQtIntervalEdit.h"
#include "../guiElements/WScaleLabel.h"
#include "WPropertyWidget.h"
/**
......@@ -80,7 +82,7 @@ protected:
/**
* Used to show the property as text.
*/
QLabel m_asText;
WScaleLabel m_asText;
/**
* The layout used for the pure output (information properties)
......
......@@ -31,6 +31,8 @@
#include <QtGui/QSlider>
#include <QtGui/QHBoxLayout>
#include "../guiElements/WScaleLabel.h"
#include "WPropertyWidget.h"
class WScaleLabel;
......
......@@ -31,6 +31,8 @@
#include <QtGui/QSlider>
#include <QtGui/QHBoxLayout>
#include "../guiElements/WScaleLabel.h"
#include "WPropertyWidget.h"
/**
......@@ -88,7 +90,7 @@ protected:
/**
* Used to show the property as text.
*/
QLabel m_asText;
WScaleLabel m_asText;
/**
* The layout used for the pure output (information properties)
......
......@@ -54,10 +54,8 @@ WPropertyStringWidget::WPropertyStringWidget( WPropString property, QGridLayout*
m_infoLayout.setMargin( WGLOBAL_MARGIN );
m_infoLayout.setSpacing( WGLOBAL_SPACING );
m_informationWidgets.setLayout( &m_infoLayout );
m_asText.setWordWrap( true );
// To have word warp work correctly -> set size policy
m_asText.setSizePolicy( QSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding ) );
// To have word warp work correctly -> set size policy
m_asText.setTextInteractionFlags( Qt::TextSelectableByMouse );
// set the initial values
......
......@@ -31,6 +31,7 @@
#include <QtGui/QSlider>
#include <QtGui/QHBoxLayout>
#include "../guiElements/WScaleLabel.h"
#include "WPropertyWidget.h"
/**
......@@ -78,7 +79,7 @@ protected:
/**
* Used to show the property as text.
*/
QLabel m_asText;
WScaleLabel m_asText;
/**
* The layout used for the pure output (information properties)
......
......@@ -31,6 +31,8 @@
#include <QtGui/QPushButton>
#include <QtGui/QHBoxLayout>
#include "../guiElements/WScaleLabel.h"
#include "WPropertyWidget.h"
/**
......@@ -85,7 +87,7 @@ protected:
/**
* Used to show the property as text.
*/
QLabel m_asText;
WScaleLabel m_asText;
/**
* The layout used for the pure output (information properties)
......
......@@ -43,6 +43,9 @@
#include "WPropertyTriggerWidget.h"
#include "WPropertyIntervalWidget.h"
#include "WPropertyWidget.h"
#include "../WGuiConsts.h"
#include "WPropertyWidget.moc"
#include "WQtPropertyGroupWidget.h"
......@@ -51,6 +54,7 @@ WPropertyWidget::WPropertyWidget( boost::shared_ptr< WPropertyBase > property,
m_property( property ),
m_propertyGrid( propertyGrid ),
m_label( this ),
m_separator( this ),
m_useLabel( m_propertyGrid ),
m_parameterWidgets(), // parent gets set by the QStackWidget
m_informationWidgets(), // parent gets set by the QStackWidget
......@@ -59,7 +63,10 @@ WPropertyWidget::WPropertyWidget( boost::shared_ptr< WPropertyBase > property,
if( m_useLabel )
{
// initialize members
m_label.setMargin( 0 );
m_label.addAdditionalWidth( 8 ); // a 4 px margin around the label
m_label.setText( property->getName().c_str() );
// set tooltips
m_label.setToolTip( getTooltip().c_str() );
setToolTip( m_label.toolTip() );
......@@ -70,6 +77,36 @@ WPropertyWidget::WPropertyWidget( boost::shared_ptr< WPropertyBase > property,
m_propertyGrid->addWidget( this, row, 1 );
m_propertyGrid->setColumnStretch( 0, 0.0 );
m_propertyGrid->setColumnStretch( 1, 10000.0 );
// ONLY style if in label mode
// define some colors
QPalette palette;
QColor defaultCol = palette.window().color();
// separator color
QColor sepCol = defaultCol.darker( 200 );
// label color
QColor labelCol = defaultCol.darker( 115 );
// property color
QColor propertyCol = defaultCol;
// set spearator style
m_separator.setFrameShape( QFrame::HLine );
m_separator.setFrameShadow( QFrame::Plain );
m_propertyGrid->addWidget( &m_separator, row + 1, 0, 1, 2 );
m_separator.setStyleSheet( "QWidget{ color:" + sepCol.name() + ";}" );
// set style of label
m_label.setObjectName( "ControlPanelPropertyLabelWidget" );
// increase size of label to be the whole layout cell
m_label.setSizePolicy( QSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::Expanding ) );
m_label.setStyleSheet( "background-color:" + labelCol.name() + ";" );
// set style of this property widget
setObjectName( "ControlPanelPropertyWidget" );
setStyleSheet( "QStackedWidget#ControlPanelPropertyWidget{ background-color:" + propertyCol.name() +
"; margin-left:1px; margin-right:1px; }" );
}
// add both widgets to the stacked widget, it then uses the first as default.
......@@ -85,6 +122,7 @@ WPropertyWidget::WPropertyWidget( boost::shared_ptr< WPropertyBase > property,
// if the property is hidden initially, hide widget too
setHidden( m_property->isHidden() );
m_label.setHidden( m_property->isHidden() );
m_separator.setHidden( m_property->isHidden() );
// setup the update callback
m_connection = m_property->getUpdateCondition()->subscribeSignal( boost::bind( &WPropertyWidget::requestUpdate, this ) );
......@@ -108,6 +146,7 @@ bool WPropertyWidget::event( QEvent* event )
{
setHidden( m_property->isHidden() );
m_label.setHidden( m_property->isHidden() );
m_separator.setHidden( m_property->isHidden() );
update();
return true;
}
......
......@@ -32,6 +32,7 @@
#include <QtGui/QWidget>
#include <QtGui/QStackedWidget>
#include <QtGui/QLabel>
#include <QtGui/QFrame>
#include <QtGui/QGridLayout>
#include "core/common/WPropertyBase.h"
......@@ -133,6 +134,11 @@ protected:
*/
WScaleLabel m_label;
/**
* Separator after each property
*/
QFrame m_separator;
/**
* If set to true, the widgets uses the control layout to combine the widget with a label
*/
......
......@@ -25,9 +25,11 @@
#include <string>
#include <algorithm>
#include <QtCore/QSignalMapper>
#include <QtGui/QApplication>
#include <QtGui/QGroupBox>
#include <QtGui/QPushButton>
#include <QtGui/QToolButton>
#include <QtGui/QScrollArea>
#include "../events/WEventTypes.h"
......@@ -193,24 +195,28 @@ void WQtPropertyGroupWidget::addGroup( WQtPropertyGroupWidget* widget, bool asSc
boxLayout->setSpacing( 0 );
// create a button as title
QPushButton* boxTitle = new QPushButton( this );
QToolButton* boxTitle = new QToolButton( this );
boxTitle->setText( widget->getName() );
boxLayout->addWidget( boxTitle, 0, 0 );
// set the button up
QSizePolicy sizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum );
QSizePolicy sizePolicy( QSizePolicy::Minimum, QSizePolicy::Maximum );
sizePolicy.setHorizontalStretch( 0 );
sizePolicy.setVerticalStretch( 0 );
boxTitle->setSizePolicy( sizePolicy );
boxTitle->setCheckable( true );
boxTitle->setChecked( true );
boxTitle->setFlat( true );
QFont font;
font.setBold( true );
boxTitle->setFont( font );
boxTitle->setText( widget->getName() );
boxTitle->setAutoRaise( true );
boxTitle->setAutoFillBackground( true );
// some styling
QPalette palette;
QColor defaultCol = palette.window().color().darker( 150 );
boxTitle->setStyleSheet( "background-color: " + defaultCol.name() + "; font-weight:bold;" );
// toggle should cause the body widget to appear/disappear
connect( boxTitle, SIGNAL( toggled( bool ) ), group, SLOT( setVisible( bool ) ) );
QSignalMapper* signalMapper = new QSignalMapper( this );
signalMapper->setMapping( boxTitle, group );
connect( boxTitle, SIGNAL( released() ), signalMapper, SLOT( map() ) );
connect( signalMapper, SIGNAL( mapped( QWidget* ) ), this, SLOT( switchVisibility( QWidget* ) ) );
// create a body widget
if( asScrollArea )
......@@ -259,3 +265,8 @@ WPropertyGroupBase::SPtr WQtPropertyGroupWidget::getPropertyGroup()
{
return m_group;
}
void WQtPropertyGroupWidget::switchVisibility( QWidget* who )
{
who->setVisible( !who->isVisible() );
}
......@@ -131,6 +131,13 @@ public:
*/
WPropertyGroupBase::SPtr getPropertyGroup();
public slots:
/**
* Change visibility of this group.
* \param who the widget to switch
*/
void switchVisibility( QWidget* who );
signals:
/**
......
......@@ -28,18 +28,24 @@
#include "WScaleLabel.moc"
WScaleLabel::WScaleLabel( QWidget *parent /*= NULL */ ):
QLabel( parent )
QLabel( parent ),
m_additionalWidth( 0 )
{
setMinimumWidth( fontMetrics().width( m_orgText.left( WMIN_LABEL_LENGTH ) + tr( ".." ) ) );
setSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::Expanding );
setMinimumWidth( fontMetrics().width( m_orgText.left( WMIN_LABEL_LENGTH ) + tr( ".." ) ) + m_additionalWidth );
setSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::Maximum );
setMargin( WGLOBAL_MARGIN );
setTextInteractionFlags( Qt::TextSelectableByMouse );
}
WScaleLabel::WScaleLabel( const QString &text, QWidget *parent /*= NULL */ ) :
QLabel( text, parent ),
m_orgText( text )
m_orgText( text ),
m_additionalWidth( 0 )
{
setMinimumWidth( fontMetrics().width( m_orgText.left( WMIN_LABEL_LENGTH ) + tr( ".." ) ) );
setSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::Expanding );
setMinimumWidth( fontMetrics().width( m_orgText.left( WMIN_LABEL_LENGTH ) + tr( ".." ) ) + m_additionalWidth );
setSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::Maximum );
setMargin( WGLOBAL_MARGIN );
setTextInteractionFlags( Qt::TextSelectableByMouse );
}
void WScaleLabel::resizeEvent( QResizeEvent* /*event*/ )
......@@ -49,18 +55,20 @@ void WScaleLabel::resizeEvent( QResizeEvent* /*event*/ )
QSize WScaleLabel::sizeHint() const
{
return QSize( fontMetrics().width( m_orgText ), QLabel::sizeHint().height() );
return QSize( fontMetrics().width( m_orgText ) + 2 * margin() + m_additionalWidth,
QLabel::sizeHint().height() );
}
QSize WScaleLabel::minimumSizeHint() const
{
return QSize( fontMetrics().width( m_orgText.left( WMIN_LABEL_LENGTH ) + tr( ".." ) ), QLabel::minimumSizeHint().height() );
return QSize( fontMetrics().width( m_orgText.left( WMIN_LABEL_LENGTH ) + 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( ".." ) ) );
setMinimumWidth( fontMetrics().width( m_orgText.left( WMIN_LABEL_LENGTH ) + tr( ".." ) ) + 2 * margin() + m_additionalWidth );
fitTextToSize();
}
......@@ -82,3 +90,8 @@ void WScaleLabel::fitTextToSize()
QLabel::setText( m_orgText );
}
}
void WScaleLabel::addAdditionalWidth( int w )
{
m_additionalWidth = w;
}
......@@ -55,21 +55,29 @@ public:
*
* \return prefered size of the label
*/
QSize sizeHint() const;
virtual QSize sizeHint() const;
/**
* overwritten from QLabel, returning the widgets prefered size
*
* \return minimum size of the label
*/
QSize minimumSizeHint() const;
virtual QSize minimumSizeHint() const;
/**
* reimplemented function to setText
*
* \param text text of the label
*/
void setText( const QString &text );
virtual void setText( const QString &text );
/**
* Set this to reserve extra space for a margin. This function does not set the margin. This is still your task, using stylesheets. You will
* not need this when using QLabel::setMargin().
*
* \param margin the margin to keep in mind for size calculations
*/
virtual void addAdditionalWidth( int margin );
protected:
/**
* custom implementation of the resize event
......@@ -88,6 +96,11 @@ private:
* QString to remember the original unshortend text of the widget
*/
QString m_orgText;
/**
* The additional width we need to reserver (like for margins).
*/
int m_additionalWidth;
};
#endif // WSCALELABEL_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