Salome HOME
Translation of sketch operations
[modules/shaper.git] / src / ModuleBase / ModuleBase_WidgetChoice.cpp
index 024b736788cdc5962c2c5ad6559c6b569635a706..5797e7cc8de201b0882d34a9a37610fe44bdf8cd 100644 (file)
@@ -5,7 +5,8 @@
 // Author:      Vitaly Smetannikov
 
 #include "ModuleBase_WidgetChoice.h"
-#include <ModuleBase_Tools.h>
+#include "ModuleBase_Tools.h"
+#include "ModuleBase_IconFactory.h"
 
 #include <ModelAPI_AttributeInteger.h>
 #include <ModelAPI_Data.h>
@@ -22,9 +23,8 @@
 
 
 ModuleBase_WidgetChoice::ModuleBase_WidgetChoice(QWidget* theParent, 
-                                                 const Config_WidgetAPI* theData, 
-                                                 const std::string& theParentId)
-    : ModuleBase_ModelWidget(theParent, theData, theParentId), myCombo(0), myButtons(0)
+                                                 const Config_WidgetAPI* theData)
+: ModuleBase_ModelWidget(theParent, theData), myCombo(0), myButtons(0)
 {
   QHBoxLayout* aLayout = new QHBoxLayout(this);
   ModuleBase_Tools::adjustMargins(aLayout);
@@ -34,6 +34,9 @@ ModuleBase_WidgetChoice::ModuleBase_WidgetChoice(QWidget* theParent,
   std::string aTypes = theData->getProperty("string_list");
   QStringList aList = QString(aTypes.c_str()).split(' ');
 
+  if (theData->getBooleanAttribute("use_in_title", false))
+    myButtonTitles = QString(aTypes.c_str()).split(" ");
+
   // Widget type can be combobox or radiobuttons
   std::string aWgtType = theData->getProperty("widget_type");
   if ((aWgtType.length() > 0) && (aWgtType == "radiobuttons")) {
@@ -56,10 +59,11 @@ ModuleBase_WidgetChoice::ModuleBase_WidgetChoice(QWidget* theParent,
       int aId = 0;
       foreach(QString aBtnTxt, aList) {
         QToolButton* aBtn = new QToolButton(aGroupBox);
+        aBtn->setFocusPolicy(Qt::StrongFocus);
         aBtn->setCheckable(true);
         aBtn->setToolTip(aBtnTxt);
 
-        QPixmap aIcon(aIconList.at(aId));
+        QPixmap aIcon = ModuleBase_IconFactory::loadPixmap(aIconList.at(aId));
         aBtn->setIcon(aIcon);
         aBtn->setIconSize(aIcon.size());
         
@@ -77,11 +81,10 @@ ModuleBase_WidgetChoice::ModuleBase_WidgetChoice(QWidget* theParent,
     }
     myButtons->button(0)->setChecked(true);
     connect(myButtons, SIGNAL(buttonClicked(int)), this, SLOT(onCurrentIndexChanged(int)));
-    connect(myButtons, SIGNAL(buttonClicked(int)), this, SIGNAL(itemSelected(int)));
   } else {
     myLabel = new QLabel(aLabelText, this);
     if (!aLabelIcon.isEmpty())
-      myLabel->setPixmap(QPixmap(aLabelIcon));
+      myLabel->setPixmap(ModuleBase_IconFactory::loadPixmap(aLabelIcon));
     aLayout->addWidget(myLabel);
 
     std::string aToolstr = theData->widgetTooltip();
@@ -95,7 +98,6 @@ ModuleBase_WidgetChoice::ModuleBase_WidgetChoice(QWidget* theParent,
     myCombo->addItems(aList);
 
     connect(myCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(onCurrentIndexChanged(int)));
-    connect(myCombo, SIGNAL(currentIndexChanged(int)), this, SIGNAL(itemSelected(int)));
   }
 }
 
@@ -103,7 +105,7 @@ ModuleBase_WidgetChoice::~ModuleBase_WidgetChoice()
 {
 }
   
-bool ModuleBase_WidgetChoice::storeValueCustom() const
+bool ModuleBase_WidgetChoice::storeValueCustom()
 {
   DataPtr aData = myFeature->data();
   std::shared_ptr<ModelAPI_AttributeInteger> aIntAttr = aData->integer(attributeID());
@@ -130,7 +132,7 @@ bool ModuleBase_WidgetChoice::restoreValueCustom()
       bool isBlocked = myButtons->blockSignals(true);
       myButtons->button(aIntAttr->value())->setChecked(true);
       myButtons->blockSignals(isBlocked);
-      emit itemSelected(aIntAttr->value());
+      emit itemSelected(this, aIntAttr->value());
     }
   }
   return true;
@@ -158,9 +160,19 @@ QList<QWidget*> ModuleBase_WidgetChoice::getControls() const
   return aControls;
 }
 
+QString ModuleBase_WidgetChoice::getPropertyPanelTitle(int theIndex)
+{
+  QString aTitle;
+  if (myButtonTitles.length() > theIndex)
+    aTitle = tr(myButtonTitles[theIndex].toStdString().c_str());
+  return aTitle;
+}
+
 void ModuleBase_WidgetChoice::onCurrentIndexChanged(int theIndex)
 {
   emit valuesChanged();
   // Don't transfer focus
   // emit focusOutWidget(this);
+
+  emit itemSelected(this, theIndex);
 }