From 6dffec58e6c28dbc908b718e3bfd92c236d4a9fc Mon Sep 17 00:00:00 2001 From: vsv Date: Thu, 5 Nov 2015 19:19:38 +0300 Subject: [PATCH] Replace combobox by radiobuttons in boolean operations --- src/FeaturesPlugin/boolean_widget.xml | 19 ++-- src/ModuleBase/ModuleBase_WidgetChoice.cpp | 115 +++++++++++++++++---- src/ModuleBase/ModuleBase_WidgetChoice.h | 8 ++ src/PartSet/PartSet_icons.qrc | 3 + src/PartSet/icons/bool_common.png | Bin 0 -> 403 bytes src/PartSet/icons/bool_cut.png | Bin 0 -> 279 bytes src/PartSet/icons/bool_fuse.png | Bin 0 -> 300 bytes 7 files changed, 115 insertions(+), 30 deletions(-) create mode 100644 src/PartSet/icons/bool_common.png create mode 100644 src/PartSet/icons/bool_cut.png create mode 100644 src/PartSet/icons/bool_fuse.png diff --git a/src/FeaturesPlugin/boolean_widget.xml b/src/FeaturesPlugin/boolean_widget.xml index 8fc0925ca..cdf755b6c 100644 --- a/src/FeaturesPlugin/boolean_widget.xml +++ b/src/FeaturesPlugin/boolean_widget.xml @@ -1,9 +1,18 @@ + @@ -12,18 +21,12 @@ - diff --git a/src/ModuleBase/ModuleBase_WidgetChoice.cpp b/src/ModuleBase/ModuleBase_WidgetChoice.cpp index c89508324..4b09ffab6 100644 --- a/src/ModuleBase/ModuleBase_WidgetChoice.cpp +++ b/src/ModuleBase/ModuleBase_WidgetChoice.cpp @@ -15,35 +15,86 @@ #include #include #include +#include +#include +#include +#include + ModuleBase_WidgetChoice::ModuleBase_WidgetChoice(QWidget* theParent, const Config_WidgetAPI* theData, const std::string& theParentId) - : ModuleBase_ModelWidget(theParent, theData, theParentId) + : ModuleBase_ModelWidget(theParent, theData, theParentId), myCombo(0), myButtons(0) { QHBoxLayout* aLayout = new QHBoxLayout(this); ModuleBase_Tools::adjustMargins(aLayout); QString aLabelText = QString::fromStdString(theData->widgetLabel()); QString aLabelIcon = QString::fromStdString(theData->widgetIcon()); - myLabel = new QLabel(aLabelText, this); - if (!aLabelIcon.isEmpty()) - myLabel->setPixmap(QPixmap(aLabelIcon)); - aLayout->addWidget(myLabel); - - std::string aToolstr = theData->widgetTooltip(); - if (!aToolstr.empty()) { - myLabel->setToolTip(QString::fromStdString(aToolstr)); - } - - myCombo = new QComboBox(this); - aLayout->addWidget(myCombo, 1); - std::string aTypes = theData->getProperty("string_list"); QStringList aList = QString(aTypes.c_str()).split(' '); - myCombo->addItems(aList); - connect(myCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(onCurrentIndexChanged(int))); + // Widget type can be combobox or radiobuttons + std::string aWgtType = theData->getProperty("widget_type"); + if ((aWgtType.length() > 0) && (aWgtType == "radiobuttons")) { + myButtons = new QButtonGroup(this); + QGroupBox* aGroupBox = new QGroupBox(aLabelText, this); + aLayout->addWidget(aGroupBox); + + + QLayout* aBtnLayout = 0; + std::string aWgtDir = theData->getProperty("buttons_dir"); + if (aWgtDir == "horizontal") + aBtnLayout = new QHBoxLayout(aGroupBox); + else + aBtnLayout = new QVBoxLayout(aGroupBox); + ModuleBase_Tools::adjustMargins(aBtnLayout); + + std::string aIcons = theData->getProperty("icons_list"); + QStringList aIconList = QString(aIcons.c_str()).split(' '); + if (aIconList.length() == aList.length()) { + int aId = 0; + foreach(QString aBtnTxt, aList) { + QToolButton* aBtn = new QToolButton(aGroupBox); + aBtn->setCheckable(true); + aBtn->setToolTip(aBtnTxt); + + QPixmap aIcon(aIconList.at(aId)); + aBtn->setIcon(aIcon); + aBtn->setIconSize(aIcon.size()); + + aBtnLayout->addWidget(aBtn); + myButtons->addButton(aBtn, aId++); + } + + } else { + int aId = 0; + foreach(QString aBtnTxt, aList) { + QRadioButton* aBtn = new QRadioButton(aBtnTxt, aGroupBox); + aBtnLayout->addWidget(aBtn); + myButtons->addButton(aBtn, aId++); + } + } + myButtons->button(0)->setChecked(true); + connect(myButtons, SIGNAL(buttonClicked(int)), this, SLOT(onCurrentIndexChanged(int))); + } else { + myLabel = new QLabel(aLabelText, this); + if (!aLabelIcon.isEmpty()) + myLabel->setPixmap(QPixmap(aLabelIcon)); + aLayout->addWidget(myLabel); + + std::string aToolstr = theData->widgetTooltip(); + if (!aToolstr.empty()) { + myLabel->setToolTip(QString::fromStdString(aToolstr)); + } + + myCombo = new QComboBox(this); + aLayout->addWidget(myCombo, 1); + + myCombo->addItems(aList); + + connect(myCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(onCurrentIndexChanged(int))); + } } ModuleBase_WidgetChoice::~ModuleBase_WidgetChoice() @@ -55,7 +106,10 @@ bool ModuleBase_WidgetChoice::storeValueCustom() const DataPtr aData = myFeature->data(); std::shared_ptr aIntAttr = aData->integer(attributeID()); - aIntAttr->setValue(myCombo->currentIndex()); + if (myCombo) + aIntAttr->setValue(myCombo->currentIndex()); + else + aIntAttr->setValue(myButtons->checkedId()); updateObject(myFeature); return true; } @@ -65,22 +119,39 @@ bool ModuleBase_WidgetChoice::restoreValueCustom() DataPtr aData = myFeature->data(); std::shared_ptr aIntAttr = aData->integer(attributeID()); - bool isBlocked = myCombo->blockSignals(true); - myCombo->setCurrentIndex(aIntAttr->value()); - myCombo->blockSignals(isBlocked); + if (aIntAttr->value() != -1) { + if (myCombo) { + bool isBlocked = myCombo->blockSignals(true); + myCombo->setCurrentIndex(aIntAttr->value()); + myCombo->blockSignals(isBlocked); + } else { + bool isBlocked = myButtons->blockSignals(true); + myButtons->button(aIntAttr->value())->setChecked(true); + myButtons->blockSignals(isBlocked); + } + } return true; } bool ModuleBase_WidgetChoice::focusTo() { - myCombo->setFocus(); + if (myCombo) + myCombo->setFocus(); + else + myButtons->button(0)->setFocus(); return true; } QList ModuleBase_WidgetChoice::getControls() const { QList aControls; - aControls.append(myCombo); + if (myCombo) + aControls.append(myCombo); + //else { + // //foreach(QAbstractButton* aBtn, myButtons->buttons()) + // //if (myButtons->checkedId() != -1) + // // aControls.append(myButtons->button(myButtons->checkedId())); + //} return aControls; } diff --git a/src/ModuleBase/ModuleBase_WidgetChoice.h b/src/ModuleBase/ModuleBase_WidgetChoice.h index 72f6df4cd..8e25ee1f9 100644 --- a/src/ModuleBase/ModuleBase_WidgetChoice.h +++ b/src/ModuleBase/ModuleBase_WidgetChoice.h @@ -13,6 +13,7 @@ class QWidget; class QLabel; class QComboBox; +class QButtonGroup; /** * \ingroup GUI @@ -25,6 +26,12 @@ class QComboBox; * string_list="Cut Fuse Common" * /> * \endcode +* Aditionally can be used: +* A key "widget_type". It can have values "combobox" or "radiobuttons". +* By default it uses "combobox". +* A key "buttons_dir" which is applicable only for "radiobuttons" mode. +* It defines direction of radiobuttons layout. it can be "vertical" or "horizontal" +* Default value is "vertical" */ class MODULEBASE_EXPORT ModuleBase_WidgetChoice : public ModuleBase_ModelWidget { @@ -62,6 +69,7 @@ private: /// The control QComboBox* myCombo; + QButtonGroup* myButtons; }; #endif diff --git a/src/PartSet/PartSet_icons.qrc b/src/PartSet/PartSet_icons.qrc index 8361c656e..8b840862a 100644 --- a/src/PartSet/PartSet_icons.qrc +++ b/src/PartSet/PartSet_icons.qrc @@ -74,5 +74,8 @@ icons/by_two_points_32x32.png icons/cylindrical_face_32x32.png icons/dimension_vert_32x32.png + icons/bool_cut.png + icons/bool_fuse.png + icons/bool_common.png diff --git a/src/PartSet/icons/bool_common.png b/src/PartSet/icons/bool_common.png new file mode 100644 index 0000000000000000000000000000000000000000..99812c5462d3b982f58000b90fb47f0fd3bc62c9 GIT binary patch literal 403 zcmeAS@N?(olHy`uVBq!ia0vp^3LwnE1|*BCs=fdz#^NA%Cx&(BWL^R}Ea{HEjtmSN z`?>!lvI6;>1s;*b3=DjSL74G){)!Z!phSslL`iUdT1k0gQ7S`0VrE{6US4X6f{C7i zp4p$CdJNY{<73fV5V=4cknx3)${q*X~mstceC$FsR-jUcHQotApBu`9V_FC8VD2D{2 z@`tNTjn?rOZFd~X)?+HVkfLr8vX`@P$}HzoH)C}qBSZ(!_gO4XVtXF|1t-X#sh? z8tJ8eO0N|-Qr;{sYHc#J!lvI6;>1s;*b3=DjSL74G){)!Z!phSslL`iUdT1k0gQ7S`0VrE{6US4X6f{C7i zp4p$Czi3hXsOj;QV-dQCS~p5MXdcTF)Z@9lNS%G}c0*}aI z1_r)EAj~ML;ne^XlqhkHC<)F_D=AMbN@XZW%*-p%%S$a$Fwry6GyBt%d>^Q0m8Xki zNQ8UxkN^MeFIp5oYI=O-ScLAO){T-5n#ZyP^>{9;JQMmbKgi})Lm+#PRl*g<0`>zE zE|1PD^qh4FGCbq6NM?d*=EKfMk*m*L)4TU)ZRyo@?{Dy^h#o$(ENjE0CU;o_kj@K7 z7=5+3)w9oH)mn2PO{jV0tA