1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: ModuleBase_ModelWidget.h
4 // Created: 25 Apr 2014
5 // Author: Natalia ERMOLAEVA
7 #include "ModuleBase_ModelWidget.h"
9 #include <ModelAPI_Data.h>
10 #include <ModelAPI_Attribute.h>
11 #include <ModelAPI_Events.h>
12 #include <ModelAPI_Session.h>
14 #include <Config_Keywords.h>
15 #include <Config_WidgetAPI.h>
17 #include <Events_Loop.h>
20 #include <QGraphicsDropShadowEffect>
24 ModuleBase_ModelWidget::ModuleBase_ModelWidget(QWidget* theParent,
25 const Config_WidgetAPI* theData,
26 const std::string& theParentId)
28 myParentId(theParentId),
31 myDefaultValue = theData->getProperty(ATTR_DEFAULT);
32 myIsComputedDefault = theData->getProperty(ATTR_DEFAULT) == DOUBLE_WDG_DEFAULT_COMPUTED;
33 myAttributeID = theData ? theData->widgetId() : "";
35 connect(this, SIGNAL(valuesChanged()), this, SLOT(onWidgetValuesChanged()));
38 bool ModuleBase_ModelWidget::isInitialized(ObjectPtr theObject) const
40 return theObject->data()->attribute(attributeID())->isInitialized();
43 void ModuleBase_ModelWidget::enableFocusProcessing()
45 QList<QWidget*> aMyControls = getControls();
46 foreach(QWidget* eachControl, aMyControls) {
47 eachControl->setFocusPolicy(Qt::StrongFocus);
48 eachControl->installEventFilter(this);
52 void ModuleBase_ModelWidget::setHighlighted(bool isHighlighted)
54 QList<QWidget*> aWidgetList = getControls();
55 foreach(QWidget* aWidget, aWidgetList) {
56 QLabel* aLabel = qobject_cast<QLabel*>(aWidget);
57 // We won't set the effect to QLabels - it looks ugly
60 // If effect is the installed on a different widget, setGraphicsEffect() will
61 // remove the effect from the widget and install it on this widget.
62 // That's why we create a new effect for each widget
63 QGraphicsDropShadowEffect* aGlowEffect = new QGraphicsDropShadowEffect();
64 aGlowEffect->setOffset(.0);
65 aGlowEffect->setBlurRadius(10.0);
66 aGlowEffect->setColor(QColor(0, 170, 255)); // Light-blue color, #00AAFF
67 aWidget->setGraphicsEffect(aGlowEffect);
69 QGraphicsEffect* anEffect = aWidget->graphicsEffect();
71 anEffect->deleteLater();
72 aWidget->setGraphicsEffect(NULL);
77 void ModuleBase_ModelWidget::setFeature(const FeaturePtr& theFeature, const bool theToStoreValue)
79 myFeature = theFeature;
84 bool ModuleBase_ModelWidget::focusTo()
86 QList<QWidget*> aControls = getControls();
87 QList<QWidget*>::const_iterator anIt = aControls.begin(), aLast = aControls.end();
88 for (; anIt != aLast; anIt++) {
89 QWidget* aWidget = *anIt;
90 if (aWidget && aWidget->focusPolicy() != Qt::NoFocus) {
98 void ModuleBase_ModelWidget::activate()
100 // the control value is stored to the mode by the focus in on the widget
101 // we need the value is initialized in order to enable the apply button in the property panel.
102 // It should happens in the creation mode only because all fields are filled in the edition mode
103 if (!isEditingMode()) {
104 AttributePtr anAttribute = myFeature->data()->attribute(myAttributeID);
105 if (anAttribute.get() != NULL && !anAttribute->isInitialized()) {
106 if (isComputedDefault()) {
107 if (myFeature->compute(myAttributeID)) {
119 void ModuleBase_ModelWidget::updateObject(ObjectPtr theObj) const
121 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
122 static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY);
123 ModelAPI_EventCreator::get()->sendUpdated(theObj, anEvent);
126 void ModuleBase_ModelWidget::moveObject(ObjectPtr theObj) const
128 static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_MOVED);
129 ModelAPI_EventCreator::get()->sendUpdated(theObj, anEvent);
130 Events_Loop::loop()->flush(anEvent);
133 bool ModuleBase_ModelWidget::eventFilter(QObject* theObject, QEvent *theEvent)
135 QWidget* aWidget = qobject_cast<QWidget*>(theObject);
136 if (theEvent->type() == QEvent::FocusIn) {
137 if (getControls().contains(aWidget)) {
138 emit focusInWidget(this);
141 // pass the event on to the parent class
143 return QObject::eventFilter(theObject, theEvent);
146 //**************************************************************
147 void ModuleBase_ModelWidget::onWidgetValuesChanged()