QGIS API Documentation 3.99.0-Master (752b475928d)
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 <QMap>
25#include <QPointer>
26#include <QWidget>
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.
void setVisibleRange(double visibleRange)
Sets the visible range of the scroll area (i.e.
void setMargin(double margin)
Sets the document margin for the associated viewport.
void removeHighlights(int category)
Removes all highlights with matching category from the scrollbar.
double margin() const
Returns the document margins for the associated viewport.
double visibleRange() const
Returns the visible range of the scroll area (i.e.
double lineHeight() const
Returns the line height for text associated with the scroll area.
QScrollBar * scrollBar() const
Returns the associated scroll bar.
void addHighlight(const QgsScrollBarHighlight &highlight)
Adds a highlight to the scrollbar.
void setLineHeight(double height)
Sets the line height for text associated with the scroll area.
QAbstractScrollArea * scrollArea() const
Returns the associated scroll area.
void setScrollArea(QAbstractScrollArea *scrollArea)
Sets the associated scroll bar.
void removeAllHighlights()
Removes all highlights from the scroll bar.
QHash< int, QVector< QgsScrollBarHighlight > > highlights() const
Returns the hash of all highlights in the scrollbar, with highlight categories as hash keys.
Encapsulates the details of a highlight in a scrollbar, used alongside QgsScrollBarHighlightControlle...
int position
Position in scroll bar.
Priority
Priority, which dictates how overlapping highlights are rendered.
QgsScrollBarHighlight(int category, int position, const QColor &color, QgsScrollBarHighlight::Priority priority=QgsScrollBarHighlight::Priority::NormalPriority)
Constructor for QgsScrollBarHighlight.
QgsScrollBarHighlight()=default
QgsScrollBarHighlight::Priority priority
Priority, which dictates how overlapping highlights are rendered.
QColor color
Highlight color.
#define SIP_SKIP
Definition qgis_sip.h:134