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
16class KPixmapSequence;
17class QWidget;
18class QEvent;
19class QRect;
20
21/*!
22 * \class KPixmapSequenceOverlayPainter
23 * \inmodule KWidgetsAddons
24 *
25 * \brief Paints a KPixmapSequence on top of any widget at any position.
26 *
27 * The KPixmapSequenceOverlayPainter paints an overlay on top of an arbitrary QWidget
28 * using a KPixmapSequence. This is typically used for spinners indicating that a process
29 * is not finished yet.
30 *
31 * \since 4.4
32 */
33class KWIDGETSADDONS_EXPORT KPixmapSequenceOverlayPainter : public QObject
34{
35 Q_OBJECT
36
37public:
38 /*!
39 * Constructor
40 */
41 explicit KPixmapSequenceOverlayPainter(QObject *parent = nullptr);
42
43 /*!
44 *
45 */
46 KPixmapSequenceOverlayPainter(const KPixmapSequence &seq, QObject *parent = nullptr);
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
82public 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 * \a 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 * \a align alignment of the overlay. Qt::AlignJustify does not make sense here.
115 *
116 * Defaults to Qt::Center.
117 */
118 void setAlignment(Qt::Alignment align);
119
120 /*!
121 * Set the offset relative to the placement determined by alignment
122 * and rect.
123 *
124 * \a offset An optional offset which allows an absolute placement.
125 *
126 * Defaults to an empty point.
127 */
128 void setOffset(const QPoint &offset);
129
130 /*!
131 * Start drawing the sequence.
132 *
133 * The overlay will be drawn until a call to stop()
134 */
135 void start();
136
137 /*!
138 * Stop drawing the overlay.
139 */
140 void stop();
141
142protected:
143 bool eventFilter(QObject *obj, QEvent *event) override;
144
145private:
146 std::unique_ptr<class KPixmapSequenceOverlayPainterPrivate> const d;
147};
148
149#endif
150

source code of kwidgetsaddons/src/kpixmapsequenceoverlaypainter.h