QGIS API Documentation 3.41.0-Master (cea29feecf2)
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:
39 QgsRangeSlider( QWidget *parent SIP_TRANSFERTHIS = nullptr );
40
46 QgsRangeSlider( Qt::Orientation orientation, QWidget *parent SIP_TRANSFERTHIS = nullptr );
47
54 int minimum() const;
55
62 int maximum() const;
63
70 int lowerValue() const;
71
78 int upperValue() const;
79
85 void setTickPosition( QSlider::TickPosition position );
86
92 QSlider::TickPosition tickPosition() const;
93
99 void setTickInterval( int interval );
100
106 int tickInterval() const;
107
113 void setOrientation( Qt::Orientation orientation );
114
120 Qt::Orientation orientation() const;
121
130 bool flippedDirection() const;
131
141 void setFlippedDirection( bool flipped );
142
143 void paintEvent( QPaintEvent *event ) override;
144 void mousePressEvent( QMouseEvent *event ) override;
145 void mouseMoveEvent( QMouseEvent *event ) override;
146 void mouseReleaseEvent( QMouseEvent *event ) override;
147 void keyPressEvent( QKeyEvent *event ) override;
148 QSize sizeHint() const override;
149 QSize minimumSizeHint() const override;
150
159 int singleStep() const;
160
169 int pageStep() const;
170
181 int fixedRangeSize() const;
182
193 void setFixedRangeSize( int size );
194
195 public slots:
196
203 void setMaximum( int maximum );
204
211 void setMinimum( int minimum );
212
219 void setRangeLimits( int minimum, int maximum );
220
228 void setLowerValue( int value );
229
237 void setUpperValue( int value );
238
245 void setRange( int lower, int upper );
246
255 void setSingleStep( int step );
256
265 void setPageStep( int step );
266
267 bool event( QEvent *event ) override;
268
269 signals:
270
274 void rangeChanged( int minimum, int maximum );
275
279 void rangeLimitsChanged( int minimum, int maximum );
280
289 void fixedRangeSizeChanged( int size );
290
291 private:
292 int pick( const QPoint &pt ) const;
293 int pixelPosToRangeValue( int pos ) const;
294 bool updateHoverControl( const QPoint &pos );
295 bool newHoverControl( const QPoint &pos );
296 QRect selectedRangeRect();
297 void drawFocusRect();
298
299 int mLowerValue = 0;
300 int mUpperValue = 0;
301
302 int mSingleStep = 1;
303 int mPageStep = 10;
304
305 int mFixedRangeSize = -1;
306
307 QStyleOptionSlider mStyleOption;
308 enum Control
309 {
310 None,
311 Lower,
312 Upper,
313 Both,
314 Range
315 };
316
317 void applyStep( int step );
318 int unFlippedSliderPosition( int value ) const;
319
320 Control mActiveControl = None;
321 int mStartDragPos = -1;
322 int mLowerClickOffset = 0;
323 int mUpperClickOffset = 0;
324 int mRangeDragOffset = 0;
325 int mPreDragLowerValue = -1;
326 int mPreDragUpperValue = -1;
327 Control mHoverControl = None;
328 Control mFocusControl = Lower;
329 QStyle::SubControl mHoverSubControl = QStyle::SC_None;
330 QRect mHoverRect;
331
332 bool mFlipped = false;
333};
334
335#endif // QGSRANGESLIDER_H
A slider control with two interactive endpoints, for interactive selection of a range of values.
void fixedRangeSizeChanged(int size)
Emitted when the widget's fixed range size is changed.
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