From: sbh Date: Mon, 27 Oct 2014 12:11:11 +0000 (+0300) Subject: Issue #143 highlight active restored X-Git-Tag: V_0.5~69^2~6 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=268a85f7e866514f9cc63a15ca9585979601ada7;p=modules%2Fshaper.git Issue #143 highlight active restored --- diff --git a/src/ModuleBase/ModuleBase_ModelWidget.cpp b/src/ModuleBase/ModuleBase_ModelWidget.cpp index e2b934ee6..dde892d22 100644 --- a/src/ModuleBase/ModuleBase_ModelWidget.cpp +++ b/src/ModuleBase/ModuleBase_ModelWidget.cpp @@ -39,9 +39,8 @@ void ModuleBase_ModelWidget::enableFocusProcessing() { QList aMyControls = getControls(); foreach(QWidget* eachControl, aMyControls) { - if(!myFocusInWidgets.contains(eachControl)) { - enableFocusProcessing(eachControl); - } + eachControl->setFocusPolicy(Qt::StrongFocus); + eachControl->installEventFilter(this); } } @@ -92,20 +91,15 @@ void ModuleBase_ModelWidget::updateObject(ObjectPtr theObj) const ModelAPI_EventCreator::get()->sendUpdated(theObj, anEvent); } -void ModuleBase_ModelWidget::enableFocusProcessing(QWidget* theWidget) -{ - theWidget->setFocusPolicy(Qt::StrongFocus); - theWidget->installEventFilter(this); - myFocusInWidgets.append(theWidget); -} - bool ModuleBase_ModelWidget::eventFilter(QObject* theObject, QEvent *theEvent) { QWidget* aWidget = qobject_cast(theObject); - if (theEvent->type() == QEvent::MouseButtonRelease && - myFocusInWidgets.contains(aWidget)) { - emit focusInWidget(this); + if (theEvent->type() == QEvent::FocusIn) { + if (getControls().contains(aWidget)) { + emit focusInWidget(this); + } } // pass the event on to the parent class + return QObject::eventFilter(theObject, theEvent); } diff --git a/src/ModuleBase/ModuleBase_ModelWidget.h b/src/ModuleBase/ModuleBase_ModelWidget.h index 9f2f6f455..48a650e32 100644 --- a/src/ModuleBase/ModuleBase_ModelWidget.h +++ b/src/ModuleBase/ModuleBase_ModelWidget.h @@ -139,10 +139,6 @@ signals: void updateObject(ObjectPtr theObj) const; - private: - /// Let the widget process FocusIn events - void enableFocusProcessing(QWidget* theWidget); - protected: std::string myAttributeID; /// the attribute name of the model feature std::string myParentId; /// name of parent @@ -151,10 +147,6 @@ signals: 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 - QList myFocusInWidgets; }; #endif diff --git a/src/ModuleBase/ModuleBase_Operation.cpp b/src/ModuleBase/ModuleBase_Operation.cpp index 19876df75..36bc9f6f3 100644 --- a/src/ModuleBase/ModuleBase_Operation.cpp +++ b/src/ModuleBase/ModuleBase_Operation.cpp @@ -187,8 +187,8 @@ void ModuleBase_Operation::start() void ModuleBase_Operation::resume() { if (myPropertyPanel) - connect(myPropertyPanel, SIGNAL(widgetActivated(ModuleBase_ModelWidget*)), this, - SLOT(onWidgetActivated(ModuleBase_ModelWidget*))); + connect(myPropertyPanel, SIGNAL(widgetActivated(ModuleBase_ModelWidget*)), + this, SLOT(onWidgetActivated(ModuleBase_ModelWidget*))); emit resumed(); } diff --git a/src/XGUI/XGUI_PropertyPanel.cpp b/src/XGUI/XGUI_PropertyPanel.cpp index 93a35bdc9..9f6a706cf 100644 --- a/src/XGUI/XGUI_PropertyPanel.cpp +++ b/src/XGUI/XGUI_PropertyPanel.cpp @@ -23,7 +23,8 @@ #endif XGUI_PropertyPanel::XGUI_PropertyPanel(QWidget* theParent) - : ModuleBase_IPropertyPanel(theParent), myActiveWidget(0) + : ModuleBase_IPropertyPanel(theParent), + myActiveWidget(NULL) { this->setWindowTitle(tr("Property Panel")); QAction* aViewAct = this->toggleViewAction(); @@ -71,6 +72,7 @@ void XGUI_PropertyPanel::cleanContent() { myWidgets.clear(); qDeleteAll(myCustomWidget->children()); + myActiveWidget = NULL; } void XGUI_PropertyPanel::setModelWidgets(const QList& theWidgets) @@ -87,7 +89,7 @@ void XGUI_PropertyPanel::setModelWidgets(const QList& t connect(*anIt, SIGNAL(focusOutWidget(ModuleBase_ModelWidget*)), this, SLOT(activateNextWidget(ModuleBase_ModelWidget*))); connect(*anIt, SIGNAL(focusInWidget(ModuleBase_ModelWidget*)), - this, SIGNAL(widgetActivated(ModuleBase_ModelWidget*))); + this, SLOT(activateWidget(ModuleBase_ModelWidget*))); ModuleBase_WidgetPoint2D* aPointWidget = dynamic_cast(*anIt); if (aPointWidget) @@ -121,20 +123,17 @@ QWidget* XGUI_PropertyPanel::contentWidget() void XGUI_PropertyPanel::updateContentWidget(FeaturePtr theFeature) { - int aS = myWidgets.size(); foreach(ModuleBase_ModelWidget* eachWidget, myWidgets) { eachWidget->setFeature(theFeature); eachWidget->restoreValue(); } - // the repaint is used here to immediatelly react in GUI to the values change. + // the repaint is used here to immediately react in GUI to the values change. repaint(); } - void XGUI_PropertyPanel::activateNextWidget(ModuleBase_ModelWidget* theWidget) { - QObject* aSender = sender(); ModuleBase_ModelWidget* aNextWidget = 0; QList::const_iterator anIt = myWidgets.begin(), aLast = myWidgets.end(); bool isFoundWidget = false; @@ -146,8 +145,11 @@ void XGUI_PropertyPanel::activateNextWidget(ModuleBase_ModelWidget* theWidget) } isFoundWidget = (*anIt) == theWidget; } - myActiveWidget = aNextWidget; - emit widgetActivated(myActiveWidget); + // Normaly focusTo is enough to activate widget + // here is a special case on mouse click in the viewer + if(aNextWidget == NULL) { + activateWidget(NULL); + } } void XGUI_PropertyPanel::activateNextWidget() @@ -160,3 +162,15 @@ void XGUI_PropertyPanel::setAcceptEnabled(bool isEnabled) QPushButton* anOkBtn = findChild(XGUI::PROP_PANEL_OK); anOkBtn->setEnabled(isEnabled); } + +void XGUI_PropertyPanel::activateWidget(ModuleBase_ModelWidget* theWidget) +{ + if(myActiveWidget) { + myActiveWidget->setHighlighted(false); + } + if(theWidget) { + theWidget->setHighlighted(true); + } + myActiveWidget = theWidget; + emit widgetActivated(theWidget); +} diff --git a/src/XGUI/XGUI_PropertyPanel.h b/src/XGUI/XGUI_PropertyPanel.h index b29d51579..ebd529d11 100644 --- a/src/XGUI/XGUI_PropertyPanel.h +++ b/src/XGUI/XGUI_PropertyPanel.h @@ -51,12 +51,19 @@ Q_OBJECT // Enables / disables "ok" ("accept") button void setAcceptEnabled(bool); -signals: + protected slots: + // Makes the given widget active, highlights it and removes + // highlighting from the previous active widget + // emits widgetActivated(theWidget) signal + void activateWidget(ModuleBase_ModelWidget* theWidget); + + signals: /// Signal about the point 2d set to the feature /// \param the feature /// \param the attribute of the feature void storedPoint2D(ObjectPtr theFeature, const std::string& theAttribute); + private: QWidget* myCustomWidget; QList myWidgets; diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index 8ca4729a3..14730f774 100644 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -1011,10 +1011,6 @@ void XGUI_Workshop::createDockWidgets() connect(aCancelBtn, SIGNAL(clicked()), myOperationMgr, SLOT(onAbortOperation())); connect(myPropertyPanel, SIGNAL(keyReleased(QKeyEvent*)), myOperationMgr, SLOT(onKeyReleased(QKeyEvent*))); - //connect(myPropertyPanel, SIGNAL(widgetActivated(ModuleBase_ModelWidget*)), myOperationMgr, - // SLOT(onWidgetActivated(ModuleBase_ModelWidget*))); - //connect(myOperationMgr, SIGNAL(activateNextWidget(ModuleBase_ModelWidget*)), myPropertyPanel, - // SLOT(onActivateNextWidget(ModuleBase_ModelWidget*))); connect(myOperationMgr, SIGNAL(operationValidated(bool)), myPropertyPanel, SLOT(setAcceptEnabled(bool)));