QGIS API Documentation 3.37.0-Master (fdefdf9c27f)
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
182 int fixedRangeSize() const;
183
194 void setFixedRangeSize( int size );
195
196 public slots:
197
204 void setMaximum( int maximum );
205
212 void setMinimum( int minimum );
213
220 void setRangeLimits( int minimum, int maximum );
221
229 void setLowerValue( int value );
230
238 void setUpperValue( int value );
239
246 void setRange( int lower, int upper );
247
256 void setSingleStep( int step );
257
266 void setPageStep( int step );
267
268 bool event( QEvent *event ) override;
269
270 signals:
271
275 void rangeChanged( int minimum, int maximum );
276
280 void rangeLimitsChanged( int minimum, int maximum );
281
290 void fixedRangeSizeChanged( int size );
291
292 private:
293
294 int pick( const QPoint &pt ) const;
295 int pixelPosToRangeValue( int pos ) const;
296 bool updateHoverControl( const QPoint &pos );
297 bool newHoverControl( const QPoint &pos );
298 QRect selectedRangeRect();
299 void drawFocusRect();
300
301 int mLowerValue = 0;
302 int mUpperValue = 0;
303
304 int mSingleStep = 1;
305 int mPageStep = 10;
306
307 int mFixedRangeSize = -1;
308
309 QStyleOptionSlider mStyleOption;
310 enum Control
311 {
312 None,
313 Lower,
314 Upper,
315 Both,
316 Range
317 };
318
319 void applyStep( int step );
320 int unFlippedSliderPosition( int value ) const;
321
322 Control mActiveControl = None;
323 int mStartDragPos = -1;
324 int mLowerClickOffset = 0;
325 int mUpperClickOffset = 0;
326 int mRangeDragOffset = 0;
327 int mPreDragLowerValue = -1;
328 int mPreDragUpperValue = -1;
329 Control mHoverControl = None;
330 Control mFocusControl = Lower;
331 QStyle::SubControl mHoverSubControl = QStyle::SC_None;
332 QRect mHoverRect;
333
334 bool mFlipped = false;
335};
336
337#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.
int ANALYSIS_EXPORT lower(int n, int i)
Lower function.
Definition: MathUtils.cpp:337
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53