37 : QWidget(parent), m_angle(0), m_timerId(-1), m_delay(40),
38 m_displayedWhenStopped(false), m_color(Qt::black) {
39 setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
40 setFocusPolicy(Qt::NoFocus);
46 m_displayedWhenStopped = state;
52 return m_displayedWhenStopped;
58 if (m_timerId == -1) {
59 m_timerId = startTimer(m_delay);
64 if (m_timerId != -1) {
74 if (m_timerId != -1) {
80 if (m_timerId != -1) {
81 m_timerId = startTimer(m_delay);
108 m_angle = (m_angle + 30) % 360;
117 if (!m_displayedWhenStopped && !
isAnimated()) {
121 int width = qMin(this->width(), this->height());
124 p.setRenderHint(QPainter::Antialiasing);
126 auto outerRadius = int((width - 1) * 0.5);
127 auto innerRadius = int((width - 1) * 0.5 * 0.38);
129 int capsuleHeight = outerRadius - innerRadius;
131 (width > 32) ?
int(capsuleHeight * 0.23) : int(capsuleHeight * 0.35);
132 int capsuleRadius = capsuleWidth / 2;
134 for (
int i = 0; i < 12; ++i) {
135 QColor
color = m_color;
136 color.setAlphaF(
int(1.0f - (i / 12.0f)));
140 p.translate(rect().center());
141 p.rotate(
int(m_angle - i * 30.0f));
142 p.drawRoundedRect(
int(-capsuleWidth * 0.5), -(innerRadius + capsuleHeight),
143 capsuleWidth, capsuleHeight, capsuleRadius,
virtual void timerEvent(QTimerEvent *event)
QProgressIndicator::timerEvent do the actual animation.
auto heightForWidth(int w) const -> int
QProgressIndicator::heightForWidth square ratio.
void stopAnimation()
Stops the spin animation.
virtual void paintEvent(QPaintEvent *event)
QProgressIndicator::paintEvent draw the spinner.
auto isAnimated() const -> bool
Returns a Boolean value indicating whether the component is currently animated.
void startAnimation()
Starts the spin animation.
auto isDisplayedWhenStopped() const -> bool
Returns a Boolean value indicating whether the receiver shows itself even when it is not animating.
void setColor(const QColor &color)
Sets the color of the components to the given color.
void setDisplayedWhenStopped(bool state)
Sets whether the component hides itself when it is not animating.
virtual auto sizeHint() const -> QSize
QProgressIndicator::sizeHint default minimum size.
QProgressIndicator(QWidget *parent=0)
QProgressIndicator::QProgressIndicator constructor.
void setAnimationDelay(int delay)
Sets the delay between animation steps.
auto color() const -> const QColor &
Returns the color of the component.