]> git.sur5r.net Git - minitube/blob - src/waitingspinnerwidget.h
Upload to unstable
[minitube] / src / waitingspinnerwidget.h
1 /* Original Work Copyright (c) 2012-2014 Alexander Turkin
2    Modified 2014 by William Hallatt
3    Modified 2015 by Jacob Dawid
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
22 #pragma once
23
24 // Qt includes
25 #include <QWidget>
26 #include <QTimer>
27 #include <QColor>
28
29 class WaitingSpinnerWidget : 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     WaitingSpinnerWidget(QWidget *parent = 0,
35                          bool centerOnParent = true,
36                          bool disableParentWhenSpinning = true);
37
38     /*! Constructor - use this constructor to automatically create a modal
39    * ("blocking") spinner on top of the calling widget/window.  If a valid
40    * parent widget is provided, "centreOnParent" will ensure that
41    * QtWaitingSpinner automatically centres itself on it, if not,
42    * "centreOnParent" is ignored. */
43     WaitingSpinnerWidget(Qt::WindowModality modality,
44                          QWidget *parent = 0,
45                          bool centerOnParent = true,
46                          bool disableParentWhenSpinning = true);
47
48 public slots:
49     void start();
50     void stop();
51
52 public:
53     void setColor(QColor color);
54     void setRoundness(qreal roundness);
55     void setMinimumTrailOpacity(qreal minimumTrailOpacity);
56     void setTrailFadePercentage(qreal trail);
57     void setRevolutionsPerSecond(qreal revolutionsPerSecond);
58     void setNumberOfLines(int lines);
59     void setLineLength(int length);
60     void setLineWidth(int width);
61     void setInnerRadius(int radius);
62     void setText(QString text);
63
64     QColor color();
65     qreal roundness();
66     qreal minimumTrailOpacity();
67     qreal trailFadePercentage();
68     qreal revolutionsPersSecond();
69     int numberOfLines();
70     int lineLength();
71     int lineWidth();
72     int innerRadius();
73
74     bool isSpinning() const;
75
76 private slots:
77     void rotate();
78
79 protected:
80     void paintEvent(QPaintEvent *paintEvent);
81
82 private:
83     static int lineCountDistanceFromPrimary(int current, int primary,
84                                             int totalNrOfLines);
85     static QColor currentLineColor(int distance, int totalNrOfLines,
86                                    qreal trailFadePerc, qreal minOpacity,
87                                    QColor color);
88
89     void initialize();
90     void updateSize();
91     void updateTimer();
92     void updatePosition();
93
94 private:
95     QColor  _color;
96     qreal   _roundness; // 0..100
97     qreal   _minimumTrailOpacity;
98     qreal   _trailFadePercentage;
99     qreal   _revolutionsPerSecond;
100     int     _numberOfLines;
101     int     _lineLength;
102     int     _lineWidth;
103     int     _innerRadius;
104
105 private:
106     WaitingSpinnerWidget(const WaitingSpinnerWidget&);
107     WaitingSpinnerWidget& operator=(const WaitingSpinnerWidget&);
108
109     QTimer *_timer;
110     bool    _centerOnParent;
111     bool    _disableParentWhenSpinning;
112     int     _currentCounter;
113     bool    _isSpinning;
114 };