From: sbh Date: Thu, 2 Oct 2014 14:46:01 +0000 (+0400) Subject: Within Issue #143 highlight active inputs X-Git-Tag: V_0.5~119^2~2 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=ef9ec2df08d5809313076b149a3a89082a47c75f;p=modules%2Fshaper.git Within Issue #143 highlight active inputs --- diff --git a/src/Config/Config_Keywords.h b/src/Config/Config_Keywords.h index 8f0fda2e1..87be5d399 100644 --- a/src/Config/Config_Keywords.h +++ b/src/Config/Config_Keywords.h @@ -55,6 +55,7 @@ const static char* PREVIOUS_FEATURE_PARAM = "previous_feature_param"; const static char* ANY_WDG_TOOLTIP = FEATURE_TOOLTIP; const static char* ANY_WDG_ICON = FEATURE_ICON; const static char* ANY_WDG_LABEL = "label"; +const static char* ANY_WDG_DEFAULT = "default"; const static char* SOURCE_FILE = "path"; const static char* VALIDATOR_PARAMETERS = "parameters"; @@ -65,7 +66,6 @@ const static char* INFO_WDG_TOOLTIP = FEATURE_TOOLTIP; const static char* DOUBLE_WDG_MIN = "min"; const static char* DOUBLE_WDG_MAX = "max"; const static char* DOUBLE_WDG_STEP = "step"; -const static char* DOUBLE_WDG_DEFAULT = "default"; const static char* DOUBLE_WDG_DEFAULT_COMPUTED = "computed"; //toolbox/switch properties diff --git a/src/ModuleBase/CMakeLists.txt b/src/ModuleBase/CMakeLists.txt index 92a73fce8..884e44be9 100644 --- a/src/ModuleBase/CMakeLists.txt +++ b/src/ModuleBase/CMakeLists.txt @@ -3,6 +3,7 @@ SET(CMAKE_AUTOMOC ON) SET(PROJECT_HEADERS ModuleBase.h + ModuleBase_Tools.h ModuleBase_IModule.h ModuleBase_Operation.h ModuleBase_OperationDescription.h @@ -30,6 +31,7 @@ SET(PROJECT_HEADERS ) SET(PROJECT_SOURCES + ModuleBase_Tools.cpp ModuleBase_Operation.cpp ModuleBase_OperationDescription.cpp ModuleBase_ModelWidget.cpp diff --git a/src/ModuleBase/ModuleBase_ModelWidget.cpp b/src/ModuleBase/ModuleBase_ModelWidget.cpp index 939345b51..e2b934ee6 100644 --- a/src/ModuleBase/ModuleBase_ModelWidget.cpp +++ b/src/ModuleBase/ModuleBase_ModelWidget.cpp @@ -16,8 +16,11 @@ #include #include +#include +#include +#include -ModuleBase_ModelWidget::ModuleBase_ModelWidget(QObject* theParent, const Config_WidgetAPI* theData, +ModuleBase_ModelWidget::ModuleBase_ModelWidget(QWidget* theParent, const Config_WidgetAPI* theData, const std::string& theParentId) : QObject(theParent), myParentId(theParentId) @@ -42,6 +45,31 @@ void ModuleBase_ModelWidget::enableFocusProcessing() } } +void ModuleBase_ModelWidget::setHighlighted(bool isHighlighted) +{ + QList aWidgetList = getControls(); + foreach(QWidget* aWidget, aWidgetList) { + 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); + } + } +} + bool ModuleBase_ModelWidget::focusTo() { QList aControls = getControls(); @@ -73,7 +101,7 @@ void ModuleBase_ModelWidget::enableFocusProcessing(QWidget* theWidget) bool ModuleBase_ModelWidget::eventFilter(QObject* theObject, QEvent *theEvent) { - QWidget* aWidget = dynamic_cast(theObject); + QWidget* aWidget = qobject_cast(theObject); if (theEvent->type() == QEvent::MouseButtonRelease && myFocusInWidgets.contains(aWidget)) { emit focusInWidget(this); diff --git a/src/ModuleBase/ModuleBase_ModelWidget.h b/src/ModuleBase/ModuleBase_ModelWidget.h index 91b973854..9f2f6f455 100644 --- a/src/ModuleBase/ModuleBase_ModelWidget.h +++ b/src/ModuleBase/ModuleBase_ModelWidget.h @@ -32,21 +32,13 @@ Q_OBJECT /// Constructor /// \theParent the parent object /// \theData the widget configuation. The attribute of the model widget is obtained from - ModuleBase_ModelWidget(QObject* theParent, const Config_WidgetAPI* theData, + ModuleBase_ModelWidget(QWidget* theParent, const Config_WidgetAPI* theData, const std::string& theParentId); /// Destructor virtual ~ModuleBase_ModelWidget() { } - /// Set the given wrapped value to the current widget - /// This value should be processed in the widget according to the needs - /// \param theValue the wrapped widget value - virtual bool setValue(ModuleBase_WidgetValue* theValue) - { - return false; - } - /// Returns the state whether the attribute of the feature is initialized /// \param theObject a model feature to be checked /// \return the boolean result @@ -60,25 +52,45 @@ Q_OBJECT /// valid even if they are not initialized bool isObligatory() { return myIsObligatory; } + /// Defines if it is supposed that the widget should interact with the viewer. + virtual bool isViewerSelector() { return false; } + + /// Set the given wrapped value to the current widget + /// This value should be processed in the widget according to the needs + /// \param theValue the wrapped widget value + virtual bool setValue(ModuleBase_WidgetValue* theValue) + { + return false; + } + /// Saves the internal parameters to the given feature /// \param theObject a model feature to be changed virtual bool storeValue() const = 0; virtual bool restoreValue() = 0; - void enableFocusProcessing(); /// Set focus to the first control of the current widget. The focus policy of the control is checked. /// If the widget has the NonFocus focus policy, it is skipped. /// \return the state whether the widget can accept the focus virtual bool focusTo(); + /// Returns the internal parent wiget control, that can be shown anywhere + /// \returns the widget + virtual QWidget* getControl() const = 0; + /// Returns list of widget controls /// \return a control list virtual QList getControls() const = 0; + /// FocusIn events processing virtual bool eventFilter(QObject* theObject, QEvent *theEvent); + + void enableFocusProcessing(); + + void setHighlighted(bool isHighlighted); + /// Returns the attribute name /// \returns the string value std::string attributeID() const @@ -97,14 +109,12 @@ Q_OBJECT { return myFeature; } + void setFeature(const FeaturePtr& theFeature) { myFeature = theFeature; } - /// Defines if it is supposed that the widget should interact with the viewer. - virtual bool isViewerSelector() { return false; } - signals: /// The signal about widget values changed void valuesChanged(); @@ -138,9 +148,9 @@ signals: std::string myParentId; /// name of parent FeaturePtr myFeature; - bool myIsComputedDefault; /// Value should be computed on execute, - /// like radius for circle's constraint (can not be zero) - bool myIsObligatory; /// Non-obligatory widget is valid even if it is not initialized + bool myIsComputedDefault; /// Value should be computed on execute, + /// like radius for circle's constraint (can not be zero) + bool myIsObligatory; /// Non-obligatory widget is valid even if it is not initialized private: /// Contains a list of widgets that may accept focus diff --git a/src/ModuleBase/ModuleBase_Tools.cpp b/src/ModuleBase/ModuleBase_Tools.cpp index f68de8da5..ffb17b5c2 100644 --- a/src/ModuleBase/ModuleBase_Tools.cpp +++ b/src/ModuleBase/ModuleBase_Tools.cpp @@ -12,4 +12,35 @@ namespace ModuleBase_Tools { //****************************************************************** //****************************************************************** + +void adjustMargins(QWidget* theWidget) +{ + if(!theWidget) + return; + adjustMargins(theWidget->layout()); +} + +void adjustMargins(QLayout* theLayout) +{ + if(!theLayout) + return; + theLayout->setContentsMargins(5, 5, 5, 5); + theLayout->setSpacing(5); +} + +void zeroMargins(QWidget* theWidget) +{ + if(!theWidget) + return; + zeroMargins(theWidget->layout()); +} + +void zeroMargins(QLayout* theLayout) +{ + if(!theLayout) + return; + theLayout->setContentsMargins(0, 0, 0, 0); + theLayout->setSpacing(5); +} + } diff --git a/src/ModuleBase/ModuleBase_Tools.h b/src/ModuleBase/ModuleBase_Tools.h index e2a09c546..6c903d3fb 100644 --- a/src/ModuleBase/ModuleBase_Tools.h +++ b/src/ModuleBase/ModuleBase_Tools.h @@ -7,21 +7,22 @@ #include "ModuleBase.h" -#include -#include +#include +#include class GeomAPI_Shape; namespace ModuleBase_Tools { -/** - * Returns returns a shape if the result has a shape method. Otherwise returns NULL pointer +/* + * Methods to adjust margins and spacings. */ -MODULEBASE_EXPORT boost::shared_ptr shape(ResultPtr theResult); +MODULEBASE_EXPORT void adjustMargins(QWidget* theWidget); +MODULEBASE_EXPORT void adjustMargins(QLayout* theLayout); -MODULEBASE_EXPORT FeaturePtr feature(ObjectPtr theObject); +MODULEBASE_EXPORT void zeroMargins(QWidget* theWidget); +MODULEBASE_EXPORT void zeroMargins(QLayout* theLayout); } -; #endif diff --git a/src/ModuleBase/ModuleBase_WidgetBoolValue.cpp b/src/ModuleBase/ModuleBase_WidgetBoolValue.cpp index 6cd23ff97..cc0197d57 100644 --- a/src/ModuleBase/ModuleBase_WidgetBoolValue.cpp +++ b/src/ModuleBase/ModuleBase_WidgetBoolValue.cpp @@ -24,11 +24,11 @@ ModuleBase_WidgetBoolValue::ModuleBase_WidgetBoolValue(QWidget* theParent, { QString aText = QString::fromStdString(theData->widgetLabel()); QString aToolTip = QString::fromStdString(theData->widgetTooltip()); - QString aDefault = QString::fromStdString(theData->getProperty("default")); + bool isChecked = theData->getBooleanAttribute(ANY_WDG_DEFAULT, false); myCheckBox = new QCheckBox(aText, theParent); myCheckBox->setToolTip(aToolTip); - myCheckBox->setChecked(aDefault == "true"); + myCheckBox->setChecked(isChecked); connect(myCheckBox, SIGNAL(toggled(bool)), this, SIGNAL(valuesChanged())); } diff --git a/src/ModuleBase/ModuleBase_WidgetChoice.cpp b/src/ModuleBase/ModuleBase_WidgetChoice.cpp index ba5a281ed..3a3ed7459 100644 --- a/src/ModuleBase/ModuleBase_WidgetChoice.cpp +++ b/src/ModuleBase/ModuleBase_WidgetChoice.cpp @@ -3,6 +3,7 @@ // Author: Vitaly Smetannikov #include "ModuleBase_WidgetChoice.h" +#include #include #include @@ -20,7 +21,7 @@ ModuleBase_WidgetChoice::ModuleBase_WidgetChoice(QWidget* theParent, { myContainer = new QWidget(theParent); QHBoxLayout* aLayout = new QHBoxLayout(myContainer); - aLayout->setContentsMargins(0, 0, 0, 0); + ModuleBase_Tools::adjustMargins(aLayout); QString aLabelText = QString::fromStdString(theData->widgetLabel()); QString aLabelIcon = QString::fromStdString(theData->widgetIcon()); @@ -82,4 +83,4 @@ void ModuleBase_WidgetChoice::onCurrentIndexChanged(int theIndex) { emit valuesChanged(); emit focusOutWidget(this); -} \ No newline at end of file +} diff --git a/src/ModuleBase/ModuleBase_WidgetDoubleValue.cpp b/src/ModuleBase/ModuleBase_WidgetDoubleValue.cpp index 48620cbdc..d6d6d6566 100644 --- a/src/ModuleBase/ModuleBase_WidgetDoubleValue.cpp +++ b/src/ModuleBase/ModuleBase_WidgetDoubleValue.cpp @@ -4,6 +4,7 @@ #include #include +#include #include #include @@ -37,7 +38,7 @@ ModuleBase_WidgetDoubleValue::ModuleBase_WidgetDoubleValue(QWidget* theParent, { myContainer = new QWidget(theParent); QHBoxLayout* aControlLay = new QHBoxLayout(myContainer); - aControlLay->setContentsMargins(0, 0, 0, 0); + ModuleBase_Tools::adjustMargins(aControlLay); QString aLabelText = QString::fromStdString(theData->widgetLabel()); QString aLabelIcon = QString::fromStdString(theData->widgetIcon()); @@ -77,7 +78,7 @@ ModuleBase_WidgetDoubleValue::ModuleBase_WidgetDoubleValue(QWidget* theParent, mySpinBox->setSingleStep(aStepVal); } - aProp = theData->getProperty(DOUBLE_WDG_DEFAULT); + aProp = theData->getProperty(ANY_WDG_DEFAULT); double aDefVal = QString::fromStdString(aProp).toDouble(&isOk); if (isOk) { mySpinBox->setValue(aDefVal); diff --git a/src/ModuleBase/ModuleBase_WidgetFactory.cpp b/src/ModuleBase/ModuleBase_WidgetFactory.cpp index 00a479ad1..9ce1c133f 100644 --- a/src/ModuleBase/ModuleBase_WidgetFactory.cpp +++ b/src/ModuleBase/ModuleBase_WidgetFactory.cpp @@ -22,6 +22,8 @@ #include #include #include +#include + #include #include @@ -62,7 +64,6 @@ void ModuleBase_WidgetFactory::createWidget(QWidget* theParent) return; QVBoxLayout* aWidgetLay = new QVBoxLayout(theParent); - aWidgetLay->setContentsMargins(2, 2, 2, 2); do { //Iterate over each node std::string aWdgType = myWidgetApi->widgetType(); //Create a widget (doublevalue, groupbox, toolbox, etc. @@ -78,6 +79,7 @@ void ModuleBase_WidgetFactory::createWidget(QWidget* theParent) //if current widget is groupbox (container) process it's children recursively QString aGroupName = qs(myWidgetApi->getProperty(CONTAINER_PAGE_NAME)); createWidget(aWidget); + ModuleBase_Tools::adjustMargins(aWidget); QGroupBox* aGrBox = qobject_cast(aWidget); aGrBox->setTitle(aGroupName); } @@ -88,6 +90,7 @@ void ModuleBase_WidgetFactory::createWidget(QWidget* theParent) do { QString aPageName = qs(myWidgetApi->getProperty(CONTAINER_PAGE_NAME)); QWidget* aPage = new QWidget(aWidget); + ModuleBase_Tools::adjustMargins(aPage); createWidget(aPage); if (aWdgType == WDG_SWITCH) { ModuleBase_WidgetSwitch* aSwitch = qobject_cast(aWidget); diff --git a/src/ModuleBase/ModuleBase_WidgetFeature.cpp b/src/ModuleBase/ModuleBase_WidgetFeature.cpp index 4269711c8..fcc226b3e 100644 --- a/src/ModuleBase/ModuleBase_WidgetFeature.cpp +++ b/src/ModuleBase/ModuleBase_WidgetFeature.cpp @@ -6,6 +6,7 @@ #include #include +#include #include #include @@ -33,7 +34,7 @@ ModuleBase_WidgetFeature::ModuleBase_WidgetFeature(QWidget* theParent, { myContainer = new QWidget(theParent); QHBoxLayout* aControlLay = new QHBoxLayout(myContainer); - aControlLay->setContentsMargins(0, 0, 0, 0); + ModuleBase_Tools::adjustMargins(aControlLay); QString aLabelText = QString::fromStdString(theData->widgetLabel()); myLabel = new QLabel(aLabelText, myContainer); diff --git a/src/ModuleBase/ModuleBase_WidgetFileSelector.cpp b/src/ModuleBase/ModuleBase_WidgetFileSelector.cpp index a2e8186c8..9f16b74f6 100644 --- a/src/ModuleBase/ModuleBase_WidgetFileSelector.cpp +++ b/src/ModuleBase/ModuleBase_WidgetFileSelector.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include @@ -36,7 +37,7 @@ ModuleBase_WidgetFileSelector::ModuleBase_WidgetFileSelector(QWidget* theParent, myMainWidget = new QWidget(theParent); QGridLayout* aMainLay = new QGridLayout(myMainWidget); - aMainLay->setContentsMargins(0, 0, 0, 0); + ModuleBase_Tools::adjustMargins(aMainLay); QLabel* aTitleLabel = new QLabel(myTitle, myMainWidget); aTitleLabel->setIndent(1); aMainLay->addWidget(aTitleLabel, 0, 0); diff --git a/src/ModuleBase/ModuleBase_WidgetPoint2D.cpp b/src/ModuleBase/ModuleBase_WidgetPoint2D.cpp index 3271fe723..c6d341d00 100644 --- a/src/ModuleBase/ModuleBase_WidgetPoint2D.cpp +++ b/src/ModuleBase/ModuleBase_WidgetPoint2D.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include @@ -33,10 +34,12 @@ ModuleBase_WidgetPoint2D::ModuleBase_WidgetPoint2D(QWidget* theParent, : ModuleBase_ModelWidget(theParent, theData, theParentId) { myOptionParam = theData->getProperty(PREVIOUS_FEATURE_PARAM); - myGroupBox = new QGroupBox(QString::fromStdString(theData->getProperty(CONTAINER_PAGE_NAME)), - theParent); + QString aPageName = QString::fromStdString(theData->getProperty(CONTAINER_PAGE_NAME)); + myGroupBox = new QGroupBox(aPageName, theParent); + myGroupBox->setFlat(false); + QGridLayout* aGroupLay = new QGridLayout(myGroupBox); - aGroupLay->setContentsMargins(2, 0, 2, 0); + ModuleBase_Tools::adjustMargins(aGroupLay); aGroupLay->setColumnStretch(1, 1); { QLabel* aLabel = new QLabel(myGroupBox); diff --git a/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp b/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp index fcd287c55..fa05bba82 100644 --- a/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp +++ b/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp @@ -3,7 +3,8 @@ // Author: Vitaly Smetannikov #include "ModuleBase_WidgetShapeSelector.h" -#include "ModuleBase_IWorkshop.h" +#include +#include #include #include @@ -58,8 +59,8 @@ ModuleBase_WidgetShapeSelector::ModuleBase_WidgetShapeSelector(QWidget* theParen { myContainer = new QWidget(theParent); QHBoxLayout* aLayout = new QHBoxLayout(myContainer); + ModuleBase_Tools::adjustMargins(aLayout); - aLayout->setContentsMargins(0, 0, 0, 0); QString aLabelText = QString::fromStdString(theData->widgetLabel()); QString aLabelIcon = QString::fromStdString(theData->widgetIcon()); myLabel = new QLabel(aLabelText, myContainer); diff --git a/src/PartSet/PartSet_OperationFeatureBase.cpp b/src/PartSet/PartSet_OperationFeatureBase.cpp index c1da278fa..d722998f8 100644 --- a/src/PartSet/PartSet_OperationFeatureBase.cpp +++ b/src/PartSet/PartSet_OperationFeatureBase.cpp @@ -115,6 +115,13 @@ void PartSet_OperationFeatureBase::mouseReleased(QMouseEvent* theEvent, Handle(V void PartSet_OperationFeatureBase::onWidgetActivated(ModuleBase_ModelWidget* theWidget) { + if(myActiveWidget) { + myActiveWidget->setHighlighted(false); + } + if(theWidget) { + theWidget->setHighlighted(true); + } + myActiveWidget = theWidget; activateByPreselection(); if (myInitFeature && myActiveWidget) { diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index 8c76c2fd1..b48c1edcb 100644 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -44,7 +44,8 @@ #include #include #include -#include "ModuleBase_WidgetFactory.h" +#include +#include #include #include @@ -498,6 +499,7 @@ void XGUI_Workshop::onOperationStarted() myPropertyPanel->cleanContent(); aFactory.createWidget(myPropertyPanel->contentWidget()); + ModuleBase_Tools::zeroMargins(myPropertyPanel->contentWidget()); QList aWidgets = aFactory.getModelWidgets(); QList::const_iterator anIt = aWidgets.begin(), aLast = aWidgets.end();