Commit 3000a29a authored by Mathias Goldau's avatar Mathias Goldau
Browse files

[MERGE]

parents 7fbe4e0e 7e46c190
......@@ -57,6 +57,8 @@ WQtMessagePopup::WQtMessagePopup( QWidget* parent, const QString& title, const Q
{
setAutoClose( true );
setWindowRole( "MessagePopup" );
// these settings seem to be ignored somehow
setWindowModality( Qt::NonModal );
......
......@@ -73,11 +73,6 @@ void WPropertyTriggerWidget::update()
m_asText.setText( m_triggerProperty->get() == WPVBaseTypes::PV_TRIGGER_TRIGGERED ? QString( "Operation triggered" ) : QString( "Ready" ) );
}
QPushButton* WPropertyTriggerWidget::getButton()
{
return &m_button;
}
void WPropertyTriggerWidget::changed()
{
// set the value
......
......@@ -32,6 +32,7 @@
#include <QtGui/QHBoxLayout>
#include "../guiElements/WScaleLabel.h"
#include "../guiElements/WScaleToolButton.h"
#include "WPropertyWidget.h"
......@@ -56,13 +57,6 @@ public:
*/
virtual ~WPropertyTriggerWidget();
/**
* Returns the QT PushButton widget used. It always returns a valid pointer.
*
* \return the button
*/
virtual QPushButton* getButton();
protected:
/**
* Called whenever the widget should update.
......@@ -77,7 +71,7 @@ protected:
/**
* If asButton is set to true: use this button instead of the m_checkbox
*/
QPushButton m_button;
WScaleToolButton m_button;
/**
* Layout used to position the label and the checkbox
......
......@@ -752,13 +752,13 @@ void WQtControlPanel::selectRoiTreeItem()
roi->getProperties()->getProperty( "active" )->toPropBool()->set( m_roiTreeWidget->selectedItems().at( 0 )->checkState( 0 ) );
}
buildPropTab( props, boost::shared_ptr< WProperties >() );
buildPropTab( props, boost::shared_ptr< WProperties >(), "ROI" );
}
void WQtControlPanel::selectDataModule( osg::ref_ptr< WGETexture3D > texture )
{
clearAndDeleteTabs();
buildPropTab( texture->getProperties(), texture->getInformationProperties() );
buildPropTab( texture->getProperties(), texture->getInformationProperties(), "Colormap" );
}
QTreeWidgetItem* WQtControlPanel::findModuleItem( WModule::SPtr module ) const
......@@ -878,7 +878,18 @@ void WQtControlPanel::setActiveModule( WModule::SPtr module, bool forceUpdate )
// set new property tabs if module is not crashed
if( !module->isCrashed() )
{
buildPropTab( module->getProperties(), module->getInformationProperties() );
std::string name = module->getName();
WPropertyBase::SPtr namePropCandidate = module->getProperties()->findProperty( "Name" );
if( namePropCandidate )
{
WPropString nameProp = namePropCandidate->toPropString();
if( nameProp )
{
name = ( name == nameProp->get() ) ? name : name + " - " + nameProp->get();
}
}
buildPropTab( module->getProperties(), module->getInformationProperties(), name );
}
// re-select the previous tab
......@@ -936,29 +947,34 @@ void WQtControlPanel::setActiveModule( WModule::SPtr module, bool forceUpdate )
m_ignoreSelectionChange = false;
}
void WQtControlPanel::buildPropTab( boost::shared_ptr< WProperties > props, boost::shared_ptr< WProperties > infoProps )
void WQtControlPanel::buildPropTab( boost::shared_ptr< WProperties > props, boost::shared_ptr< WProperties > infoProps, const std::string& name )
{
WQtPropertyGroupWidget* tab = NULL;
WQtPropertyGroupWidget* infoTab = NULL;
QWidget* tab = NULL;
QWidget* infoTab = NULL;
WQtPropertyGroupWidget* propWidget = NULL;
WQtPropertyGroupWidget* propInfoWidget = NULL;
QSizePolicy sizePolicy( QSizePolicy::Preferred, QSizePolicy::Maximum );
sizePolicy.setHorizontalStretch( 0 );
sizePolicy.setVerticalStretch( 0 );
if( props )
{
tab = new WQtPropertyGroupWidget( props );
if( tab )
{
tab->setName( "Settings" );
}
propWidget = new WQtPropertyGroupWidget( props, 0, this );
tab = WQtPropertyGroupWidget::createPropertyGroupBox( propWidget, false, this, QString::fromStdString( name ) );
propWidget->setName( "Settings" );
tab->setSizePolicy( sizePolicy );
}
if( infoProps )
{
infoTab = new WQtPropertyGroupWidget( infoProps );
if( infoTab )
{
infoTab->setName( "Information" );
}
propInfoWidget = new WQtPropertyGroupWidget( infoProps, 0, this );
infoTab = WQtPropertyGroupWidget::createPropertyGroupBox( propInfoWidget, false, this, QString::fromStdString( name ) );
propInfoWidget->setName( "Information" );
infoTab->setSizePolicy( sizePolicy );
}
int infoIdx = addTabWidgetContent( infoTab );
int propIdx = addTabWidgetContent( tab );
int infoIdx = addTabWidgetContent( infoTab, propInfoWidget );
int propIdx = addTabWidgetContent( tab, propWidget );
// select the property widget preferably
if( m_previousTab == "" )
......@@ -1046,9 +1062,9 @@ void WQtControlPanel::changeTreeItem( QTreeWidgetItem* item, int /* column */ )
}
}
int WQtControlPanel::addTabWidgetContent( WQtPropertyGroupWidget* content )
int WQtControlPanel::addTabWidgetContent( QWidget* content, WQtPropertyGroupWidget* propContents )
{
if( !content || content->isEmpty() )
if( !content || !propContents || propContents->isEmpty() )
{
// we destroy the widget if we not use it to avoid empty widgets popping up
if( content )
......@@ -1062,7 +1078,7 @@ int WQtControlPanel::addTabWidgetContent( WQtPropertyGroupWidget* content )
sa->setWidget( content );
sa->setWidgetResizable( true );
return m_tabWidget->addTab( sa, content->getName() );
return m_tabWidget->addTab( sa, propContents->getName() );
}
int WQtControlPanel::getFirstSubject()
......
......@@ -81,10 +81,11 @@ public:
* Adds a page to the context widget
*
* \param content A widget with controls
* \param propContents The prop group widget.
*
* \return the index of the new tab
*/
int addTabWidgetContent( WQtPropertyGroupWidget* content );
int addTabWidgetContent( QWidget* content, WQtPropertyGroupWidget* propContents );
/**
* Adds a subject entry to the tree widget
......@@ -428,8 +429,9 @@ private slots:
*
* \param props the properties.
* \param infoProps the information properties shown on a separate tab
* \param name the name used as title. Can be empty but should not.
*/
void buildPropTab( boost::shared_ptr< WProperties > props, boost::shared_ptr< WProperties > infoProps );
void buildPropTab( boost::shared_ptr< WProperties > props, boost::shared_ptr< WProperties > infoProps, const std::string& name );
/**
* Function gets change when a change to a tree item occurs.
......
......@@ -34,6 +34,7 @@
#include "../events/WEventTypes.h"
#include "../events/WPropertyChangedEvent.h"
#include "../guiElements/WScaleToolButton.h"
#include "core/common/WPropertyGroupBase.h"
#include "core/common/WLogger.h"
......@@ -43,10 +44,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,13 +167,17 @@ 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 )
QWidget* WQtPropertyGroupWidget::createPropertyGroupBox( WQtPropertyGroupWidget* widget, bool asScrollArea, QWidget* parent, const QString& title )
{
QSizePolicy sizePolicy( QSizePolicy::Minimum, QSizePolicy::Maximum );
sizePolicy.setHorizontalStretch( 0 );
sizePolicy.setVerticalStretch( 0 );
// create a scrollbox and group box containing the widget
QWidget* group = new QWidget( this );
QWidget* group = new QWidget();
QScrollArea* scrollArea = 0;
QGridLayout* grid = new QGridLayout();
......@@ -188,54 +194,134 @@ void WQtPropertyGroupWidget::addGroup( WQtPropertyGroupWidget* widget, bool asSc
}
// encapsulate it into an collapsable widget
QFrame* box = new QFrame( this );
QFrame* box = new QFrame( parent );
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() );
WScaleToolButton* boxTitle = new WScaleToolButton( box );
QString titleText = ( title == "" ) ? widget->getName() : title;
boxTitle->setText( titleText );
boxTitle->setToolTip( titleText );
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 );
sizePolicy.setVerticalStretch( 0 );
boxTitle->setSizePolicy( sizePolicy );
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 );
signalMapper->setMapping( boxTitle, group );
QSignalMapper* signalMapper = new QSignalMapper( box );
signalMapper->setMapping( boxTitle, boxContent );
connect( boxTitle, SIGNAL( released() ), signalMapper, SLOT( map() ) );
connect( signalMapper, SIGNAL( mapped( QWidget* ) ), this, SLOT( switchVisibility( QWidget* ) ) );
connect( signalMapper, SIGNAL( mapped( QWidget* ) ), widget, SLOT( switchVisibility( QWidget* ) ) );
// 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
int row = m_controlLayout->rowCount();
m_controlLayout->addWidget( box, row, 0, 1, 2 );
// hide the box too if the property gets hidden
box->setHidden( widget->isHidden() );
connect( widget, SIGNAL( hideSignal( bool ) ), box, SLOT( setHidden( bool ) ) );
return box;
}
QWidget* WQtPropertyGroupWidget::createPropertyGroupBox( WPropertyGroupBase::SPtr group, const QString& title, size_t depth, QWidget* parent )
{
QSizePolicy sizePolicy( QSizePolicy::Preferred, QSizePolicy::Maximum );
sizePolicy.setHorizontalStretch( 0 );
sizePolicy.setVerticalStretch( 0 );
WQtPropertyGroupWidget* propWidget = new WQtPropertyGroupWidget( group, depth, parent );
propWidget->setName( title );
QWidget* tab = WQtPropertyGroupWidget::createPropertyGroupBox( propWidget, false, parent, title );
tab->setSizePolicy( sizePolicy );
tab->setWindowTitle( title );
return tab;
}
void WQtPropertyGroupWidget::addGroup( WQtPropertyGroupWidget* widget, bool asScrollArea )
{
QWidget* box = WQtPropertyGroupWidget::createPropertyGroupBox( widget, asScrollArea, this );
// insert into layout
int row = m_controlLayout->rowCount();
m_controlLayout->addWidget( box, row, 0, 1, 2 );
// also keep track of group widgets
m_propWidgets[ widget->getPropertyGroup() ] = box;
}
......
......@@ -59,9 +59,35 @@ 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 );
/**
* This function creates the fancy box around your specified group widget.
*
* \param widget the widget to put into the box
* \param asScrollArea if true, the widget is embedded into a scroll area
* \param parent the parent widget
* \param title the title to use for the box. If empty, the property group name is used.
*
* \return the box widget
*/
static QWidget* createPropertyGroupBox( WQtPropertyGroupWidget* widget, bool asScrollArea = false, QWidget* parent = NULL,
const QString& title = "" );
/**
* Create a property widget using the given group.
*
* \param group the property group to represent
* \param title the title of the widget
* \param depth the nesting depth
* \param parent the parent widget
*
* \return the widget.
*/
static QWidget* createPropertyGroupBox( WPropertyGroupBase::SPtr group, const QString& title = "", size_t depth = 0, QWidget* parent = 0 );
/**
* destructor
......@@ -204,6 +230,11 @@ private:
* The connection for propertyChangeNotifier().
*/
boost::signals2::connection m_connection;
/**
* The depth of this group.
*/
size_t m_nestingDepth;
};
#endif // WQTPROPERTYGROUPWIDGET_H
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
// For more information see http://www.openwalnut.org/copying
//
// This file is part of OpenWalnut.
//
// OpenWalnut is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// OpenWalnut is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
//
//---------------------------------------------------------------------------
#include "../WGuiConsts.h"
#include "WScaleToolButton.h"
#include "WScaleToolButton.moc"
WScaleToolButton::WScaleToolButton( QWidget *parent /*= NULL */ ):
QToolButton( parent ),
m_additionalWidth( 0 )
{
setMinimumWidth( fontMetrics().width( m_orgText.left( WMIN_LABEL_LENGTH ) + tr( ".." ) ) + m_additionalWidth );
setSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::Maximum );
}
WScaleToolButton::WScaleToolButton( const QString &text, QWidget *parent /*= NULL */ ) :
QToolButton( parent ),
m_orgText( text ),
m_additionalWidth( 0 )
{
setText( text );
setMinimumWidth( fontMetrics().width( m_orgText.left( WMIN_LABEL_LENGTH ) + tr( ".." ) ) + m_additionalWidth );
setSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::Maximum );
}
void WScaleToolButton::resizeEvent( QResizeEvent* /*event*/ )
{
fitTextToSize();
}
QSize WScaleToolButton::sizeHint() const
{
return QSize( fontMetrics().width( m_orgText ) + m_additionalWidth,
QToolButton::sizeHint().height() );
}
QSize WScaleToolButton::minimumSizeHint() const
{
return QSize( fontMetrics().width( m_orgText.left( WMIN_LABEL_LENGTH ) + 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 );
fitTextToSize();
}
void WScaleToolButton::fitTextToSize()
{
int newwidth = width();
QFontMetrics fn = fontMetrics();
if( newwidth < fn.width( m_orgText ) )
{
QString useText = m_orgText.left( m_orgText.length() - 1 );
while( fn.width( useText + tr( ".." ) ) > newwidth || useText.length() == 0 )
{
useText = useText.left( useText.length() - 1 );
}
QToolButton::setText( useText + tr( ".." ) );
}
else
{
QToolButton::setText( m_orgText );
}
}
void WScaleToolButton::addAdditionalWidth( int w )
{
m_additionalWidth = w;
}
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
// For more information see http://www.openwalnut.org/copying
//
// This file is part of OpenWalnut.
//
// OpenWalnut is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// OpenWalnut is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
//
//---------------------------------------------------------------------------
#ifndef WSCALETOOLBUTTON_H
#define WSCALETOOLBUTTON_H
#include <QtGui/QToolButton>
#include <QtCore/QString>
/**
* Special Button that can shrink and expand in a layout
*/
class WScaleToolButton: public QToolButton
{
Q_OBJECT
public:
/**
* Constructor
*
* \param parent the widgets parent
*/
explicit WScaleToolButton( QWidget *parent = NULL );
/**
* Constructor. Creates the button with its original text
*
* \param text text of the button
* \param parent the widgets parent
*/
WScaleToolButton( const QString &text, QWidget *parent = NULL );
/**
* overwritten from QToolButton, returning the widgets prefered size
*
* \return prefered size of the button
*/
virtual QSize sizeHint() const;
/**
* overwritten from QToolButton, returning the widgets prefered size
*
* \return minimum size of the button
*/
virtual QSize minimumSizeHint() const;
/**
* reimplemented function to setText
*
* \param text text of the button
*/
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 QToolButton::setMargin().