Salome HOME
Merge remote-tracking branch 'remotes/origin/HigherLevelObjectsHistory'
[modules/shaper.git] / src / XGUI / XGUI_TransparencyWidget.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 "XGUI_TransparencyWidget.h"
21
22 #include <QCheckBox>
23 #include <QDoubleSpinBox>
24 #include <QHBoxLayout>
25 #include <QLabel>
26 #include <QSlider>
27
28 XGUI_TransparencyWidget::XGUI_TransparencyWidget(QWidget* theParent, const QString& theLabelText)
29   : QWidget(theParent)
30 {
31   QHBoxLayout* aLay = new QHBoxLayout(this);
32   aLay->setContentsMargins(0, 0, 0, 0);
33
34   mySpinValue = new QDoubleSpinBox(this);
35   mySpinValue->setRange(0, 1);
36   mySpinValue->setSingleStep(0.1);
37   mySliderValue = new QSlider(Qt::Horizontal, this);
38   mySliderValue->setRange(0, 100);
39
40   myPreview = new QCheckBox("Preview", this);
41   myPreview->setChecked(true);
42
43   if (!theLabelText.isEmpty())
44     aLay->addWidget(new QLabel(theLabelText, this));
45   aLay->addWidget(mySpinValue);
46   aLay->addWidget(mySliderValue);
47   aLay->addWidget(myPreview);
48
49   connect(mySpinValue, SIGNAL(valueChanged(double)), this, SLOT(onSpinValueChanged(double)));
50   connect(mySliderValue, SIGNAL(valueChanged(int)), this, SLOT(onSliderValueChanged(int)));
51   connect(myPreview, SIGNAL(toggled(bool)), this, SIGNAL(previewStateChanged()));
52 }
53
54 void XGUI_TransparencyWidget::setValue(double theValue)
55 {
56   bool isSpinBlocked = mySpinValue->blockSignals(true);
57   bool isSliderBlocked = mySliderValue->blockSignals(true);
58
59   mySpinValue->setValue(theValue);
60   mySliderValue->setValue(theValue * 100);
61
62   mySpinValue->blockSignals(isSpinBlocked);
63   mySliderValue->blockSignals(isSliderBlocked);
64 }
65
66 double XGUI_TransparencyWidget::getValue() const
67 {
68   return mySpinValue->value();
69 }
70
71 bool XGUI_TransparencyWidget::isPreviewNeeded() const
72 {
73   return myPreview->isChecked();
74 }
75
76 void XGUI_TransparencyWidget::onSpinValueChanged(double theValue)
77 {
78   setValue(theValue);
79   emit transparencyValueChanged();
80 }
81
82 void XGUI_TransparencyWidget::onSliderValueChanged(int theValue)
83 {
84   setValue((double)theValue / 100);
85   emit transparencyValueChanged();
86 }