QGIS API Documentation 3.39.0-Master (9ea1ddbe645)
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
61
63 int category = -1;
64
66 int position = -1;
67
69 QColor color;
70
73};
74
81{
82 public:
83
86
90 QScrollBar *scrollBar() const;
91
97 QAbstractScrollArea *scrollArea() const;
98
104 void setScrollArea( QAbstractScrollArea *scrollArea );
105
111 double lineHeight() const;
112
118 void setLineHeight( double height );
119
125 double visibleRange() const;
126
132 void setVisibleRange( double visibleRange );
133
139 double margin() const;
140
146 void setMargin( double margin );
147
153 QHash<int, QVector<QgsScrollBarHighlight>> highlights() const SIP_SKIP;
154
158 void addHighlight( const QgsScrollBarHighlight &highlight );
159
163 void removeHighlights( int category );
164
168 void removeAllHighlights();
169
170 private:
171
172 QHash<int, QVector<QgsScrollBarHighlight> > mHighlights;
173 double mLineHeight = 0.0;
174 double mVisibleRange = 0.0; // in pixels
175 double mMargin = 0.0; // in pixels
176 QAbstractScrollArea *mScrollArea = nullptr;
177 QPointer<QgsScrollBarHighlightOverlay> mOverlay;
178};
179
181#ifndef SIP_RUN
182class QgsScrollBarHighlightOverlay : public QWidget
183{
184 Q_OBJECT
185
186 public:
187 QgsScrollBarHighlightOverlay( QgsScrollBarHighlightController *scrollBarController );
188
189 void doResize();
190 void doMove();
191 void scheduleUpdate();
192
193 protected:
194 void paintEvent( QPaintEvent *paintEvent ) override;
195 bool eventFilter( QObject *object, QEvent *event ) override;
196
197 private:
198 void drawHighlights( QPainter *painter,
199 int docStart,
200 int docSize,
201 double docSizeToHandleSizeRatio,
202 int handleOffset,
203 const QRect &viewport );
204 void updateCache();
205 QRect overlayRect() const;
206 QRect handleRect() const;
207
208 // line start to line end
209 QMap<QgsScrollBarHighlight::Priority, QMap<QRgb, QMap<int, int>>> mHighlightCache;
210
211 inline QScrollBar *scrollBar() const { return mHighlightController->scrollBar(); }
212 QgsScrollBarHighlightController *mHighlightController = nullptr;
213 bool mIsCacheUpdateScheduled = true;
214};
215#endif
217
218#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