Salome HOME
Issue #2876: Fix synchronization of objects display on module activation
[modules/shaper.git] / src / ModuleBase / ModuleBase_WidgetLabel.cpp
1 // Copyright (C) 2014-2019  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #include "ModuleBase_WidgetLabel.h"
21
22 #include <Config_WidgetAPI.h>
23 #include <Config_Keywords.h>
24 #include <ModuleBase_IconFactory.h>
25 #include <ModuleBase_Tools.h>
26
27 #include <ModelAPI_AttributeString.h>
28
29 #include <QLabel>
30 #include <QVBoxLayout>
31
32
33 ModuleBase_WidgetLabel::ModuleBase_WidgetLabel(QWidget* theParent,
34                                                const Config_WidgetAPI* theData)
35 : ModuleBase_ModelWidget(theParent, theData)
36 {
37   QString aText = translate(theData->getProperty("title"));
38   QString aLabelIcon = QString::fromStdString(theData->getProperty("icon"));
39   myLabel = new QLabel(aText, theParent);
40   if (!aLabelIcon.isEmpty()) {
41     myLabel->setPixmap(ModuleBase_IconFactory::loadPixmap(aLabelIcon));
42     myLabel->setAlignment(Qt::AlignHCenter | Qt::AlignTop);
43   } else {
44     myLabel->setAlignment(Qt::AlignLeft | Qt::AlignTop);
45   }
46   myLabel->setWordWrap(true);
47   myLabel->setIndent(5);
48   myLabel->setContentsMargins(0,0,0,4);
49
50   QVBoxLayout* aLayout = new QVBoxLayout(this);
51   ModuleBase_Tools::zeroMargins(aLayout);
52   aLayout->addWidget(myLabel);
53   setLayout(aLayout);
54
55   std::string aStyleSheet = theData->getProperty(ATTR_STYLE_SHEET).c_str();
56   if (!aStyleSheet.empty())
57     myLabel->setStyleSheet(QString("QLabel {%1}").arg(aStyleSheet.c_str()));
58 }
59
60 ModuleBase_WidgetLabel::~ModuleBase_WidgetLabel()
61 {
62 }
63
64 QList<QWidget*> ModuleBase_WidgetLabel::getControls() const
65 {
66   return QList<QWidget*>();
67 }
68
69 bool ModuleBase_WidgetLabel::restoreValueCustom()
70 {
71   DataPtr aData = myFeature->data();
72   AttributeStringPtr aStrAttr = aData->string(attributeID());
73   if (aStrAttr.get()) {
74     std::string aMsg;
75     if (aStrAttr.get()) {
76       aMsg = aStrAttr->value();
77     }
78     QString aText = ModuleBase_Tools::translate(myFeature->getKind(), aMsg);
79     myLabel->setText(aText);
80   }
81   return true;
82 }
83
84 bool ModuleBase_WidgetLabel::focusTo()
85 {
86   restoreValue();
87   return false;
88 }