ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
QRoundProgressBar Class Reference

The QRoundProgressBar class represents a circular progress bar and maintains its API similar to the QProgressBar. More...

#include <QRoundProgressBar.h>

Inheritance diagram for QRoundProgressBar:
Collaboration diagram for QRoundProgressBar:

Public Types

enum  BarStyle { StyleDonut , StylePie , StyleLine }
 The BarStyle enum defines general look of the progress bar. More...
 

Public Slots

void setRange (double min, double max)
 Defines minimum und maximum of the allowed value range. If the current value does not fit into the range, it will be automatically adjusted. More...
 
void setMinimum (double min)
 Defines minimum of the allowed value range. If the current value does not fit into the range, it will be automatically adjusted. More...
 
void setMaximum (double max)
 Defines maximum of the allowed value range. If the current value does not fit into the range, it will be automatically adjusted. More...
 
void setValue (double val)
 Sets a value which will be shown on the widget. More...
 
void setValue (int val)
 Integer version of the previous slot. More...
 

Public Member Functions

 QRoundProgressBar (QWidget *parent=0)
 
double nullPosition () const
 Return position (in degrees) of minimum value. More...
 
void setNullPosition (double position)
 Defines position of minimum value. More...
 
void setBarStyle (BarStyle style)
 Sets visual style of the widget. More...
 
BarStyle barStyle () const
 Returns current progree bar style. More...
 
void setOutlinePenWidth (double penWidth)
 Sets width of the outline circle pen. More...
 
double outlinePenWidth () const
 Returns width of the outline circle pen. More...
 
void setDataPenWidth (double penWidth)
 Sets width of the data circle pen. More...
 
double dataPenWidth () const
 Returns width of the data circle pen. More...
 
void setDataColors (const QGradientStops &stopPoints)
 Sets colors of the visible data and makes gradient brush from them. Gradient colors can be set for Donut and Pie styles (see setBarStyle() function). More...
 
void setFormat (const QString &format)
 Defines the string used to generate the current text. If no format is set, no text will be shown. More...
 
void resetFormat ()
 Sets format string to empty string. No text will be shown therefore. See setFormat() for more information. More...
 
QString format () const
 Returns the string used to generate the current text. More...
 
void setDecimals (int count)
 Sets number of decimals to show after the comma (default is 1). More...
 
int decimals () const
 Returns number of decimals to show after the comma (default is 1). More...
 
double value () const
 Returns current value shown on the widget. More...
 
double minimum () const
 Returns minimum of the allowed value range. More...
 
double maximum () const
 Returns maximum of the allowed value range. More...
 

Static Public Attributes

static const int PositionLeft = 180
 
static const int PositionTop = 90
 
static const int PositionRight = 0
 
static const int PositionBottom = -90
 

Protected Member Functions

virtual void paintEvent (QPaintEvent *event)
 
virtual void drawBackground (QPainter &p, const QRectF &baseRect)
 
virtual void drawBase (QPainter &p, const QRectF &baseRect)
 
virtual void drawValue (QPainter &p, const QRectF &baseRect, double value, double arcLength)
 
virtual void calculateInnerRect (const QRectF &baseRect, double outerRadius, QRectF &innerRect, double &innerRadius)
 
virtual void drawInnerBackground (QPainter &p, const QRectF &innerRect)
 
virtual void drawText (QPainter &p, const QRectF &innerRect, double innerRadius, double value)
 
virtual QString valueToText (double value) const
 
virtual void valueFormatChanged ()
 
virtual QSize minimumSizeHint () const
 
virtual bool hasHeightForWidth () const
 
virtual int heightForWidth (int w) const
 
void rebuildDataBrushIfNeeded ()
 

Protected Attributes

double m_min
 
double m_max
 
double m_value
 
double m_nullPosition
 
BarStyle m_barStyle
 
double m_outlinePenWidth
 
double m_dataPenWidth
 
QGradientStops m_gradientData
 
