QGIS API Documentation 3.36.0-Maidenhead (09951dc0acf)
Loading...
Searching...
No Matches
qgsrangeslider.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsrangeslider.h
3 ---------------------
4 begin : November 2020
5 copyright : (C) 2020 by Nyall Dawson
6 email : nyall dot dawson at gmail dot com
7 ***************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
15
16#ifndef QGSRANGESLIDER_H
17#define QGSRANGESLIDER_H
18
19#include "qgis_gui.h"
20#include "qgis_sip.h"
21
22#include <QWidget>
23#include <QStyleOptionSlider>
24
31class GUI_EXPORT QgsRangeSlider : public QWidget
32{
33 Q_OBJECT
34
35 public:
36
40 QgsRangeSlider( QWidget *parent SIP_TRANSFERTHIS = nullptr );
41
47 QgsRangeSlider( Qt::Orientation orientation, QWidget *parent SIP_TRANSFERTHIS = nullptr );
48
55 int minimum() const;
56
63 int maximum() const;
64
71 int lowerValue() const;
72
79 int upperValue() const;
80
86 void setTickPosition( QSlider::TickPosition position );
87
93 QSlider::TickPosition tickPosition() const;
94
100 void setTickInterval( int interval );
101
107 int tickInterval() const;
108
114 void setOrientation( Qt::Orientation orientation );
115
121 Qt::Orientation orientation() const;
122
131 bool flippedDirection() const;
132
142 void setFlippedDirection( bool flipped );
143
144 void paintEvent( QPaintEvent *event ) override;
145 void mousePressEvent( QMouseEvent *event ) override;
146 void mouseMoveEvent( QMouseEvent *event ) override;
147 void mouseReleaseEvent( QMouseEvent *event ) override;
148 void keyPressEvent( QKeyEvent *event ) override;
149 QSize sizeHint() const override;
150 QSize minimumSizeHint() const override;
151
160 int singleStep() const;
161
170 int pageStep() const;
171
172 public slots:
173
180 void setMaximum( int maximum );
181
188 void setMinimum( int minimum );
189
196 void setRangeLimits( int minimum, int maximum );
197
205 void setLowerValue( int value );
206
214 void setUpperValue( int value );
215
222 void setRange( int lower, int upper );
223
232 void setSingleStep( int step );
233
242 void setPageStep( int step );
243
244 bool event( QEvent *event ) override;
245
246 signals:
247
251 void rangeChanged( int minimum, int maximum );
252
256 void rangeLimitsChanged( int minimum, int maximum );
257
258 private:
259
260 int pick( const QPoint &pt ) const;
261 int pixelPosToRangeValue( int pos ) const;
262 bool updateHoverControl( const QPoint &pos );
263 bool newHoverControl( const QPoint &pos );
264 QRect selectedRangeRect();
265 void drawFocusRect();
266
267 int mLowerValue = 0;
268 int mUpperValue = 0;
269
270 int mSingleStep = 1;
271 int mPageStep = 10;
272
273 QStyleOptionSlider mStyleOption;
274 enum Control
275 {
276 None,
277 Lower,
278 Upper,
279 Both,
280 Range
281 };
282
283 void applyStep( int step );
284 int unFlippedSliderPosition( int value ) const;
285
286 Control mActiveControl = None;
287 int mStartDragPos = -1;
288 int mLowerClickOffset = 0;
289 int mUpperClickOffset = 0;
290 int mRangeDragOffset = 0;
291 int mPreDragLowerValue = -1;
292 int mPreDragUpperValue = -1;
293 Control mHoverControl = None;
294 Control mFocusControl = Lower;
295 QStyle::SubControl mHoverSubControl = QStyle::SC_None;
296 QRect mHoverRect;
297
298 bool mFlipped = false;
299};
300
301#endif // QGSRANGESLIDER_H
A slider control with two interactive endpoints, for interactive selection of a range of values.
void rangeLimitsChanged(int minimum, int maximum)
Emitted when the limits of values allowed in the widget is changed.
void rangeChanged(int minimum, int maximum)
Emitted when the range selected in the widget is changed.
#define SIP_TRANSFERTHIS
Definition qgis_sip.h:53