ifw-fcf  2.0.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
spinner.h
Go to the documentation of this file.
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 Spinner : public QWidget {
30  Q_OBJECT
31 public:
34  Spinner(QWidget *parent = 0,
35  bool centerOnParent = false,
36  bool disableParentWhenSpinning = false);
37 
43  Spinner(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);
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  Spinner(const Spinner&);
107  Spinner& operator=(const Spinner&);
108 
109  QTimer *_timer;
110  bool _centerOnParent;
111  bool _disableParentWhenSpinning;
112  int _currentCounter;
113  bool _isSpinning;
114 };
void setLineWidth(int width)
Definition: spinner.cpp:156
qreal minimumTrailOpacity()
Definition: spinner.cpp:174
void setColor(QColor color)
Definition: spinner.cpp:210
Definition: spinner.h:29
void setLineLength(int length)
Definition: spinner.cpp:151
int lineLength()
Definition: spinner.cpp:190
int innerRadius()
Definition: spinner.cpp:198
void setRevolutionsPerSecond(qreal revolutionsPerSecond)
Definition: spinner.cpp:214
qreal revolutionsPersSecond()
Definition: spinner.cpp:182
void setInnerRadius(int radius)
Definition: spinner.cpp:161
int lineWidth()
Definition: spinner.cpp:194
void setMinimumTrailOpacity(qreal minimumTrailOpacity)
Definition: spinner.cpp:223
void setText(QString text)
qreal roundness()
Definition: spinner.cpp:170
qreal trailFadePercentage()
Definition: spinner.cpp:178
void setNumberOfLines(int lines)
Definition: spinner.cpp:145
QColor color()
Definition: spinner.cpp:166
void stop()
Definition: spinner.cpp:131
Spinner(QWidget *parent=0, bool centerOnParent=false, bool disableParentWhenSpinning=false)
Definition: spinner.cpp:38
void start()
Definition: spinner.cpp:116
void setTrailFadePercentage(qreal trail)
Definition: spinner.cpp:219
void setRoundness(qreal roundness)
Definition: spinner.cpp:206
void paintEvent(QPaintEvent *paintEvent)
Definition: spinner.cpp:83
bool isSpinning() const
Definition: spinner.cpp:202
int numberOfLines()
Definition: spinner.cpp:186