Commit 09be500c authored by Sebastian Eichelbaum's avatar Sebastian Eichelbaum
Browse files

[CHANGE] we now have an indentation for nesed groups and different colors...

[CHANGE] we now have an indentation for nesed groups and different colors using the well known "solarized" palette.
parent 53d25a4f
......@@ -942,7 +942,7 @@ void WQtControlPanel::buildPropTab( boost::shared_ptr< WProperties > props, boos
WQtPropertyGroupWidget* infoTab = NULL;
if( props )
{
tab = new WQtPropertyGroupWidget( props );
tab = new WQtPropertyGroupWidget( props, 0, this );
if( tab )
{
tab->setName( "Settings" );
......@@ -950,7 +950,7 @@ void WQtControlPanel::buildPropTab( boost::shared_ptr< WProperties > props, boos
}
if( infoProps )
{
infoTab = new WQtPropertyGroupWidget( infoProps );
infoTab = new WQtPropertyGroupWidget( infoProps, 0, this );
if( infoTab )
{
infoTab->setName( "Information" );
......
......@@ -43,10 +43,11 @@
#include "WQtPropertyGroupWidget.h"
#include "WQtPropertyGroupWidget.moc"
WQtPropertyGroupWidget::WQtPropertyGroupWidget( WPropertyGroupBase::SPtr group, QWidget* parent )
WQtPropertyGroupWidget::WQtPropertyGroupWidget( WPropertyGroupBase::SPtr group, size_t depth, QWidget* parent )
: QWidget( parent ),
m_name( group->getName().c_str() ),
m_group( group )
m_group( group ),
m_nestingDepth( depth )
{
// note: never do layouts as none pointers
// on destruction of a widget it will try to delete them which will cause crashes
......@@ -165,7 +166,7 @@ void WQtPropertyGroupWidget::addProp( WPropertyBase::SPtr property )
void WQtPropertyGroupWidget::addGroup( WPropertyGroupBase::SPtr prop )
{
addGroup( new WQtPropertyGroupWidget( prop ) );
addGroup( new WQtPropertyGroupWidget( prop, m_nestingDepth + 1, this ) );
}
void WQtPropertyGroupWidget::addGroup( WQtPropertyGroupWidget* widget, bool asScrollArea )
......@@ -190,15 +191,29 @@ void WQtPropertyGroupWidget::addGroup( WQtPropertyGroupWidget* widget, bool asSc
// encapsulate it into an collapsable widget
QFrame* box = new QFrame( this );
box->setFrameShape( QFrame::StyledPanel );
QGridLayout* boxLayout = new QGridLayout( box );
box->setObjectName( "PropertyGroupBox" );
QGridLayout* boxLayout = new QGridLayout();
boxLayout->setMargin( 0 );
boxLayout->setSpacing( 0 );
box->setLayout( boxLayout );
// create a button as title
QToolButton* boxTitle = new QToolButton( this );
boxTitle->setText( widget->getName() );
boxLayout->addWidget( boxTitle, 0, 0 );
// we need a separate widget to indent the content widget a bit without indenting the title ... yes this really looks like the mess you can
// do with DIVs in HTML :-/. What we do here is adding a widget which then contains the content widget and indents it. Setting the contents
// margins directly in the QFrame* box would also indent the title button which is not wanted
QWidget* boxContent = new QWidget();
boxContent->setContentsMargins( 5, 0, 0, 0 );
boxContent->setObjectName( "PropertyGroupBoxContent" );
QGridLayout* boxContentLayout = new QGridLayout();
boxContent->setLayout( boxContentLayout );
boxContentLayout->setMargin( 0 );
boxContentLayout->setSpacing( 0 );
boxLayout->addWidget( boxContent, 1, 0 );
// set the button up
QSizePolicy sizePolicy( QSizePolicy::Minimum, QSizePolicy::Maximum );
sizePolicy.setHorizontalStretch( 0 );
......@@ -207,10 +222,55 @@ void WQtPropertyGroupWidget::addGroup( WQtPropertyGroupWidget* widget, bool asSc
boxTitle->setAutoRaise( true );
boxTitle->setAutoFillBackground( true );
// content widget
QWidget* content = new QWidget();
content->setObjectName( "PropertyGroupContent" );
boxContentLayout->addWidget( content, 1, 0 );
// content layout
QGridLayout* contentLayout = new QGridLayout();
content->setLayout( contentLayout );
contentLayout->setMargin( 0 );
contentLayout->setSpacing( 0 );
// some styling
QPalette palette;
QColor defaultCol = palette.window().color().darker( 150 );
QPalette palette; // the palette is used to get default colors of the style/system
QColor defaultCol = palette.window().color().darker( 120 );
switch( widget->m_nestingDepth % 10 ) // NOTE: the first level 0 does not need a color as it does not provide a boxtitle, so we begin with 1
{
// All these colors are taken from the solarized pallette http://ethanschoonover.com/solarized
case 1:
defaultCol = palette.window().color().darker( 150 );
break;
case 2:
defaultCol = QColor( "#268bd2" );
break;
case 3:
defaultCol = QColor( "#2aa198" );
break;
case 4:
defaultCol = QColor( "#859900" );
break;
case 5:
defaultCol = QColor( "#b58900" );
break;
case 6:
defaultCol = QColor( "#cb4b16" );
break;
case 7:
defaultCol = QColor( "#dc322f" );
break;
case 8:
defaultCol = QColor( "#d33682" );
break;
case 9:
defaultCol = QColor( "#6c71c4" );
break;
}
boxTitle->setStyleSheet( "background-color: " + defaultCol.name() + "; font-weight:bold;" );
box->setStyleSheet( "QFrame#PropertyGroupBox{background-color: " + defaultCol.name() + ";}" );
content->setStyleSheet( "#PropertyGroupContent{ background-color: "+ palette.window().color().name() +";}" );
// toggle should cause the body widget to appear/disappear
QSignalMapper* signalMapper = new QSignalMapper( this );
......@@ -221,11 +281,11 @@ void WQtPropertyGroupWidget::addGroup( WQtPropertyGroupWidget* widget, bool asSc
// create a body widget
if( asScrollArea )
{
boxLayout->addWidget( scrollArea, 1, 0 );
contentLayout->addWidget( scrollArea, 1, 0 );
}
else
{
boxLayout->addWidget( group, 1, 0 );
contentLayout->addWidget( group, 1, 0 );
}
// insert into layout
......
......@@ -59,9 +59,10 @@ public:
/**
* Creates new widget for a property group. Use this constructor to provide automatic hidden-flag management.
* \param group The group
* \param depth the nesting depth of this group, it usually is parents depth + 1.
* \param parent The widget managing this widget
*/
WQtPropertyGroupWidget( WPropertyGroupBase::SPtr group, QWidget* parent = 0 );
WQtPropertyGroupWidget( WPropertyGroupBase::SPtr group, size_t depth = 0, QWidget* parent = 0 );
/**
* destructor
......@@ -204,6 +205,11 @@ private:
* The connection for propertyChangeNotifier().
*/
boost::signals2::connection m_connection;
/**
* The depth of this group.
*/
size_t m_nestingDepth;
};
#endif // WQTPROPERTYGROUPWIDGET_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