Salome HOME
DOF is visualized in label widget.
[modules/shaper.git] / src / ModuleBase / ModuleBase_WidgetLabel.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        ModuleBase_WidgetLabel.cpp
4 // Created:     03 Dec 2014
5 // Author:      Vitaly SMETANNIKOV
6
7 #include "ModuleBase_WidgetLabel.h"
8
9 #include <Config_WidgetAPI.h>
10 #include <Config_Keywords.h>
11 #include <ModuleBase_Tools.h>
12
13 #include <ModelAPI_AttributeString.h>
14
15 #include <QLabel>
16 #include <QVBoxLayout>
17
18
19 ModuleBase_WidgetLabel::ModuleBase_WidgetLabel(QWidget* theParent,
20                                                const Config_WidgetAPI* theData)
21 : ModuleBase_ModelWidget(theParent, theData)
22 {
23   QString aText = QString::fromStdString(theData->getProperty("title"));
24   myLabel = new QLabel(aText, theParent);
25   myLabel->setWordWrap(true);
26   myLabel->setIndent(5);
27   myLabel->setAlignment(Qt::AlignLeft | Qt::AlignTop);
28   myLabel->setContentsMargins(0,0,0,4);
29
30   QVBoxLayout* aLayout = new QVBoxLayout(this);
31   ModuleBase_Tools::zeroMargins(aLayout);
32   aLayout->addWidget(myLabel);
33   setLayout(aLayout);
34
35   std::string aStyleSheet = theData->getProperty(ATTR_STYLE_SHEET).c_str();
36   if (!aStyleSheet.empty())
37     myLabel->setStyleSheet(QString("QLabel {%1}").arg(aStyleSheet.c_str()));
38 }
39
40 ModuleBase_WidgetLabel::~ModuleBase_WidgetLabel()
41 {
42 }
43
44 QList<QWidget*> ModuleBase_WidgetLabel::getControls() const
45 {
46   return QList<QWidget*>();
47 }
48
49 bool ModuleBase_WidgetLabel::restoreValueCustom()
50 {
51   DataPtr aData = myFeature->data();
52   AttributeStringPtr aStrAttr = aData->string(attributeID());
53   if (aStrAttr.get()) {
54     std::string aMsg;
55     if (aStrAttr.get()) {
56       aMsg = aStrAttr->value();
57     }
58     myLabel->setText(aMsg.c_str());
59   }
60   return true;
61 }
62
63 bool ModuleBase_WidgetLabel::focusTo() 
64
65   restoreValue();
66   return false; 
67 }