QRoundProgressBar  0.1.b
Qt circular progress bar widget
 All Classes Functions Enumerations Enumerator Pages
QRoundProgressBar.h
1 /*
2  * QRoundProgressBar - a circular progress bar Qt widget.
3  *
4  * Sintegrial Technologies (c) 2015-now
5  *
6  * The software is freeware and is distributed "as is" with the complete source codes.
7  * Anybody is free to use it in any software projects, either commercial or non-commercial.
8  * Please do not remove this copyright message and remain the name of the author unchanged.
9  *
10  * It is very appreciated if you produce some feedback to us case you are going to use
11  * the software.
12  *
13  * Please send your questions, suggestions, and information about found issues to the
14  *
15  * sintegrial@gmail.com
16  *
17  */
18 
19 #ifndef QROUNDPROGRESSBAR_H
20 #define QROUNDPROGRESSBAR_H
21 
22 #include <QWidget>
23 
60 class QRoundProgressBar : public QWidget
61 {
62  Q_OBJECT
63 public:
64  explicit QRoundProgressBar(QWidget *parent = 0);
65 
66  static const int PositionLeft = 180;
67  static const int PositionTop = 90;
68  static const int PositionRight = 0;
69  static const int PositionBottom = -90;
70 
75  double nullPosition() const { return m_nullPosition; }
81  void setNullPosition(double position);
82 
86  enum BarStyle
87  {
94  };
99  void setBarStyle(BarStyle style);
104  BarStyle barStyle() const { return m_barStyle; }
105 
110  void setOutlinePenWidth(double penWidth);
114  double outlinePenWidth() const { return m_outlinePenWidth; }
115 
120  void setDataPenWidth(double penWidth);
124  double dataPenWidth() const { return m_dataPenWidth; }
125 
136  void setDataColors(const QGradientStops& stopPoints);
137 
144  void setFormat(const QString& format);
149  void resetFormat();
153  QString format() const { return m_format; }
154 
159  void setDecimals(int count);
164  int decimals() const { return m_decimals; }
165 
170  double value() const { return m_value; }
175  double minimum() const { return m_min; }
180  double maximum() const { return m_max; }
181 
182 public Q_SLOTS:
189  void setRange(double min, double max);
196  void setMinimum(double min);
203  void setMaximum(double max);
208  void setValue(double val);
213  void setValue(int val);
214 
215 protected:
216  virtual void paintEvent(QPaintEvent *event);
217  virtual void drawBackground(QPainter& p, const QRectF& baseRect);
218  virtual void drawBase(QPainter& p, const QRectF& baseRect);
219  virtual void drawValue(QPainter& p, const QRectF& baseRect, double value, double arcLength);
220  virtual void calculateInnerRect(const QRectF& baseRect, double outerRadius, QRectF& innerRect, double& innerRadius);
221  virtual void drawInnerBackground(QPainter& p, const QRectF& innerRect);
222  virtual void drawText(QPainter& p, const QRectF& innerRect, double innerRadius, double value);
223  virtual QString valueToText(double value) const;
224  virtual void valueFormatChanged();
225 
226  virtual QSize minimumSizeHint() const { return QSize(32,32); }
227 
228  virtual bool hasHeightForWidth() const { return true; }
229  virtual int heightForWidth(int w) const { return w; }
230 
231  void rebuildDataBrushIfNeeded();
232 
233  double m_min, m_max;
234  double m_value;
235 
236  double m_nullPosition;
237  BarStyle m_barStyle;
238  double m_outlinePenWidth, m_dataPenWidth;
239 
240  QGradientStops m_gradientData;
241  bool m_rebuildBrush;
242 
243  QString m_format;
244  int m_decimals;
245 
246  static const int UF_VALUE = 1;
247  static const int UF_PERCENT = 2;
248  static const int UF_MAX = 4;
249  int m_updateFlags;
250 };
251 
252 #endif // QROUNDPROGRESSBAR_H
void setBarStyle(BarStyle style)
Sets visual style of the widget.
Definition: QRoundProgressBar.cpp:102
The QRoundProgressBar class represents a circular progress bar and maintains its API similar to the Q...
Definition: QRoundProgressBar.h:60
double outlinePenWidth() const
Returns width of the outline circle pen.
Definition: QRoundProgressBar.h:114
void setMinimum(double min)
Defines minimum of the allowed value range. If the current value does not fit into the range...
Definition: QRoundProgressBar.cpp:59
void setRange(double min, double max)
Defines minimum und maximum of the allowed value range. If the current value does not fit into the ra...
Definition: QRoundProgressBar.cpp:40
void setNullPosition(double position)
Defines position of minimum value.
Definition: QRoundProgressBar.cpp:89
void resetFormat()
Sets format string to empty string. No text will be shown therefore. See setFormat() for more informa...
Definition: QRoundProgressBar.cpp:153
double maximum() const
Returns maximum of the allowed value range.
Definition: QRoundProgressBar.h:180
void setMaximum(double max)
Defines maximum of the allowed value range. If the current value does not fit into the range...
Definition: QRoundProgressBar.cpp:64
void setDataColors(const QGradientStops &stopPoints)
Sets colors of the visible data and makes gradient brush from them. Gradient colors can be set for Do...
Definition: QRoundProgressBar.cpp:132
BarStyle
The BarStyle enum defines general look of the progress bar.
Definition: QRoundProgressBar.h:86
double dataPenWidth() const
Returns width of the data circle pen.
Definition: QRoundProgressBar.h:124
void setOutlinePenWidth(double penWidth)
Sets width of the outline circle pen.
Definition: QRoundProgressBar.cpp:112
double nullPosition() const
Return position (in degrees) of minimum value.
Definition: QRoundProgressBar.h:75
void setDecimals(int count)
Sets number of decimals to show after the comma (default is 1).
Definition: QRoundProgressBar.cpp:160
BarStyle barStyle() const
Returns current progree bar style.
Definition: QRoundProgressBar.h:104
Pie style (filled pie segment with the text in center)
Definition: QRoundProgressBar.h:91
double value() const
Returns current value shown on the widget.
Definition: QRoundProgressBar.h:170
void setDataPenWidth(double penWidth)
Sets width of the data circle pen.
Definition: QRoundProgressBar.cpp:122
Line style (thin round line around the text)
Definition: QRoundProgressBar.h:93
QString format() const
Returns the string used to generate the current text.
Definition: QRoundProgressBar.h:153
void setValue(double val)
Sets a value which will be shown on the widget.
Definition: QRoundProgressBar.cpp:69
double minimum() const
Returns minimum of the allowed value range.
Definition: QRoundProgressBar.h:175
Donut style (filled torus around the text)
Definition: QRoundProgressBar.h:89
void setFormat(const QString &format)
Defines the string used to generate the current text. If no format is set, no text will be shown...
Definition: QRoundProgressBar.cpp:143
int decimals() const
Returns number of decimals to show after the comma (default is 1).
Definition: QRoundProgressBar.h:164

Designed by Sintegrial Technologies (c) 2015-now