1 | /* |
2 | SPDX-FileCopyrightText: 2009 Sebastian Trueg <trueg@kde.org> |
3 | |
4 | SPDX-License-Identifier: LGPL-2.1-or-later |
5 | */ |
6 | |
7 | #ifndef _K_PIXMAPSEQUENCE_OVERLAY_PAINTER_H_ |
8 | #define _K_PIXMAPSEQUENCE_OVERLAY_PAINTER_H_ |
9 | |
10 | #include <QObject> |
11 | #include <QPoint> |
12 | #include <memory> |
13 | |
14 | #include <kwidgetsaddons_export.h> |
15 | |
16 | class KPixmapSequence; |
17 | class QWidget; |
18 | class QEvent; |
19 | class QRect; |
20 | |
21 | /** |
22 | * \class KPixmapSequenceOverlayPainter kpixmapsequenceoverlaypainter.h KPixmapSequenceOverlayPainter |
23 | * |
24 | * \brief Paints a KPixmapSequence on top of any widget at any position. |
25 | * |
26 | * The KPixmapSequenceOverlayPainter paints an overlay on top of an arbitrary QWidget |
27 | * using a KPixmapSequence. This is typically used for spinners indicating that a process |
28 | * is not finished yet. |
29 | * |
30 | * \author Sebastian Trueg <trueg@kde.org> |
31 | * |
32 | * \since 4.4 |
33 | */ |
34 | class KWIDGETSADDONS_EXPORT KPixmapSequenceOverlayPainter : public QObject |
35 | { |
36 | Q_OBJECT |
37 | |
38 | public: |
39 | /** |
40 | * Constructor |
41 | */ |
42 | explicit KPixmapSequenceOverlayPainter(QObject *parent = nullptr); |
43 | KPixmapSequenceOverlayPainter(const KPixmapSequence &seq, QObject *parent = nullptr); |
44 | |
45 | /** |
46 | * Destructor |
47 | */ |
48 | ~KPixmapSequenceOverlayPainter() override; |
49 | |
50 | /** |
51 | * The sequence used to draw the overlay. |
52 | * |
53 | * \sa setSequence |
54 | */ |
55 | KPixmapSequence sequence() const; |
56 | |
57 | /** |
58 | * The interval between frames. |
59 | * |
60 | * \sa setInterval |
61 | */ |
62 | int interval() const; |
63 | |
64 | /** |
65 | * The optional rect to draw the pixmaps in. |
66 | * \sa setRect |
67 | */ |
68 | QRect rect() const; |
69 | |
70 | /** |
71 | * The alignment of the pixmaps in the rect. |
72 | * \sa setAlignment |
73 | */ |
74 | Qt::Alignment alignment() const; |
75 | |
76 | /** |
77 | * The optional offset within the rect. |
78 | * \sa setOffset |
79 | */ |
80 | QPoint offset() const; |
81 | |
82 | public Q_SLOTS: |
83 | /** |
84 | * Set the sequence to be used. By default the KDE busy sequence is used. |
85 | */ |
86 | void setSequence(const KPixmapSequence &seq); |
87 | |
88 | /** |
89 | * Set the interval between frames. The default is 200. |
90 | */ |
91 | void setInterval(int msecs); |
92 | |
93 | /** |
94 | * Set the widget to draw the overlay on. |
95 | */ |
96 | void setWidget(QWidget *w); |
97 | |
98 | /** |
99 | * Set the rect in which to place the sequence. Be aware that |
100 | * this optional property does not scale the pixmaps (except if |
101 | * it is smaller) but allows to change the placement. |
102 | * |
103 | * \param rect The rect in which to draw the pixmap using alignment |
104 | * and offset. Be aware that setting a rect bigger than the widget |
105 | * can lead to weird painting errors. |
106 | * |
107 | * Defaults to the widget's rect. |
108 | */ |
109 | void setRect(const QRect &rect); |
110 | |
111 | /** |
112 | * Set the alignment of the sequence in rect. |
113 | * |
114 | * \param align alignment of the overlay. Qt::AlignJustify does not make sense here. |
115 | * Defaults to Qt::Center. |
116 | */ |
117 | void setAlignment(Qt::Alignment align); |
118 | |
119 | /** |
120 | * Set the offset relative to the placement determined by alignment |
121 | * and rect. |
122 | * |
123 | * \param offset An optional offset which allows an absolute placement. |
124 | * |
125 | * Defaults to an empty point. |
126 | */ |
127 | void setOffset(const QPoint &offset); |
128 | |
129 | /** |
130 | * Start drawing the sequence. |
131 | * |
132 | * The overlay will be drawn until a call to stop() |
133 | */ |
134 | void start(); |
135 | |
136 | /** |
137 | * Stop drawing the overlay. |
138 | */ |
139 | void stop(); |
140 | |
141 | protected: |
142 | bool eventFilter(QObject *obj, QEvent *event) override; |
143 | |
144 | private: |
145 | std::unique_ptr<class KPixmapSequenceOverlayPainterPrivate> const d; |
146 | }; |
147 | |
148 | #endif |
149 | |