1 // Copyright (C) 2014-2019 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 email : webmaster.salome@opencascade.com
20 #include "XGUI_TransparencyWidget.h"
23 #include <QDoubleSpinBox>
24 #include <QHBoxLayout>
28 XGUI_TransparencyWidget::XGUI_TransparencyWidget(QWidget* theParent, const QString& theLabelText)
31 QHBoxLayout* aLay = new QHBoxLayout(this);
32 aLay->setContentsMargins(0, 0, 0, 0);
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);
40 myPreview = new QCheckBox("Preview", this);
41 myPreview->setChecked(true);
43 if (!theLabelText.isEmpty())
44 aLay->addWidget(new QLabel(theLabelText, this));
45 aLay->addWidget(mySpinValue);
46 aLay->addWidget(mySliderValue);
47 aLay->addWidget(myPreview);
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()));
54 void XGUI_TransparencyWidget::setValue(double theValue)
56 bool isSpinBlocked = mySpinValue->blockSignals(true);
57 bool isSliderBlocked = mySliderValue->blockSignals(true);
59 mySpinValue->setValue(theValue);
60 mySliderValue->setValue(theValue * 100);
62 mySpinValue->blockSignals(isSpinBlocked);
63 mySliderValue->blockSignals(isSliderBlocked);
66 double XGUI_TransparencyWidget::getValue() const
68 return mySpinValue->value();
71 bool XGUI_TransparencyWidget::isPreviewNeeded() const
73 return myPreview->isChecked();
76 void XGUI_TransparencyWidget::onSpinValueChanged(double theValue)
79 emit transparencyValueChanged();
82 void XGUI_TransparencyWidget::onSliderValueChanged(int theValue)
84 setValue((double)theValue / 100);
85 emit transparencyValueChanged();