1 // Copyright (C) 2014-2017 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
21 #include "XGUI_TransparencyWidget.h"
24 #include <QDoubleSpinBox>
25 #include <QHBoxLayout>
29 XGUI_TransparencyWidget::XGUI_TransparencyWidget(QWidget* theParent, const QString& theLabelText)
32 QHBoxLayout* aLay = new QHBoxLayout(this);
33 aLay->setContentsMargins(0, 0, 0, 0);
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);
41 myPreview = new QCheckBox("Preview", this);
42 myPreview->setChecked(true);
44 if (!theLabelText.isEmpty())
45 aLay->addWidget(new QLabel(theLabelText, this));
46 aLay->addWidget(mySpinValue);
47 aLay->addWidget(mySliderValue);
48 aLay->addWidget(myPreview);
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()));
55 void XGUI_TransparencyWidget::setValue(double theValue)
57 bool isSpinBlocked = mySpinValue->blockSignals(true);
58 bool isSliderBlocked = mySliderValue->blockSignals(true);
60 mySpinValue->setValue(theValue);
61 mySliderValue->setValue(theValue * 100);
63 mySpinValue->blockSignals(isSpinBlocked);
64 mySliderValue->blockSignals(isSliderBlocked);
67 double XGUI_TransparencyWidget::getValue() const
69 return mySpinValue->value();
72 bool XGUI_TransparencyWidget::isPreviewNeeded() const
74 return myPreview->isChecked();
77 void XGUI_TransparencyWidget::onSpinValueChanged(double theValue)
80 emit transparencyValueChanged();
83 void XGUI_TransparencyWidget::onSliderValueChanged(int theValue)
85 setValue((double)theValue / 100);
86 emit transparencyValueChanged();