| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
#ifndef QTWAITINGSPINNER_H |
| 22 |
#define QTWAITINGSPINNER_H |
| 23 |
|
| 24 |
#include <QWidget> |
| 25 |
|
| 26 |
#include <QColor> |
| 27 |
#include <QTimer> |
| 28 |
|
| 29 |
class QtWaitingSpinner : public QWidget { |
| 30 |
Q_OBJECT |
| 31 |
public: |
| 32 |
|
| 33 |
|
| 34 |
explicit QtWaitingSpinner(QWidget *parent = 0); |
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
QtWaitingSpinner(Qt::WindowModality modality, QWidget *parent = 0, |
| 42 |
bool centreOnParent = true); |
| 43 |
|
| 44 |
public Q_SLOTS: |
| 45 |
void start(); |
| 46 |
void stop(); |
| 47 |
|
| 48 |
public: |
| 49 |
void setColor(QColor color); |
| 50 |
void setRoundness(qreal roundness); |
| 51 |
void setMinimumTrailOpacity(qreal minOpacity); |
| 52 |
void setTrailFadePercentage(qreal trail); |
| 53 |
void setRevolutionsPerSecond(int rps); |
| 54 |
void setNumberOfLines(int lines); |
| 55 |
void setLineLength(int length); |
| 56 |
void setLineWidth(int width); |
| 57 |
void setInnerRadius(int radius); |
| 58 |
|
| 59 |
bool isSpinning() const; |
| 60 |
|
| 61 |
private Q_SLOTS: |
| 62 |
void rotate(); |
| 63 |
|
| 64 |
protected: |
| 65 |
void paintEvent(QPaintEvent *ev); |
| 66 |
|
| 67 |
private: |
| 68 |
static int calculateTimerInterval(int lines, int speed); |
| 69 |
static int lineCountDistanceFromPrimary(int current, int primary, |
| 70 |
int totalNrOfLines); |
| 71 |
static QColor currentLineColor(int distance, int totalNrOfLines, |
| 72 |
qreal trailFadePerc, qreal minOpacity, |
| 73 |
QColor color); |
| 74 |
|
| 75 |
void initialise(); |
| 76 |
void updateSize(); |
| 77 |
void updateTimer(); |
| 78 |
void updatePosition(); |
| 79 |
|
| 80 |
private: |
| 81 |
|
| 82 |
QColor m_color; |
| 83 |
qreal m_roundness; |
| 84 |
qreal m_minTrailOpacity; |
| 85 |
qreal m_trailFadePercentage; |
| 86 |
int m_revPerSec; |
| 87 |
int m_numberOfLines; |
| 88 |
int m_lineLength; |
| 89 |
int m_lineWidth; |
| 90 |
int m_innerRadius; |
| 91 |
|
| 92 |
private: |
| 93 |
QtWaitingSpinner(const QtWaitingSpinner &); |
| 94 |
QtWaitingSpinner &operator=(const QtWaitingSpinner &); |
| 95 |
|
| 96 |
QTimer *m_timer; |
| 97 |
QWidget *m_parent; |
| 98 |
bool m_centreOnParent; |
| 99 |
int m_currentCounter; |
| 100 |
bool m_isSpinning; |
| 101 |
}; |
| 102 |
|
| 103 |
#endif |