rock_widget_collection  0.1
Public Slots | Public Member Functions | Protected Member Functions | Properties | List of all members
ProgressIndicator Class Reference

The ProgressIndicator class lets an application display a progress indicator to show that a lengthy task is under way. More...

#include <ProgressIndicator.h>

Inherits QWidget.

Public Slots

void startAnimation ()
 
void stopAnimation ()
 
void setAnimationDelay (int delay)
 
void setDisplayedWhenStopped (bool state)
 
void setColor (const QColor &color)
 
void setPenColor (const QColor &color)
 

Public Member Functions

 ProgressIndicator (QWidget *parent=0)
 
int animationDelay () const
 
bool isAnimated () const
 
bool isDisplayedWhenStopped () const
 
const QColor & color () const
 
const QColor & penColor () const
 
virtual QSize sizeHint () const
 
int heightForWidth (int w) const
 

Protected Member Functions

virtual void timerEvent (QTimerEvent *event)
 
virtual void paintEvent (QPaintEvent *event)
 

Properties

int delay
 
bool displayedWhenStopped
 
QColor color
 
QColor penColor
 

Detailed Description

The ProgressIndicator class lets an application display a progress indicator to show that a lengthy task is under way.

Progress indicators are indeterminate and do nothing more than spin to show that the application is busy.

