1 | /* |
2 | SPDX-FileCopyrightText: 2019 Harald Sitter <sitter@kde.org> |
3 | |
4 | SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL |
5 | */ |
6 | |
7 | #ifndef KBUSYINDICATORWIDGET_H |
8 | #define KBUSYINDICATORWIDGET_H |
9 | |
10 | #include <QWidget> |
11 | #include <kwidgetsaddons_export.h> |
12 | #include <memory> |
13 | |
14 | /*! |
15 | * \class KBusyIndicatorWidget |
16 | * \inmodule KWidgetsAddons |
17 | * |
18 | * \brief Rotating spinning icon to indicate busyness. |
19 | * |
20 | * When you need to communicate to the user that your application is busy with |
21 | * something you'll want to use a KBusyIndicatorWidget to display an spinnning |
22 | * indicator icon. The spinning animation can be stopped and started. |
23 | * |
24 | * A way of using this widget is to combine it with a QLabel to construct a |
25 | * status line: |
26 | * |
27 | * \code |
28 | * auto layout = new QHBoxLayout; |
29 | * layout->addWidget(new KBusyIndicatorWidget); |
30 | * layout->addWidget(new QLabel(QStringLiteral("Watering the flowers..."))); |
31 | * \endcode |
32 | * |
33 | * \image kbusyindicatorwidget.png "KBusyIndicatorWidget with label" |
34 | * |
35 | * The KBusyIndicatorWidget differs from the KPixmapSequenceWidget by animating |
36 | * a scaled icon instead of rendering a pixmap sequence. It supports multiple, |
37 | * semi-arbitrary sizes, with quality constrained only by the resolution of the |
38 | * available icons. |
39 | * |
40 | * \since 5.61.0 |
41 | */ |
42 | class KWIDGETSADDONS_EXPORT KBusyIndicatorWidget : public QWidget |
43 | { |
44 | Q_OBJECT |
45 | |
46 | /*! |
47 | * \property KBusyIndicatorWidget::isRunning |
48 | */ |
49 | Q_PROPERTY(bool isRunning READ isRunning WRITE setRunning) |
50 | |
51 | public: |
52 | /*! |
53 | * Create a new KBusyIndicatorWidget widget |
54 | */ |
55 | explicit KBusyIndicatorWidget(QWidget *parent = nullptr); |
56 | |
57 | ~KBusyIndicatorWidget() override; |
58 | |
59 | /*! |
60 | * Return the smallest reasonable size for the widget |
61 | */ |
62 | QSize minimumSizeHint() const override; |
63 | |
64 | /*! |
65 | * Returns whether the spinning animation is running |
66 | * |
67 | * \sa setRunning() |
68 | * |
69 | * \since 6.11.0 |
70 | */ |
71 | bool isRunning() const; |
72 | |
73 | public Q_SLOTS: |
74 | /*! |
75 | * Start the spinning animation |
76 | * |
77 | * \sa setRunning() |
78 | * |
79 | * \since 6.10.0 |
80 | */ |
81 | void start(); |
82 | |
83 | /*! |
84 | * Stop the spinning animation |
85 | * |
86 | * \sa setRunning() |
87 | * |
88 | * \since 6.10.0 |
89 | */ |
90 | void stop(); |
91 | |
92 | /*! |
93 | * By calling this method with @p enable = true the spinning |
94 | * abnimation will be started. Stopped if false. |
95 | * |
96 | * \sa start() |
97 | * \sa stop() |
98 | * |
99 | * \since 6.11.0 |
100 | */ |
101 | void setRunning(const bool enable = true); |
102 | |
103 | protected: |
104 | void showEvent(QShowEvent *event) override; |
105 | void hideEvent(QHideEvent *event) override; |
106 | void resizeEvent(QResizeEvent *event) override; |
107 | void paintEvent(QPaintEvent *) override; |
108 | bool event(QEvent *event) override; |
109 | |
110 | private: |
111 | std::unique_ptr<class KBusyIndicatorWidgetPrivate> const d; |
112 | }; |
113 | |
114 | #endif // KBUSYINDICATORWIDGET_H |
115 | |