Salome HOME
Copyright update 2020
[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, const QString& theLabelText)
30   : QWidget(theParent)
31 {
32   QVBoxLayout* aLay = new QVBoxLayout(this);
33   aLay->setContentsMargins(0, 0, 0, 0);
34
35   QWidget* aInfoWgt = new QWidget(this);
36   QHBoxLayout* aInfoLay = new QHBoxLayout(aInfoWgt);
37   aInfoLay->setContentsMargins(0, 0, 0, 0);
38
39   aInfoLay->addWidget(new QLabel(tr("Opaque")));
40
41   myValLbl = new QLabel("0%", aInfoWgt);
42   myValLbl->setAlignment(Qt::AlignCenter);
43   aInfoLay->addWidget(myValLbl, 1);
44
45   aInfoLay->addWidget(new QLabel(tr("Transparent")));
46   aLay->addWidget(aInfoWgt);
47
48   mySliderValue = new QSlider(Qt::Horizontal, this);
49   mySliderValue->setRange(0, 100);
50   aLay->addWidget(mySliderValue);
51
52   connect(mySliderValue, SIGNAL(valueChanged(int)), this, SLOT(onSliderValueChanged(int)));
53 }
54
55 void XGUI_TransparencyWidget::setValue(double theValue)
56 {
57   bool isSliderBlocked = mySliderValue->blockSignals(true);
58   int aVal = theValue * 100;
59   mySliderValue->setValue(aVal);
60   myValLbl->setText(QString("%1%").arg(aVal));
61   mySliderValue->blockSignals(isSliderBlocked);
62 }
63
64 double XGUI_TransparencyWidget::getValue() const
65 {
66   return mySliderValue->value() / 100.;
67 }
68
69 void XGUI_TransparencyWidget::onSliderValueChanged(int theValue)
70 {
71   myValLbl->setText(QString("%1%").arg(theValue));
72   emit transparencyValueChanged();
73 }