Based on QProgressIndicator 1.0.2 (http://qt-apps.org/content/show.php/QProgressIndicator?content=115762) by Morgan Leborgne (mojo2000)

See Also
QProgressBar

Definition at line 16 of file ProgressIndicator.h.

Constructor & Destructor Documentation

ProgressIndicator::ProgressIndicator ( QWidget *  parent = 0)

Definition at line 5 of file ProgressIndicator.cc.

6  : QWidget(parent),
7  m_angle(0),
8  m_timerId(-1),
9  m_delay(40),
10  m_displayedWhenStopped(false),
11  m_color(Qt::black),
12  m_penColor(Qt::lightGray)
13 {
14  setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
15  setFocusPolicy(Qt::NoFocus);
16 }

Member Function Documentation

int ProgressIndicator::animationDelay ( ) const
inline

Returns the delay between animation steps.

Returns
The number of milliseconds between animation steps. By default, the animation delay is set to 40 milliseconds.
See Also
setAnimationDelay

Definition at line 30 of file ProgressIndicator.h.

30 { return m_delay; }
const QColor& ProgressIndicator::color ( ) const
inline

Returns the color of the component.

See Also
setColor

Definition at line 47 of file ProgressIndicator.h.

47 { return m_color; }
int ProgressIndicator::heightForWidth ( int  w) const

Definition at line 83 of file ProgressIndicator.cc.

84 {
85  return w;
86 }
bool ProgressIndicator::isAnimated ( ) const

Returns a Boolean value indicating whether the component is currently animated.

Returns
Animation state.
See Also
startAnimation stopAnimation

Definition at line 18 of file ProgressIndicator.cc.

19 {
20  return (m_timerId != -1);
21 }
bool ProgressIndicator::isDisplayedWhenStopped ( ) const

Returns a Boolean value indicating whether the receiver shows itself even when it is not animating.

Returns
Return true if the progress indicator shows itself even when it is not animating. By default, it returns false.
See Also
setDisplayedWhenStopped

Definition at line 30 of file ProgressIndicator.cc.

31 {
32  return m_displayedWhenStopped;
33 }
void ProgressIndicator::paintEvent ( QPaintEvent *  event)
protectedvirtual

Definition at line 95 of file ProgressIndicator.cc.

96 {
97  if (!m_displayedWhenStopped && !isAnimated())
98  return;
99 
100  int width = qMin(this->width(), this->height());
101 
102  QPainter p(this);
103  p.setRenderHint(QPainter::Antialiasing);
104 
105  int outerRadius = (width-1)*0.5;
106  int innerRadius = (width-1)*0.5*0.38;
107 
108  int capsuleHeight = outerRadius - innerRadius;
109  int capsuleWidth = (width > 32 ) ? capsuleHeight *.23 : capsuleHeight *.35;
110  int capsuleRadius = capsuleWidth/2;
111 
112  for (int i=0; i<12; i++)
113  {
114  QColor color = m_color;
115  qreal alpha = 1.0f - (i/12.0f);
116  color.setAlphaF(alpha);
117 
118  QColor penColor = m_penColor;
119  penColor.setAlphaF(alpha);
120  QPen pen;
121  pen.setWidth(1);
122  pen.setColor(penColor);
123  p.setPen(pen);
124 
125  p.setBrush(color);
126  p.save();
127  p.translate(rect().center());
128  p.rotate(m_angle - i*30.0f);
129  p.drawRoundedRect(-capsuleWidth*0.5, -(innerRadius+capsuleHeight), capsuleWidth, capsuleHeight, capsuleRadius, capsuleRadius);
130  p.restore();
131  }
132 }
const QColor & penColor() const
const QColor & color() const
bool isAnimated() const
const QColor& ProgressIndicator::penColor ( ) const
inline

Returns the color of the outline of the component.

See Also
setColor

Definition at line 52 of file ProgressIndicator.h.

52 { return m_penColor; }
void ProgressIndicator::setAnimationDelay ( int  delay)
slot

Sets the delay between animation steps. Setting the delay to a value larger than 40 slows the animation, while setting the delay to a smaller value speeds it up.

Parameters
delayThe delay, in milliseconds.
See Also
animationDelay

Definition at line 53 of file ProgressIndicator.cc.

54 {
55  if (m_timerId != -1)
56  killTimer(m_timerId);
57 
58  m_delay = delay;
59 
60  if (m_timerId != -1)
61  m_timerId = startTimer(m_delay);
62 }
void ProgressIndicator::setColor ( const QColor &  color)
slot

Sets the color of the components to the given color.

See Also
color

Definition at line 64 of file ProgressIndicator.cc.

65 {
66  m_color = color;
67 
68  update();
69 }
const QColor & color() const
void ProgressIndicator::setDisplayedWhenStopped ( bool  state)
slot

Sets whether the component hides itself when it is not animating.

Parameters
stateThe animation state. Set false to hide the progress indicator when it is not animating; otherwise true.
See Also
isDisplayedWhenStopped

Definition at line 23 of file ProgressIndicator.cc.

24 {
25  m_displayedWhenStopped = state;
26 
27  update();
28 }
void ProgressIndicator::setPenColor ( const QColor &  color)
slot

Sets the color of the pen (responsible for the outline of the components) to the given color.

See Also
color

Definition at line 71 of file ProgressIndicator.cc.

72 {
73  m_penColor = color;
74 
75  update();
76 }
const QColor & color() const
QSize ProgressIndicator::sizeHint ( ) const
virtual

Definition at line 78 of file ProgressIndicator.cc.

79 {
80  return QSize(20,20);
81 }
void ProgressIndicator::startAnimation ( )
slot

Starts the spin animation.

See Also
stopAnimation isAnimated

Definition at line 35 of file ProgressIndicator.cc.

36 {
37  m_angle = 0;
38 
39  if (m_timerId == -1)
40  m_timerId = startTimer(m_delay);
41 }
void ProgressIndicator::stopAnimation ( )
slot

Stops the spin animation.

See Also
startAnimation isAnimated

Definition at line 43 of file ProgressIndicator.cc.

44 {
45  if (m_timerId != -1)
46  killTimer(m_timerId);
47 
48  m_timerId = -1;
49 
50  update();
51 }
void ProgressIndicator::timerEvent ( QTimerEvent *  event)
protectedvirtual

Definition at line 88 of file ProgressIndicator.cc.

89 {
90  m_angle = (m_angle+30)%360;
91 
92  update();
93 }

Property Documentation

QColor ProgressIndicator::color
readwrite

Definition at line 21 of file ProgressIndicator.h.

int ProgressIndicator::delay
readwrite

Definition at line 19 of file ProgressIndicator.h.

bool ProgressIndicator::displayedWhenStopped
readwrite

Definition at line 20 of file ProgressIndicator.h.

QColor ProgressIndicator::penColor
readwrite

Definition at line 22 of file ProgressIndicator.h.


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