1 // File: ModuleBase_ModelWidget.h
2 // Created: 25 Apr 2014
3 // Author: Natalia ERMOLAEVA
5 #include "ModuleBase_ModelWidget.h"
7 #include <ModelAPI_Data.h>
8 #include <ModelAPI_Attribute.h>
9 #include <ModelAPI_Events.h>
10 #include <ModelAPI_Session.h>
12 #include <Config_Keywords.h>
13 #include <Config_WidgetAPI.h>
15 #include <Events_Loop.h>
19 #include <QGraphicsDropShadowEffect>
23 ModuleBase_ModelWidget::ModuleBase_ModelWidget(QWidget* theParent, const Config_WidgetAPI* theData,
24 const std::string& theParentId)
26 myParentId(theParentId)
28 myIsComputedDefault = false;
29 myIsObligatory = theData ? theData->getBooleanAttribute(FEATURE_OBLIGATORY, true) : true;
30 myAttributeID = theData ? theData->widgetId() : "";
33 bool ModuleBase_ModelWidget::isInitialized(ObjectPtr theObject) const
35 return theObject->data()->attribute(attributeID())->isInitialized();
38 void ModuleBase_ModelWidget::enableFocusProcessing()
40 QList<QWidget*> aMyControls = getControls();
41 foreach(QWidget* eachControl, aMyControls) {
42 eachControl->setFocusPolicy(Qt::StrongFocus);
43 eachControl->installEventFilter(this);
47 void ModuleBase_ModelWidget::setHighlighted(bool isHighlighted)
49 QList<QWidget*> aWidgetList = getControls();
50 foreach(QWidget* aWidget, aWidgetList) {
51 QLabel* aLabel = qobject_cast<QLabel*>(aWidget);
52 // We won't set the effect to QLabels - it looks ugly
55 // If effect is the installed on a different widget, setGraphicsEffect() will
56 // remove the effect from the widget and install it on this widget.
57 // That's why we create a new effect for each widget
58 QGraphicsDropShadowEffect* aGlowEffect = new QGraphicsDropShadowEffect();
59 aGlowEffect->setOffset(.0);
60 aGlowEffect->setBlurRadius(10.0);
61 aGlowEffect->setColor(QColor(0, 170, 255)); // Light-blue color, #00AAFF
62 aWidget->setGraphicsEffect(aGlowEffect);
64 QGraphicsEffect* anEffect = aWidget->graphicsEffect();
66 anEffect->deleteLater();
67 aWidget->setGraphicsEffect(NULL);
72 bool ModuleBase_ModelWidget::focusTo()
74 QList<QWidget*> aControls = getControls();
75 QList<QWidget*>::const_iterator anIt = aControls.begin(), aLast = aControls.end();
76 for (; anIt != aLast; anIt++) {
77 QWidget* aWidget = *anIt;
78 if (aWidget && aWidget->focusPolicy() != Qt::NoFocus) {
87 void ModuleBase_ModelWidget::updateObject(ObjectPtr theObj) const
89 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
90 static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY);
91 ModelAPI_EventCreator::get()->sendUpdated(theObj, anEvent);
94 bool ModuleBase_ModelWidget::eventFilter(QObject* theObject, QEvent *theEvent)
96 QWidget* aWidget = qobject_cast<QWidget*>(theObject);
97 if (theEvent->type() == QEvent::FocusIn) {
98 if (getControls().contains(aWidget)) {
99 emit focusInWidget(this);
102 // pass the event on to the parent class
104 return QObject::eventFilter(theObject, theEvent);