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