Salome HOME
Issue #624: vertical buttons in switcher are implemented as a row of toolbuttons
authorasl <asl@opencascade.com>
Mon, 10 Aug 2015 12:04:25 +0000 (15:04 +0300)
committerasl <asl@opencascade.com>
Mon, 10 Aug 2015 12:04:42 +0000 (15:04 +0300)
18 files changed:
src/Config/Config_Keywords.h
src/ConstructionPlugin/axis_widget.xml
src/FeaturesPlugin/extrusion_widget.xml
src/FeaturesPlugin/extrusioncut_widget.xml
src/FeaturesPlugin/extrusionfuse_widget.xml
src/FeaturesPlugin/revolution_widget.xml
src/FeaturesPlugin/revolutioncut_widget.xml
src/FeaturesPlugin/revolutionfuse_widget.xml
src/ModuleBase/CMakeLists.txt
src/ModuleBase/ModuleBase_PagedContainer.cpp
src/ModuleBase/ModuleBase_PagedContainer.h
src/ModuleBase/ModuleBase_ToolBox.cpp [new file with mode: 0644]
src/ModuleBase/ModuleBase_ToolBox.h [new file with mode: 0644]
src/ModuleBase/ModuleBase_WidgetFactory.cpp
src/ModuleBase/ModuleBase_WidgetSwitch.cpp
src/ModuleBase/ModuleBase_WidgetSwitch.h
src/ModuleBase/ModuleBase_WidgetToolbox.cpp
src/ModuleBase/ModuleBase_WidgetToolbox.h

index f16d08ed57cea9ae83f94654b9a7ac2f2e56d558..4a39432139760c4e7fca8f5b8411cb537822669a 100644 (file)
@@ -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
index 86afa347385f6d33e9e0d53579d30f94aeb772cf..72d12f740c90f1aaef7903e33bebf90210e166bf 100644 (file)
@@ -2,7 +2,7 @@
 
 <source>
   <toolbox id="CreationMethod">
-    <box id="AxisByPointsCase" title="By two points">
+    <box id="AxisByPointsCase" title="By two points" icon=":icons/point.png">
       <shape_selector id="FirstPoint"
         label="First point"
         icon=":icons/point.png"
@@ -21,7 +21,7 @@
         <validator id="PartSet_DifferentShapes"/>
       </shape_selector>
     </box>
-    <box id="AxisByCylindricalFaceCase" title="As axis of cylindrical face">
+    <box id="AxisByCylindricalFaceCase" title="As axis of cylindrical face" icon=":icons/circle.png">
       <shape_selector id="CylindricalFace"
         label="Main object" 
         icon=":icons/circle.png" 
index 12e7181a74323205261825f0a3aa0e0e17e68a2a..95bc4841bc4548de04bdf05f6c6b71f554a6268d 100644 (file)
@@ -9,7 +9,7 @@
     <validator id="PartSet_SketchEntityValidator" parameters="Sketch"/>
   </multi_selector>
   <toolbox id="CreationMethod">
-    <box id="BySizes" title="By sizes">
+    <box id="BySizes" title="By sizes" icon=":icons/dimension_up.png">
       <groupbox>
         <doublevalue
           id="to_size"
@@ -33,7 +33,7 @@
         </doublevalue>
       </groupbox>
     </box>
-    <box id="ByPlanesAndOffsets" title="By bounding planes and offsets">
+    <box id="ByPlanesAndOffsets" title="By bounding planes and offsets" icon=":icons/plane_inverted.png">
       <groupbox title="To">
         <shape_selector id="to_object"
                         icon=":icons/plane_inverted.png"
index 9d749ae27d0329efa2cd611d73b87026d34c8723..078a77c2c3deec28e31053f8212833d51eba936c 100755 (executable)
@@ -8,7 +8,7 @@
       tooltip="Create or edit a sketch">
     </sketch_launcher>
     <toolbox id="CreationMethod">
-      <box id="BySizes" title="By sizes">
+      <box id="BySizes" title="By sizes" icon=":icons/dimension_up.png">
         <groupbox>
           <doublevalue
             id="to_size"
@@ -32,7 +32,7 @@
           </doublevalue>
         </groupbox>
       </box>
