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

[CHANGE] made further layout improvements with automatically downscaling...

[CHANGE] made further layout improvements with automatically downscaling buttons; prepared propertygroupwidget to be used separately to allow opening the properties of a widget separately
parent 09be500c
......@@ -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, 0, this );
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, 0, this );
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
......@@ -429,7 +430,7 @@ private slots:
* \param props the properties.
* \param infoProps the information properties shown on a separate tab
*/
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"
......@@ -169,10 +170,14 @@ void WQtPropertyGroupWidget::addGroup( WPropertyGroupBase::SPtr 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();
......@@ -189,7 +194,7 @@ 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 );
box->setObjectName( "PropertyGroupBox" );
QGridLayout* boxLayout = new QGridLayout();
......@@ -198,8 +203,10 @@ void WQtPropertyGroupWidget::addGroup( WQtPropertyGroupWidget* widget, bool asSc
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
......@@ -215,9 +222,6 @@ void WQtPropertyGroupWidget::addGroup( WQtPropertyGroupWidget* widget, bool asSc
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 );
......@@ -273,10 +277,10 @@ void WQtPropertyGroupWidget::addGroup( WQtPropertyGroupWidget* widget, bool asSc
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 )
......@@ -288,14 +292,21 @@ void WQtPropertyGroupWidget::addGroup( WQtPropertyGroupWidget* widget, bool asSc
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;
}
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;
}
......
......@@ -64,6 +64,19 @@ public:
*/
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 = "" );
/**
* destructor
*/
......
//---------------------------------------------------------------------------
//
// 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().
*
* \param margin the margin to keep in mind for size calculations
*/
virtual void addAdditionalWidth( int margin );
protected:
/**
* custom implementation of the resize event
* to fit the QString into the butons current size
*
* \param event resize event passed from the parent widgets event handling
*/
virtual void resizeEvent( QResizeEvent * event );
private:
/**
* set the actual text which is shown on the QToolButton
*/
void fitTextToSize();
/**
* 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 // 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