1 | /* |
2 | * The MIT License (MIT) |
3 | * |
4 | * Copyright (c) 2011 Morgan Leborgne |
5 | * |
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
7 | * of this software and associated documentation files (the "Software"), to deal |
8 | * in the Software without restriction, including without limitation the rights |
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
10 | * copies of the Software, and to permit persons to whom the Software is |
11 | * furnished to do so, subject to the following conditions: |
12 | * |
13 | * The above copyright notice and this permission notice shall be included in all |
14 | * copies or substantial portions of the Software. |
15 | * |
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
22 | * SOFTWARE. |
23 | */ |
24 | |
25 | #ifndef QPROGRESSINDICATOR_H |
26 | #define QPROGRESSINDICATOR_H |
27 | |
28 | #include <QWidget> |
29 | #include <QColor> |
30 | |
31 | /*! |
32 | \class QProgressIndicator |
33 | \brief The QProgressIndicator class lets an application display a progress indicator to show that a lengthy task is under way. |
34 | |
35 | Progress indicators are indeterminate and do nothing more than spin to show that the application is busy. |
36 | \sa QProgressBar |
37 | */ |
38 | class QProgressIndicator : public QWidget |
39 | { |
40 | Q_OBJECT |
41 | Q_PROPERTY(int delay READ animationDelay WRITE setAnimationDelay) |
42 | Q_PROPERTY(bool displayedWhenStopped READ isDisplayedWhenStopped WRITE setDisplayedWhenStopped) |
43 | Q_PROPERTY(QColor color READ color WRITE setColor) |
44 | public: |
45 | QProgressIndicator(QWidget* parent = 0); |
46 | |
47 | /*! Returns the delay between animation steps. |
48 | \return The number of milliseconds between animation steps. By default, the animation delay is set to 40 milliseconds. |
49 | \sa setAnimationDelay |
50 | */ |
51 | int animationDelay() const { return m_delay; } |
52 | |
53 | /*! Returns a Boolean value indicating whether the component is currently animated. |
54 | \return Animation state. |
55 | \sa startAnimation stopAnimation |
56 | */ |
57 | bool isAnimated () const; |
58 | |
59 | /*! Returns a Boolean value indicating whether the receiver shows itself even when it is not animating. |
60 | \return Return true if the progress indicator shows itself even when it is not animating. By default, it returns false. |
61 | \sa setDisplayedWhenStopped |
62 | */ |
63 | bool isDisplayedWhenStopped() const; |
64 | |
65 | /*! Returns the color of the component. |
66 | \sa setColor |
67 | */ |
68 | const QColor & color() const { return m_color; } |
69 | |
70 | virtual QSize sizeHint() const; |
71 | int heightForWidth(int w) const; |
72 | public slots: |
73 | /*! Starts the spin animation. |
74 | \sa stopAnimation isAnimated |
75 | */ |
76 | void startAnimation(); |
77 | |
78 | /*! Stops the spin animation. |
79 | \sa startAnimation isAnimated |
80 | */ |
81 | void stopAnimation(); |
82 | |
83 | /*! Sets the delay between animation steps. |
84 | Setting the \a delay to a value larger than 40 slows the animation, while setting the \a delay to a smaller value speeds it up. |
85 | \param delay The delay, in milliseconds. |
86 | \sa animationDelay |
87 | */ |
88 | void setAnimationDelay(int delay); |
89 | |
90 | /*! Sets whether the component hides itself when it is not animating. |
91 | \param state The animation state. Set false to hide the progress indicator when it is not animating; otherwise true. |
92 | \sa isDisplayedWhenStopped |
93 | */ |
94 | void setDisplayedWhenStopped(bool state); |
95 | |
96 | /*! Sets the color of the components to the given color. |
97 | \sa color |
98 | */ |
99 | void setColor(const QColor & color); |
100 | protected: |
101 | virtual void timerEvent(QTimerEvent * event); |
102 | virtual void paintEvent(QPaintEvent * event); |
103 | private: |
104 | int m_angle; |
105 | int m_timerId; |
106 | int m_delay; |
107 | bool m_displayedWhenStopped; |
108 | QColor m_color; |
109 | }; |
110 | |
111 | #endif // QPROGRESSINDICATOR_H |
112 | |