QGIS API Documentation 3.39.0-Master (47f7b3a4989)
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:
42
46 enum class Priority : int
47 {
48 Invalid = -1,
49 LowPriority = 0,
50 NormalPriority = 1,
51 HighPriority = 2,
52 HighestPriority = 3
53 };
54
58 QgsScrollBarHighlight( int category, int position, const QColor &color, QgsScrollBarHighlight::Priority priority = QgsScrollBarHighlight::Priority::NormalPriority );
59
64
66 int category = -1;
67
69 int position = -1;
70
72 QColor color;
73
76};
77
84{
85 public:
86
89
93 QScrollBar *scrollBar() const;
94
100 QAbstractScrollArea *scrollArea() const;
101
107 void setScrollArea( QAbstractScrollArea *scrollArea );
108
114 double lineHeight() const;
115
121 void setLineHeight( double height );
122
128 double visibleRange() const;
129
135 void setVisibleRange( double visibleRange );
136
142 double margin() const;
143
149 void setMargin( double margin );
150
156 QHash<int, QVector<QgsScrollBarHighlight>> highlights() const SIP_SKIP;
157
161 void addHighlight( const QgsScrollBarHighlight &highlight );
162
166 void removeHighlights( int category );
167
171 void removeAllHighlights();
172
173 private:
174
175 QHash<int, QVector<QgsScrollBarHighlight> > mHighlights;
176 double mLineHeight = 0.0;
177 double mVisibleRange = 0.0; // in pixels
178 double mMargin = 0.0; // in pixels
179 QAbstractScrollArea *mScrollArea = nullptr;
180 QPointer<QgsScrollBarHighlightOverlay> mOverlay;
181};
182
184#ifndef SIP_RUN
185class QgsScrollBarHighlightOverlay : public QWidget
186{
187 Q_OBJECT
188
189 public:
190 QgsScrollBarHighlightOverlay( QgsScrollBarHighlightController *scrollBarController );
191
192 void doResize();
193 void doMove();
194 void scheduleUpdate();
195
196 protected:
197 void paintEvent( QPaintEvent *paintEvent ) override;
198 bool eventFilter( QObject *object, QEvent *event ) override;
199
200 private:
201 void drawHighlights( QPainter *painter,
202 int docStart,
203 int docSize,
204 double docSizeToHandleSizeRatio,
205 int handleOffset,
206 const QRect &viewport );
207 void updateCache();
208 QRect overlayRect() const;
209 QRect handleRect() const;
210
211 // line start to line end
212 QMap<QgsScrollBarHighlight::Priority, QMap<QRgb, QMap<int, int>>> mHighlightCache;
213
214 inline QScrollBar *scrollBar() const { return mHighlightController->scrollBar(); }
215 QgsScrollBarHighlightController *mHighlightController = nullptr;
216 bool mIsCacheUpdateScheduled = true;
217};
218#endif
220
221#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
Default constructor for QgsScrollBarHighlight.
QColor color
Highlight color.
#define SIP_SKIP
Definition qgis_sip.h:126