KanoopGuiQt 1.3.0
Qt GUI utility library
Loading...
Searching...
No Matches
spinnerwidget.h
1#ifndef SPINNERWIDGET_H
2#define SPINNERWIDGET_H
3#include <QTimer>
4#include <QFrame>
5#include <Kanoop/gui/libkanoopgui.h>
6
7/**
8 * @brief Animated spinner widget for indicating background activity.
9 *
10 * SpinnerWidget renders a rotating set of pre-built pixmaps driven by an
11 * internal QTimer. An optional numeric value can be painted in the center.
12 * Call setSpinning(true) to start the animation and setSpinning(false) to stop.
13 */
14class LIBKANOOPGUI_EXPORT SpinnerWidget : public QFrame
15{
16 Q_OBJECT
17public:
18 /**
19 * @brief Construct with an optional parent.
20 * @param parent Optional QWidget parent
21 */
22 explicit SpinnerWidget(QWidget* parent = nullptr);
23
24 /**
25 * @brief Return the integer value painted in the center of the spinner.
26 * @return Current value
27 */
28 int value() const { return _value; }
29
30 /**
31 * @brief Return whether the optional text overlay is visible.
32 * @return true if text is shown
33 */
34 bool isTextVisible() const { return _textVisible; }
35
36 /**
37 * @brief Return whether the spinner animation is currently running.
38 * @return true if the timer is active
39 */
40 bool isSpinning() const { return _timer.isActive(); }
41
42public slots:
43 /**
44 * @brief Start or stop the spinner animation.
45 * @param value true to start, false to stop
46 */
47 void setSpinning(bool value);
48
49 /**
50 * @brief Set the numeric value displayed in the center.
51 * @param value Integer to paint
52 */
53 void setValue(int value) { _value = value; update(); }
54
55 /**
56 * @brief Show or hide the center text overlay.
57 * @param value true to show, false to hide
58 */
59 void setTextVisible(bool value) { _textVisible = value; update(); }
60
61private:
62 void buildPixmaps();
63 virtual void paintEvent(QPaintEvent* event) override;
64 virtual void resizeEvent(QResizeEvent* event) override;
65
66 int _value;
67 int _index;
68 bool _textVisible;
69
70 QList<QPixmap> _pixmaps;
71 QTimer _timer;
72
73 static const double DegreesPerTick;
74
75private slots:
76 void onSpinTimer();
77};
78
79#endif // SPINNERWIDGET_H
Animated spinner widget for indicating background activity.
bool isTextVisible() const
Return whether the optional text overlay is visible.
void setTextVisible(bool value)
Show or hide the center text overlay.
void setValue(int value)
Set the numeric value displayed in the center.
void setSpinning(bool value)
Start or stop the spinner animation.
bool isSpinning() const
Return whether the spinner animation is currently running.
int value() const
Return the integer value painted in the center of the spinner.
SpinnerWidget(QWidget *parent=nullptr)
Construct with an optional parent.