bool m_rebuildBrush
 
QString m_format
 
int m_decimals
 
int m_updateFlags
 

Static Protected Attributes

static const int UF_VALUE = 1
 
static const int UF_PERCENT = 2
 
static const int UF_MAX = 4
 

Detailed Description

The QRoundProgressBar class represents a circular progress bar and maintains its API similar to the QProgressBar.

Styles

QRoundProgressBar currently supports Donut, Pie and Line styles. See setBarStyle() for more details.

Colors

Generally QRoundProgressBar uses its palette and font attributes to define how it will look.

The following QPalette members are considered:

  • QPalette::Window background of the whole widget (normally should be set to Qt::NoBrush)
  • QPalette::Base background of the non-filled progress bar area (should be set to Qt::NoBrush to make it transparent)
  • QPalette::AlternateBase background of the central circle where the text is shown (for Donut style)
  • QPalette::Shadow foreground of the non-filled progress bar area (i.e. border color)
  • QPalette::Highlight background of the filled progress bar area
  • QPalette::Text color of the text shown in the center

Create a QPalette with given attributes and apply it via setPalette().

Color gradient

Donut and Pie styles allow to use color gradient for currernt value area instead of plain brush fill. See setDataColors() for more details.

Value text

Value text is generally drawn inside the QRoundProgressBar using its font() and QPalette::Text role from its palette().

