1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: ModuleBase_WidgetEditor.cpp
4 // Created: 25 Apr 2014
5 // Author: Natalia ERMOLAEVA
7 #include <ModuleBase_WidgetEditor.h>
8 #include <ModuleBase_ParamSpinBox.h>
9 #include <ModuleBase_Tools.h>
11 #include <Config_Keywords.h>
12 #include <Config_WidgetAPI.h>
14 #include <Events_Loop.h>
15 #include <ModelAPI_Events.h>
17 #include <ModelAPI_Feature.h>
18 #include <ModelAPI_Data.h>
19 #include <ModelAPI_Object.h>
20 #include <ModelAPI_AttributeDouble.h>
22 #include <GeomDataAPI_Point2D.h>
24 #include <QApplication>
28 #include <QWidgetAction>
30 #include <QRegExpValidator>
31 #include <QDesktopWidget>
35 ModuleBase_WidgetEditor::ModuleBase_WidgetEditor(QWidget* theParent,
36 const Config_WidgetAPI* theData,
37 const std::string& theParentId)
38 : ModuleBase_WidgetDoubleValue(theParent, theData, theParentId)
42 ModuleBase_WidgetEditor::~ModuleBase_WidgetEditor()
46 void ModuleBase_WidgetEditor::editedValue(double& outValue, QString& outText)
48 QDialog aDlg(QApplication::desktop(), Qt::FramelessWindowHint);
49 QHBoxLayout* aLay = new QHBoxLayout(&aDlg);
50 aLay->setContentsMargins(2, 2, 2, 2);
52 ModuleBase_ParamSpinBox* anEditor = new ModuleBase_ParamSpinBox(&aDlg);
53 anEditor->enableKeyPressEvent(true);
55 connect(anEditor, SIGNAL(keyReleased(QKeyEvent*)), this, SIGNAL(keyReleased(QKeyEvent*)));
58 anEditor->setMinimum(0);
59 anEditor->setMaximum(DBL_MAX);
60 if (outText.isEmpty())
61 anEditor->setValue(outValue);
63 anEditor->setText(outText);
65 aLay->addWidget(anEditor);
68 anEditor->selectAll();
69 QObject::connect(anEditor, SIGNAL(editingFinished()), &aDlg, SLOT(accept()));
71 aDlg.move(QCursor::pos());
75 disconnect(anEditor, SIGNAL(keyReleased(QKeyEvent*)), this, SIGNAL(keyReleased(QKeyEvent*)));
78 outText = anEditor->text();
80 double aValue = outText.toDouble(&isDouble);
83 outText = ""; // return empty string, if it's can be converted to a double
87 bool ModuleBase_WidgetEditor::focusTo()
89 // nds: it seems, that the timer is not necessary anymore
91 // We can not launch here modal process for value editing because
92 // it can be called on other focusOutWidget event and will block it
93 //QTimer::singleShot(1, this, SLOT(showPopupEditor()));
100 void ModuleBase_WidgetEditor::showPopupEditor()
102 // we need to emit the focus in event manually in order to save the widget as an active
103 // in the property panel before the mouse leave event happens in the viewer. The module
104 // ask an active widget and change the feature visualization if the widget is not the current one.
105 emit focusInWidget(this);
107 // nds: it seems, that the envents processing is not necessary anymore
108 // White while all events will be processed
109 //QApplication::processEvents();
110 double aValue = mySpinBox->value();
112 if (mySpinBox->hasVariable())
113 aText = mySpinBox->text();
115 editedValue(aValue, aText);
116 if (aText.isEmpty()) {
117 ModuleBase_Tools::setSpinValue(mySpinBox, aValue);
119 ModuleBase_Tools::setSpinText(mySpinBox, aText);
121 emit valuesChanged();
122 // the focus leaves the control automatically by the Enter/Esc event
123 // it is processed in operation manager
124 //emit focusOutWidget(this);