From 31c4ff77330b870d466fbd6b38e1fa566600f79a Mon Sep 17 00:00:00 2001 From: nds Date: Mon, 14 Dec 2015 14:15:02 +0300 Subject: [PATCH] SketchShapePlugin: checked group box/multi editor controls, which highlight the parent page group box. --- src/ModuleBase/CMakeLists.txt | 2 + src/ModuleBase/ModuleBase_IWidgetCreator.h | 12 +- src/ModuleBase/ModuleBase_ModelWidget.cpp | 21 +-- src/ModuleBase/ModuleBase_Tools.cpp | 19 +++ src/ModuleBase/ModuleBase_Tools.h | 7 + .../ModuleBase_WidgetCheckGroupBox.cpp | 128 ++++++++++++++++++ .../ModuleBase_WidgetCheckGroupBox.h | 77 +++++++++++ .../ModuleBase_WidgetCreatorFactory.cpp | 14 +- .../ModuleBase_WidgetCreatorFactory.h | 10 +- src/ModuleBase/ModuleBase_WidgetFactory.cpp | 19 ++- src/SketchShapePlugin/CMakeLists.txt | 4 + .../SketchShapePlugin_PageGroupBox.cpp | 6 +- .../SketchShapePlugin_PageGroupBox.h | 4 + .../SketchShapePlugin_Plugin.cpp | 9 -- .../SketchShapePlugin_Plugin.h | 5 - .../SketchShapePlugin_WidgetCheckGroupBox.cpp | 32 +++++ .../SketchShapePlugin_WidgetCheckGroupBox.h | 33 +++++ .../SketchShapePlugin_WidgetCreator.cpp | 28 +++- .../SketchShapePlugin_WidgetCreator.h | 12 +- .../SketchShapePlugin_WidgetMultiSelector.cpp | 37 +++++ .../SketchShapePlugin_WidgetMultiSelector.h | 36 +++++ src/SketchShapePlugin/plugin-SketchShape.xml | 59 ++++---- 22 files changed, 492 insertions(+), 82 deletions(-) create mode 100755 src/ModuleBase/ModuleBase_WidgetCheckGroupBox.cpp create mode 100755 src/ModuleBase/ModuleBase_WidgetCheckGroupBox.h create mode 100755 src/SketchShapePlugin/SketchShapePlugin_WidgetCheckGroupBox.cpp create mode 100755 src/SketchShapePlugin/SketchShapePlugin_WidgetCheckGroupBox.h create mode 100755 src/SketchShapePlugin/SketchShapePlugin_WidgetMultiSelector.cpp create mode 100755 src/SketchShapePlugin/SketchShapePlugin_WidgetMultiSelector.h diff --git a/src/ModuleBase/CMakeLists.txt b/src/ModuleBase/CMakeLists.txt index 304feb69c..48c904e16 100644 --- a/src/ModuleBase/CMakeLists.txt +++ b/src/ModuleBase/CMakeLists.txt @@ -39,6 +39,7 @@ SET(PROJECT_HEADERS ModuleBase_ViewerFilters.h ModuleBase_ViewerPrs.h ModuleBase_WidgetBoolValue.h + ModuleBase_WidgetCheckGroupBox.h ModuleBase_WidgetChoice.h ModuleBase_WidgetCreatorFactory.h ModuleBase_WidgetDoubleValue.h @@ -92,6 +93,7 @@ SET(PROJECT_SOURCES ModuleBase_ViewerFilters.cpp ModuleBase_ViewerPrs.cpp ModuleBase_WidgetBoolValue.cpp + ModuleBase_WidgetCheckGroupBox.cpp ModuleBase_WidgetChoice.cpp ModuleBase_WidgetCreatorFactory.cpp ModuleBase_WidgetDoubleValue.cpp diff --git a/src/ModuleBase/ModuleBase_IWidgetCreator.h b/src/ModuleBase/ModuleBase_IWidgetCreator.h index ecdee3a84..91a076d44 100755 --- a/src/ModuleBase/ModuleBase_IWidgetCreator.h +++ b/src/ModuleBase/ModuleBase_IWidgetCreator.h @@ -11,6 +11,9 @@ class ModuleBase_ModelWidget; class ModuleBase_PageBase; +class ModuleBase_IWorkshop; + +class Config_WidgetAPI; class QWidget; @@ -39,13 +42,18 @@ public: /// \param theType a type /// \param theParent a parent widget virtual ModuleBase_PageBase* createPageByType(const std::string& theType, - QWidget* theParent) = 0; + QWidget* theParent, + Config_WidgetAPI* theWidgetApi, + std::string theParentId) = 0; /// Create widget by its type /// \param theType a type /// \param theParent a parent widget virtual ModuleBase_ModelWidget* createWidgetByType(const std::string& theType, - QWidget* theParent = NULL) = 0; + QWidget* theParent, + Config_WidgetAPI* theWidgetApi, + std::string theParentId, + ModuleBase_IWorkshop* theWorkshop) = 0; }; typedef std::shared_ptr WidgetCreatorPtr; diff --git a/src/ModuleBase/ModuleBase_ModelWidget.cpp b/src/ModuleBase/ModuleBase_ModelWidget.cpp index ff7554f1d..d9c678185 100644 --- a/src/ModuleBase/ModuleBase_ModelWidget.cpp +++ b/src/ModuleBase/ModuleBase_ModelWidget.cpp @@ -18,8 +18,6 @@ #include #include -#include -#include #include #include @@ -104,21 +102,10 @@ void ModuleBase_ModelWidget::setHighlighted(bool isHighlighted) QLabel* aLabel = qobject_cast(aWidget); // We won't set the effect to QLabels - it looks ugly if(aLabel) continue; - if(isHighlighted) { - // If effect is the installed on a different widget, setGraphicsEffect() will - // remove the effect from the widget and install it on this widget. - // That's why we create a new effect for each widget - QGraphicsDropShadowEffect* aGlowEffect = new QGraphicsDropShadowEffect(); - aGlowEffect->setOffset(.0); - aGlowEffect->setBlurRadius(10.0); - aGlowEffect->setColor(QColor(0, 170, 255)); // Light-blue color, #00AAFF - aWidget->setGraphicsEffect(aGlowEffect); - } else { - QGraphicsEffect* anEffect = aWidget->graphicsEffect(); - if(anEffect) - anEffect->deleteLater(); - aWidget->setGraphicsEffect(NULL); - } + // If effect is the installed on a different widget, setGraphicsEffect() will + // remove the effect from the widget and install it on this widget. + // That's why we create a new effect for each widget + ModuleBase_Tools::setShadowEffect(aWidget, isHighlighted); } } diff --git a/src/ModuleBase/ModuleBase_Tools.cpp b/src/ModuleBase/ModuleBase_Tools.cpp index d33467c7e..66f2979fa 100755 --- a/src/ModuleBase/ModuleBase_Tools.cpp +++ b/src/ModuleBase/ModuleBase_Tools.cpp @@ -29,6 +29,8 @@ #include #include #include +#include +#include #include @@ -91,6 +93,23 @@ void setFocus(QWidget* theWidget, const QString& theInfo) #endif } +void setShadowEffect(QWidget* theWidget, const bool isSetEffect) +{ + if (isSetEffect) { + QGraphicsDropShadowEffect* aGlowEffect = new QGraphicsDropShadowEffect(); + aGlowEffect->setOffset(.0); + aGlowEffect->setBlurRadius(10.0); + aGlowEffect->setColor(QColor(0, 170, 255)); // Light-blue color, #00AAFF + theWidget->setGraphicsEffect(aGlowEffect); + } + else { + QGraphicsEffect* anEffect = theWidget->graphicsEffect(); + if(anEffect) + anEffect->deleteLater(); + theWidget->setGraphicsEffect(NULL); + } +} + QPixmap composite(const QString& theAdditionalIcon, const QString& theIcon) { QImage anIcon(theIcon); diff --git a/src/ModuleBase/ModuleBase_Tools.h b/src/ModuleBase/ModuleBase_Tools.h index 7aa9f9d64..c8d3c6afa 100755 --- a/src/ModuleBase/ModuleBase_Tools.h +++ b/src/ModuleBase/ModuleBase_Tools.h @@ -55,6 +55,13 @@ MODULEBASE_EXPORT void activateWindow(QWidget* theWidget, const QString& theInfo */ MODULEBASE_EXPORT void setFocus(QWidget* theWidget, const QString& theInfo = QString()); + +//! Sets or removes the shadow effect to the widget +//! \param theWidget a widget to be styled +//! \param isSetEffect if true, the shadow effect is set, overwise cleared +//! \return resulting pixmap +MODULEBASE_EXPORT void setShadowEffect(QWidget* theWidget, const bool isSetEffect); + /** * \ingroup GUI * Methods to modify a resource pixmap diff --git a/src/ModuleBase/ModuleBase_WidgetCheckGroupBox.cpp b/src/ModuleBase/ModuleBase_WidgetCheckGroupBox.cpp new file mode 100755 index 000000000..89d9356b9 --- /dev/null +++ b/src/ModuleBase/ModuleBase_WidgetCheckGroupBox.cpp @@ -0,0 +1,128 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D --> + +// File: ModuleBase_WidgetCheckGroupBox.cpp +// Created: 13 Dec 2015 +// Author: Natalia ERMOLAEVA + +#include +#include + +#include +#include + +#include +#include +#include +#include + +#include + +ModuleBase_WidgetCheckGroupBox::ModuleBase_WidgetCheckGroupBox(QWidget* theParent, + const Config_WidgetAPI* theData, + const std::string& theParentId) +: ModuleBase_ModelWidget(theParent, theData, theParentId), + ModuleBase_PageBase() +{ + QString aToolTip = QString::fromStdString(theData->widgetTooltip()); + bool isChecked = theData->getBooleanAttribute(ATTR_DEFAULT, false); + + QVBoxLayout* aMainLayout = new QVBoxLayout(this); + ModuleBase_Tools::zeroMargins(aMainLayout); + myGroupBox = new QGroupBox(this); + myGroupBox->setCheckable(true); + myGroupBox->setToolTip(aToolTip); + myGroupBox->setChecked(isChecked); + + myMainLayout = new QGridLayout(myGroupBox); + ModuleBase_Tools::adjustMargins(myMainLayout); + myGroupBox->setLayout(myMainLayout); + + // default vertical size policy is preferred + aMainLayout->addWidget(myGroupBox); + connect(myGroupBox, SIGNAL(clicked(bool)), this, SLOT(onPageClicked())); +} + +ModuleBase_WidgetCheckGroupBox::~ModuleBase_WidgetCheckGroupBox() +{ +} + +void ModuleBase_WidgetCheckGroupBox::setTitle(const QString& theTitle) +{ + myGroupBox->setTitle(theTitle); +} + +QWidget* ModuleBase_WidgetCheckGroupBox::pageWidget() +{ + return myGroupBox; +} + +QList ModuleBase_WidgetCheckGroupBox::getControls() const +{ + QList aControls; + aControls.append(myGroupBox); + + return aControls; +} + +void ModuleBase_WidgetCheckGroupBox::onPageClicked() +{ + storeValue(); +} + +void ModuleBase_WidgetCheckGroupBox::addPageStretch() +{ +} + +void ModuleBase_WidgetCheckGroupBox::placeModelWidget(ModuleBase_ModelWidget* theWidget) +{ + const int kCol = 0; + const int kRow = myMainLayout->count(); + // it seems, that the align on left is not necessary here, but leads to widgets, which are + // not extended on full width of the parent page. The case is grouped widgets in + // the sketch translation operation + myMainLayout->addWidget(theWidget, kRow, kCol, Qt::AlignTop);// | Qt::AlignLeft); + myMainLayout->setRowStretch(kRow, 0); + +} + +void ModuleBase_WidgetCheckGroupBox::placePageWidget(ModuleBase_PageBase* theWidget) +{ + QWidget* aWidget = dynamic_cast(theWidget); + if (!aWidget) { +#ifdef _DEBUG + std::cout << "ModuleBase_PageGroupBox::placePageWidget: can not cast page" << std::endl; +#endif + return; + } + const int kCol = 0; + const int kRow = myMainLayout->count(); + myMainLayout->addWidget(aWidget, kRow, kCol); + myMainLayout->setRowStretch(kRow, 0); +} + +QLayout* ModuleBase_WidgetCheckGroupBox::pageLayout() +{ + return myMainLayout; +} + +bool ModuleBase_WidgetCheckGroupBox::storeValueCustom() const +{ + DataPtr aData = myFeature->data(); + std::shared_ptr aBool = aData->boolean(attributeID()); + aBool->setValue(myGroupBox->isChecked()); + updateObject(myFeature); + + return true; +} + +bool ModuleBase_WidgetCheckGroupBox::restoreValueCustom() +{ + DataPtr aData = myFeature->data(); + std::shared_ptr aRef = aData->boolean(attributeID()); + + bool isBlocked = myGroupBox->blockSignals(true); + myGroupBox->setChecked(aRef->value()); + myGroupBox->blockSignals(isBlocked); + + return true; +} diff --git a/src/ModuleBase/ModuleBase_WidgetCheckGroupBox.h b/src/ModuleBase/ModuleBase_WidgetCheckGroupBox.h new file mode 100755 index 000000000..4d8c12a41 --- /dev/null +++ b/src/ModuleBase/ModuleBase_WidgetCheckGroupBox.h @@ -0,0 +1,77 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D --> + +// File: ModuleBase_WidgetCheckGroupBox.h +// Created: 13 Dec 2015 +// Author: Natalia ERMOLAEVA + +#ifndef ModuleBase_WidgetCheckGroupBox_H_ +#define ModuleBase_WidgetCheckGroupBox_H_ + +#include +#include +#include + +class QGroupBox; +class QGridLayout; + +/** +* \ingroup GUI +* Implements a model widget for switch as a container widget. It can be defined in XML with "toolbox" keyword +*/ +class MODULEBASE_EXPORT ModuleBase_WidgetCheckGroupBox : public ModuleBase_ModelWidget, + public ModuleBase_PageBase +{ + Q_OBJECT +public: + /// Constructor + /// \param theParent the parent object + /// \param theData the widget configuration. The attribute of the model widget is obtained from + /// \param theParentId is Id of a parent of the current attribute + ModuleBase_WidgetCheckGroupBox(QWidget* theParent, const Config_WidgetAPI* theData, + const std::string& theParentId); + virtual ~ModuleBase_WidgetCheckGroupBox(); + + void setTitle(const QString& theTitle); + + /// Methods to be redefined from ModuleBase_PageBase: start + /// Cast the page to regular QWidget + virtual QWidget* pageWidget(); + /// Methods to be redefined from ModuleBase_PageBase: end + + /// Methods to be redefined from ModuleBase_ModelWidget: start + /// Returns list of widget controls + /// \return a control list + virtual QList getControls() const; + /// Methods to be redefined from ModuleBase_ModelWidget: end + +protected slots: + // store value to the model + void onPageClicked(); + +protected: + /// Methods to be redefined from ModuleBase_PageBase: start + /// Adds the given widget to page's layout + virtual void placeModelWidget(ModuleBase_ModelWidget* theWidget); + /// Adds the given page to page's layout + virtual void placePageWidget(ModuleBase_PageBase* theWidget); + /// Returns page's layout (QGridLayout) + virtual QLayout* pageLayout(); + /// Adds a stretch to page's layout + virtual void addPageStretch(); + /// Methods to be redefined from ModuleBase_PageBase: end + + + /// Methods to be redefined from ModuleBase_ModelWidget: start + /// Saves the internal parameters to the given feature + /// \return True in success + virtual bool storeValueCustom() const; + /// Restore value from attribute data to the widget's control + virtual bool restoreValueCustom(); + /// Methods to be redefined from ModuleBase_ModelWidget: end + +private: + QGroupBox* myGroupBox; + QGridLayout* myMainLayout; ///< page's layout +}; + +#endif /* ModuleBase_WidgetCheckGroupBox_H_ */ diff --git a/src/ModuleBase/ModuleBase_WidgetCreatorFactory.cpp b/src/ModuleBase/ModuleBase_WidgetCreatorFactory.cpp index 1427e22a7..cdf53e151 100755 --- a/src/ModuleBase/ModuleBase_WidgetCreatorFactory.cpp +++ b/src/ModuleBase/ModuleBase_WidgetCreatorFactory.cpp @@ -7,6 +7,8 @@ #include #include +#include + #include #include @@ -62,13 +64,14 @@ bool ModuleBase_WidgetCreatorFactory::hasPageWidget(const std::string& theType) } ModuleBase_PageBase* ModuleBase_WidgetCreatorFactory::createPageByType( - const std::string& theType, QWidget* theParent) + const std::string& theType, QWidget* theParent, + Config_WidgetAPI* theWidgetApi, std::string theParentId) { ModuleBase_PageBase* aPage = 0; if (myPageToCreator.contains(theType)) { WidgetCreatorPtr aCreator = myPageToCreator[theType]; - aPage = aCreator->createPageByType(theType, theParent); + aPage = aCreator->createPageByType(theType, theParent, theWidgetApi, theParentId); } return aPage; @@ -76,13 +79,16 @@ ModuleBase_PageBase* ModuleBase_WidgetCreatorFactory::createPageByType( ModuleBase_ModelWidget* ModuleBase_WidgetCreatorFactory::createWidgetByType( - const std::string& theType, QWidget* theParent) + const std::string& theType, QWidget* theParent, + Config_WidgetAPI* theWidgetApi, std::string theParentId, + ModuleBase_IWorkshop* theWorkshop) { ModuleBase_ModelWidget* aWidget = 0; if (myCreators.contains(theType)) { WidgetCreatorPtr aCreator = myCreators[theType]; - aWidget = aCreator->createWidgetByType(theType, theParent); + aWidget = aCreator->createWidgetByType(theType, theParent, theWidgetApi, theParentId, + theWorkshop); } return aWidget; diff --git a/src/ModuleBase/ModuleBase_WidgetCreatorFactory.h b/src/ModuleBase/ModuleBase_WidgetCreatorFactory.h index 63c4d6260..98f4d211d 100755 --- a/src/ModuleBase/ModuleBase_WidgetCreatorFactory.h +++ b/src/ModuleBase/ModuleBase_WidgetCreatorFactory.h @@ -18,6 +18,7 @@ class ModuleBase_ModelWidget; class ModuleBase_PageBase; +class ModuleBase_IWorkshop; class QWidget; @@ -47,13 +48,18 @@ class MODULEBASE_EXPORT ModuleBase_WidgetCreatorFactory /// \param theType a type /// \param theParent a parent widget ModuleBase_PageBase* createPageByType(const std::string& theType, - QWidget* theParent = NULL); + QWidget* theParent, + Config_WidgetAPI* theWidgetApi, + std::string theParentId); /// Create widget by its type /// \param theType a type /// \param theParent a parent widget ModuleBase_ModelWidget* createWidgetByType(const std::string& theType, - QWidget* theParent = NULL); + QWidget* theParent, + Config_WidgetAPI* theWidgetApi, + std::string theParentId, + ModuleBase_IWorkshop* theWorkshop); private: /// Constructor is hidden diff --git a/src/ModuleBase/ModuleBase_WidgetFactory.cpp b/src/ModuleBase/ModuleBase_WidgetFactory.cpp index dec5f78ab..f32f0aca8 100644 --- a/src/ModuleBase/ModuleBase_WidgetFactory.cpp +++ b/src/ModuleBase/ModuleBase_WidgetFactory.cpp @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -131,9 +132,20 @@ ModuleBase_PageBase* ModuleBase_WidgetFactory::createPageByType(const std::strin aPage->setTitle(aGroupName); aResult = aPage; } - + else if (theType == WDG_CHECK_GROUP) { + QString aGroupName = qs(myWidgetApi->getProperty(CONTAINER_PAGE_NAME)); + ModuleBase_WidgetCheckGroupBox* aPage = new ModuleBase_WidgetCheckGroupBox(theParent, + myWidgetApi, myParentId); + aPage->setTitle(aGroupName); + aResult = aPage; + } if (!aResult) - aResult = ModuleBase_WidgetCreatorFactory::get()->createPageByType(theType, theParent); + aResult = ModuleBase_WidgetCreatorFactory::get()->createPageByType(theType, theParent, + myWidgetApi, myParentId); + + ModuleBase_ModelWidget* aWidget = dynamic_cast(aResult); + if (aWidget) + myModelWidgets.append(aWidget); return aResult; } @@ -180,7 +192,8 @@ ModuleBase_ModelWidget* ModuleBase_WidgetFactory::createWidgetByType(const std:: } else { result = myWorkshop->module()->createWidgetByType(theType, theParent, myWidgetApi, myParentId); if (!result) - result = ModuleBase_WidgetCreatorFactory::get()->createWidgetByType(theType, theParent); + result = ModuleBase_WidgetCreatorFactory::get()->createWidgetByType(theType, theParent, + myWidgetApi, myParentId, myWorkshop); #ifdef _DEBUG if (!result) { qDebug("ModuleBase_WidgetFactory::fillWidget: find bad widget type %s", theType.c_str()); diff --git a/src/SketchShapePlugin/CMakeLists.txt b/src/SketchShapePlugin/CMakeLists.txt index 200ca71ba..f2516cd65 100755 --- a/src/SketchShapePlugin/CMakeLists.txt +++ b/src/SketchShapePlugin/CMakeLists.txt @@ -10,7 +10,9 @@ SET(PROJECT_HEADERS SketchShapePlugin_Plugin.h SketchShapePlugin_Validators.h SketchShapePlugin_Tools.h + SketchShapePlugin_WidgetCheckGroupBox.h SketchShapePlugin_WidgetCreator.h + SketchShapePlugin_WidgetMultiSelector.h ) SET(PROJECT_SOURCES @@ -19,7 +21,9 @@ SET(PROJECT_SOURCES SketchShapePlugin_Plugin.cpp SketchShapePlugin_Validators.cpp SketchShapePlugin_Tools.cpp + SketchShapePlugin_WidgetCheckGroupBox.cpp SketchShapePlugin_WidgetCreator.cpp + SketchShapePlugin_WidgetMultiSelector.cpp ) SET(PROJECT_LIBRARIES diff --git a/src/SketchShapePlugin/SketchShapePlugin_PageGroupBox.cpp b/src/SketchShapePlugin/SketchShapePlugin_PageGroupBox.cpp index a28cec528..db4d9eb70 100755 --- a/src/SketchShapePlugin/SketchShapePlugin_PageGroupBox.cpp +++ b/src/SketchShapePlugin/SketchShapePlugin_PageGroupBox.cpp @@ -9,6 +9,10 @@ SketchShapePlugin_PageGroupBox::SketchShapePlugin_PageGroupBox(QWidget* theParent) : ModuleBase_PageGroupBox(theParent) { - setTitle("SketchShapePlugin_PageGroupBox"); +} + +void SketchShapePlugin_PageGroupBox::setHighlightedGroupBox(bool isHighlighted) +{ + ModuleBase_Tools::setShadowEffect(this, isHighlighted); } diff --git a/src/SketchShapePlugin/SketchShapePlugin_PageGroupBox.h b/src/SketchShapePlugin/SketchShapePlugin_PageGroupBox.h index 3da8919d4..f372d14f8 100755 --- a/src/SketchShapePlugin/SketchShapePlugin_PageGroupBox.h +++ b/src/SketchShapePlugin/SketchShapePlugin_PageGroupBox.h @@ -23,6 +23,10 @@ public: SketchShapePlugin_PageGroupBox(QWidget* theParent = 0); /// Destructs the page virtual ~SketchShapePlugin_PageGroupBox() {} + + //! Switch On/Off highlighting of the widget + //! Set highlight to the parent group box if there is such parent + void setHighlightedGroupBox(bool isHighlighted); }; #endif /* SKETCHSHAPEPLUGIN_PAGEGROUPBOX_H_ */ diff --git a/src/SketchShapePlugin/SketchShapePlugin_Plugin.cpp b/src/SketchShapePlugin/SketchShapePlugin_Plugin.cpp index 751e41b82..9121a4219 100755 --- a/src/SketchShapePlugin/SketchShapePlugin_Plugin.cpp +++ b/src/SketchShapePlugin/SketchShapePlugin_Plugin.cpp @@ -52,12 +52,3 @@ FeaturePtr SketchShapePlugin_Plugin::createFeature(std::string theFeatureID) return FeaturePtr(); } -/*ModuleBase_ModelWidget* SketchShapePlugin_Plugin::createWidgetByType(const std::string& theType, - QWidget* theParent) -{ - ModuleBase_ModelWidget* aWidget = 0; - if (theType == "sketchshape_groupbox") - aWidget = new SketchShapePlugin_PageGroupBox(theParent); - return aWidget; -}*/ - diff --git a/src/SketchShapePlugin/SketchShapePlugin_Plugin.h b/src/SketchShapePlugin/SketchShapePlugin_Plugin.h index 3c037c965..69721d20f 100755 --- a/src/SketchShapePlugin/SketchShapePlugin_Plugin.h +++ b/src/SketchShapePlugin/SketchShapePlugin_Plugin.h @@ -28,11 +28,6 @@ public: /// Creates the feature object of this plugin by the feature string ID virtual FeaturePtr createFeature(std::string theFeatureID); - /// Create widget by its type - /// \param theType a type - /// \param theParent a parent widget - //virtual ModuleBase_ModelWidget* createWidgetByType(const std::string& theType, - // QWidget* theParent = NULL); public: SketchShapePlugin_Plugin(); }; diff --git a/src/SketchShapePlugin/SketchShapePlugin_WidgetCheckGroupBox.cpp b/src/SketchShapePlugin/SketchShapePlugin_WidgetCheckGroupBox.cpp new file mode 100755 index 000000000..6c304fc19 --- /dev/null +++ b/src/SketchShapePlugin/SketchShapePlugin_WidgetCheckGroupBox.cpp @@ -0,0 +1,32 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D --> + +// File: SketchShapePlugin_PageGroupBox.h +// Created: 13 Dec 2015 +// Author: Natalia ERMOLAEVA + +#include + +#include + +SketchShapePlugin_WidgetCheckGroupBox::SketchShapePlugin_WidgetCheckGroupBox(QWidget* theParent, + const Config_WidgetAPI* theData, + const std::string& theParentId) + : ModuleBase_WidgetCheckGroupBox(theParent, theData, theParentId) +{ +} + +void SketchShapePlugin_WidgetCheckGroupBox::setHighlighted(bool isHighlighted) +{ + SketchShapePlugin_PageGroupBox* aShapeGroupBox = 0; + QWidget* aParent = qobject_cast(parent()); + while (aParent) { + aShapeGroupBox = dynamic_cast(aParent); + if (aShapeGroupBox) + break; + aParent = qobject_cast(aParent->parent()); + } + + if (aShapeGroupBox) + aShapeGroupBox->setHighlightedGroupBox(isHighlighted); +} + diff --git a/src/SketchShapePlugin/SketchShapePlugin_WidgetCheckGroupBox.h b/src/SketchShapePlugin/SketchShapePlugin_WidgetCheckGroupBox.h new file mode 100755 index 000000000..1744081e3 --- /dev/null +++ b/src/SketchShapePlugin/SketchShapePlugin_WidgetCheckGroupBox.h @@ -0,0 +1,33 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D --> + +// File: SketchShapePlugin_PageGroupBox.h +// Created: 13 Dec 2015 +// Author: Natalia ERMOLAEVA + +#ifndef SKETCHSHAPEPLUGIN_WIDGET_CHECK_GROUP_BOX_H_ +#define SKETCHSHAPEPLUGIN_WIDGET_CHECK_GROUP_BOX_H_ + +#include + +class QWidget; + +/*! + * \ingroup GUI + * Represent a property panel's list of ModuleBase_ModelWidgets. + */ +class SketchShapePlugin_WidgetCheckGroupBox : public ModuleBase_WidgetCheckGroupBox +{ + //Q_OBJECT +public: + /// Constructs a page that looks like a QGroupBox + SketchShapePlugin_WidgetCheckGroupBox(QWidget* theParent, const Config_WidgetAPI* theData, + const std::string& theParentId); + /// Destructs the page + virtual ~SketchShapePlugin_WidgetCheckGroupBox() {} + + //! Switch On/Off highlighting of the widget + //! Set highlight to the parent group box if there is such parent + virtual void setHighlighted(bool isHighlighted); +}; + +#endif /* SKETCHSHAPEPLUGIN_WIDGET_CHECK_GROUP_BOX_H_ */ diff --git a/src/SketchShapePlugin/SketchShapePlugin_WidgetCreator.cpp b/src/SketchShapePlugin/SketchShapePlugin_WidgetCreator.cpp index a5fa8cda4..ad994b496 100755 --- a/src/SketchShapePlugin/SketchShapePlugin_WidgetCreator.cpp +++ b/src/SketchShapePlugin/SketchShapePlugin_WidgetCreator.cpp @@ -1,12 +1,19 @@ // Copyright (C) 2014-20xx CEA/DEN, EDF R&D #include "SketchShapePlugin_WidgetCreator.h" + #include "SketchShapePlugin_PageGroupBox.h" +#include "SketchShapePlugin_WidgetMultiSelector.h" +#include "SketchShapePlugin_WidgetCheckGroupBox.h" + SketchShapePlugin_WidgetCreator::SketchShapePlugin_WidgetCreator() : ModuleBase_IWidgetCreator() { myPages.insert("sketchshape_groupbox"); + myPages.insert("sketchshape_check_groupbox"); + + myWidgets.insert("sketchshape_multi_selector"); } const std::set& SketchShapePlugin_WidgetCreator::pageTypes() @@ -16,11 +23,12 @@ const std::set& SketchShapePlugin_WidgetCreator::pageTypes() const std::set& SketchShapePlugin_WidgetCreator::widgetTypes() { - return myTypes; + return myWidgets; } ModuleBase_PageBase* SketchShapePlugin_WidgetCreator::createPageByType( - const std::string& theType, QWidget* theParent) + const std::string& theType, QWidget* theParent, + Config_WidgetAPI* theWidgetApi, std::string theParentId) { ModuleBase_PageBase* aPage = 0; if (myPages.find(theType) == myPages.end()) @@ -29,20 +37,26 @@ ModuleBase_PageBase* SketchShapePlugin_WidgetCreator::createPageByType( if (theType == "sketchshape_groupbox") { aPage = new SketchShapePlugin_PageGroupBox(theParent); } + else if (theType == "sketchshape_check_groupbox") { + aPage = new SketchShapePlugin_WidgetCheckGroupBox(theParent, theWidgetApi, theParentId); + } return aPage; } ModuleBase_ModelWidget* SketchShapePlugin_WidgetCreator::createWidgetByType( - const std::string& theType, QWidget* theParent) + const std::string& theType, QWidget* theParent, + Config_WidgetAPI* theWidgetApi, std::string theParentId, + ModuleBase_IWorkshop* theWorkshop) { ModuleBase_ModelWidget* aWidget = 0; - if (myTypes.find(theType) == myTypes.end()) + if (myWidgets.find(theType) == myWidgets.end()) return aWidget; - //if (theType == "sketchshape_groupbox") { - // aWidget = new SketchShapePlugin_PageGroupBox(theParent); - //} + if (theType == "sketchshape_multi_selector") { + aWidget = new SketchShapePlugin_WidgetMultiSelector(theParent, theWorkshop, theWidgetApi, + theParentId); + } return aWidget; } diff --git a/src/SketchShapePlugin/SketchShapePlugin_WidgetCreator.h b/src/SketchShapePlugin/SketchShapePlugin_WidgetCreator.h index 7d3e734b4..1ce859f99 100755 --- a/src/SketchShapePlugin/SketchShapePlugin_WidgetCreator.h +++ b/src/SketchShapePlugin/SketchShapePlugin_WidgetCreator.h @@ -9,6 +9,7 @@ #include class ModuleBase_ModelWidget; +class ModuleBase_IWorkshop; class QWidget; /** @@ -36,17 +37,22 @@ public: /// \param theType a type /// \param theParent a parent widget virtual ModuleBase_PageBase* createPageByType(const std::string& theType, - QWidget* theParent); + QWidget* theParent, + Config_WidgetAPI* theWidgetApi, + std::string theParentId); /// Create widget by its type /// \param theType a type /// \param theParent a parent widget virtual ModuleBase_ModelWidget* createWidgetByType(const std::string& theType, - QWidget* theParent = NULL); + QWidget* theParent, + Config_WidgetAPI* theWidgetApi, + std::string theParentId, + ModuleBase_IWorkshop* theWorkshop); private: std::set myPages; /// types of pages - std::set myTypes; /// types of widgets + std::set myWidgets; /// types of widgets }; typedef std::shared_ptr SketchShapePlguinWidgetCreatorPtr; diff --git a/src/SketchShapePlugin/SketchShapePlugin_WidgetMultiSelector.cpp b/src/SketchShapePlugin/SketchShapePlugin_WidgetMultiSelector.cpp new file mode 100755 index 000000000..f0ccc0f65 --- /dev/null +++ b/src/SketchShapePlugin/SketchShapePlugin_WidgetMultiSelector.cpp @@ -0,0 +1,37 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D --> + +// File: SketchShapePlugin_PageGroupBox.h +// Created: 13 Dec 2015 +// Author: Natalia ERMOLAEVA + +#include + +#include + +#include + +#include + +SketchShapePlugin_WidgetMultiSelector::SketchShapePlugin_WidgetMultiSelector(QWidget* theParent, + ModuleBase_IWorkshop* theWorkshop, + const Config_WidgetAPI* theData, + const std::string& theParentId) + : ModuleBase_WidgetMultiSelector(theParent, theWorkshop, theData, theParentId) +{ +} + +void SketchShapePlugin_WidgetMultiSelector::setHighlighted(bool isHighlighted) +{ + SketchShapePlugin_PageGroupBox* aShapeGroupBox = 0; + QWidget* aParent = qobject_cast(parent()); + while (aParent) { + aShapeGroupBox = dynamic_cast(aParent); + if (aShapeGroupBox) + break; + aParent = qobject_cast(aParent->parent()); + } + + if (aShapeGroupBox) + aShapeGroupBox->setHighlightedGroupBox(isHighlighted); +} + diff --git a/src/SketchShapePlugin/SketchShapePlugin_WidgetMultiSelector.h b/src/SketchShapePlugin/SketchShapePlugin_WidgetMultiSelector.h new file mode 100755 index 000000000..3e8c96814 --- /dev/null +++ b/src/SketchShapePlugin/SketchShapePlugin_WidgetMultiSelector.h @@ -0,0 +1,36 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D --> + +// File: SketchShapePlugin_PageGroupBox.h +// Created: 13 Dec 2015 +// Author: Natalia ERMOLAEVA + +#ifndef SKETCHSHAPEPLUGIN_WIDGET_MULTI_SELECTOR_H_ +#define SKETCHSHAPEPLUGIN_WIDGET_MULTI_SELECTOR_H_ + +#include + +class ModuleBase_IWorkshop; +class QWidget; + +/*! + * \ingroup GUI + * Represent a property panel's list of ModuleBase_ModelWidgets. + */ +class SketchShapePlugin_WidgetMultiSelector : public ModuleBase_WidgetMultiSelector +{ + //Q_OBJECT +public: + /// Constructs a multi selector widget, which can not be highlighted itself, + /// the parent SketchShapePlugin_GroupBox is highlighted instead of it + SketchShapePlugin_WidgetMultiSelector(QWidget* theParent, ModuleBase_IWorkshop* theWorkshop, + const Config_WidgetAPI* theData, + const std::string& theParentId); + /// Destructs the page + virtual ~SketchShapePlugin_WidgetMultiSelector() {} + + //! Switch On/Off highlighting of the widget + //! Set highlight to the parent group box if there is such parent + virtual void setHighlighted(bool isHighlighted); +}; + +#endif /* SKETCHSHAPEPLUGIN_PAGEGROUPBOX_H_ */ diff --git a/src/SketchShapePlugin/plugin-SketchShape.xml b/src/SketchShapePlugin/plugin-SketchShape.xml index 6f51667ca..ace539bf6 100755 --- a/src/SketchShapePlugin/plugin-SketchShape.xml +++ b/src/SketchShapePlugin/plugin-SketchShape.xml @@ -12,35 +12,36 @@ - - - - - - - - - - - - - - + + + + + + + + + + + + + + + -- 2.39.2