Salome HOME
Merge branch 'Pre_2.8.0_development'
[modules/shaper.git] / src / ModuleBase / ModuleBase_WidgetLabel.cpp
1 // Copyright (C) 2014-2017  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
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
19 //
20
21 #include "ModuleBase_WidgetLabel.h"
22
23 #include <Config_WidgetAPI.h>
24 #include <Config_Keywords.h>
25 #include <ModuleBase_IconFactory.h>
26 #include <ModuleBase_Tools.h>
27
28 #include <ModelAPI_AttributeString.h>
29
30 #include <QLabel>
31 #include <QVBoxLayout>
32
33
34 ModuleBase_WidgetLabel::ModuleBase_WidgetLabel(QWidget* theParent,
35                                                const Config_WidgetAPI* theData)
36 : ModuleBase_ModelWidget(theParent, theData)
37 {
38   QString aText = translate(theData->getProperty("title"));
39   QString aLabelIcon = QString::fromStdString(theData->getProperty("icon"));
40   myLabel = new QLabel(aText, theParent);
41   if (!aLabelIcon.isEmpty()) {
42     myLabel->setPixmap(ModuleBase_IconFactory::loadPixmap(aLabelIcon));
43     myLabel->setAlignment(Qt::AlignHCenter | Qt::AlignTop);
44   } else {
45     myLabel->setAlignment(Qt::AlignLeft | Qt::AlignTop);
46   }
47   myLabel->setWordWrap(true);
48   myLabel->setIndent(5);
49   myLabel->setContentsMargins(0,0,0,4);
50
51   QVBoxLayout* aLayout = new QVBoxLayout(this);
52   ModuleBase_Tools::zeroMargins(aLayout);
53   aLayout->addWidget(myLabel);
54   setLayout(aLayout);
55
56   std::string aStyleSheet = theData->getProperty(ATTR_STYLE_SHEET).c_str();
57   if (!aStyleSheet.empty())
58     myLabel->setStyleSheet(QString("QLabel {%1}").arg(aStyleSheet.c_str()));
59 }
60
61 ModuleBase_WidgetLabel::~ModuleBase_WidgetLabel()
62 {
63 }
64
65 QList<QWidget*> ModuleBase_WidgetLabel::getControls() const
66 {
67   return QList<QWidget*>();
68 }
69
70 bool ModuleBase_WidgetLabel::restoreValueCustom()
71 {
72   DataPtr aData = myFeature->data();
73   AttributeStringPtr aStrAttr = aData->string(attributeID());
74   if (aStrAttr.get()) {
75     std::string aMsg;
76     if (aStrAttr.get()) {
77       aMsg = aStrAttr->value();
78     }
79     QString aText = ModuleBase_Tools::translate(myFeature->getKind(), aMsg);
80     myLabel->setText(aText);
81   }
82   return true;
83 }
84
85 bool ModuleBase_WidgetLabel::focusTo()
86 {
87   restoreValue();
88   return false;
89 }