swift
loadindicator.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (C) 2015 swift Project Community / Contributors
2 // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3 // Class based on qLed: Copyright (C) 2010 by P. Sereno, http://www.sereno-online.com
4 
6 
7 #ifndef SWIFT_GUI_LOADINDICATOR_H
8 #define SWIFT_GUI_LOADINDICATOR_H
9 
10 #include <QColor>
11 #include <QList>
12 #include <QObject>
13 #include <QSize>
14 #include <QWidget>
15 #include <Qt>
16 
17 #include "gui/swiftguiexport.h"
18 
19 class QPaintEvent;
20 class QPainter;
21 class QTimerEvent;
22 
23 namespace swift::gui
24 {
30  class SWIFT_GUI_EXPORT CLoadIndicator : public QWidget
31  {
32  Q_OBJECT
33 
34  public:
36  CLoadIndicator(int width = 64, int height = 64, QWidget *parent = nullptr);
37 
41  int getAnimationDelayTimeMs() const { return m_delayMs; }
42 
46  bool isAnimated() const;
47 
51  bool isDisplayedWhenStopped() const;
52 
55  const QColor &color() const { return m_color; }
56 
58  virtual QSize sizeHint() const override;
59 
61  virtual int heightForWidth(int w) const override;
62 
64  void paint(QPainter &painter) const;
65 
67  void centerLoadIndicator(const QPoint &middle);
68 
69  signals:
71  void timedOut();
72 
73  public slots:
76  int startAnimation(std::chrono::milliseconds timeout = std::chrono::milliseconds(0),
77  bool processEvents = false);
78 
81  void stopAnimation(int indicatorId = -1);
82 
86  void setAnimationDelay(int delay);
87 
91  void setDisplayedWhenStopped(bool state);
92 
95  void setColor(const QColor &color);
96 
97  protected:
99  virtual void timerEvent(QTimerEvent *event) override;
100 
102  virtual void paintEvent(QPaintEvent *event) override;
103 
105  bool isParentVisible() const;
106 
107  private:
108  int m_angle = 0;
109  int m_timerId = -1;
110  int m_delayMs = 1000;
111  int m_currentId = 1;
112  QList<int> m_pendingIds;
113  bool m_displayedWhenStopped = false;
114  QColor m_color = Qt::blue;
115  };
116 
121  {
122  public:
124  CLoadIndicatorEnabled(QWidget *usingWidget);
125 
128 
131 
134 
136  bool isShowingLoadIndicator() const;
137 
139  void showLoading(std::chrono::milliseconds timeout = std::chrono::milliseconds(0), bool processEvents = true);
140 
142  void hideLoading();
143 
145  bool isLoadInProgress() const;
146 
147  protected:
149  void centerLoadIndicator();
150 
153  virtual void indicatorTimedOut();
154 
155  QWidget *m_usingWidget = nullptr;
156  CLoadIndicator *m_loadIndicator = nullptr;
157  bool m_loadInProgress = false;
158  int m_indicatorId = -1;
159  };
160 } // namespace swift::gui
161 
162 #endif // SWIFT_GUI_LOADINDICATOR_H
Enable widget class for load indicator.
CLoadIndicatorEnabled & operator=(const CLoadIndicatorEnabled &)=delete
Copy assignment operator.
CLoadIndicatorEnabled(const CLoadIndicatorEnabled &)=delete
Copy constructor.
virtual ~CLoadIndicatorEnabled()
Destructor.
The QProgressIndicator class lets an application display a progress indicator to show that a lengthy ...
Definition: loadindicator.h:31
const QColor & color() const
Returns the color of the component.
Definition: loadindicator.h:55
int getAnimationDelayTimeMs() const
Returns the delay between animation steps.
Definition: loadindicator.h:41
void timedOut()
Timed out.
GUI related classes.
#define SWIFT_GUI_EXPORT
Export a class or function from the library.