Salome HOME
Issue #1005: To improve user-friendship of error-messages for features and attributes
[modules/shaper.git] / src / ModuleBase / ModuleBase_WidgetLabel.cpp
1 // Copyright (C) 2014-2016 CEA/DEN, EDF R&D
2
3 // File:        ModuleBase_WidgetLabel.cpp
4 // Created:     03 Dec 2014
5 // Author:      Vitaly SMETANNIKOV
6
7 // Modified by Clarisse Genrault (CEA) : 17 Nov 2016
8
9 #include "ModuleBase_WidgetLabel.h"
10
11 #include <Config_WidgetAPI.h>
12 #include <Config_Keywords.h>
13 #include <ModuleBase_IconFactory.h>
14 #include <ModuleBase_Tools.h>
15
16 #include <ModelAPI_AttributeString.h>
17
18 #include <QLabel>
19 #include <QVBoxLayout>
20
21
22 ModuleBase_WidgetLabel::ModuleBase_WidgetLabel(QWidget* theParent,
23                                                const Config_WidgetAPI* theData)
24 : ModuleBase_ModelWidget(theParent, theData)
25 {
26   QString aText = translate(theData->getProperty("title"));
27   QString aLabelIcon = QString::fromStdString(theData->getProperty("icon"));
28   myLabel = new QLabel(aText, theParent);
29   if (!aLabelIcon.isEmpty()) {
30     myLabel->setPixmap(ModuleBase_IconFactory::loadPixmap(aLabelIcon));
31     myLabel->setAlignment(Qt::AlignHCenter | Qt::AlignTop);
32   } else {
33     myLabel->setAlignment(Qt::AlignLeft | Qt::AlignTop);
34   }
35   myLabel->setWordWrap(true);
36   myLabel->setIndent(5);
37   myLabel->setContentsMargins(0,0,0,4);
38
39   QVBoxLayout* aLayout = new QVBoxLayout(this);
40   ModuleBase_Tools::zeroMargins(aLayout);
41   aLayout->addWidget(myLabel);
42   setLayout(aLayout);
43
44   std::string aStyleSheet = theData->getProperty(ATTR_STYLE_SHEET).c_str();
45   if (!aStyleSheet.empty())
46     myLabel->setStyleSheet(QString("QLabel {%1}").arg(aStyleSheet.c_str()));
47 }
48
49 ModuleBase_WidgetLabel::~ModuleBase_WidgetLabel()
50 {
51 }
52
53 QList<QWidget*> ModuleBase_WidgetLabel::getControls() const
54 {
55   return QList<QWidget*>();
56 }
57
58 bool ModuleBase_WidgetLabel::restoreValueCustom()
59 {
60   DataPtr aData = myFeature->data();
61   AttributeStringPtr aStrAttr = aData->string(attributeID());
62   if (aStrAttr.get()) {
63     std::string aMsg;
64     if (aStrAttr.get()) {
65       aMsg = aStrAttr->value();
66     }
67     QString aText = ModuleBase_Tools::translate(myFeature->getKind(), aMsg);
68     myLabel->setText(aText);
69   }
70   return true;
71 }
72
73 bool ModuleBase_WidgetLabel::focusTo()
74 {
75   restoreValue();
76   return false;
77 }