To define pattern of the text, use setFormat() function (see Qt's QProgressBar for more details).

To define number of decimals to be shown, use setDecimals() function.

Font

To use own font for value text, apply it via setFont().

By default, font size will be adjusted automatically to fit the inner circle of the widget.

Definition at line 59 of file QRoundProgressBar.h.

Member Enumeration Documentation

◆ BarStyle

The BarStyle enum defines general look of the progress bar.

Enumerator
StyleDonut 

Donut style (filled torus around the text)

StylePie 

Pie style (filled pie segment with the text in center)

StyleLine 

Line style (thin round line around the text)

Definition at line 84 of file QRoundProgressBar.h.

Constructor & Destructor Documentation

◆ QRoundProgressBar()

QRoundProgressBar::QRoundProgressBar ( QWidget *  parent = 0)
explicit

Definition at line 13 of file QRoundProgressBar.cpp.

Member Function Documentation

◆ barStyle()

BarStyle QRoundProgressBar::barStyle ( ) const
inline

Returns current progree bar style.

See also
setBarStyle

Definition at line 101 of file QRoundProgressBar.h.

◆ calculateInnerRect()

void QRoundProgressBar::calculateInnerRect ( const QRectF &  baseRect,
double  outerRadius,
QRectF &  innerRect,
double &  innerRadius 
)
protectedvirtual

Definition at line 231 of file QRoundProgressBar.cpp.

References m_barStyle, m_outlinePenWidth, and StyleLine.

Referenced by paintEvent().

◆ dataPenWidth()

double QRoundProgressBar::dataPenWidth ( ) const
inline

Returns width of the data circle pen.

Definition at line 121 of file QRoundProgressBar.h.

◆ decimals()

int QRoundProgressBar::decimals ( ) const
inline

Returns number of decimals to show after the comma (default is 1).

See also
setFormat, setDecimals

Definition at line 165 of file QRoundProgressBar.h.

◆ drawBackground()

void QRoundProgressBar::drawBackground ( QPainter &  p,
const QRectF &  baseRect 
)
protectedvirtual

Definition at line 168 of file QRoundProgressBar.cpp.

Referenced by paintEvent().

◆ drawBase()

void QRoundProgressBar::drawBase ( QPainter &  p,
const QRectF &  baseRect 
)
protectedvirtual

Definition at line 173 of file QRoundProgressBar.cpp.

References color, m_barStyle, m_outlinePenWidth, StyleDonut, StyleLine, and StylePie.

Referenced by paintEvent().

◆ drawInnerBackground()

void QRoundProgressBar::drawInnerBackground ( QPainter &  p,
const QRectF &  innerRect 
)
protectedvirtual

Definition at line 247 of file QRoundProgressBar.cpp.

References m_barStyle, and StyleDonut.

Referenced by paintEvent().

◆ drawText()

void QRoundProgressBar::drawText ( QPainter &  p,
const QRectF &  innerRect,
double  innerRadius,
double  value 
)
protectedvirtual

Definition at line 255 of file QRoundProgressBar.cpp.

References color, m_decimals, m_format, value(), and valueToText().

Referenced by paintEvent().

◆ drawValue()

void QRoundProgressBar::drawValue ( QPainter &  p,
const QRectF &  baseRect,
double  value,
double  arcLength 
)
protectedvirtual

Definition at line 199 of file QRoundProgressBar.cpp.

References color, m_barStyle, m_dataPenWidth, m_min, m_nullPosition, m_outlinePenWidth, StyleLine, and value().

Referenced by paintEvent().

◆ format()

QString QRoundProgressBar::format ( ) const
inline

Returns the string used to generate the current text.

Definition at line 154 of file QRoundProgressBar.h.

Referenced by setFormat().

◆ hasHeightForWidth()

virtual bool QRoundProgressBar::hasHeightForWidth ( ) const
inlineprotectedvirtual

Definition at line 241 of file QRoundProgressBar.h.

◆ heightForWidth()

virtual int QRoundProgressBar::heightForWidth ( int  w) const
inlineprotectedvirtual

Definition at line 242 of file QRoundProgressBar.h.

◆ maximum()

double QRoundProgressBar::maximum ( ) const
inline

Returns maximum of the allowed value range.

See also
setMaximum, setRange

Definition at line 181 of file QRoundProgressBar.h.

◆ minimum()

double QRoundProgressBar::minimum ( ) const
inline

Returns minimum of the allowed value range.

See also
setMinimum, setRange

Definition at line 176 of file QRoundProgressBar.h.

◆ minimumSizeHint()

virtual QSize QRoundProgressBar::minimumSizeHint ( ) const
inlineprotectedvirtual

Definition at line 239 of file QRoundProgressBar.h.

◆ nullPosition()

double QRoundProgressBar::nullPosition ( ) const
inline

Return position (in degrees) of minimum value.

See also
setNullPosition

Definition at line 73 of file QRoundProgressBar.h.

◆ outlinePenWidth()

double QRoundProgressBar::outlinePenWidth ( ) const
inline

Returns width of the outline circle pen.

Definition at line 111 of file QRoundProgressBar.h.

◆ paintEvent()

void QRoundProgressBar::paintEvent ( QPaintEvent *  event)
protectedvirtual

◆ rebuildDataBrushIfNeeded()

void QRoundProgressBar::rebuildDataBrushIfNeeded ( )
protected

Definition at line 302 of file QRoundProgressBar.cpp.

References m_gradientData, m_nullPosition, and m_rebuildBrush.

Referenced by paintEvent().

◆ resetFormat()

void QRoundProgressBar::resetFormat ( )

Sets format string to empty string. No text will be shown therefore. See setFormat() for more information.

Definition at line 113 of file QRoundProgressBar.cpp.

References m_format, and valueFormatChanged().

◆ setBarStyle()

void QRoundProgressBar::setBarStyle ( QRoundProgressBar::BarStyle  style)

Sets visual style of the widget.

See also
barStyle

Definition at line 72 of file QRoundProgressBar.cpp.

References m_barStyle.

◆ setDataColors()

void QRoundProgressBar::setDataColors ( const QGradientStops &  stopPoints)

Sets colors of the visible data and makes gradient brush from them. Gradient colors can be set for Donut and Pie styles (see setBarStyle() function).

Warning: this function will override widget's palette() to set dynamically created gradient brush.

Parameters
stopPointsList of colors (should have at least 2 values, see Qt's QGradientStops for more details). Color value at point 0 corresponds to the minimum() value, while color value at point 1 corresponds to the maximum(). Other colors will be distributed accordingly to the defined ranges (see setRange()).

Definition at line 96 of file QRoundProgressBar.cpp.

References m_gradientData, and m_rebuildBrush.

◆ setDataPenWidth()

void QRoundProgressBar::setDataPenWidth ( double  penWidth)

Sets width of the data circle pen.

Parameters
penWidthwidth of the data circle pen (in pixels)

Definition at line 88 of file QRoundProgressBar.cpp.

References m_dataPenWidth.

◆ setDecimals()

void QRoundProgressBar::setDecimals ( int  count)

Sets number of decimals to show after the comma (default is 1).

See also
setFormat

Definition at line 119 of file QRoundProgressBar.cpp.

References count, m_decimals, and valueFormatChanged().

◆ setFormat()

void QRoundProgressBar::setFormat ( const QString &  format)

Defines the string used to generate the current text. If no format is set, no text will be shown.

Parameters
formatsee QProgressBar's format description
See also
setDecimals

Definition at line 105 of file QRoundProgressBar.cpp.

References format(), m_format, and valueFormatChanged().

◆ setMaximum

void QRoundProgressBar::setMaximum ( double  max)
slot

Defines maximum of the allowed value range. If the current value does not fit into the range, it will be automatically adjusted.

Parameters
maxmaximum of the allowed value range
See also
setRange

Definition at line 45 of file QRoundProgressBar.cpp.

References m_min, and setRange().

◆ setMinimum

void QRoundProgressBar::setMinimum ( double  min)
slot

Defines minimum of the allowed value range. If the current value does not fit into the range, it will be automatically adjusted.

Parameters
minminimum of the allowed value range
See also
setRange

Definition at line 43 of file QRoundProgressBar.cpp.

References m_max, and setRange().

◆ setNullPosition()

void QRoundProgressBar::setNullPosition ( double  position)

Defines position of minimum value.

Parameters
positionposition on the circle (in degrees) of minimum value
See also
nullPosition

Definition at line 62 of file QRoundProgressBar.cpp.

References m_gradientData, m_nullPosition, m_rebuildBrush, and position.

◆ setOutlinePenWidth()

void QRoundProgressBar::setOutlinePenWidth ( double  penWidth)

Sets width of the outline circle pen.

Parameters
penWidthwidth of the outline circle pen (in pixels)

Definition at line 80 of file QRoundProgressBar.cpp.

References m_outlinePenWidth.

◆ setRange

void QRoundProgressBar::setRange ( double  min,
double  max 
)
slot

Defines minimum und maximum of the allowed value range. If the current value does not fit into the range, it will be automatically adjusted.

Parameters
minminimum of the allowed value range
maxmaximum of the allowed value range

Definition at line 27 of file QRoundProgressBar.cpp.

References m_gradientData, m_max, m_min, m_rebuildBrush, and m_value.

Referenced by setMaximum(), and setMinimum().

◆ setValue [1/2]

void QRoundProgressBar::setValue ( double  val)
slot

Sets a value which will be shown on the widget.

Parameters
valmust be between minimum() and maximum()

Definition at line 47 of file QRoundProgressBar.cpp.

References m_max, m_min, and m_value.

Referenced by setValue().

◆ setValue [2/2]

void QRoundProgressBar::setValue ( int  val)
slot

Integer version of the previous slot.

Parameters
valmust be between minimum() and maximum()

Definition at line 60 of file QRoundProgressBar.cpp.

References setValue().

◆ value()

double QRoundProgressBar::value ( ) const
inline

Returns current value shown on the widget.

See also
setValue()

Definition at line 171 of file QRoundProgressBar.h.

Referenced by drawText(), drawValue(), and valueToText().

◆ valueFormatChanged()

void QRoundProgressBar::valueFormatChanged ( )
protectedvirtual

Definition at line 290 of file QRoundProgressBar.cpp.

References m_format, m_updateFlags, UF_MAX, UF_PERCENT, and UF_VALUE.

Referenced by resetFormat(), setDecimals(), and setFormat().

◆ valueToText()

QString QRoundProgressBar::valueToText ( double  value) const
protectedvirtual

Definition at line 272 of file QRoundProgressBar.cpp.

References m_decimals, m_format, m_max, m_min, m_updateFlags, UF_MAX, UF_PERCENT, UF_VALUE, and value().

Referenced by drawText().

Member Data Documentation

◆ m_barStyle

BarStyle QRoundProgressBar::m_barStyle
protected

◆ m_dataPenWidth

double QRoundProgressBar::m_dataPenWidth
protected

Definition at line 251 of file QRoundProgressBar.h.

Referenced by drawValue(), and setDataPenWidth().

◆ m_decimals

int QRoundProgressBar::m_decimals
protected

Definition at line 257 of file QRoundProgressBar.h.

Referenced by drawText(), setDecimals(), and valueToText().

◆ m_format

QString QRoundProgressBar::m_format
protected

◆ m_gradientData

QGradientStops QRoundProgressBar::m_gradientData
protected

◆ m_max

double QRoundProgressBar::m_max
protected

Definition at line 246 of file QRoundProgressBar.h.

Referenced by paintEvent(), setMinimum(), setRange(), setValue(), and valueToText().

◆ m_min

double QRoundProgressBar::m_min
protected

Definition at line 246 of file QRoundProgressBar.h.

Referenced by drawValue(), paintEvent(), setMaximum(), setRange(), setValue(), and valueToText().

◆ m_nullPosition

double QRoundProgressBar::m_nullPosition
protected

Definition at line 249 of file QRoundProgressBar.h.

Referenced by drawValue(), rebuildDataBrushIfNeeded(), and setNullPosition().

◆ m_outlinePenWidth

double QRoundProgressBar::m_outlinePenWidth
protected

Definition at line 251 of file QRoundProgressBar.h.

Referenced by calculateInnerRect(), drawBase(), drawValue(), and setOutlinePenWidth().

◆ m_rebuildBrush

bool QRoundProgressBar::m_rebuildBrush
protected

◆ m_updateFlags

int QRoundProgressBar::m_updateFlags
protected

Definition at line 262 of file QRoundProgressBar.h.

Referenced by valueFormatChanged(), and valueToText().

◆ m_value

double QRoundProgressBar::m_value
protected

Definition at line 247 of file QRoundProgressBar.h.

Referenced by paintEvent(), setRange(), and setValue().

◆ PositionBottom

const int QRoundProgressBar::PositionBottom = -90
static

Definition at line 67 of file QRoundProgressBar.h.

◆ PositionLeft

const int QRoundProgressBar::PositionLeft = 180
static

Definition at line 64 of file QRoundProgressBar.h.

◆ PositionRight

const int QRoundProgressBar::PositionRight = 0
static

Definition at line 66 of file QRoundProgressBar.h.

◆ PositionTop

const int QRoundProgressBar::PositionTop = 90
static

Definition at line 65 of file QRoundProgressBar.h.

◆ UF_MAX

const int QRoundProgressBar::UF_MAX = 4
staticprotected

Definition at line 261 of file QRoundProgressBar.h.

Referenced by valueFormatChanged(), and valueToText().

◆ UF_PERCENT

const int QRoundProgressBar::UF_PERCENT = 2
staticprotected

Definition at line 260 of file QRoundProgressBar.h.

Referenced by valueFormatChanged(), and valueToText().

◆ UF_VALUE

const int QRoundProgressBar::UF_VALUE = 1
staticprotected

Definition at line 259 of file QRoundProgressBar.h.

Referenced by valueFormatChanged(), and valueToText().


The documentation for this class was generated from the following files: