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>
21 #include <QGraphicsDropShadowEffect>
25 ModuleBase_ModelWidget::ModuleBase_ModelWidget(QWidget* theParent, const Config_WidgetAPI* theData,
26 const std::string& theParentId)
28 myParentId(theParentId)
30 myIsComputedDefault = false;
31 myAttributeID = theData ? theData->widgetId() : "";
34 bool ModuleBase_ModelWidget::isInitialized(ObjectPtr theObject) const
36 return theObject->data()->attribute(attributeID())->isInitialized();
39 void ModuleBase_ModelWidget::enableFocusProcessing()
41 QList<QWidget*> aMyControls = getControls();
42 foreach(QWidget* eachControl, aMyControls) {
43 eachControl->setFocusPolicy(Qt::StrongFocus);
44 eachControl->installEventFilter(this);
48 void ModuleBase_ModelWidget::setHighlighted(bool isHighlighted)
50 QList<QWidget*> aWidgetList = getControls();
51 foreach(QWidget* aWidget, aWidgetList) {
52 QLabel* aLabel = qobject_cast<QLabel*>(aWidget);
53 // We won't set the effect to QLabels - it looks ugly
56 // If effect is the installed on a different widget, setGraphicsEffect() will
57 // remove the effect from the widget and install it on this widget.
58 // That's why we create a new effect for each widget
59 QGraphicsDropShadowEffect* aGlowEffect = new QGraphicsDropShadowEffect();
60 aGlowEffect->setOffset(.0);
61 aGlowEffect->setBlurRadius(10.0);
62 aGlowEffect->setColor(QColor(0, 170, 255)); // Light-blue color, #00AAFF
63 aWidget->setGraphicsEffect(aGlowEffect);
65 QGraphicsEffect* anEffect = aWidget->graphicsEffect();
67 anEffect->deleteLater();
68 aWidget->setGraphicsEffect(NULL);
73 bool ModuleBase_ModelWidget::focusTo()
75 QList<QWidget*> aControls = getControls();
76 QList<QWidget*>::const_iterator anIt = aControls.begin(), aLast = aControls.end();
77 for (; anIt != aLast; anIt++) {
78 QWidget* aWidget = *anIt;
79 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 void ModuleBase_ModelWidget::moveObject(ObjectPtr theObj) const
96 static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_MOVED);
97 ModelAPI_EventCreator::get()->sendUpdated(theObj, anEvent);
98 Events_Loop::loop()->flush(anEvent);
101 bool ModuleBase_ModelWidget::eventFilter(QObject* theObject, QEvent *theEvent)
103 QWidget* aWidget = qobject_cast<QWidget*>(theObject);
104 if (theEvent->type() == QEvent::FocusIn) {
105 if (getControls().contains(aWidget)) {
106 emit focusInWidget(this);
109 // pass the event on to the parent class
111 return QObject::eventFilter(theObject, theEvent);