1 /** -*- mode: c++ ; c-basic-offset: 2 -*-
2  *
3  *  @file FloatParameter.h
4  *
5  *  Copyright 2017 Sebastien Fourey
6  *
7  *  This file is part of G'MIC-Qt, a generic plug-in for raster graphics
8  *  editors, offering hundreds of filters thanks to the underlying G'MIC
9  *  image processing framework.
10  *
11  *  gmic_qt is free software: you can redistribute it and/or modify
12  *  it under the terms of the GNU General Public License as published by
13  *  the Free Software Foundation, either version 3 of the License, or
14  *  (at your option) any later version.
15  *
16  *  gmic_qt is distributed in the hope that it will be useful,
17  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  *  GNU General Public License for more details.
20  *
21  *  You should have received a copy of the GNU General Public License
22  *  along with gmic_qt.  If not, see <http://www.gnu.org/licenses/>.
23  *
24  */
25 #ifndef GMIC_QT_FLOATPARAMETER_H
26 #define GMIC_QT_FLOATPARAMETER_H
27 
28 #include <QString>
29 #include "AbstractParameter.h"
30 class QSlider;
31 class QLabel;
32 
33 namespace GmicQt
34 {
35 class CustomDoubleSpinBox;
36 
37 class FloatParameter : public AbstractParameter {
38   Q_OBJECT
39 public:
40   FloatParameter(QObject * parent);
41   ~FloatParameter() override;
42   virtual int size() const override;
43   bool addTo(QWidget *, int row) override;
44   QString value() const override;
45   QString defaultValue() const override;
46   void setValue(const QString & value) override;
47   void reset() override;
48   bool initFromText(const char * text, int & textLength) override;
49 
50 protected:
51   void timerEvent(QTimerEvent * event) override;
52 
53 public slots:
54   void onSliderMoved(int);
55   void onSliderValueChanged(int);
56   void onSpinBoxChanged(double);
57 
58 private:
59   void connectSliderSpinBox();
60   void disconnectSliderSpinBox();
61   QString _name;
62   float _min;
63   float _max;
64   float _default;
65   float _value;
66   QLabel * _label;
67   QSlider * _slider;
68   CustomDoubleSpinBox * _spinBox;
69   int _timerId;
70   static const int UPDATE_DELAY = 300;
71   static const int SLIDER_MAX_RANGE = 1000;
72   bool _connected;
73 };
74 
75 } // namespace GmicQt
76 
77 #endif // GMIC_QT_FLOATPARAMETER_H
78