Commit 6db23ea6 authored by Sebastian Eichelbaum's avatar Sebastian Eichelbaum

[CHANGE] - now, bool properties are handled by QActions in the gui and the toolbars

parent 6fa7f7db
......@@ -31,6 +31,13 @@ useAutoDisplay = no # automatically add a standard module after loading a data m
toolBarStyle = 0
compatiblesToolBarStyle = 0 # this pref allows the compatibles toolbar to have a different style
# Position of the compatibles toolbar
# 0 -> top
# 1 -> bottom
# 2 -> left
# 3 -> right
compatiblesToolBarPos = 0 # position of the compatibles toolbar
####################################################################
# Dataset Browser
......
......@@ -37,6 +37,13 @@ toolBarIconText = no # show text next to module's icon
toolBarStyle = 0
compatiblesToolBarStyle = 0 # this pref allows the compatibles toolbar to have a different style
# Position of the compatibles toolbar
# 0 -> top
# 1 -> bottom
# 2 -> left
# 3 -> right
compatiblesToolBarPos = 0 # position of the compatibles toolbar
####################################################################
# Dataset Browser
......
......@@ -14,8 +14,10 @@ SET(GUI_QT4_MOC_HDRS
WMainWindow.h
WQtConfigWidget.h
WQtNavGLWidget.h
WQtCombinerToolbar.h
guiElements/WQtPushButton.h
guiElements/WQtApplyModuleAction.h
guiElements/WQtPropertyBoolAction.h
datasetbrowser/WPropertyWidget.h
datasetbrowser/WPropertyBoolWidget.h
datasetbrowser/WPropertyIntWidget.h
......
......@@ -48,6 +48,7 @@
#include "events/WModuleReadyEvent.h"
#include "events/WModuleCrashEvent.h"
#include "events/WEventTypes.h"
#include "guiElements/WQtPropertyBoolAction.h"
#include "datasetbrowser/WPropertyBoolWidget.h"
#include "../../common/WColor.h"
#include "../../common/WPreferences.h"
......@@ -66,6 +67,7 @@
WMainWindow::WMainWindow() :
QMainWindow(),
m_currentCompatiblesToolbar( NULL ),
m_iconManager(),
m_fibLoaded( false )
{
......@@ -82,6 +84,7 @@ void WMainWindow::setupGUI()
m_iconManager.addIcon( std::string( "moduleBusy" ), moduleBusy_xpm );
m_iconManager.addIcon( std::string( "moduleCrashed" ), moduleCrashed_xpm );
m_iconManager.addIcon( std::string( "remove" ), remove_xpm );
m_iconManager.addIcon( std::string( "o" ), o_xpm ); // duumy icon for modules
if( objectName().isEmpty() )
{
......@@ -215,8 +218,6 @@ void WMainWindow::setupGUI()
}
setupPermanentToolBar();
setupCompatiblesToolBar();
}
void WMainWindow::setupPermanentToolBar()
......@@ -263,7 +264,6 @@ void WMainWindow::setupPermanentToolBar()
m_permanentToolBar->addWidget( projectSaveButton );
m_permanentToolBar->addSeparator();
m_permanentToolBar->addWidget( roiButton );
m_permanentToolBar->addSeparator();
addToolBar( Qt::TopToolBarArea, m_permanentToolBar );
......@@ -337,11 +337,11 @@ void WMainWindow::moduleSpecificSetup( boost::shared_ptr< WModule > module )
}
else
{
WPropertyBoolWidget* button = new WPropertyBoolWidget( prop->toPropBool(), NULL, m_permanentToolBar, true );
button->setToolTip( "Toggle Axial Slice" );
button->getButton()->setMaximumSize( 24, 24 );
button->getButton()->setIcon( m_iconManager.getIcon( "axial" ) );
m_permanentToolBar->addWidget( button );
WQtPropertyBoolAction* a = new WQtPropertyBoolAction( prop->toPropBool(), m_permanentToolBar );
a->setToolTip( "Toggle Axial Slice" );
a->setText( "Toggle Axial Slice" );
a->setIcon( m_iconManager.getIcon( "axial" ) );
m_permanentToolBar->addAction( a );
}
prop = module->getProperties()->findProperty( "showCoronal" );
......@@ -353,11 +353,11 @@ void WMainWindow::moduleSpecificSetup( boost::shared_ptr< WModule > module )
}
else
{
WPropertyBoolWidget* button = new WPropertyBoolWidget( prop->toPropBool(), NULL, m_permanentToolBar, true );
button->setToolTip( "Toggle Coronal Slice" );
button->getButton()->setMaximumSize( 24, 24 );
button->getButton()->setIcon( m_iconManager.getIcon( "coronal" ) );
m_permanentToolBar->addWidget( button );
WQtPropertyBoolAction* a = new WQtPropertyBoolAction( prop->toPropBool(), m_permanentToolBar );
a->setToolTip( "Toggle Coronal Slice" );
a->setText( "Toggle Coronal Slice" );
a->setIcon( m_iconManager.getIcon( "coronal" ) );
m_permanentToolBar->addAction( a );
}
prop = module->getProperties()->findProperty( "showSagittal" );
......@@ -369,11 +369,11 @@ void WMainWindow::moduleSpecificSetup( boost::shared_ptr< WModule > module )
}
else
{
WPropertyBoolWidget* button = new WPropertyBoolWidget( prop->toPropBool(), NULL, m_permanentToolBar, true );
button->setToolTip( "Toggle Sagittal Slice" );
button->getButton()->setMaximumSize( 24, 24 );
button->getButton()->setIcon( m_iconManager.getIcon( "sagittal" ) );
m_permanentToolBar->addWidget( button );
WQtPropertyBoolAction* a = new WQtPropertyBoolAction( prop->toPropBool(), m_permanentToolBar );
a->setToolTip( "Toggle Saggital Slice" );
a->setText( "Toggle Saggital Slice" );
a->setIcon( m_iconManager.getIcon( "sagittal" ) );
m_permanentToolBar->addAction( a );
}
// now setup the nav widget sliders
......@@ -438,28 +438,10 @@ Qt::ToolButtonStyle WMainWindow::getToolbarStyle() const
return static_cast< Qt::ToolButtonStyle >( toolBarStyle );
}
Qt::ToolButtonStyle WMainWindow::getCompatiblesToolbarStyle() const
{
// this sets the toolbar style
int compToolBarStyle = getToolbarStyle(); // this defaults to the global toolbar style
WPreferences::getPreference( "qt4gui.compatiblesToolBarStyle", &compToolBarStyle );
if ( ( compToolBarStyle < 0 ) || ( compToolBarStyle > 3 ) ) // ensure a valid value
{
compToolBarStyle = 0;
}
// cast and return
return static_cast< Qt::ToolButtonStyle >( compToolBarStyle );
}
void WMainWindow::setupCompatiblesToolBar()
void WMainWindow::setCompatiblesToolbar( WQtCombinerToolbar* toolbar )
{
m_iconManager.addIcon( std::string( "o" ), o_xpm ); // duumy icon for modules
m_compatiblesToolBar = new WQtToolBar( "Compatible Modules Toolbar", this );
// this sets the toolbar style
m_compatiblesToolBar->setToolButtonStyle( getCompatiblesToolbarStyle() );
delete m_currentCompatiblesToolbar;
m_currentCompatiblesToolbar = toolbar;
// optional toolbar break
{
......@@ -469,13 +451,35 @@ void WMainWindow::setupCompatiblesToolBar()
{
// Blank toolbar for nicer layout in case of toolbar break
// This can be done nicer very probably.
WQtToolBar* blankToolBar = new WQtToolBar( "Blank Toolbar", this );
addToolBar( Qt::TopToolBarArea, blankToolBar );
//WQtToolBar* blankToolBar = new WQtToolBar( "Blank Toolbar", this );
//addToolBar( Qt::TopToolBarArea, blankToolBar );
addToolBarBreak( Qt::TopToolBarArea );
}
}
addToolBar( Qt::TopToolBarArea, m_compatiblesToolBar );
// and the position of the toolbar
int compatiblesToolbarPos = 0;
WPreferences::getPreference( "qt4gui.compatiblesToolBarPos", &compatiblesToolbarPos );
Qt::ToolBarArea pos = Qt::TopToolBarArea;
switch ( compatiblesToolbarPos )
{
case 0:
pos = Qt::TopToolBarArea;
break;
case 1:
pos = Qt::BottomToolBarArea;
break;
case 2:
pos = Qt::LeftToolBarArea;
break;
case 3:
pos = Qt::RightToolBarArea;
break;
default:
pos = Qt::TopToolBarArea;
break;
}
addToolBar( pos, m_currentCompatiblesToolbar );
}
WQtDatasetBrowser* WMainWindow::getDatasetBrowser()
......@@ -483,11 +487,6 @@ WQtDatasetBrowser* WMainWindow::getDatasetBrowser()
return m_datasetBrowser;
}
WQtToolBar* WMainWindow::getCompatiblesToolBar()
{
return m_compatiblesToolBar;
}
void WMainWindow::projectSave( const std::vector< boost::shared_ptr< WProjectFileIO > >& writer )
{
QFileDialog fd;
......
......@@ -45,6 +45,7 @@
#include "ribbonMenu/WQtRibbonMenu.h"
#include "WQtCustomDockWidget.h"
#include "WQtToolBar.h"
#include "WQtCombinerToolbar.h"
#include "WIconManager.h"
#include "datasetbrowser/WQtDatasetBrowser.h"
......@@ -86,11 +87,6 @@ public:
*/
WQtRibbonMenu* getRibbonMenu();
/**
* returns a pointer to the tool bar showing the compatible modules
*/
WQtToolBar* getCompatiblesToolBar();
/**
* Return icon manager
*/
......@@ -127,12 +123,11 @@ public:
Qt::ToolButtonStyle getToolbarStyle() const;
/**
* This method returns the default style for the compatibles toolbar. It allows modification of the style for especially for the compatibles
* toolbar.
* This method removes the old compatibles toolbar and sets the specified one.
*
* \return the toolbar style for the compatibles toolbar
* \param toolbar the toolbar to set. If NULL, the toolbar gets reset.
*/
Qt::ToolButtonStyle getCompatiblesToolbarStyle() const;
void setCompatiblesToolbar( WQtCombinerToolbar* toolbar = NULL );
protected:
......@@ -239,9 +234,9 @@ private:
void setupPermanentToolBar();
/**
* Sets up the initial state of the tool bar showing the compatible modules
* The currently set compatibles toolbar
*/
void setupCompatiblesToolBar();
WQtCombinerToolbar* m_currentCompatiblesToolbar;
WIconManager m_iconManager; //!< manager to provide icons in the gui thread
......@@ -251,8 +246,6 @@ private:
WQtToolBar* m_permanentToolBar; //!< The permanent toolbar of the main window.
WQtToolBar* m_compatiblesToolBar; //!< This toolbar shows the compatible modules if a module is selected in the dataset browser
WQtDatasetBrowser* m_datasetBrowser; //!< dataset browser
boost::shared_ptr<WQtGLWidget> m_mainGLWidget; //!< the main GL widget of the GUI
......
//---------------------------------------------------------------------------
//
// 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 <list>
#include <QtGui/QAction>
#include <QtGui/QPushButton>
#include <QtGui/QMenu>
#include "../../common/WPreferences.h"
#include "WMainWindow.h"
#include "WQtToolBar.h"
#include "guiElements/WQtApplyModuleAction.h"
#include "WQtCombinerToolbar.h"
WQtCombinerToolbar::WQtCombinerToolbar( WMainWindow* parent, WModuleFactory::CompatiblesList compatibles )
: QToolBar( "Compatible Modules", parent )
{
// setup toolbar
setAllowedAreas( Qt::AllToolBarAreas );
// this sets the toolbar style
int compToolBarStyle = parent->getToolbarStyle(); // this defaults to the global toolbar style
WPreferences::getPreference( "qt4gui.compatiblesToolBarStyle", &compToolBarStyle );
if ( ( compToolBarStyle < 0 ) || ( compToolBarStyle > 3 ) ) // ensure a valid value
{
compToolBarStyle = 0;
}
// cast and set
setToolButtonStyle( static_cast< Qt::ToolButtonStyle >( compToolBarStyle ) );
// create an action for each group:
for ( WModuleFactory::CompatiblesList::const_iterator groups = compatibles.begin(); groups != compatibles.end(); ++groups )
{
// create a new action for this group
WQtApplyModuleAction* group = new WQtApplyModuleAction( this,
parent->getIconManager(),
*( *groups ).second.begin() );
addAction( group );
// only add a sub menu if there are more than 1 items in the group
if ( ( *groups ).second.size() > 1 )
{
QMenu* groupMenu = new QMenu( this );
// iterate all the children
for ( WModuleFactory::CompatibleCombiners::const_iterator combiner = ( *groups ).second.begin();
combiner != ( *groups ).second.end(); ++combiner )
{
WQtApplyModuleAction* a = new WQtApplyModuleAction( this,
parent->getIconManager(),
( *combiner ),
true );
a->setIconVisibleInMenu( true );
groupMenu->addAction( a );
}
group->setMenu( groupMenu );
}
}
// The following makes the bar having button size from the beginning.
QPushButton* dummyButton = new QPushButton;
dummyButton->setFixedWidth( 0 );
addWidget( dummyButton );
}
WQtCombinerToolbar::~WQtCombinerToolbar()
{
}
//---------------------------------------------------------------------------
//
// 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 WQTCOMBINERTOOLBAR_H
#define WQTCOMBINERTOOLBAR_H
#include <QtGui/QToolBar>
#include "../../kernel/WModuleFactory.h"
class WMainWindow;
/**
* This is a toolbar. Its main usage for now is the "compatible modules" toolbar.
*/
class WQtCombinerToolbar : public QToolBar
{
Q_OBJECT
public:
/**
* Constructs the toolbar.
* \param parent the parent widget of this widget, i.e. the widget that manages it.
* \param compatibles the list of combiners
*/
explicit WQtCombinerToolbar( WMainWindow* parent, WModuleFactory::CompatiblesList compatibles );
/**
* destructor
*/
virtual ~WQtCombinerToolbar();
protected:
private:
};
#endif // WQTCOMBINERTOOLBAR_H
......@@ -269,6 +269,10 @@ void WQtConfigWidget::registerComponents()
tbs->setMax( 3 );
ctbs->setMin( 0 );
ctbs->setMax( 3 );
WPropInt ctbpos = m_defaultProperties->addProperty( "qt4gui.compatiblesToolBarPos", "The position of the compatibles toolbar in OpenWalnut", 0,
m_propCondition );
ctbpos->setMin( 0 );
ctbpos->setMax( 3 );
WPropGroup moduleWhiteList = m_defaultProperties->addPropertyGroup( "modules.whiteListGroup", "moduleWhiteList" );
m_skipPropertyWrite.push_back( "modules.whiteListGroup" );
......
......@@ -24,6 +24,8 @@
#include <list>
#include <QtGui/QAction>
#include "WQtToolBar.h"
WQtToolBar::WQtToolBar( const QString & title, QWidget* parent )
......
......@@ -26,29 +26,19 @@
#include "../../../common/WPropertyVariable.h"
WPropertyBoolWidget::WPropertyBoolWidget( WPropBool property, QGridLayout* propertyGrid, QWidget* parent, bool asButton ):
WPropertyBoolWidget::WPropertyBoolWidget( WPropBool property, QGridLayout* propertyGrid, QWidget* parent ):
WPropertyWidget( property, propertyGrid, parent ),
m_boolProperty( property ),
m_checkbox( &m_parameterWidgets ),
m_button( &m_parameterWidgets ),
m_layout( &m_parameterWidgets ),
m_asButton( asButton ),
m_asText( &m_informationWidgets ),
m_infoLayout( &m_informationWidgets )
{
// initialize members
m_button.setCheckable( true );
update();
// layout both against each other
m_button.setVisible( m_asButton );
m_checkbox.setVisible( !m_asButton );
m_layout.addWidget( m_asButton ? static_cast< QWidget* >( &m_button ) : static_cast< QWidget* >( &m_checkbox ) );
if ( m_asButton )
{
m_layout.setContentsMargins( 1, 1, 1, 1 );
}
m_layout.addWidget( static_cast< QWidget* >( &m_checkbox ) );
m_parameterWidgets.setLayout( &m_layout );
// Information Output ( Property Purpose = PV_PURPOSE_INFORMATION )
......@@ -56,8 +46,7 @@ WPropertyBoolWidget::WPropertyBoolWidget( WPropBool property, QGridLayout* prope
m_informationWidgets.setLayout( &m_infoLayout );
// connect the modification signal of m_checkbox with our callback
connect( &m_checkbox, SIGNAL( toggled( bool ) ), this, SLOT( changed() ) );
connect( &m_button, SIGNAL( toggled( bool ) ), this, SLOT( changed() ) );
connect( &m_checkbox, SIGNAL( toggled( bool ) ), this, SLOT( checkboxChanged() ) );
}
WPropertyBoolWidget::~WPropertyBoolWidget()
......@@ -69,25 +58,12 @@ void WPropertyBoolWidget::update()
{
// simply set the new state
m_checkbox.setChecked( m_boolProperty->get() );
m_button.setChecked( m_boolProperty->get() );
m_asText.setText( m_boolProperty->get() ? QString( "Yes" ) : QString( "No" ) );
}
QPushButton* WPropertyBoolWidget::getButton()
void WPropertyBoolWidget::checkboxChanged()
{
return &m_button;
}
void WPropertyBoolWidget::changed()
{
// set the value
if ( m_asButton )
{
invalidate( !m_boolProperty->set( m_button.isChecked() ) );
}
else
{
invalidate( !m_boolProperty->set( m_checkbox.isChecked() ) );
}
invalidate( !m_boolProperty->set( m_checkbox.isChecked() ) );
m_checkbox.setChecked( m_boolProperty->get() );
}
......@@ -28,7 +28,7 @@
#include <string>
#include <QtGui/QCheckBox>
#include <QtGui/QPushButton>
#include <QtGui/QAction>
#include <QtGui/QHBoxLayout>
#include "WPropertyWidget.h"
......@@ -47,23 +47,14 @@ public:
* \param property the property to handle
* \param parent the parent widget.
* \param propertyGrid the grid used to layout the labels and property widgets
* \param asButton display the property as toggle button.
*/
WPropertyBoolWidget( WPropBool property, QGridLayout* propertyGrid, QWidget* parent = 0, bool asButton = false );
WPropertyBoolWidget( WPropBool property, QGridLayout* propertyGrid, QWidget* parent = 0 );
/**
* Destructor.
*/
virtual ~WPropertyBoolWidget();
/**
* Returns the QT PushButton widget used if asButton has been true. It always returns a valid pointer. If asButtons has been false, the
* button is simply not visible.
*
* \return the button
*/
virtual QPushButton* getButton();
protected:
/**
......@@ -81,21 +72,11 @@ protected:
*/
QCheckBox m_checkbox;
/**
* If asButton is set to true: use this button instead of the m_checkbox
*/
QPushButton m_button;
/**
* Layout used to position the label and the checkbox
*/
QHBoxLayout m_layout;
/**
* Use the button instead of the checkbox to toggle the value.
*/
bool m_asButton;
/**
* Used to show the property as text.
*/
......@@ -111,9 +92,10 @@ private:
public slots:
/**
* called whenever the user modifies the widget
* called whenever the user modifies the checkbox
*/
void changed();
void checkboxChanged();
};
#endif // WPROPERTYBOOLWIDGET_H
......
......@@ -469,13 +469,13 @@ void WQtDatasetBrowser::selectTreeItem()
{
// TODO(schurade): qt doc says clear() doesn't delete tabs so this is possibly a memory leak
m_tabWidget->clear();
// the WQtToolbar also deletes the buttons!
m_mainWindow->getCompatiblesToolBar()->clearButtons();
boost::shared_ptr< WModule > module;
boost::shared_ptr< WProperties > props;
boost::shared_ptr< WProperties > infoProps;
WQtCombinerToolbar* newToolbar = NULL;
if ( m_moduleTreeWidget->selectedItems().size() != 0 )
{
// disable delete action for tree items that have children.
......@@ -494,7 +494,7 @@ void WQtDatasetBrowser::selectTreeItem()
case MODULEHEADER:
// deletion of headers and subjects is not allowed
m_deleteModuleAction->setEnabled( false );
createCompatibleButtons( module ); // module is NULL at this point
newToolbar = createCompatibleButtons( module ); // module is NULL at this point
break;
case DATASET:
module = ( static_cast< WQtDatasetTreeItem* >( m_moduleTreeWidget->selectedItems().at( 0 ) ) )->getModule();
......@@ -506,7 +506,7 @@ void WQtDatasetBrowser::selectTreeItem()
props = module->getProperties();
infoProps = module->getInformationProperties();
createCompatibleButtons( module );
newToolbar = createCompatibleButtons( module );
{
boost::shared_ptr< WMData > dataModule = boost::shared_dynamic_cast< WMData >( module );
......@@ -541,7 +541,7 @@ void WQtDatasetBrowser::selectTreeItem()
}
props = module->getProperties();
infoProps = module->getInformationProperties();
createCompatibleButtons( module );
newToolbar = createCompatibleButtons( module );
break;
case ROIHEADER:
case ROIBRANCH:
......@@ -551,6 +551,11 @@ void WQtDatasetBrowser::selectTreeItem()
break;
}
}
// set the new toolbar
// NOTE: setCompatiblesToolbar removes the toolbar if NULL is specified.
m_mainWindow->setCompatiblesToolbar( newToolbar );
buildPropTab( props, infoProps );
}
......@@ -558,7 +563,7 @@ void WQtDatasetBrowser::selectRoiTreeItem()
{
// TODO(schurade): qt doc says clear() doesn't delete tabs so this is possibly a memory leak
m_tabWidget->clear();
m_mainWindow->getCompatiblesToolBar()->clearButtons();
m_mainWindow->setCompatiblesToolbar();
boost::shared_ptr< WModule > module;
boost::shared_ptr< WProperties > props;
......@@ -701,39 +706,12 @@ void WQtDatasetBrowser::buildPropTab( boost::shared_ptr< WProperties > props, bo
}
}