]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Minor GUI tweaks according to MPV's notes + re-factoring:
authorsbh <sergey.belash@opencascade.com>
Fri, 4 Apr 2014 08:21:55 +0000 (12:21 +0400)
committersbh <sergey.belash@opencascade.com>
Fri, 4 Apr 2014 08:21:55 +0000 (12:21 +0400)
* Posibility to fetch from xml icons, tooltips added to property panel's widgets.
* Property panel's margins and spacers corrected
* XGUI_MainWindow re-factoring: pices of code for dock widgets creation extracted as functions

src/Config/Config_WidgetAPI.cpp
src/Config/Config_WidgetAPI.h
src/Config/plugin-PartSet.xml
src/PartSet/PartSet_Module.cpp
src/XGUI/XGUI_MainWindow.cpp
src/XGUI/XGUI_MainWindow.h
src/XGUI/XGUI_WidgetFactory.cpp
src/XGUI/XGUI_Workshop.cpp

index 38b4476ade39806eec6eaf0f6213a177f73b9017..14d5fa2aa9b18323806403b393f6de708c78580a 100644 (file)
@@ -29,12 +29,13 @@ void Config_WidgetAPI::reset()
   if(aRoot) {
     myCurrentNode = aRoot->children;
   }
-
 }
 
 bool Config_WidgetAPI::nextWidget()
 {
-  myCurrentNode = myCurrentNode->next;
+  if(myCurrentNode) {
+    myCurrentNode = myCurrentNode->next;
+  }
   return myCurrentNode != NULL;
 }
 
@@ -57,6 +58,21 @@ std::string Config_WidgetAPI::getProperty(const char* thePropName)
   return result;
 }
 
+std::string Config_WidgetAPI::widgetTooltip()
+{
+  return getProperty("tooltip");
+}
+
+std::string Config_WidgetAPI::widgetIcon()
+{
+  return getProperty("icon");
+}
+
+std::string Config_WidgetAPI::widgetLabel()
+{
+  return getProperty("label");
+}
+
 bool Config_WidgetAPI::isNode(xmlNodePtr theNode, const char* theNodeName, ...)
 {
   bool result = false;
index 0bcb4a454405e0b91769a97e66b452a82e0c26ea..59f44f2b89642cf8b84a576c241a2495518058a8 100644 (file)
@@ -34,7 +34,13 @@ public:
 
   void reset();
   bool nextWidget();
+
   std::string widgetType();
+
+  std::string widgetIcon();
+  std::string widgetLabel();
+  std::string widgetTooltip();
+
   std::string getProperty(const char* thePropName);
 
 protected:
index 76c67c75c1d1f43003fb156c03bc7d511b7da112..decbb89ef409d9429361c1e2e0b1034162b91805 100644 (file)
@@ -9,9 +9,12 @@
   <workbench id="Construction">
     <group id="Basic">
       <feature id="Point" text="Point" tooltip="Create a new point" icon=":icons/point.png">
-        <value id="x" type="double" label="X:" min="0" max="" step="0.1" default="0"/>
-        <value id="y" type="double" label="Y:" min="0" max="" step="0.1" default="1"/>
-        <value id="z" type="double" label="Z:" min="0" max="10" step="0.1" default="2"/>
+        <value id="x" type="double" label="X:" min="0" max="" step="0.1" default="0" 
+               icon=":pictures/x_point.png" tooltip="Set X"/>
+        <value id="y" type="double" label="Y:" min="0" max="" step="0.1" default="1" 
+               icon=":pictures/y_point.png" tooltip="Set Y"/>
+        <value id="z" type="double" label="Z:" min="0" max="10" step="0.1" default="2" 
+               icon=":pictures/z_point.png" tooltip="Set Z"/>
       </feature>
       <feature id="Axis" text="Axis" tooltip="Create a new axis" icon=":icons/axis.png" keysequence=""/>
       <feature id="Plane" text="Plane" tooltip="Create a new plane" icon=":icons/plane.png" keysequence=""/>
index 7f87997da0b2c0c3b1ad50f5bba8f66445f7da28..f8e60b9e4c75e2efcf2642093c53ef5d1eacf2a0 100644 (file)
@@ -40,9 +40,7 @@ void PartSet_Module::createFeatures()
 void PartSet_Module::featureCreated(XGUI_Command* theFeature)
 {
   QString aFtId = theFeature->getId();
-  if (aFtId == "new_point") {
-    theFeature->connectTo(this, SLOT(onCommandTriggered()));
-  }
+  theFeature->connectTo(this, SLOT(onCommandTriggered()));
 }
 
 void PartSet_Module::onCommandTriggered()
index 0e6ee35b8e93f2b1c26a53ac2cac8ce072367f34..40a0d26cfae25c68f665bc88c03f02287c5f8586 100644 (file)
@@ -23,6 +23,7 @@
 #include <QScrollArea>
 #include <QComboBox>
 
+
 XGUI_MainWindow::XGUI_MainWindow(QWidget* parent)
     : QMainWindow(parent), 
     myObjectBrowser(0), 
@@ -31,23 +32,12 @@ XGUI_MainWindow::XGUI_MainWindow(QWidget* parent)
   setWindowTitle(tr("WINDOW_TITLE"));
   myMenuBar = new XGUI_MainMenu(this);
 
-  QDockWidget* aDoc = new QDockWidget(this);
-  aDoc->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
-  aDoc->setWindowTitle(tr("OBJECT_BROWSER_TITLE"));
-  myObjectBrowser = new QTreeWidget(aDoc);
-  myObjectBrowser->setColumnCount(1);
-  myObjectBrowser->setHeaderHidden(true);
-  aDoc->setWidget(myObjectBrowser);
-  addDockWidget(Qt::LeftDockWidgetArea, aDoc);
-  //aDoc->hide();
-
   QMdiArea* aMdiArea = new QMdiArea(this);
   setCentralWidget(aMdiArea);
 
   myViewer = new XGUI_Viewer(this);
 
-  //fillObjectBrowser();
-  //addPropertyPanel();
+  createDockWidgets();
 }
 
 XGUI_MainWindow::~XGUI_MainWindow(void)
