Salome HOME
Set focus into dimension editor
[modules/shaper.git] / src / ModuleBase / ModuleBase_WidgetEditor.cpp
1 // File:        ModuleBase_WidgetEditor.cpp
2 // Created:     25 Apr 2014
3 // Author:      Natalia ERMOLAEVA
4
5 #include <ModuleBase_WidgetEditor.h>
6
7 #include <Config_Keywords.h>
8 #include <Config_WidgetAPI.h>
9
10 #include <Events_Loop.h>
11 #include <Model_Events.h>
12
13 #include <ModelAPI_Feature.h>
14 #include <ModelAPI_Data.h>
15 #include <ModelAPI_Object.h>
16 #include <ModelAPI_AttributeDouble.h>
17
18 #include <GeomDataAPI_Point2D.h>
19
20 #include <QWidget>
21 #include <QLineEdit>
22 #include <QTimer>
23 #include <QDialog>
24 #include <QLayout>
25
26 ModuleBase_WidgetEditor::ModuleBase_WidgetEditor(QWidget* theParent,
27                                                  const Config_WidgetAPI* theData)
28 : ModuleBase_ModelWidget(theParent, theData), myValue(0)
29 {
30 }
31
32 ModuleBase_WidgetEditor::~ModuleBase_WidgetEditor()
33 {
34   //delete myEditor;
35 }
36
37 bool ModuleBase_WidgetEditor::storeValue(FeaturePtr theFeature) const
38 {
39   DataPtr aData = theFeature->data();
40   AttributeDoublePtr aReal = aData->real(attributeID());
41   bool isOk;
42   if (isOk && aReal->value() != myValue) {
43     aReal->setValue(myValue);
44     Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_FEATURE_UPDATED));
45   }
46   return true;
47 }
48
49 bool ModuleBase_WidgetEditor::restoreValue(FeaturePtr theFeature)
50 {
51   boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
52   AttributeDoublePtr aRef = aData->real(attributeID());
53
54   myValue = aRef->value();
55   return true;
56 }
57
58 void ModuleBase_WidgetEditor::focusTo()
59 {
60   QPoint aPoint = QCursor::pos();
61
62   QDialog aDlg;
63   aDlg.setWindowFlags(Qt::FramelessWindowHint);
64   QHBoxLayout* aLay = new QHBoxLayout(&aDlg);
65   aLay->setContentsMargins(0,0,0,0);
66
67   QLineEdit* aEditor = new QLineEdit(QString::number(myValue), &aDlg);
68   connect(aEditor, SIGNAL(returnPressed()), &aDlg, SLOT(accept()));
69   aLay->addWidget(aEditor);
70
71   aDlg.move(aPoint);
72   int aRes = aDlg.exec();
73
74   if (aRes == QDialog::Accepted)
75     myValue = aEditor->text().toDouble();
76
77   emit focusOutWidget(this);
78 }
79
80 QWidget* ModuleBase_WidgetEditor::getControl() const
81 {
82   return 0;
83 }
84
85 QList<QWidget*> ModuleBase_WidgetEditor::getControls() const
86 {
87   QList<QWidget*> aControls;
88   return aControls;
89 }
90