QGIS API Documentation 3.99.0-Master (21b3aa880ba)
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:
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:
85
89 QScrollBar *scrollBar() const;
90
96 QAbstractScrollArea *scrollArea() const;
97
103 void setScrollArea( QAbstractScrollArea *scrollArea );
104
110 double lineHeight() const;
111
117 void setLineHeight( double height );
118
124 double visibleRange() const;
125
131 void setVisibleRange( double visibleRange );
132
138 double margin() const;
139
145 void setMargin( double margin );
146
152 QHash<int, QVector<QgsScrollBarHighlight>> highlights() const SIP_SKIP;
153
157 void addHighlight( const QgsScrollBarHighlight &highlight );
158
162 void removeHighlights( int category );
163
167 void removeAllHighlights();
168
169 private:
170 QHash<int, QVector<QgsScrollBarHighlight>> mHighlights;
171 double mLineHeight = 0.0;
172 double mVisibleRange = 0.0; // in pixels
173 double mMargin = 0.0; // in pixels
174 QAbstractScrollArea *mScrollArea = nullptr;
175 QPointer<QgsScrollBarHighlightOverlay> mOverlay;
176};
177
179#ifndef SIP_RUN
180class QgsScrollBarHighlightOverlay : public QWidget
181{
182 Q_OBJECT
183
184 public:
185 QgsScrollBarHighlightOverlay( QgsScrollBarHighlightController *scrollBarController );
186
187 void doResize();
188 void doMove();
189 void scheduleUpdate();
190
191 protected:
192 void paintEvent( QPaintEvent *paintEvent ) override;
193 bool eventFilter( QObject *object, QEvent *event ) override;
194
195 private:
196 void drawHighlights( QPainter *painter, int docStart, int docSize, double docSizeToHandleSizeRatio, int handleOffset, const QRect &viewport );
197 void updateCache();
198 QRect overlayRect() const;
199 QRect handleRect() const;
200
201 // line start to line end
202 QMap<QgsScrollBarHighlight::Priority, QMap<QRgb, QMap<int, int>>> mHighlightCache;
203
204 inline QScrollBar *scrollBar() const { return mHighlightController->scrollBar(); }
205 QgsScrollBarHighlightController *mHighlightController = nullptr;
206 bool mIsCacheUpdateScheduled = true;
207};
208#endif
210
211#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