ifw-fcf 6.0.0
Loading...
Searching...
No Matches
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
4Permission is hereby granted, free of charge, to any person obtaining a copy of
5this software and associated documentation files (the "Software"), to deal in
6the Software without restriction, including without limitation the rights to
7use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
8the Software, and to permit persons to whom the Software is furnished to do so,
9subject to the following conditions:
10
11The above copyright notice and this permission notice shall be included in all
12copies or substantial portions of the Software.
13
14THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
16FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
17COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
18IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19CONNECTION 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
29class Spinner : public QWidget {
30 Q_OBJECT
31public:
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
48public slots:
49 void start();
50 void stop();
51
52public:
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();
69 int numberOfLines();
70 int lineLength();
71 int lineWidth();
72 int innerRadius();
73
74 bool isSpinning() const;
75
76private slots:
77 void rotate();
78
79protected:
80 void paintEvent(QPaintEvent *paintEvent);
81
82private:
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
94private:
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
105private:
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};
Definition: spinner.h:29
void setMinimumTrailOpacity(qreal minimumTrailOpacity)
Definition: spinner.cpp:223
void stop()
Definition: spinner.cpp:131
int lineWidth()
Definition: spinner.cpp:194
void setInnerRadius(int radius)
Definition: spinner.cpp:161
qreal revolutionsPersSecond()
Definition: spinner.cpp:182
int numberOfLines()
Definition: spinner.cpp:186
int lineLength()
Definition: spinner.cpp:190
void setTrailFadePercentage(qreal trail)
Definition: spinner.cpp:219
int innerRadius()
Definition: spinner.cpp:198
bool isSpinning() const
Definition: spinner.cpp:202
void setRevolutionsPerSecond(qreal revolutionsPerSecond)
Definition: spinner.cpp:214
void setNumberOfLines(int lines)
Definition: spinner.cpp:145
void setRoundness(qreal roundness)
Definition: spinner.cpp:206
void setLineLength(int length)
Definition: spinner.cpp:151
void start()
Definition: spinner.cpp:116
void setText(QString text)
QColor color()
Definition: spinner.cpp:166
void setLineWidth(int width)
Definition: spinner.cpp:156
qreal minimumTrailOpacity()
Definition: spinner.cpp:174
qreal trailFadePercentage()
Definition: spinner.cpp:178
qreal roundness()
Definition: spinner.cpp:170
void paintEvent(QPaintEvent *paintEvent)
Definition: spinner.cpp:83
void setColor(QColor color)
Definition: spinner.cpp:210