@@ -100,7 +90,69 @@ void XGUI_MainWindow::hidePythonConsole()
     myPythonConsole->parentWidget()->hide();
 }
 
+/*
+ * Creates dock widgets, places them in corresponding area
+ * and tabifies if necessary.
+ */
+void XGUI_MainWindow::createDockWidgets()
+{
+  QDockWidget* aObjDock = createObjectBrowser();
+  addDockWidget(Qt::LeftDockWidgetArea, aObjDock);
+  QDockWidget* aPropPanelDock = createPropertyPanel();
+  addDockWidget(Qt::LeftDockWidgetArea, aPropPanelDock);
+
+  tabifyDockWidget(aPropPanelDock, aObjDock);
+}
+
+
+QDockWidget* XGUI_MainWindow::createPropertyPanel()
+{
+  QDockWidget* aPropPanel = new QDockWidget(this);
+  aPropPanel->setWindowTitle(tr("Property Panel"));
+
+  QWidget* aContent = new QWidget(aPropPanel);
+  QVBoxLayout* aMainLay = new QVBoxLayout(aContent);
+  aMainLay->setContentsMargins(3, 3, 3, 3);
+  aPropPanel->setWidget(aContent);
+
+  QWidget* aCustomWidget = new QWidget(aContent);
+  aCustomWidget->setObjectName("PropertyPanelWidget");
+  aMainLay->addWidget(aCustomWidget);
+  aMainLay->addStretch(1);
+
+  QFrame* aFrm = new QFrame(aContent);
+  aFrm->setFrameStyle(QFrame::Sunken);
+  aFrm->setFrameShape(QFrame::Panel);
+  QHBoxLayout* aBtnLay = new QHBoxLayout(aFrm);
+  aBtnLay->setContentsMargins(0, 0, 0, 0);
+  aMainLay->addWidget(aFrm);
+
+  QPushButton* aBtn = new QPushButton(QIcon(":pictures/button_help.png"), "", aFrm);
+  aBtn->setFlat(true);
+  aBtnLay->addWidget(aBtn);
+  aBtnLay->addStretch(1);
+  aBtn = new QPushButton(QIcon(":pictures/button_ok.png"), "", aFrm);
+  aBtn->setFlat(true);
+  aBtnLay->addWidget(aBtn);
+  aBtn = new QPushButton(QIcon(":pictures/button_cancel.png"), "", aFrm);
+  aBtn->setFlat(true);
+  aBtnLay->addWidget(aBtn);
+
+  return aPropPanel;
+}
 
