Salome HOME
#1857 In the Sketcher, ability to zoom the view from a given size
[modules/shaper.git] / src / ModuleBase / ModuleBase_LabelValue.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        ModuleBase_IWorkshop.cpp
4 // Created:     30 Nov 2016
5 // Author:      Natalia ERMOLAEVA
6
7 #include <ModuleBase_LabelValue.h>
8 #include <ModuleBase_IconFactory.h>
9 #include <ModuleBase_Tools.h>
10
11 #include <QHBoxLayout>
12 #include <QLabel>
13 #include <QLocale>
14
15 ModuleBase_LabelValue::ModuleBase_LabelValue(QWidget* theParent, const QString& theText,
16                                              const QString& theToolTip, const QString& theIcon,
17                                              int thePrecision)
18 : QWidget(theParent), myPrecision(thePrecision), myValue(0)
19 {
20   QHBoxLayout* aLayout = new QHBoxLayout(this);
21   aLayout->setContentsMargins(2, 0, 0, 0);
22   aLayout->setSpacing(0);
23
24   myLabel = new QLabel(QString("%1 : ").arg(theText), this);
25   if (!theIcon.isEmpty()) {
26     myLabel->setPixmap(ModuleBase_IconFactory::loadPixmap(theIcon));
27     aLayout->setSpacing(4);
28   }
29   myLabel->setToolTip(!theToolTip.isEmpty() ? theToolTip : theText);
30   aLayout->addWidget(myLabel);
31
32   myLabelValue = new QLabel("", this);
33   aLayout->addWidget(myLabelValue, 1);
34
35   setLocale(ModuleBase_Tools::doubleLocale());
36   aLayout->addStretch(1);
37 }
38
39 ModuleBase_LabelValue::~ModuleBase_LabelValue()
40 {
41 }
42
43 void ModuleBase_LabelValue::setValue(const double theValue)
44 {
45   myValue = theValue;
46
47   QString aStrValue = locale().toString(theValue, myPrecision >= 0 ? 'f' : 'g', qAbs(myPrecision));
48   myLabelValue->setText(aStrValue);
49   myLabelValue->setToolTip(aStrValue);
50 }