Salome HOME
Get rid of compilation warnings. Part II. MSVC warnings.
[modules/shaper.git] / src / XGUI / XGUI_TransparencyWidget.cpp
1 // Copyright (C) 2014-2020  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 "XGUI_TransparencyWidget.h"
21
22 #include <QCheckBox>
23 #include <QDoubleSpinBox>
24 #include <QVBoxLayout>
25 #include <QHBoxLayout>
26 #include <QLabel>
27 #include <QSlider>
28
29 XGUI_TransparencyWidget::XGUI_TransparencyWidget(QWidget* theParent,
30                                                  const QString& /*theLabelText*/)
31   : QWidget(theParent)
32 {
33   QVBoxLayout* aLay = new QVBoxLayout(this);
34   aLay->setContentsMargins(0, 0, 0, 0);
35
36   QWidget* aInfoWgt = new QWidget(this);
37   QHBoxLayout* aInfoLay = new QHBoxLayout(aInfoWgt);
38   aInfoLay->setContentsMargins(0, 0, 0, 0);
39
40   aInfoLay->addWidget(new QLabel(tr("Opaque")));
41
42   myValLbl = new QLabel("0%", aInfoWgt);
43   myValLbl->setAlignment(Qt::AlignCenter);
44   aInfoLay->addWidget(myValLbl, 1);
45
46   aInfoLay->addWidget(new QLabel(tr("Transparent")));
47   aLay->addWidget(aInfoWgt);
48
49   mySliderValue = new QSlider(Qt::Horizontal, this);
50   mySliderValue->setRange(0, 100);
51   aLay->addWidget(mySliderValue);
52
53   connect(mySliderValue, SIGNAL(valueChanged(int)), this, SLOT(onSliderValueChanged(int)));
54 }
55
56 void XGUI_TransparencyWidget::setValue(double theValue)
57 {
58   bool isSliderBlocked = mySliderValue->blockSignals(true);
59   int aVal = theValue * 100;
60   mySliderValue->setValue(aVal);
61   myValLbl->setText(QString("%1%").arg(aVal));
62   mySliderValue->blockSignals(isSliderBlocked);
63 }
64
65 double XGUI_TransparencyWidget::getValue() const
66 {
67   return mySliderValue->value() / 100.;
68 }
69
70 void XGUI_TransparencyWidget::onSliderValueChanged(int theValue)
71 {
72   myValLbl->setText(QString("%1%").arg(theValue));
73   emit transparencyValueChanged();
74 }