source: calamares/trunk/fuentes/src/libcalamaresui/widgets/waitingspinnerwidget.h @ 7538

Last change on this file since 7538 was 7538, checked in by kbut, 13 months ago

sync with github

File size: 4.0 KB
Line 
1/* === This file is part of Calamares - <https://github.com/calamares> ===
2 *
3 *   SPDX-License-Identifier: MIT
4 *   License-Filename: LICENSES/MIT-QtWaitingSpinner
5 */
6
7/* Original Work Copyright (c) 2012-2014 Alexander Turkin
8   Modified 2014 by William Hallatt
9   Modified 2015 by Jacob Dawid
10Permission is hereby granted, free of charge, to any person obtaining a copy of
11this software and associated documentation files (the "Software"), to deal in
12the Software without restriction, including without limitation the rights to
13use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
14the Software, and to permit persons to whom the Software is furnished to do so,
15subject to the following conditions:
16
17The above copyright notice and this permission notice shall be included in all
18copies or substantial portions of the Software.
19
20THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
22FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
23COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
24IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
25CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26*/
27
28#pragma once
29
30// Qt includes
31#include <QWidget>
32#include <QTimer>
33#include <QColor>
34
35class WaitingSpinnerWidget : public QWidget {
36    Q_OBJECT
37public:
38    /*! Constructor for "standard" widget behaviour - use this
39   * constructor if you wish to, e.g. embed your widget in another. */
40    WaitingSpinnerWidget(QWidget *parent = 0,
41                         bool centerOnParent = true,
42                         bool disableParentWhenSpinning = true);
43
44    /*! Constructor - use this constructor to automatically create a modal
45   * ("blocking") spinner on top of the calling widget/window.  If a valid
46   * parent widget is provided, "centreOnParent" will ensure that
47   * QtWaitingSpinner automatically centres itself on it, if not,
48   * "centreOnParent" is ignored. */
49    WaitingSpinnerWidget(Qt::WindowModality modality,
50                         QWidget *parent = 0,
51                         bool centerOnParent = true,
52                         bool disableParentWhenSpinning = true);
53
54public slots:
55    void start();
56    void stop();
57
58public:
59    void setColor(QColor color);
60    void setRoundness(qreal roundness);
61    void setMinimumTrailOpacity(qreal minimumTrailOpacity);
62    void setTrailFadePercentage(qreal trail);
63    void setRevolutionsPerSecond(qreal revolutionsPerSecond);
64    void setNumberOfLines(int lines);
65    void setLineLength(int length);
66    void setLineWidth(int width);
67    void setInnerRadius(int radius);
68    void setText(QString text);
69
70    QColor color();
71    qreal roundness();
72    qreal minimumTrailOpacity();
73    qreal trailFadePercentage();
74    qreal revolutionsPersSecond();
75    int numberOfLines();
76    int lineLength();
77    int lineWidth();
78    int innerRadius();
79
80    bool isSpinning() const;
81
82private slots:
83    void rotate();
84
85protected:
86    void paintEvent(QPaintEvent *paintEvent);
87
88private:
89    static int lineCountDistanceFromPrimary(int current, int primary,
90                                            int totalNrOfLines);
91    static QColor currentLineColor(int distance, int totalNrOfLines,
92                                   qreal trailFadePerc, qreal minOpacity,
93                                   QColor color);
94
95    void initialize();
96    void updateSize();
97    void updateTimer();
98    void updatePosition();
99
100private:
101    QColor  _color;
102    qreal   _roundness; // 0..100
103    qreal   _minimumTrailOpacity;
104    qreal   _trailFadePercentage;
105    qreal   _revolutionsPerSecond;
106    int     _numberOfLines;
107    int     _lineLength;
108    int     _lineWidth;
109    int     _innerRadius;
110
111private:
112    WaitingSpinnerWidget(const WaitingSpinnerWidget&);
113    WaitingSpinnerWidget& operator=(const WaitingSpinnerWidget&);
114
115    QTimer *_timer;
116    bool    _centerOnParent;
117    bool    _disableParentWhenSpinning;
118    int     _currentCounter;
119    bool    _isSpinning;
120};
Note: See TracBrowser for help on using the repository browser.