-      <box id="ByPlanesAndOffsets" title="By bounding planes and offsets">
+      <box id="ByPlanesAndOffsets" title="By bounding planes and offsets" icon=":icons/plane_inverted.png">
         <groupbox title="To">
           <shape_selector id="to_object"
                           icon=":icons/plane_inverted.png"
index 380dd7692a35aa43fc0aabad40df141e0409c4af..f80bdd18712ae5800625de48ab68caef19abc137 100644 (file)
@@ -8,7 +8,7 @@
       tooltip="Create or edit a sketch">
     </sketch_launcher>
     <toolbox id="CreationMethod">
-      <box id="BySizes" title="By sizes">
+      <box id="BySizes" title="By sizes" icon=":icons/dimension_up.png">
         <groupbox>
           <doublevalue
             id="to_size"
@@ -32,7 +32,7 @@
           </doublevalue>
         </groupbox>
       </box>
-      <box id="ByPlanesAndOffsets" title="By bounding planes and offsets">
+      <box id="ByPlanesAndOffsets" title="By bounding planes and offsets" icon=":icons/plane_inverted.png">
         <groupbox title="To">
           <shape_selector id="to_object"
                           icon=":icons/plane_inverted.png"
index 47b5ee04e7c4344daba778d77ee3d217ceb71f8f..b956fed62c93ec7fdd0440e1e32b7ff0f31d8cd4 100644 (file)
@@ -17,7 +17,7 @@
     <validator id="GeomValidators_ShapeType" parameters="line"/>
   </shape_selector>
   <toolbox id="CreationMethod">
-    <box id="ByAngles" title="By angles">
+    <box id="ByAngles" title="By angles" icon=":icons/angle_up.png">
       <groupbox>
         <doublevalue
           id="to_angle"
@@ -41,7 +41,7 @@
         </doublevalue>
       </groupbox>
     </box>
-    <box id="ByPlanesAndOffsets" title="By bounding planes and offsets">
+    <box id="ByPlanesAndOffsets" title="By bounding planes and offsets" icon=":icons/plane_inverted.png">
       <groupbox title="To">
         <shape_selector id="to_object"
                         icon=":icons/plane_inverted.png"
index 32218ce9c9757b12965975d85a4226d880f8b8b2..5b7c9155eb39141e37a4c914d8f4445852672f3d 100644 (file)
@@ -16,7 +16,7 @@
       <validator id="GeomValidators_ShapeType" parameters="line"/>
     </shape_selector>
     <toolbox id="CreationMethod">
-      <box id="ByAngles" title="By angles">
+      <box id="ByAngles" title="By angles" icon=":icons/angle_up.png">
         <groupbox>
           <doublevalue
             id="to_angle"
@@ -40,7 +40,7 @@
           </doublevalue>
         </groupbox>
       </box>
-      <box id="ByPlanesAndOffsets" title="By bounding planes and offsets">
+      <box id="ByPlanesAndOffsets" title="By bounding planes and offsets" icon=":icons/plane_inverted.png">
         <groupbox title="To">
           <shape_selector id="to_object"
                           icon=":icons/plane_inverted.png"
index 599058cb40cd6f5e3d3833c495c40b7c40bb881c..047090f822737014d50d934157539437127f136a 100644 (file)
@@ -16,7 +16,7 @@
       <validator id="GeomValidators_ShapeType" parameters="line"/>
     </shape_selector>
     <toolbox id="CreationMethod">
-      <box id="ByAngles" title="By angles">
+      <box id="ByAngles" title="By angles" icon=":icons/angle_up.png">
         <groupbox>
           <doublevalue
             id="to_angle"
@@ -40,7 +40,7 @@
           </doublevalue>
         </groupbox>
       </box>
-      <box id="ByPlanesAndOffsets" title="By bounding planes and offsets">
+      <box id="ByPlanesAndOffsets" title="By bounding planes and offsets" icon=":icons/plane_inverted.png">
         <groupbox title="To">
           <shape_selector id="to_object"
                           icon=":icons/plane_inverted.png"
