From: nds Date: Thu, 10 Dec 2015 06:41:12 +0000 (+0300) Subject: #1042 Sometimes when setting distance constraints, the input field is not displayed... X-Git-Tag: V_2.1.0~201 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=df51e63f5d87b0c8fa46f5cda0c7c92aad5da888;p=modules%2Fshaper.git #1042 Sometimes when setting distance constraints, the input field is not displayed in the 3D view --- diff --git a/src/ModuleBase/ModuleBase_DoubleSpinBox.cpp b/src/ModuleBase/ModuleBase_DoubleSpinBox.cpp index 06c1afcd6..0f5ebcfc1 100644 --- a/src/ModuleBase/ModuleBase_DoubleSpinBox.cpp +++ b/src/ModuleBase/ModuleBase_DoubleSpinBox.cpp @@ -201,7 +201,7 @@ QString ModuleBase_DoubleSpinBox::removeTrailingZeroes(const QString& src) const return res; } -void ModuleBase_DoubleSpinBox::keyPressEvent(QKeyEvent *theEvent) +void ModuleBase_DoubleSpinBox::keyPressEvent(QKeyEvent* theEvent) { bool isEmitKeyRelease = false; switch (theEvent->key()) { @@ -220,7 +220,27 @@ void ModuleBase_DoubleSpinBox::keyPressEvent(QKeyEvent *theEvent) QDoubleSpinBox::keyPressEvent(theEvent); if (isEmitKeyRelease) - emit keyReleased(theEvent); + emit enterPressed(); +} + +void ModuleBase_DoubleSpinBox::keyReleaseEvent(QKeyEvent* theEvent) +{ + switch (theEvent->key()) { + case Qt::Key_Enter: + case Qt::Key_Return: { + // the enter has already been processed when key is pressed, + // key release should not be processed in operation manager + if (myIsEmitKeyPressEvent) { + theEvent->accept(); + emit enterReleased(); + return; + } + } + break; + default: + break; + } + QDoubleSpinBox::keyReleaseEvent(theEvent); } /*! diff --git a/src/ModuleBase/ModuleBase_DoubleSpinBox.h b/src/ModuleBase/ModuleBase_DoubleSpinBox.h index ef22f8ad1..d0b20e6ac 100644 --- a/src/ModuleBase/ModuleBase_DoubleSpinBox.h +++ b/src/ModuleBase/ModuleBase_DoubleSpinBox.h @@ -63,7 +63,8 @@ Q_OBJECT signals: /// The signal about key release on the control, that corresponds to the attribute /// \param theEvent key release event - void keyReleased(QKeyEvent* theEvent); + void enterPressed(); + void enterReleased(); protected slots: /// Called on text changed @@ -74,6 +75,9 @@ signals: protected: /// Removes extra trailing zero symbols QString removeTrailingZeroes(const QString&) const; + /// Called on key press event + virtual void keyReleaseEvent(QKeyEvent* theEvent); + /// Called on key press event virtual void keyPressEvent(QKeyEvent* theEvent); diff --git a/src/ModuleBase/ModuleBase_IViewer.h b/src/ModuleBase/ModuleBase_IViewer.h index 3c8f67653..4dce665ce 100644 --- a/src/ModuleBase/ModuleBase_IViewer.h +++ b/src/ModuleBase/ModuleBase_IViewer.h @@ -36,6 +36,8 @@ Q_OBJECT //! Returns Vsd_View object from currently active view window virtual Handle(V3d_View) activeView() const = 0; + virtual QWidget* activeViewPort() const = 0; + //! Enable or disable selection in the viewer //! \param isEnabled is enable or disable flag virtual void enableSelection(bool isEnabled) = 0; diff --git a/src/ModuleBase/ModuleBase_WidgetEditor.cpp b/src/ModuleBase/ModuleBase_WidgetEditor.cpp index 6ef0847ab..aa4cd79b7 100644 --- a/src/ModuleBase/ModuleBase_WidgetEditor.cpp +++ b/src/ModuleBase/ModuleBase_WidgetEditor.cpp @@ -36,7 +36,8 @@ ModuleBase_WidgetEditor::ModuleBase_WidgetEditor(QWidget* theParent, const Config_WidgetAPI* theData, const std::string& theParentId) : ModuleBase_WidgetDoubleValue(theParent, theData, theParentId), - myIsKeyReleasedEmitted(false) + //myIsEnterPressedEmitted(false), + myXPosition(-1), myYPosition(-1) { } @@ -52,9 +53,9 @@ void ModuleBase_WidgetEditor::editedValue(double& outValue, QString& outText) ModuleBase_ParamSpinBox* anEditor = new ModuleBase_ParamSpinBox(&aDlg); anEditor->enableKeyPressEvent(true); - if (!myIsEditing) { - connect(anEditor, SIGNAL(keyReleased(QKeyEvent*)), this, SLOT(onKeyReleased(QKeyEvent*))); - } + //if (!myIsEditing) { + // connect(anEditor, SIGNAL(enterPressed()), this, SLOT(onEnterPressed())); + //} anEditor->setMinimum(0); anEditor->setMaximum(DBL_MAX); @@ -67,14 +68,18 @@ void ModuleBase_WidgetEditor::editedValue(double& outValue, QString& outText) ModuleBase_Tools::setFocus(anEditor, "ModuleBase_WidgetEditor::editedValue"); anEditor->selectAll(); - QObject::connect(anEditor, SIGNAL(editingFinished()), &aDlg, SLOT(accept())); + QObject::connect(anEditor, SIGNAL(enterReleased()), &aDlg, SLOT(accept())); + + QPoint aPoint = QCursor::pos(); + if (myXPosition >= 0 && myYPosition >= 0) + aPoint = QPoint(myXPosition, myYPosition); - aDlg.move(QCursor::pos()); + aDlg.move(aPoint); aDlg.exec(); - if (!myIsEditing) { - disconnect(anEditor, SIGNAL(keyReleased(QKeyEvent*)), this, SLOT(onKeyReleased(QKeyEvent*))); - } + //if (!myIsEditing) { + // disconnect(anEditor, SIGNAL(keyReleased(QKeyEvent*)), this, SLOT(onEnterPressed())); + //} outText = anEditor->text(); bool isDouble; @@ -87,25 +92,19 @@ void ModuleBase_WidgetEditor::editedValue(double& outValue, QString& outText) bool ModuleBase_WidgetEditor::focusTo() { - // nds: it seems, that the timer is not necessary anymore - - // We can not launch here modal process for value editing because - // it can be called on other focusOutWidget event and will block it - //QTimer::singleShot(1, this, SLOT(showPopupEditor())); - showPopupEditor(); - return true; } -void ModuleBase_WidgetEditor::showPopupEditor() +void ModuleBase_WidgetEditor::showPopupEditor(const bool theSendSignals) { - myIsKeyReleasedEmitted = false; + //myIsEnterPressedEmitted = false; // we need to emit the focus in event manually in order to save the widget as an active // in the property panel before the mouse leave event happens in the viewer. The module // ask an active widget and change the feature visualization if the widget is not the current one. - emit focusInWidget(this); + if (theSendSignals) + emit focusInWidget(this); // nds: it seems, that the envents processing is not necessary anymore // White while all events will be processed @@ -121,16 +120,27 @@ void ModuleBase_WidgetEditor::showPopupEditor() } else { ModuleBase_Tools::setSpinText(mySpinBox, aText); } - emit valuesChanged(); - // the focus leaves the control automatically by the Enter/Esc event - // it is processed in operation manager - //emit focusOutWidget(this); - - if (myIsKeyReleasedEmitted) - emit enterClicked(); + if (theSendSignals) { + emit valuesChanged(); + // the focus leaves the control automatically by the Enter/Esc event + // it is processed in operation manager + //emit focusOutWidget(this); + + //if (myIsEnterPressedEmitted) + if (!myIsEditing) + emit enterClicked(); + } + else + storeValue(); } -void ModuleBase_WidgetEditor::onKeyReleased(QKeyEvent* theEvent) +/*void ModuleBase_WidgetEditor::onEnterPressed() +{ + myIsEnterPressedEmitted = true; +}*/ + +void ModuleBase_WidgetEditor::setCursorPosition(const int theX, const int theY) { - myIsKeyReleasedEmitted = true; + myXPosition = theX; + myYPosition = theY; } diff --git a/src/ModuleBase/ModuleBase_WidgetEditor.h b/src/ModuleBase/ModuleBase_WidgetEditor.h index 8f494b366..063dd2b2b 100644 --- a/src/ModuleBase/ModuleBase_WidgetEditor.h +++ b/src/ModuleBase/ModuleBase_WidgetEditor.h @@ -43,11 +43,15 @@ Q_OBJECT /// \return the state whether the widget can accept the focus virtual bool focusTo(); - /// Shous popup window under cursor for data editing - void showPopupEditor(); + /// Shous popup window under cursor for data editing + /// \param theSendSignals a flag whether the signals should be sent or the value + /// is to be applyed directly + void showPopupEditor(const bool theSendSignals = true); -protected slots: - void onKeyReleased(QKeyEvent* theEvent); + void setCursorPosition(const int theX, const int theY); + +//protected slots: + //void onEnterPressed(); private: void editedValue(double& outValue, QString& outText); @@ -59,7 +63,9 @@ private: ///< the kinds of possible features QStringList myFeatureKinds; - bool myIsKeyReleasedEmitted; + //bool myIsEnterPressedEmitted; + + int myXPosition, myYPosition; }; #endif diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index 1f0598bb4..68d855a48 100755 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -473,6 +473,7 @@ void PartSet_Module::onKeyRelease(ModuleBase_IViewWindow* theWnd, QKeyEvent* the anOpMgr->onKeyReleased(theEvent); } +#include void PartSet_Module::onOperationActivatedByPreselection() { if (!mySketchReentrantMgr->canBeCommittedByPreselection()) @@ -483,6 +484,64 @@ void PartSet_Module::onOperationActivatedByPreselection() // Set final definitions if they are necessary //propertyPanelDefined(aOperation); /// Commit sketcher operations automatically + ModuleBase_OperationFeature* aFOperation = dynamic_cast + (anOperation); + if (aFOperation) { + if (PartSet_SketcherMgr::isDistanceOperation(aFOperation)) { + // Activate dimension value editing on double click + ModuleBase_IPropertyPanel* aPanel = aFOperation->propertyPanel(); + QList aWidgets = aPanel->modelWidgets(); + // Find corresponded widget to activate value editing + foreach (ModuleBase_ModelWidget* aWgt, aWidgets) { + if (aWgt->attributeID() == "ConstraintValue") { + FeaturePtr aFeature = aFOperation->feature(); + // the featue should be displayed in order to find the AIS text position, + // the place where the editor will be shown + aFeature->setDisplayed(true); + /// the execute is necessary to perform in the feature compute for flyout position + aFeature->execute(); + + Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_CREATED)); + Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY)); + + PartSet_WidgetEditor* anEditor = dynamic_cast(aWgt); + if (anEditor) { + int aX = 0, anY = 0; + XGUI_ModuleConnector* aConnector = dynamic_cast(myWorkshop); + XGUI_Workshop* aWorkshop = aConnector->workshop(); + XGUI_Displayer* aDisplayer = aWorkshop->displayer(); + AISObjectPtr anAIS = aDisplayer->getAISObject(aFeature); + Handle(AIS_InteractiveObject) anAISIO; + if (anAIS.get() != NULL) { + anAISIO = anAIS->impl(); + } + if (anAIS.get() != NULL) { + Handle(AIS_InteractiveObject) anAISIO = anAIS->impl(); + + if (!anAISIO.IsNull()) { + Handle(AIS_Dimension) aDim = Handle(AIS_Dimension)::DownCast(anAISIO); + if (!aDim.IsNull()) { + gp_Pnt aPosition = aDim->GetTextPosition(); + + ModuleBase_IViewer* aViewer = myWorkshop->viewer(); + Handle(V3d_View) aView = aViewer->activeView(); + int aCX, aCY; + aView->Convert(aPosition.X(), aPosition.Y(), aPosition.Z(), aCX, aCY); + + QWidget* aViewPort = aViewer->activeViewPort(); + QPoint aGlPoint = aViewPort->mapToGlobal(QPoint(aCX, aCY)); + aX = aGlPoint.x(); + anY = aGlPoint.y(); + } + } + anEditor->setCursorPosition(aX, anY); + anEditor->showPopupEditor(false); + } + } + } + } + } + } anOperation->commit(); } } diff --git a/src/SketchPlugin/SketchPlugin_Feature.h b/src/SketchPlugin/SketchPlugin_Feature.h index 2f386d18d..de39f17b8 100644 --- a/src/SketchPlugin/SketchPlugin_Feature.h +++ b/src/SketchPlugin/SketchPlugin_Feature.h @@ -10,7 +10,6 @@ #include "SketchPlugin.h" #include #include -#include #include #include #include diff --git a/src/XGUI/XGUI_ViewerProxy.cpp b/src/XGUI/XGUI_ViewerProxy.cpp index 053a87abe..54dc14670 100644 --- a/src/XGUI/XGUI_ViewerProxy.cpp +++ b/src/XGUI/XGUI_ViewerProxy.cpp @@ -52,6 +52,17 @@ Handle(V3d_View) XGUI_ViewerProxy::activeView() const #endif } +QWidget* XGUI_ViewerProxy::activeViewPort() const +{ +#ifdef HAVE_SALOME + return myWorkshop->salomeConnector()->viewer()->activeView(); +#else + AppElements_Viewer* aViewer = myWorkshop->mainWindow()->viewer(); + return (aViewer->activeViewWindow()) ? + aViewer->activeViewWindow()->viewPortApp(): 0; +#endif +} + void XGUI_ViewerProxy::setViewProjection(double theX, double theY, double theZ, double theTwist) { Handle(V3d_View) aView3d = activeView(); diff --git a/src/XGUI/XGUI_ViewerProxy.h b/src/XGUI/XGUI_ViewerProxy.h index 8763be818..bce1db650 100644 --- a/src/XGUI/XGUI_ViewerProxy.h +++ b/src/XGUI/XGUI_ViewerProxy.h @@ -35,6 +35,8 @@ Q_OBJECT //! Returns Vsd_View object from currently active view window virtual Handle(V3d_View) activeView() const; + virtual QWidget* activeViewPort() const; + //! Enable or disable selection in the viewer virtual void enableSelection(bool isEnabled);