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 myAttributeID = theData ? theData->widgetId() : "";
32 bool ModuleBase_ModelWidget::isInitialized(ObjectPtr theObject) const
34 return theObject->data()->attribute(attributeID())->isInitialized();
37 void ModuleBase_ModelWidget::enableFocusProcessing()
39 QList<QWidget*> aMyControls = getControls();
40 foreach(QWidget* eachControl, aMyControls) {
41 eachControl->setFocusPolicy(Qt::StrongFocus);
42 eachControl->installEventFilter(this);
46 void ModuleBase_ModelWidget::setHighlighted(bool isHighlighted)
48 QList<QWidget*> aWidgetList = getControls();
49 foreach(QWidget* aWidget, aWidgetList) {
50 QLabel* aLabel = qobject_cast<QLabel*>(aWidget);
51 // We won't set the effect to QLabels - it looks ugly
54 // If effect is the installed on a different widget, setGraphicsEffect() will
55 // remove the effect from the widget and install it on this widget.
56 // That's why we create a new effect for each widget
57 QGraphicsDropShadowEffect* aGlowEffect = new QGraphicsDropShadowEffect();
58 aGlowEffect->setOffset(.0);
59 aGlowEffect->setBlurRadius(10.0);
60 aGlowEffect->setColor(QColor(0, 170, 255)); // Light-blue color, #00AAFF
61 aWidget->setGraphicsEffect(aGlowEffect);
63 QGraphicsEffect* anEffect = aWidget->graphicsEffect();
65 anEffect->deleteLater();
66 aWidget->setGraphicsEffect(NULL);
71 bool ModuleBase_ModelWidget::focusTo()
73 QList<QWidget*> aControls = getControls();
74 QList<QWidget*>::const_iterator anIt = aControls.begin(), aLast = aControls.end();
75 for (; anIt != aLast; anIt++) {
76 QWidget* aWidget = *anIt;
77 if (aWidget && aWidget->focusPolicy() != Qt::NoFocus) {
86 void ModuleBase_ModelWidget::updateObject(ObjectPtr theObj) const
88 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
89 static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY);
90 ModelAPI_EventCreator::get()->sendUpdated(theObj, anEvent);
93 bool ModuleBase_ModelWidget::eventFilter(QObject* theObject, QEvent *theEvent)
95 QWidget* aWidget = qobject_cast<QWidget*>(theObject);
96 if (theEvent->type() == QEvent::FocusIn) {
97 if (getControls().contains(aWidget)) {
98 emit focusInWidget(this);
101 // pass the event on to the parent class
103 return QObject::eventFilter(theObject, theEvent);