+QDockWidget* XGUI_MainWindow::createObjectBrowser()
+{
+  QDockWidget* aObjDock = new QDockWidget(this);
+  aObjDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
+  aObjDock->setWindowTitle(tr("OBJECT_BROWSER_TITLE"));
+  myObjectBrowser = new QTreeWidget(aObjDock);
+  myObjectBrowser->setColumnCount(1);
+  myObjectBrowser->setHeaderHidden(true);
+  aObjDock->setWidget(myObjectBrowser);
+//  fillObjectBrowser();
+  return aObjDock;
+}
 
 //******************************************************
 
@@ -152,93 +204,3 @@ void XGUI_MainWindow::fillObjectBrowser()
     aItem->setIcon(0, QIcon(":pictures/features.png"));
   }
 }
-
-void XGUI_MainWindow::addPropertyPanel()
-{
-  QDockWidget* aPropPanel = new QDockWidget(this);
-  aPropPanel->setWindowTitle("Property Panel");
-
-  QWidget* aContent = new QWidget(aPropPanel);
-  QVBoxLayout* aMainLay = new QVBoxLayout(aContent);
-  aMainLay->setContentsMargins(3, 3, 3, 3);
-  aPropPanel->setWidget(aContent);
-
-  QWidget* aCustomWidget = new QWidget(aContent);
-  aCustomWidget->setObjectName("PropertyPanelWidget");
-  aMainLay->addWidget(aCustomWidget);
-
-  /*
-  QWidget* aNameWgt = new QWidget(aContent);
-  QHBoxLayout* aNameLay = new QHBoxLayout(aNameWgt);
-  aNameLay->setContentsMargins(0,0,0,0);
-  aMainLay->addWidget(aNameWgt);
-
-  aNameLay->addWidget(new QLabel("Name", aNameWgt));
-  aNameLay->addWidget(new QLineEdit(aNameWgt));
-  */
-
-/* Moved into PartSetModule by sbh
-  QComboBox* aCombo = new QComboBox(aContent);
-  aCombo->addItem("By coordinates");
-  aMainLay->addWidget(aCombo);
-
-  QWidget* aGrpBox1 = new QWidget(aContent);
-  QFormLayout* aFrmLay = new QFormLayout(aGrpBox1);
-  aFrmLay->setContentsMargins(0, 6, 0, 0);
-  aMainLay->addWidget(aGrpBox1);
-
-  QLabel* aLbl = new QLabel(aGrpBox1);
-  aLbl->setPixmap(QPixmap(":pictures/x_point.png"));
-  aFrmLay->addRow(aLbl, new QDoubleSpinBox(aGrpBox1));
-
-  aLbl = new QLabel(aGrpBox1);
-  aLbl->setPixmap(QPixmap(":pictures/y_point.png"));
-  aFrmLay->addRow(aLbl, new QDoubleSpinBox(aGrpBox1));
-
-  aLbl = new QLabel(aGrpBox1);
-  aLbl->setPixmap(QPixmap(":pictures/z_point.png"));
-  aFrmLay->addRow(aLbl, new QDoubleSpinBox(aGrpBox1));
-  */
-
-  /*
-  aGrpBox1 = new QGroupBox("Normal vector", aContent);
-  aGrpBox1->setFlat(true);
-  aFrmLay = new QFormLayout(aGrpBox1);
-  aFrmLay->setContentsMargins(0, 6, 0, 0);
-  aMainLay->addWidget(aGrpBox1);
-
-  aLbl = new QLabel(aGrpBox1);
-  aLbl->setPixmap(QPixmap(":pictures/x_size.png"));
-  aFrmLay->addRow(aLbl, new QDoubleSpinBox(aGrpBox1));
-
-  aLbl = new QLabel(aGrpBox1);
-  aLbl->setPixmap(QPixmap(":pictures/y_size.png"));
-  aFrmLay->addRow(aLbl, new QDoubleSpinBox(aGrpBox1));
-
-  aLbl = new QLabel(aGrpBox1);
-  aLbl->setPixmap(QPixmap(":pictures/z_size.png"));
-  aFrmLay->addRow(aLbl, new QDoubleSpinBox(aGrpBox1));
-  */
-
-  aMainLay->addStretch(1);
-
-  QFrame* aFrm = new QFrame(aContent);
-  aFrm->setFrameStyle(QFrame::Sunken);
-  aFrm->setFrameShape(QFrame::Panel);
-  QHBoxLayout* aBtnLay = new QHBoxLayout(aFrm);
-  aBtnLay->setContentsMargins(0, 0, 0, 0);
-  aMainLay->addWidget(aFrm);
-
-  QPushButton* aBtn = new QPushButton(QIcon(":pictures/button_help.png"), "", aFrm);
-  aBtn->setFlat(true);
-  aBtnLay->addWidget(aBtn);
-  aBtnLay->addStretch(1);
-  aBtn = new QPushButton(QIcon(":pictures/button_ok.png"), "", aFrm);
-  aBtn->setFlat(true);
-  aBtnLay->addWidget(aBtn);
-  aBtn = new QPushButton(QIcon(":pictures/button_cancel.png"), "", aFrm);
-  aBtn->setFlat(true);
-  aBtnLay->addWidget(aBtn);
-
-  addDockWidget(Qt::RightDockWidgetArea, aPropPanel);
-}
index ec5da26a6bdeaa59134c9de3c429d4dc8f1f6227..0806b5863a8e791426ab7a22051e32a24dea7fa1 100644 (file)
@@ -41,9 +41,11 @@ public:
   void hidePythonConsole();
 
 private:
