ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
WaitingSpinnerWidget.h
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - CloudViewer: www.cloudViewer.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2024 www.cloudViewer.org
5 // SPDX-License-Identifier: MIT
6 // ----------------------------------------------------------------------------
7 
8 //
9 // Created by Thomas on 14/01/2022.
10 //
11 
12 #pragma once
13 /* Original Work Copyright (c) 2012-2014 Alexander Turkin
14  Modified 2014 by William Hallatt
15  Modified 2015 by Jacob Dawid
16 Permission is hereby granted, free of charge, to any person obtaining a copy of
17 this software and associated documentation files (the "Software"), to deal in
18 the Software without restriction, including without limitation the rights to
19 use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
20 the Software, and to permit persons to whom the Software is furnished to do so,
21 subject to the following conditions:
22 The above copyright notice and this permission notice shall be included in all
23 copies or substantial portions of the Software.
24 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
25 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
26 FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
27 COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
28 IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 
31  https://github.com/snowwlex/QtWaitingSpinner
32 */
33 
34 // Qt includes
35 #include <QColor>
36 #include <QTimer>
37 #include <QWidget>
38 
39 class WaitingSpinnerWidget : public QWidget
40 {
41  Q_OBJECT
42  public:
45  explicit WaitingSpinnerWidget(QWidget *parent = nullptr,
46  bool centerOnParent = true,
47  bool disableParentWhenSpinning = true);
48 
54  explicit WaitingSpinnerWidget(Qt::WindowModality modality,
55  QWidget *parent = nullptr,
56  bool centerOnParent = true,
57  bool disableParentWhenSpinning = true);
58 
59  public Q_SLOTS:
60  void start();
61  void stop();
62 
63  public:
64  void setColor(QColor color);
65  void setRoundness(qreal roundness);
67  void setTrailFadePercentage(qreal trail);
68  void setRevolutionsPerSecond(qreal revolutionsPerSecond);
69  void setNumberOfLines(int lines);
70  void setLineLength(int length);
71  void setLineWidth(int width);
72  void setInnerRadius(int radius);
73  // void setText(QString text);
74 
75  QColor color();
76  qreal roundness();
77  qreal minimumTrailOpacity();
78  qreal trailFadePercentage();
79  qreal revolutionsPersSecond();
80  int numberOfLines();
81  int lineLength();
82  int lineWidth();
83  int innerRadius();
84 
85  bool isSpinning() const;
86 
87  private Q_SLOTS:
88  void rotate();
89 
90  protected:
91  void paintEvent(QPaintEvent *paintEvent) override;
92 
93  private:
94  static int lineCountDistanceFromPrimary(int current, int primary, int totalNrOfLines);
95  static QColor currentLineColor(
96  int distance, int totalNrOfLines, qreal trailFadePerc, qreal minOpacity, QColor color);
97 
98  void initialize();
99  void updateSize();
100  void updateTimer();
101  void updatePosition();
102 
103  private:
104  QColor _color;
105  qreal _roundness; // 0..100
106  qreal _minimumTrailOpacity;
107  qreal _trailFadePercentage;
108  qreal _revolutionsPerSecond;
109  int _numberOfLines;
110  int _lineLength;
111  int _lineWidth;
112  int _innerRadius;
113 
114  private:
116  WaitingSpinnerWidget &operator=(const WaitingSpinnerWidget &);
117 
118  QTimer *_timer;
119  bool _centerOnParent;
120  bool _disableParentWhenSpinning;
121  int _currentCounter;
122  bool _isSpinning;
123 };
int width
void paintEvent(QPaintEvent *paintEvent) override
void setNumberOfLines(int lines)
void setInnerRadius(int radius)
void setColor(QColor color)
void setLineLength(int length)
void setRoundness(qreal roundness)
void setMinimumTrailOpacity(qreal minimumTrailOpacity)
WaitingSpinnerWidget(QWidget *parent=nullptr, bool centerOnParent=true, bool disableParentWhenSpinning=true)
void setRevolutionsPerSecond(qreal revolutionsPerSecond)
void setTrailFadePercentage(qreal trail)
__host__ __device__ float length(float2 v)
Definition: cutil_math.h:1162