Debian Codegraph @

src/contrib/qtwaitingspinner/QtWaitingSpinner.h

raw symbols SCIP
1 /* Original Work Copyright (c) 2012-2014 Alexander Turkin
2 Modified 2014 by William Hallatt
3
4 Permission is hereby granted, free of charge, to any person obtaining a copy of
5 this software and associated documentation files (the "Software"), to deal in
6 the Software without restriction, including without limitation the rights to
7 use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
8 the Software, and to permit persons to whom the Software is furnished to do so,
9 subject to the following conditions:
10
11 The above copyright notice and this permission notice shall be included in all
12 copies or substantial portions of the Software.
13
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
16 FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
17 COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
18 IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
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 /*! Constructor for "standard" widget behaviour - use this
33 * constructor if you wish to, e.g. embed your widget in another. */
34 explicit QtWaitingSpinner(QWidget *parent = 0);
35
36 /*! Constructor - use this constructor to automatically create a modal
37 * ("blocking") spinner on top of the calling widget/window. If a valid
38 * parent widget is provided, "centreOnParent" will ensure that
39 * QtWaitingSpinner automatically centres itself on it, if not,
40 * "centreOnParent" is ignored. */
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 // Configurable settings.
82 QColor m_color;
83 qreal m_roundness; // 0..100
84 qreal m_minTrailOpacity;
85 qreal m_trailFadePercentage;
86 int m_revPerSec; // revolutions per second
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 // QTWAITINGSPINNER_H