OpenWalnut  1.5.0dev
WPropertyIntWidget.h
1 //---------------------------------------------------------------------------
2 //
3 // Project: OpenWalnut ( http://www.openwalnut.org )
4 //
5 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
6 // For more information see http://www.openwalnut.org/copying
7 //
8 // This file is part of OpenWalnut.
9 //
10 // OpenWalnut is free software: you can redistribute it and/or modify
11 // it under the terms of the GNU Lesser General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // OpenWalnut is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public License
21 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
22 //
23 //---------------------------------------------------------------------------
24 
25 #ifndef WPROPERTYINTWIDGET_H
26 #define WPROPERTYINTWIDGET_H
27 
28 #include <string>
29 
30 #include <QLineEdit>
31 #include <QSlider>
32 #include <QHBoxLayout>
33 #include <QToolButton>
34 
35 #include "../guiElements/WQtIntervalEdit.h"
36 #include "../guiElements/WScaleLabel.h"
37 
38 #include "WPropertyWidget.h"
39 
40 /**
41  * Implements a property widget for WPropInt.
42  */
44 {
45  Q_OBJECT
46 public:
47  /**
48  * Constructor. Creates a new widget appropriate for the specified property.
49  *
50  * \param property the property to handle
51  * \param parent the parent widget.
52  * \param propertyGrid the grid used to layout the labels and property widgets
53  */
54  WPropertyIntWidget( WPropInt property, QGridLayout* propertyGrid, QWidget* parent = 0 );
55 
56  /**
57  * Destructor.
58  */
59  virtual ~WPropertyIntWidget();
60 
61 protected:
62  /**
63  * Called whenever the widget should update.
64  */
65  virtual void update();
66 
67  /**
68  * The property represented by this widget.
69  */
71 
72  /**
73  * The slider allowing modification of the integer value
74  */
75  QSlider m_slider;
76 
77  /**
78  * The edit field showing the value of the slider
79  */
80  QLineEdit m_edit;
81 
82  /**
83  * Layout used to position the label and the checkbox
84  */
85  QHBoxLayout m_layout;
86 
87  /**
88  * Layout used to combine the property widgets with the WQtIntervalEdit.
89  */
90  QVBoxLayout m_vLayout;
91 
92  /**
93  * Converts a given value to a slider value between m_min and m_max.
94  *
95  * \param value the value.
96  *
97  * \return the percentage.
98  */
99  int toSliderValue( double value );
100 
101  /**
102  * Converts the given slider value to the real double value using m_min and m_max.
103  *
104  * \param perc the percentage.
105  *
106  * \return the real double value.
107  */
108  double fromSliderValue( int perc );
109 
110  /**
111  * The current minimum value.
112  */
113  double m_min;
114 
115  /**
116  * The current maximum value.
117  */
118  double m_max;
119 
120  /**
121  * Used to show the property as text.
122  */
124 
125  /**
126  * The layout used for the pure output (information properties)
127  */
128  QHBoxLayout m_infoLayout;
129 
130  /**
131  * The edit for the interval.
132  *
133  * \note we use double here. This is due to the need for discrete values in the sliders.
134  */
136 
137  /**
138  * Resolution of the slider.
139  */
140  static int SliderResolution;
141 
142 private:
143 public slots:
144 
145  /**
146  * Called whenever the slider changes
147  *
148  * \param value the new value
149  */
150  void sliderChanged( int value );
151 
152  /**
153  * Called whenever the edit field changes
154  */
155  void editChanged();
156 
157  /**
158  * Called when the text in m_edit changes.
159  *
160  * \param text
161  */
162  void textEdited( const QString& text );
163 
164  /**
165  * Called whenever the interval edit changes.
166  */
167  void minMaxUpdated();
168 };
169 
170 #endif // WPROPERTYINTWIDGET_H
171 
Implements a property widget for WPropInt.
WPropertyIntWidget(WPropInt property, QGridLayout *propertyGrid, QWidget *parent=0)
Constructor.
void textEdited(const QString &text)
Called when the text in m_edit changes.
virtual void update()
Called whenever the widget should update.
QLineEdit m_edit
The edit field showing the value of the slider.
double m_max
The current maximum value.
void sliderChanged(int value)
Called whenever the slider changes.
WQtIntervalEdit< double, int32_t > m_intervalEdit
The edit for the interval.
WScaleLabel m_asText
Used to show the property as text.
virtual ~WPropertyIntWidget()
Destructor.
QSlider m_slider
The slider allowing modification of the integer value.
int toSliderValue(double value)
Converts a given value to a slider value between m_min and m_max.
void minMaxUpdated()
Called whenever the interval edit changes.
QVBoxLayout m_vLayout
Layout used to combine the property widgets with the WQtIntervalEdit.
void editChanged()
Called whenever the edit field changes.
double fromSliderValue(int perc)
Converts the given slider value to the real double value using m_min and m_max.
double m_min
The current minimum value.
static int SliderResolution
Resolution of the slider.
QHBoxLayout m_layout
Layout used to position the label and the checkbox.
WPropInt m_integralProperty
The property represented by this widget.
QHBoxLayout m_infoLayout
The layout used for the pure output (information properties)
Class building the base for all widgets representing properties.
Special Label that can shrink and expand in a layout.
Definition: WScaleLabel.h:37