QtPass  1.2.0-pre
Multi-platform GUI for pass, the standard unix password manager.
qprogressindicator.cpp
Go to the documentation of this file.
1 #include "qprogressindicator.h"
2 #include <QPainter>
3 
9  : QWidget(parent), m_angle(0), m_timerId(-1), m_delay(40),
10  m_displayedWhenStopped(false), m_color(Qt::black) {
11  setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
12  setFocusPolicy(Qt::NoFocus);
13 }
14 
15 bool QProgressIndicator::isAnimated() const { return m_timerId != -1; }
16 
18  m_displayedWhenStopped = state;
19 
20  update();
21 }
22 
24  return m_displayedWhenStopped;
25 }
26 
28  m_angle = 0;
29 
30  if (m_timerId == -1)
31  m_timerId = startTimer(m_delay);
32 }
33 
35  if (m_timerId != -1)
36  killTimer(m_timerId);
37 
38  m_timerId = -1;
39 
40  update();
41 }
42 
44  if (m_timerId != -1)
45  killTimer(m_timerId);
46 
47  m_delay = delay;
48 
49  if (m_timerId != -1)
50  m_timerId = startTimer(m_delay);
51 }
52 
53 void QProgressIndicator::setColor(const QColor &color) {
54  m_color = color;
55 
56  update();
57 }
58 
63 QSize QProgressIndicator::sizeHint() const { return QSize(20, 20); }
64 
70 int QProgressIndicator::heightForWidth(int w) const { return w; }
71 
75 void QProgressIndicator::timerEvent(QTimerEvent * /*event*/) {
76  m_angle = (m_angle + 30) % 360;
77 
78  update();
79 }
80 
84 void QProgressIndicator::paintEvent(QPaintEvent * /*event*/) {
85  if (!m_displayedWhenStopped && !isAnimated())
86  return;
87 
88  int width = qMin(this->width(), this->height());
89 
90  QPainter p(this);
91  p.setRenderHint(QPainter::Antialiasing);
92 
93  int outerRadius = int((width - 1) * 0.5);
94  int innerRadius = int((width - 1) * 0.5 * 0.38);
95 
96  int capsuleHeight = outerRadius - innerRadius;
97  int capsuleWidth =
98  (width > 32) ? int(capsuleHeight * 0.23) : int(capsuleHeight * 0.35);
99  int capsuleRadius = capsuleWidth / 2;
100 
101  for (int i = 0; i < 12; ++i) {
102  QColor color = m_color;
103  color.setAlphaF(int(1.0f - (i / 12.0f)));
104  p.setPen(Qt::NoPen);
105  p.setBrush(color);
106  p.save();
107  p.translate(rect().center());
108  p.rotate(int(m_angle - i * 30.0f));
109  p.drawRoundedRect(int(-capsuleWidth * 0.5), -(innerRadius + capsuleHeight),
110  capsuleWidth, capsuleHeight, capsuleRadius,
111  capsuleRadius);
112  p.restore();
113  }
114 }
int delay
QProgressIndicator::delay in miliseconds.
void startAnimation()
Starts the spin animation.
bool isDisplayedWhenStopped() const
Returns a Boolean value indicating whether the receiver shows itself even when it is not animating...
int heightForWidth(int w) const
QProgressIndicator::heightForWidth square ratio.
virtual QSize sizeHint() const
QProgressIndicator::sizeHint default minimum size.
void setDisplayedWhenStopped(bool state)
Sets whether the component hides itself when it is not animating.
virtual void paintEvent(QPaintEvent *event)
QProgressIndicator::paintEvent draw the spinner.
void stopAnimation()
Stops the spin animation.
QProgressIndicator(QWidget *parent=0)
QProgressIndicator::QProgressIndicator constructor.
virtual void timerEvent(QTimerEvent *event)
QProgressIndicator::timerEvent do the actual animation.
bool isAnimated() const
Returns a Boolean value indicating whether the component is currently animated.
const QColor & color() const
Returns the color of the component.
void setColor(const QColor &color)
Sets the color of the components to the given color.
void setAnimationDelay(int delay)
Sets the delay between animation steps.