From: sbh Date: Wed, 11 Mar 2015 15:51:47 +0000 (+0300) Subject: Bugfixes for focus processing in the property panel X-Git-Tag: V_1.1.0~144 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=2727f05d03a3971bdb389ed0b4a237e8ce40d0d7;p=modules%2Fshaper.git Bugfixes for focus processing in the property panel --- diff --git a/src/ModuleBase/ModuleBase_ModelWidget.cpp b/src/ModuleBase/ModuleBase_ModelWidget.cpp index 2085e6902..c16c0b13f 100644 --- a/src/ModuleBase/ModuleBase_ModelWidget.cpp +++ b/src/ModuleBase/ModuleBase_ModelWidget.cpp @@ -20,6 +20,7 @@ #include #include #include +#include ModuleBase_ModelWidget::ModuleBase_ModelWidget(QWidget* theParent, const Config_WidgetAPI* theData, @@ -150,6 +151,11 @@ bool ModuleBase_ModelWidget::eventFilter(QObject* theObject, QEvent *theEvent) { QWidget* aWidget = qobject_cast(theObject); if (theEvent->type() == QEvent::FocusIn) { + #ifdef _DEBUG + // The following two lines are for debugging purpose only + QFocusEvent* aFocusEvent = dynamic_cast(theEvent); + bool isWinFocus = aFocusEvent->reason() == Qt::ActiveWindowFocusReason; + #endif if (getControls().contains(aWidget)) { emit focusInWidget(this); } diff --git a/src/ModuleBase/ModuleBase_ModelWidget.h b/src/ModuleBase/ModuleBase_ModelWidget.h index 87112716e..6d3437fe1 100644 --- a/src/ModuleBase/ModuleBase_ModelWidget.h +++ b/src/ModuleBase/ModuleBase_ModelWidget.h @@ -105,7 +105,7 @@ Q_OBJECT virtual void enableFocusProcessing(); //! Switch On/Off highlighting of the widget - void setHighlighted(bool isHighlighted); + virtual void setHighlighted(bool isHighlighted); /// Returns the attribute name /// \returns the string value diff --git a/src/ModuleBase/ModuleBase_PageBase.cpp b/src/ModuleBase/ModuleBase_PageBase.cpp index dac665edd..027150f22 100644 --- a/src/ModuleBase/ModuleBase_PageBase.cpp +++ b/src/ModuleBase/ModuleBase_PageBase.cpp @@ -52,12 +52,12 @@ void ModuleBase_PageBase::clearPage() } -void ModuleBase_PageBase::takeFocus() +bool ModuleBase_PageBase::takeFocus() { if(myWidgetList.isEmpty()) - return; + return false; - myWidgetList.first()->focusTo(); + return myWidgetList.first()->focusTo(); } QList ModuleBase_PageBase::modelWidgets() diff --git a/src/ModuleBase/ModuleBase_PageBase.h b/src/ModuleBase/ModuleBase_PageBase.h index 7f8f054ca..29e9dcd14 100644 --- a/src/ModuleBase/ModuleBase_PageBase.h +++ b/src/ModuleBase/ModuleBase_PageBase.h @@ -29,7 +29,7 @@ class MODULEBASE_EXPORT ModuleBase_PageBase void addPageWidget(ModuleBase_PageBase* theWidget); void clearPage(); - void takeFocus(); + bool takeFocus(); QList modelWidgets(); void alignToTop(); diff --git a/src/ModuleBase/ModuleBase_PageGroupBox.cpp b/src/ModuleBase/ModuleBase_PageGroupBox.cpp index f16e4d728..1631a8726 100644 --- a/src/ModuleBase/ModuleBase_PageGroupBox.cpp +++ b/src/ModuleBase/ModuleBase_PageGroupBox.cpp @@ -32,6 +32,8 @@ void ModuleBase_PageGroupBox::placeModelWidget(ModuleBase_ModelWidget* theWidget const int kCol = 0; const int kRow = myMainLayout->count(); myMainLayout->addWidget(theWidget, kRow, kCol, Qt::AlignTop | Qt::AlignLeft); + myMainLayout->setRowStretch(kRow, 0); + } void ModuleBase_PageGroupBox::placePageWidget(ModuleBase_PageBase* theWidget) @@ -45,7 +47,8 @@ void ModuleBase_PageGroupBox::placePageWidget(ModuleBase_PageBase* theWidget) } const int kCol = 0; const int kRow = myMainLayout->count(); - myMainLayout->addWidget(aWidget, kRow, kCol, Qt::AlignTop | Qt::AlignLeft); + myMainLayout->addWidget(aWidget, kRow, kCol); + myMainLayout->setRowStretch(kRow, 0); } QLayout* ModuleBase_PageGroupBox::pageLayout() diff --git a/src/ModuleBase/ModuleBase_PageWidget.cpp b/src/ModuleBase/ModuleBase_PageWidget.cpp index f49e53eea..d3039cac5 100644 --- a/src/ModuleBase/ModuleBase_PageWidget.cpp +++ b/src/ModuleBase/ModuleBase_PageWidget.cpp @@ -33,6 +33,7 @@ void ModuleBase_PageWidget::placeModelWidget(ModuleBase_ModelWidget* theWidget) const int kCol = 0; const int kRow = myMainLayout->count(); myMainLayout->addWidget(theWidget, kRow, kCol); + myMainLayout->setRowStretch(kRow, 0); } void ModuleBase_PageWidget::placePageWidget(ModuleBase_PageBase* theWidget) @@ -46,7 +47,8 @@ void ModuleBase_PageWidget::placePageWidget(ModuleBase_PageBase* theWidget) } const int kCol = 0; const int kRow = myMainLayout->count(); - myMainLayout->addWidget(aWidget, kRow, kCol);//, Qt::AlignTop | Qt::AlignLeft); + myMainLayout->addWidget(aWidget, kRow, kCol); + myMainLayout->setRowStretch(kRow, 0); } QLayout* ModuleBase_PageWidget::pageLayout() diff --git a/src/ModuleBase/ModuleBase_WidgetFactory.cpp b/src/ModuleBase/ModuleBase_WidgetFactory.cpp index 023c728a9..1731271aa 100644 --- a/src/ModuleBase/ModuleBase_WidgetFactory.cpp +++ b/src/ModuleBase/ModuleBase_WidgetFactory.cpp @@ -156,7 +156,6 @@ ModuleBase_ModelWidget* ModuleBase_WidgetFactory } else if (theType == WDG_SWITCH) { result = new ModuleBase_WidgetSwitch(theParent, myWidgetApi, myParentId); - return result; } else if (theType == WDG_TOOLBOX_BOX || theType == WDG_SWITCH_CASE) { // Do nothing for "box" and "case" diff --git a/src/ModuleBase/ModuleBase_WidgetToolbox.cpp b/src/ModuleBase/ModuleBase_WidgetToolbox.cpp index 616a5c357..c2e816e8d 100644 --- a/src/ModuleBase/ModuleBase_WidgetToolbox.cpp +++ b/src/ModuleBase/ModuleBase_WidgetToolbox.cpp @@ -7,16 +7,19 @@ #include #include +#include #include #include #include +#include #include ModuleBase_WidgetToolbox::ModuleBase_WidgetToolbox(QWidget* theParent, const Config_WidgetAPI* theData, const std::string& theParentId) -: ModuleBase_ModelWidget(theParent, theData, theParentId) +: ModuleBase_ModelWidget(theParent, theData, theParentId), + myIsPassFocusToCurrentPage(false) { QVBoxLayout* aMainLayout = new QVBoxLayout(this); ModuleBase_Tools::zeroMargins(aMainLayout); @@ -63,15 +66,18 @@ bool ModuleBase_WidgetToolbox::restoreValue() bool isSignalsBlocked = myToolBox->blockSignals(true); myToolBox->setCurrentIndex(idx); myToolBox->blockSignals(isSignalsBlocked); - focusTo(); return true; } QList ModuleBase_WidgetToolbox::getControls() const { - QList aList; - aList << myToolBox; - return aList; + QList aResult; + int idx = myToolBox->currentIndex(); + QList aModelWidgets = myPages[idx]->modelWidgets(); + foreach(ModuleBase_ModelWidget* eachModelWidget, aModelWidgets) { + aResult << eachModelWidget->getControls(); + } + return aResult; } bool ModuleBase_WidgetToolbox::focusTo() @@ -79,13 +85,24 @@ bool ModuleBase_WidgetToolbox::focusTo() int idx = myToolBox->currentIndex(); if (idx > myPages.count()) return false; - myPages[idx]->takeFocus(); - repaint(); - return true; + return myPages[idx]->takeFocus(); +} + +void ModuleBase_WidgetToolbox::setHighlighted(bool) +{ + //page containers sould not be highlighted, do nothing } +void ModuleBase_WidgetToolbox::enableFocusProcessing() +{ + myIsPassFocusToCurrentPage = true; +} + + void ModuleBase_WidgetToolbox::activateCustom() { + // activate current page + focusTo(); } bool ModuleBase_WidgetToolbox::storeValueCustom() const @@ -103,5 +120,5 @@ bool ModuleBase_WidgetToolbox::storeValueCustom() const void ModuleBase_WidgetToolbox::onPageChanged() { storeValue(); - focusTo(); + if (myIsPassFocusToCurrentPage) focusTo(); } diff --git a/src/ModuleBase/ModuleBase_WidgetToolbox.h b/src/ModuleBase/ModuleBase_WidgetToolbox.h index 2e106a720..21ab5a2c2 100644 --- a/src/ModuleBase/ModuleBase_WidgetToolbox.h +++ b/src/ModuleBase/ModuleBase_WidgetToolbox.h @@ -25,6 +25,8 @@ class ModuleBase_WidgetToolbox : public ModuleBase_ModelWidget virtual bool restoreValue(); virtual QList getControls() const; virtual bool focusTo(); + virtual void setHighlighted(bool isHighlighted); + virtual void enableFocusProcessing(); int addPage(ModuleBase_PageBase* theWidget, const QString& theName, const QString& theCaseId); @@ -37,6 +39,7 @@ class ModuleBase_WidgetToolbox : public ModuleBase_ModelWidget void onPageChanged(); private: + bool myIsPassFocusToCurrentPage; QToolBox* myToolBox; QStringList myCaseIds; QList myPages; diff --git a/src/PartSet/PartSet_WidgetSketchLabel.cpp b/src/PartSet/PartSet_WidgetSketchLabel.cpp index 1a20133b4..96435f627 100644 --- a/src/PartSet/PartSet_WidgetSketchLabel.cpp +++ b/src/PartSet/PartSet_WidgetSketchLabel.cpp @@ -74,7 +74,9 @@ PartSet_WidgetSketchLabel::~PartSet_WidgetSketchLabel() QList PartSet_WidgetSketchLabel::getControls() const { - return QList(); + QList aResult; + aResult << myLabel; + return aResult; } void PartSet_WidgetSketchLabel::onPlaneSelected() @@ -134,6 +136,17 @@ std::shared_ptr PartSet_WidgetSketchLabel::plane() const } +bool PartSet_WidgetSketchLabel::focusTo() +{ + myLabel->setFocus(); + return true; +} + +void PartSet_WidgetSketchLabel::enableFocusProcessing() +{ + myLabel->installEventFilter(this); +} + void PartSet_WidgetSketchLabel::activateCustom() { std::shared_ptr aPlane = plane(); diff --git a/src/PartSet/PartSet_WidgetSketchLabel.h b/src/PartSet/PartSet_WidgetSketchLabel.h index 1189dd228..9da513f5d 100644 --- a/src/PartSet/PartSet_WidgetSketchLabel.h +++ b/src/PartSet/PartSet_WidgetSketchLabel.h @@ -71,7 +71,9 @@ Q_OBJECT std::shared_ptr plane() const; /// This control accepts focus - virtual bool focusTo() { return true; } + virtual bool focusTo(); + virtual void setHighlighted(bool) { /*do nothing*/ }; + virtual void enableFocusProcessing(); signals: /// Signal on plane selection diff --git a/src/XGUI/XGUI_PropertyPanel.cpp b/src/XGUI/XGUI_PropertyPanel.cpp index 0e5fcdf60..26ea5d021 100644 --- a/src/XGUI/XGUI_PropertyPanel.cpp +++ b/src/XGUI/XGUI_PropertyPanel.cpp @@ -90,13 +90,13 @@ void XGUI_PropertyPanel::setModelWidgets(const QList& t { myWidgets = theWidgets; if (theWidgets.empty()) return; - QList::const_iterator anIt = theWidgets.begin(); - for (; anIt != theWidgets.end(); anIt++) { - connect(*anIt, SIGNAL(keyReleased(QKeyEvent*)), this, SIGNAL(keyReleased(QKeyEvent*))); - connect(*anIt, SIGNAL(focusOutWidget(ModuleBase_ModelWidget*)), - this, SLOT(activateNextWidget(ModuleBase_ModelWidget*))); - connect(*anIt, SIGNAL(focusInWidget(ModuleBase_ModelWidget*)), - this, SLOT(activateWidget(ModuleBase_ModelWidget*))); + foreach (ModuleBase_ModelWidget* aWidget, theWidgets) { + connect(aWidget, SIGNAL(focusInWidget(ModuleBase_ModelWidget*)), + this, SLOT(activateWidget(ModuleBase_ModelWidget*))); + connect(aWidget, SIGNAL(focusOutWidget(ModuleBase_ModelWidget*)), + this, SLOT(activateNextWidget(ModuleBase_ModelWidget*))); + connect(aWidget, SIGNAL(keyReleased(QKeyEvent*)), + this, SIGNAL(keyReleased(QKeyEvent*))); } ModuleBase_ModelWidget* aLastWidget = theWidgets.last(); if (aLastWidget) { @@ -159,9 +159,9 @@ void XGUI_PropertyPanel::activateNextWidget(ModuleBase_ModelWidget* theWidget) } // Normaly focusTo is enough to activate widget // here is a special case on mouse click in the viewer - //if(aNextWidget == NULL) { + if(aNextWidget == NULL) { activateWidget(aNextWidget); - //} + } } void XGUI_PropertyPanel::activateNextWidget() @@ -172,23 +172,24 @@ void XGUI_PropertyPanel::activateNextWidget() void XGUI_PropertyPanel::activateWidget(ModuleBase_ModelWidget* theWidget) { // Avoid activation of already actve widget. It could happen on focusIn event many times - if (theWidget == myActiveWidget) + if (theWidget == myActiveWidget) { return; + } if(myActiveWidget) { myActiveWidget->deactivate(); myActiveWidget->setHighlighted(false); } if(theWidget) { - if (theWidget) - emit beforeWidgetActivated(theWidget); - theWidget->activate(); + emit beforeWidgetActivated(theWidget); theWidget->setHighlighted(true); + theWidget->activate(); } myActiveWidget = theWidget; - if (myActiveWidget) + if (myActiveWidget) { emit widgetActivated(theWidget); - else if (!isEditingMode()) + } else if (!isEditingMode()) { emit noMoreWidgets(); + } } void XGUI_PropertyPanel::setCancelEnabled(bool theEnabled)