From 41695176c748943485f8844fea6e89cef9a0b6f5 Mon Sep 17 00:00:00 2001 From: asl Date: Mon, 10 Aug 2015 15:04:25 +0300 Subject: [PATCH] Issue #624: vertical buttons in switcher are implemented as a row of toolbuttons --- src/Config/Config_Keywords.h | 1 + src/ConstructionPlugin/axis_widget.xml | 4 +- src/FeaturesPlugin/extrusion_widget.xml | 4 +- src/FeaturesPlugin/extrusioncut_widget.xml | 4 +- src/FeaturesPlugin/extrusionfuse_widget.xml | 4 +- src/FeaturesPlugin/revolution_widget.xml | 4 +- src/FeaturesPlugin/revolutioncut_widget.xml | 4 +- src/FeaturesPlugin/revolutionfuse_widget.xml | 4 +- src/ModuleBase/CMakeLists.txt | 2 + src/ModuleBase/ModuleBase_PagedContainer.cpp | 3 +- src/ModuleBase/ModuleBase_PagedContainer.h | 7 +- src/ModuleBase/ModuleBase_ToolBox.cpp | 75 ++++++++++++++++++++ src/ModuleBase/ModuleBase_ToolBox.h | 43 +++++++++++ src/ModuleBase/ModuleBase_WidgetFactory.cpp | 5 +- src/ModuleBase/ModuleBase_WidgetSwitch.cpp | 5 +- src/ModuleBase/ModuleBase_WidgetSwitch.h | 6 +- src/ModuleBase/ModuleBase_WidgetToolbox.cpp | 13 ++-- src/ModuleBase/ModuleBase_WidgetToolbox.h | 11 +-- 18 files changed, 168 insertions(+), 31 deletions(-) create mode 100644 src/ModuleBase/ModuleBase_ToolBox.cpp create mode 100644 src/ModuleBase/ModuleBase_ToolBox.h diff --git a/src/Config/Config_Keywords.h b/src/Config/Config_Keywords.h index f16d08ed5..4a3943213 100644 --- a/src/Config/Config_Keywords.h +++ b/src/Config/Config_Keywords.h @@ -77,6 +77,7 @@ const static char* DOUBLE_WDG_STEP = "step"; const static char* DOUBLE_WDG_DEFAULT_COMPUTED = "computed"; // WDG_TOOLBOX/WDG_SWITCH properties const static char* CONTAINER_PAGE_NAME = "title"; +const static char* CONTAINER_PAGE_ICON = "icon"; /* * Hardcoded xml entities of plugins.xml diff --git a/src/ConstructionPlugin/axis_widget.xml b/src/ConstructionPlugin/axis_widget.xml index 86afa3473..72d12f740 100644 --- a/src/ConstructionPlugin/axis_widget.xml +++ b/src/ConstructionPlugin/axis_widget.xml @@ -2,7 +2,7 @@ - + - + - + - + - + - + - + - + - + - + - + - + - + - + getControls() const; virtual bool focusTo(); diff --git a/src/ModuleBase/ModuleBase_ToolBox.cpp b/src/ModuleBase/ModuleBase_ToolBox.cpp new file mode 100644 index 000000000..0af3267b1 --- /dev/null +++ b/src/ModuleBase/ModuleBase_ToolBox.cpp @@ -0,0 +1,75 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: ModuleBase_ToolBox.cpp +// Created: 10 August 2015 +// Author: Alexandre SOLOVYOV + +#include +#include +#include +#include +#include +#include + +ModuleBase_ToolBox::ModuleBase_ToolBox( QWidget* theParent ) + : QFrame( theParent ) +{ + QVBoxLayout* aMainLayout = new QVBoxLayout( this ); + aMainLayout->setMargin( 0 ); + aMainLayout->setSpacing( 0 ); + + myButtonsFrame = new QFrame( this ); + myStack = new QStackedWidget( this ); + aMainLayout->addWidget( myButtonsFrame, 0 ); + aMainLayout->addWidget( myStack, 1 ); + + myButtonsGroup = new QButtonGroup(); + myButtonsGroup->setExclusive( true ); + myButtonsLayout = new QHBoxLayout( myButtonsFrame ); + myButtonsLayout->setMargin( 0 ); + myButtonsLayout->setSpacing( 5 ); + myButtonsLayout->addStretch( 1 ); + + connect( myStack, SIGNAL( currentChanged( int ) ), this, SIGNAL( currentChanged( int ) ) ); + connect( myButtonsGroup, SIGNAL( buttonPressed( int ) ), this, SLOT( onButton( int ) ) ); +} + +ModuleBase_ToolBox::~ModuleBase_ToolBox() +{ +} + +void ModuleBase_ToolBox::addItem( QWidget* thePage, const QString& theName, const QIcon& theIcon ) +{ + int anOldCount = myStack->count(); + + myStack->addWidget( thePage ); + + QToolButton* aButton = new QToolButton( myButtonsFrame ); + aButton->setCheckable( true ); + aButton->setIcon( theIcon ); + aButton->setToolTip( theName ); + myButtonsGroup->addButton( aButton, anOldCount ); + myButtonsLayout->insertWidget( anOldCount, aButton ); +} + +int ModuleBase_ToolBox::count() const +{ + return myStack->count(); +} + +int ModuleBase_ToolBox::currentIndex() const +{ + return myStack->currentIndex(); +} + +void ModuleBase_ToolBox::setCurrentIndex( const int theIndex ) +{ + myStack->setCurrentIndex( theIndex ); + myButtonsGroup->button( theIndex )->setChecked( true ); +} + +void ModuleBase_ToolBox::onButton( int theIndex ) +{ + myStack->setCurrentIndex( theIndex ); +} + diff --git a/src/ModuleBase/ModuleBase_ToolBox.h b/src/ModuleBase/ModuleBase_ToolBox.h new file mode 100644 index 000000000..2b48b0849 --- /dev/null +++ b/src/ModuleBase/ModuleBase_ToolBox.h @@ -0,0 +1,43 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: ModuleBase_ToolBox.h +// Created: 10 August 2015 +// Author: Alexandre SOLOVYOV + +#ifndef ModuleBase_ToolBox_H +#define ModuleBase_ToolBox_H + +#include +#include + +class QButtonGroup; +class QFrame; +class QHBoxLayout; +class QStackedWidget; + +class MODULEBASE_EXPORT ModuleBase_ToolBox : public QFrame +{ + Q_OBJECT + +public: + ModuleBase_ToolBox( QWidget* theParent ); + virtual ~ModuleBase_ToolBox(); + + void addItem( QWidget* thePage, const QString& theName, const QIcon& theIcon ); + int count() const; + int currentIndex() const; + void setCurrentIndex( const int ); + +signals: + void currentChanged( int ); + +private slots: + void onButton( int ); + +private: + QButtonGroup* myButtonsGroup; + QFrame* myButtonsFrame; + QHBoxLayout* myButtonsLayout; + QStackedWidget* myStack; +}; +#endif diff --git a/src/ModuleBase/ModuleBase_WidgetFactory.cpp b/src/ModuleBase/ModuleBase_WidgetFactory.cpp index 2e2290491..85fb353a7 100644 --- a/src/ModuleBase/ModuleBase_WidgetFactory.cpp +++ b/src/ModuleBase/ModuleBase_WidgetFactory.cpp @@ -104,7 +104,10 @@ void ModuleBase_WidgetFactory::createWidget(ModuleBase_PageBase* thePage) createWidget(aPage); if (aWdgType == WDG_SWITCH || aWdgType == WDG_TOOLBOX) { ModuleBase_PagedContainer* aContainer = qobject_cast(aWidget); - aContainer->addPage(aPage, aPageName, aCaseId); + + QString anIconPath = qs( myWidgetApi->getProperty( CONTAINER_PAGE_ICON ) ); + QIcon anIcon( anIconPath ); + aContainer->addPage( aPage, aPageName, aCaseId, anIcon ); } } while (myWidgetApi->toNextWidget()); } diff --git a/src/ModuleBase/ModuleBase_WidgetSwitch.cpp b/src/ModuleBase/ModuleBase_WidgetSwitch.cpp index 31deb0e98..0df6f7ebf 100644 --- a/src/ModuleBase/ModuleBase_WidgetSwitch.cpp +++ b/src/ModuleBase/ModuleBase_WidgetSwitch.cpp @@ -42,9 +42,10 @@ ModuleBase_WidgetSwitch::~ModuleBase_WidgetSwitch() int ModuleBase_WidgetSwitch::addPage(ModuleBase_PageBase* thePage, const QString& theName, - const QString& theCaseId) + const QString& theCaseId, + const QIcon& theIcon ) { - int aSuperCount = ModuleBase_PagedContainer::addPage(thePage, theName, theCaseId); + int aSuperCount = ModuleBase_PagedContainer::addPage(thePage, theName, theCaseId, theIcon); myCombo->addItem(theName); int aResultCount = myCombo->count(); if (aResultCount == 2) diff --git a/src/ModuleBase/ModuleBase_WidgetSwitch.h b/src/ModuleBase/ModuleBase_WidgetSwitch.h index fe89a0749..a1cec7a77 100644 --- a/src/ModuleBase/ModuleBase_WidgetSwitch.h +++ b/src/ModuleBase/ModuleBase_WidgetSwitch.h @@ -38,8 +38,10 @@ class MODULEBASE_EXPORT ModuleBase_WidgetSwitch : public ModuleBase_PagedContain /// Add a page to the widget /// \param theWidget a page widget /// \param theName a name of page - virtual int addPage(ModuleBase_PageBase* theWidget, - const QString& theName, const QString& theCaseId); + virtual int addPage( ModuleBase_PageBase* theWidget, + const QString& theName, + const QString& theCaseId, + const QIcon& theIcon ); protected: virtual int currentPageIndex() const; diff --git a/src/ModuleBase/ModuleBase_WidgetToolbox.cpp b/src/ModuleBase/ModuleBase_WidgetToolbox.cpp index 6a16aa3d2..829afea9e 100644 --- a/src/ModuleBase/ModuleBase_WidgetToolbox.cpp +++ b/src/ModuleBase/ModuleBase_WidgetToolbox.cpp @@ -9,12 +9,14 @@ #include #include #include +#include #include #include #include #include +#include ModuleBase_WidgetToolbox::ModuleBase_WidgetToolbox(QWidget* theParent, const Config_WidgetAPI* theData, const std::string& theParentId) @@ -22,8 +24,9 @@ ModuleBase_WidgetToolbox::ModuleBase_WidgetToolbox(QWidget* theParent, const Con { QVBoxLayout* aMainLayout = new QVBoxLayout(this); ModuleBase_Tools::zeroMargins(aMainLayout); - myToolBox = new QToolBox(this); + myToolBox = new ModuleBase_ToolBox(this); // Dark-grey rounded tabs with button-like border #and bold font + // TODO: apply style to custom widget QString css = "QToolBox::tab{background-color:#c8c8c8;" "border-radius:5px;" "border:1px inset;" @@ -41,13 +44,15 @@ ModuleBase_WidgetToolbox::~ModuleBase_WidgetToolbox() } int ModuleBase_WidgetToolbox::addPage(ModuleBase_PageBase* thePage, - const QString& theName, const QString& theCaseId) + const QString& theName, + const QString& theCaseId, + const QIcon& theIcon ) { - ModuleBase_PagedContainer::addPage(thePage, theName, theCaseId); + ModuleBase_PagedContainer::addPage(thePage, theName, theCaseId, theIcon); QFrame* aFrame = dynamic_cast(thePage); aFrame->setFrameShape(QFrame::Box); aFrame->setFrameStyle(QFrame::Sunken); - myToolBox->addItem(aFrame, theName); + myToolBox->addItem(aFrame, theName, theIcon ); return myToolBox->count(); } diff --git a/src/ModuleBase/ModuleBase_WidgetToolbox.h b/src/ModuleBase/ModuleBase_WidgetToolbox.h index b315e5d3a..29c52d140 100644 --- a/src/ModuleBase/ModuleBase_WidgetToolbox.h +++ b/src/ModuleBase/ModuleBase_WidgetToolbox.h @@ -11,9 +11,8 @@ #include #include -#include - class ModuleBase_PageBase; +class ModuleBase_ToolBox; class MODULEBASE_EXPORT ModuleBase_WidgetToolbox : public ModuleBase_PagedContainer { @@ -28,8 +27,10 @@ class MODULEBASE_EXPORT ModuleBase_WidgetToolbox : public ModuleBase_PagedContai virtual bool canSetValue() const { return false; }; /// Overrides ModuleBase_PagedContainer - int addPage(ModuleBase_PageBase* theWidget, - const QString& theName, const QString& theCaseId); + virtual int addPage( ModuleBase_PageBase* theWidget, + const QString& theName, + const QString& theCaseId, + const QIcon& theIcon ); protected: /// Implements ModuleBase_PagedContainer @@ -38,7 +39,7 @@ class MODULEBASE_EXPORT ModuleBase_WidgetToolbox : public ModuleBase_PagedContai virtual void setCurrentPageIndex(int); private: - QToolBox* myToolBox; + ModuleBase_ToolBox* myToolBox; }; #endif /* MODULEBASE_WIDGETTOOLBOX_H_ */ -- 2.39.2