index 5e76d8985043eef36cecc2c057fd6f5a6a686f10..fd928e6ef0038c7538f37f9d4dbd491db523e08d 100644 (file)
@@ -31,6 +31,7 @@ SET(PROJECT_HEADERS
   ModuleBase_Preferences.h
   ModuleBase_ResultPrs.h
   ModuleBase_SelectionValidator.h
+  ModuleBase_ToolBox.h
   ModuleBase_Tools.h
   ModuleBase_ViewerFilters.h
   ModuleBase_ViewerPrs.h
@@ -79,6 +80,7 @@ SET(PROJECT_SOURCES
   ModuleBase_Preferences.cpp
   ModuleBase_ResultPrs.cpp
   ModuleBase_SelectionValidator.cpp
+  ModuleBase_ToolBox.cpp
   ModuleBase_Tools.cpp
   ModuleBase_ViewerFilters.cpp
   ModuleBase_ViewerPrs.cpp
index c4c3623ccd898aae53e8248bfdcce3e4d67c46a8..87ef65afa4d3c8949c8a93e74008133fd9c4ed49 100644 (file)
@@ -29,7 +29,8 @@ ModuleBase_PagedContainer::~ModuleBase_PagedContainer()
 }
 
 int ModuleBase_PagedContainer::addPage(ModuleBase_PageBase* thePage,
-                                      const QString& theName, const QString& theCaseId)
+                                      const QString& theName, const QString& theCaseId,
+                                      const QIcon& theIcon )
 {
   if (!myPages.count()) {
     setDefaultValue(theCaseId.toStdString());
index 74bf703c2c7aecc6455f46a03bdf2b5c5ef42091..b31f0c5709e5374132215bfb68c66789cd55ee71 100644 (file)
@@ -21,8 +21,11 @@ class MODULEBASE_EXPORT ModuleBase_PagedContainer : public ModuleBase_ModelWidge
                            const std::string& theParentId);
   virtual ~ModuleBase_PagedContainer();
 
-  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 );
+
   // ModuleBase_ModelWidget
   virtual QList<QWidget*> getControls() const;
   virtual bool focusTo();
diff --git a/src/ModuleBase/ModuleBase_ToolBox.cpp b/src/ModuleBase/ModuleBase_ToolBox.cpp
new file mode 100644 (file)
index 0000000..0af3267
--- /dev/null
@@ -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 <ModuleBase_ToolBox.h>
+#include <QButtonGroup>
+#include <QStackedWidget>
+#include <QHBoxLayout>
+#include <QVBoxLayout>
+#include <QToolButton>
+
+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 (file)
index 0000000..2b48b08
--- /dev/null
@@ -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 <ModuleBase.h>
+#include <QFrame>
+
+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
index 2e2290491abe5e78514fd9e0514a5c0fac4fd304..85fb353a7398f29d64cfb36e40957c5859e2904a 100644 (file)
@@ -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<ModuleBase_PagedContainer*>(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());
       }
index 31deb0e986bdc96d06893fa2c4cca5908456ac79..0df6f7ebf0b041a411b25009a4c2acd96b00498a 100644 (file)
@@ -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)
index fe89a0749366ca7db0f82a0cdc65ba4b4d212757..a1cec7a779402f91454144f4bbf488645e303703 100644 (file)
@@ -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;
index 6a16aa3d2647d6d4057e6352971f686ad02e1a06..829afea9e292398b7b0c54bd98ce9a4301187d15 100644 (file)
@@ -9,12 +9,14 @@
 #include <ModuleBase_PageBase.h>
 #include <ModuleBase_ModelWidget.h>
 #include <ModuleBase_Tools.h>
+#include <ModuleBase_ToolBox.h>
 
 #include <ModelAPI_AttributeString.h>
 
 #include <QWidget>
 #include <QList>
 #include <QVBoxLayout>
+#include <QIcon>
 
 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<QFrame*>(thePage);
   aFrame->setFrameShape(QFrame::Box);
   aFrame->setFrameStyle(QFrame::Sunken);
-  myToolBox->addItem(aFrame, theName);
+  myToolBox->addItem(aFrame, theName, theIcon );
   return myToolBox->count();
 }
 
index b315e5d3a43456efff85b7e904d586c6df2a21ef..29c52d140400d7396b7a567a24e460b9ccc3f2b5 100644 (file)
@@ -11,9 +11,8 @@
 #include <ModuleBase.h>
 #include <ModuleBase_PagedContainer.h>
 
-#include <QToolBox>
-
 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_ */