Kstars

QProgressIndicator.cpp
1/*
2
3 This file is part of QProgressIndicator,
4 an open-source recent files menu widget
5
6 SPDX-FileCopyrightText: 2009-2010 Morgan Leborgne
7 SPDX-License-Identifier: LGPL-3.0-or-later
8*/
9
10#include "QProgressIndicator.h"
11
12#include <QPainter>
13
14QProgressIndicator::QProgressIndicator(QWidget *parent)
15 : QWidget(parent)
16{
18 setFocusPolicy(Qt::NoFocus);
19}
20
22{
23 return (m_timerId != -1);
24}
25
27{
28 m_displayedWhenStopped = state;
29
30 update();
31}
32
34{
35 return m_displayedWhenStopped;
36}
37
39{
40 m_angle = 0;
41
42 if (m_timerId == -1)
43 m_timerId = startTimer(m_delay);
44}
45
47{
48 if (m_timerId != -1)
49 killTimer(m_timerId);
50
51 m_timerId = -1;
52
53 update();
54}
55
57{
58 if (m_timerId != -1)
59 killTimer(m_timerId);
60
61 m_delay = delay;
62
63 if (m_timerId != -1)
64 m_timerId = startTimer(m_delay);
65}
66
68{
69 m_color = color;
70
71 update();
72}
73
74QSize QProgressIndicator::sizeHint() const
75{
76 return QSize(20, 20);
77}
78
79int QProgressIndicator::heightForWidth(int w) const
80{
81 return w;
82}
83
84void QProgressIndicator::timerEvent(QTimerEvent * /*event*/)
85{
86 m_angle = (m_angle + 30) % 360;
87
88 update();
89}
90
91void QProgressIndicator::paintEvent(QPaintEvent * /*event*/)
92{
93 if (!m_displayedWhenStopped && !isAnimated())
94 return;
95
96 int width = qMin(this->width(), this->height());
97
98 QPainter p(this);
99 p.setRenderHint(QPainter::Antialiasing);
100
101 int outerRadius = (width - 1) * 0.5;
102 int innerRadius = (width - 1) * 0.5 * 0.38;
103
104 int capsuleHeight = outerRadius - innerRadius;
105 int capsuleWidth = (width > 32) ? capsuleHeight * .23 : capsuleHeight * .35;
106 int capsuleRadius = capsuleWidth / 2;
107
108 for (int i = 0; i < 12; i++)
109 {
110 QColor color = m_color;
111 color.setAlphaF(1.0f - (i / 12.0f));
112 p.setPen(Qt::NoPen);
113 p.setBrush(color);
114 p.save();
115 p.translate(rect().center());
116 p.rotate(m_angle - i * 30.0f);
117 p.drawRoundedRect(-capsuleWidth * 0.5, -(innerRadius + capsuleHeight), capsuleWidth, capsuleHeight,
118 capsuleRadius, capsuleRadius);
119 p.restore();
120 }
121}
void stopAnimation()
Stops the spin animation.
bool isDisplayedWhenStopped() const
Returns a Boolean value indicating whether the receiver shows itself even when it is not animating.
void startAnimation()
Starts the spin animation.
void setColor(const QColor &color)
Sets the color of the components to the given color.
bool isAnimated() const
Returns a Boolean value indicating whether the component is currently animated.
void setDisplayedWhenStopped(bool state)
Sets whether the component hides itself when it is not animating.
void setAnimationDelay(int delay)
Sets the delay between animation steps.
void setAlphaF(float alpha)
void killTimer(int id)
int startTimer(int interval, Qt::TimerType timerType)
QTextStream & center(QTextStream &stream)
void update()
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:04:45 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.