QGIS API Documentation 3.41.0-Master (57ec4277f5e)
Loading...
Searching...
No Matches
qgsdecoratedscrollbar.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsdecoratedscrollbar.h
3 --------------------------------------
4 Date : May 2024
5 Copyright : (C) 2024 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 QGSDECORATEDSCROLLBAR_H
17#define QGSDECORATEDSCROLLBAR_H
18
19#include "qgis_gui.h"
20#include "qgis_sip.h"
21
22#include <QColor>
23#include <QHash>
24#include <QPointer>
25#include <QWidget>
26#include <QMap>
27
28class QScrollBar;
29class QAbstractScrollArea;
30class QgsScrollBarHighlightOverlay;
31
32// ported from QtCreator's HighlightScrollBarController implementation
33
39class GUI_EXPORT QgsScrollBarHighlight
40{
41 public:
45 enum class Priority : int
46 {
47 Invalid = -1,
48 LowPriority = 0,
49 NormalPriority = 1,
50 HighPriority = 2,
51 HighestPriority = 3
52 };
53
57 QgsScrollBarHighlight( int category, int position, const QColor &color, QgsScrollBarHighlight::Priority priority = QgsScrollBarHighlight::Priority::NormalPriority );
58
60
62 int category = -1;
63
65 int position = -1;
66
68 QColor color;
69
72};
73
80{
81 public:
84
88 QScrollBar *scrollBar() const;
89
95 QAbstractScrollArea *scrollArea() const;
96
102 void setScrollArea( QAbstractScrollArea *scrollArea );
103
109 double lineHeight() const;
110
116 void setLineHeight( double height );
117
123 double visibleRange() const;
124
130 void setVisibleRange( double visibleRange );
131
137 double margin() const;
138
144 void setMargin( double margin );
145
151 QHash<int, QVector<QgsScrollBarHighlight>> highlights() const SIP_SKIP;
152
156 void addHighlight( const QgsScrollBarHighlight &highlight );
157
161 void removeHighlights( int category );
162
166 void removeAllHighlights();
167
168 private:
169 QHash<int, QVector<QgsScrollBarHighlight>> mHighlights;
170 double mLineHeight = 0.0;
171 double mVisibleRange = 0.0; // in pixels
172 double mMargin = 0.0; // in pixels
173 QAbstractScrollArea *mScrollArea = nullptr;
174 QPointer<QgsScrollBarHighlightOverlay> mOverlay;
175};
176
178#ifndef SIP_RUN
179class QgsScrollBarHighlightOverlay : public QWidget
180{
181 Q_OBJECT
182
183 public:
184 QgsScrollBarHighlightOverlay( QgsScrollBarHighlightController *scrollBarController );
185
186 void doResize();
187 void doMove();
188 void scheduleUpdate();
189
190 protected:
191 void paintEvent( QPaintEvent *paintEvent ) override;
192 bool eventFilter( QObject *object, QEvent *event ) override;
193
194 private:
195 void drawHighlights( QPainter *painter, int docStart, int docSize, double docSizeToHandleSizeRatio, int handleOffset, const QRect &viewport );
196 void updateCache();
197 QRect overlayRect() const;
198 QRect handleRect() const;
199
200 // line start to line end
201 QMap<QgsScrollBarHighlight::Priority, QMap<QRgb, QMap<int, int>>> mHighlightCache;
202
203 inline QScrollBar *scrollBar() const { return mHighlightController->scrollBar(); }
204 QgsScrollBarHighlightController *mHighlightController = nullptr;
205 bool mIsCacheUpdateScheduled = true;
206};
207#endif
209
210#endif // QGSDECORATEDSCROLLBAR_H
Adds highlights (colored markers) to a scrollbar.
Encapsulates the details of a highlight in a scrollbar, used alongside QgsScrollBarHighlightControlle...
Priority
Priority, which dictates how overlapping highlights are rendered.
@ NormalPriority
Normal priority.
QgsScrollBarHighlight()=default
QColor color
Highlight color.
#define SIP_SKIP
Definition qgis_sip.h:126