+  void createDockWidgets();
+  QDockWidget* createObjectBrowser();
+  QDockWidget* createPropertyPanel();
   //!! For test purposes only
   void fillObjectBrowser();
-  void addPropertyPanel();
 
   XGUI_MainMenu* myMenuBar;
   QTreeWidget* myObjectBrowser;
index 9cc69af893618c2f24851b02daa82603f147543e..b2551c62c667dd59a15d3c20ab2c5f6b960d7a2a 100644 (file)
@@ -14,6 +14,7 @@
 #include <QSpinBox>
 #include <QMetaProperty>
 #include <QLabel>
+#include <QPixmap>
 
 #ifdef _DEBUG
 #include <QDebug>
@@ -36,6 +37,7 @@ void XGUI_WidgetFactory::fillWidget(QWidget* theParent)
   }
 
   QVBoxLayout* aWidgetLay = new QVBoxLayout(theParent);
+  aWidgetLay->setContentsMargins(0, 0, 0, 0);
   do {
     std::string aWdgType = myWidgetApi->widgetType();
     QWidget* aWidget = NULL;
@@ -50,7 +52,6 @@ void XGUI_WidgetFactory::fillWidget(QWidget* theParent)
       aWidgetLay->addWidget(aWidget);
     }
   } while(myWidgetApi->nextWidget());
-  aWidgetLay->addStretch(1);
   theParent->setLayout(aWidgetLay);
 }
 
@@ -58,8 +59,12 @@ QWidget* XGUI_WidgetFactory::valueWidget()
 {
   QWidget* result = new QWidget();
   QHBoxLayout* aControlLay = new QHBoxLayout(result);
-  QString aLabelVal = qs(myWidgetApi->getProperty("label"));
-  QLabel* aLabel = new QLabel(aLabelVal);
+  aControlLay->setContentsMargins(0, 0, 0, 0);
+  QString aLabelText = qs(myWidgetApi->widgetLabel());
+  QString aLabelIcon = qs(myWidgetApi->widgetIcon());
+  QLabel* aLabel = new QLabel(aLabelText);
+  aLabel->setPixmap(QPixmap(aLabelIcon));
+
   aControlLay->addWidget(aLabel);
   QDoubleSpinBox* aBox = new QDoubleSpinBox(result);
   bool isOk = false;
@@ -79,8 +84,10 @@ QWidget* XGUI_WidgetFactory::valueWidget()
   if (isOk) {
     aBox->setValue(aDefVal);
   }
+  QString aTTip = qs(myWidgetApi->widgetTooltip());
+  aBox->setToolTip(aTTip);
   aControlLay->addWidget(aBox);
-  aControlLay->addStretch();
+  aControlLay->setStretch(1, 1);
 
   result->setLayout(aControlLay);
   return result;
index b083080f9a26d888817a31ab876753811f5a7af8..55e16fcf87b21e2ba6806da2ed3e3930df466fe0 100644 (file)
@@ -177,6 +177,7 @@ void XGUI_Workshop::fillPropertyPanel(const Config_WidgetMessage* theMessage)
     #endif
     return;
   }
+  qDeleteAll(aPropWidget->children());
   std::string aXml = theMessage->xmlRepresentation();
   XGUI_WidgetFactory aFactory = XGUI_WidgetFactory(aXml);
   aFactory.fillWidget(aPropWidget);