Salome HOME
It removes SketchShapePlugin from plugins
[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                                                const std::string& theParentId)
19     : ModuleBase_WidgetLabel(theParent, theData, theParentId)
20 {
21   myDefaultStyle = myLabel->styleSheet();
22   myLabel->setContentsMargins(0,0,0,4);
23   myLabel->setWordWrap(true);
24   myLabel->installEventFilter(this);
25 }
26
27 ModuleBase_WidgetErrorLabel::~ModuleBase_WidgetErrorLabel()
28 {
29 }
30
31 bool ModuleBase_WidgetErrorLabel::restoreValueCustom()
32 {
33   DataPtr aData = myFeature->data();
34   AttributeStringPtr aStrAttr = aData->string(attributeID());
35   std::string aMsg;
36   if (aStrAttr.get()) {
37     aMsg = aStrAttr->value();
38   }
39   if (aMsg.empty()) {
40     myLabel->setText("");
41     myLabel->setStyleSheet(myDefaultStyle);
42   } else {
43     myLabel->setText(aMsg.c_str());
44     //myLabel->setStyleSheet("QLabel { color : red; font : italic }");
45     myLabel->setStyleSheet("QLabel { color : red; font : bold }");
46     //myLabel->setStyleSheet("QLabel { border: 1px solid red; }");
47   }
48   return true;
49 }
50
51
52 bool ModuleBase_WidgetErrorLabel::focusTo() 
53
54   restoreValue();
55   return false; 
56 }
57
58 bool ModuleBase_WidgetErrorLabel::eventFilter(QObject* theObj, QEvent* theEvent)
59 {
60   if (theObj == myLabel) {
61     if (theEvent->type() == QEvent::Show)
62       restoreValue();
63   }
64   return ModuleBase_WidgetLabel::eventFilter(theObj, theEvent);
65 }