Salome HOME
Issue #979: Provide modal dialog box for parameters management
[modules/shaper.git] / src / ModuleBase / ModuleBase_WidgetErrorLabel.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        ModuleBase_WidgetErrorLabel.cpp
4 // Created:     03 Dec 2014
5 // Author:      Vitaly SMETANNIKOV
6
7 #include "ModuleBase_WidgetErrorLabel.h"
8
9 #include <Config_WidgetAPI.h>
10 #include <ModuleBase_Tools.h>
11 #include <ModelAPI_AttributeString.h>
12
13 #include <QLabel>
14 #include <QEvent>
15
16 ModuleBase_WidgetErrorLabel::ModuleBase_WidgetErrorLabel(QWidget* theParent,
17                                                          const Config_WidgetAPI* theData)
18 : ModuleBase_WidgetLabel(theParent, theData)
19 {
20   myDefaultStyle = myLabel->styleSheet();
21   myLabel->setContentsMargins(0,0,0,4);
22   myLabel->setWordWrap(true);
23   myLabel->installEventFilter(this);
24 }
25
26 ModuleBase_WidgetErrorLabel::~ModuleBase_WidgetErrorLabel()
27 {
28 }
29
30 bool ModuleBase_WidgetErrorLabel::restoreValueCustom()
31 {
32   DataPtr aData = myFeature->data();
33   AttributeStringPtr aStrAttr = aData->string(attributeID());
34   std::string aMsg;
35   if (aStrAttr.get()) {
36     aMsg = aStrAttr->value();
37   }
38   if (aMsg.empty()) {
39     myLabel->setText("");
40     myLabel->setStyleSheet(myDefaultStyle);
41   } else {
42     myLabel->setText(aMsg.c_str());
43     //myLabel->setStyleSheet("QLabel { color : red; font : italic }");
44     myLabel->setStyleSheet("QLabel { color : red; font : bold }");
45     //myLabel->setStyleSheet("QLabel { border: 1px solid red; }");
46   }
47   return true;
48 }
49
50
51 bool ModuleBase_WidgetErrorLabel::focusTo() 
52
53   restoreValue();
54   return false; 
55 }
56
57 bool ModuleBase_WidgetErrorLabel::eventFilter(QObject* theObj, QEvent* theEvent)
58 {
59   if (theObj == myLabel) {
60     if (theEvent->type() == QEvent::Show)
61       restoreValue();
62   }
63   return ModuleBase_WidgetLabel::eventFilter(theObj, theEvent);
64 }