11 #include <QSizePolicy>
22 CLoadIndicator::CLoadIndicator(
int width,
int height,
QWidget *parent) :
QWidget(parent)
36 m_displayedWhenStopped = state;
44 using namespace std::chrono_literals;
50 if (m_timerId == -1) { m_timerId =
startTimer(m_delayMs); }
51 if (processEvents &&
sGui)
60 const int stopId = m_currentId++;
64 if (!myself) {
return; }
71 m_pendingIds.push_back(stopId);
81 if (!m_pendingIds.
isEmpty()) {
return; }
86 SWIFT_AUDIT_X(CThreadUtils::isInThisThread(
this), Q_FUNC_INFO,
"Try to kill timer from another thread");
100 SWIFT_AUDIT_X(CThreadUtils::isInThisThread(
this), Q_FUNC_INFO,
"Try to kill timer from another thread");
119 m_angle = (m_angle + 30) % 360;
138 if (!m_displayedWhenStopped && !
isAnimated()) {
return; }
148 int outerRadius = qRound((
width - 1) * 0.5);
149 int innerRadius = qRound((
width - 1) * 0.5 * 0.38);
151 int capsuleHeight = outerRadius - innerRadius;
152 int capsuleWidth = (
width > 32) ? qRound(capsuleHeight * .23) : qRound(capsuleHeight * .35);
153 int capsuleRadius = capsuleWidth / 2;
155 for (
int i = 0; i < 12; i++)
163 painter.
rotate(m_angle - qRound(i * 30.0f));
164 painter.
drawRoundedRect(-qRound(capsuleWidth * 0.5), -(innerRadius + capsuleHeight), capsuleWidth,
165 capsuleHeight, capsuleRadius, capsuleRadius);
172 const int w = this->
width();
173 const int h = this->
height();
174 const int x = middle.
x() - w / 2;
175 const int y = middle.
y() - h / 2;
181 Q_ASSERT_X(usingWidget, Q_FUNC_INFO,
"need widget");
void processEventsToRefreshGui() const
Allow the GUI to refresh by processing events, call the event loop.
QWidget * m_usingWidget
widget which uses load indicator
void centerLoadIndicator()
Center load indicator.
bool m_loadInProgress
flag indicating loading
CLoadIndicator * m_loadIndicator
indicator itself
void showLoading(std::chrono::milliseconds timeout=std::chrono::milliseconds(0), bool processEvents=true)
Show load indicator.
bool isLoadInProgress() const
Loading in progress?
virtual void indicatorTimedOut()
Indicator timed out.
void hideLoading()
Hide load indicator.
CLoadIndicatorEnabled(QWidget *usingWidget)
Ctor.
int m_indicatorId
last indicator id returned
bool isShowingLoadIndicator() const
Showing load indicator?
The QProgressIndicator class lets an application display a progress indicator to show that a lengthy ...
void centerLoadIndicator(const QPoint &middle)
Center this load indicator.
bool isAnimated() const
Returns a Boolean value indicating whether the component is currently animated.
void setColor(const QColor &color)
Sets the color of the components to the given color.
virtual int heightForWidth(int w) const
bool isDisplayedWhenStopped() const
Returns a Boolean value indicating whether the receiver shows itself even when it is not animating.
const QColor & color() const
Returns the color of the component.
int startAnimation(std::chrono::milliseconds timeout=std::chrono::milliseconds(0), bool processEvents=false)
Starts the spin animation.
bool isParentVisible() const
Is parent widget visible?
void paint(QPainter &painter) const
Paint to another painter.
virtual void paintEvent(QPaintEvent *event)
void timedOut()
Timed out.
virtual void timerEvent(QTimerEvent *event)
void stopAnimation(int indicatorId=-1)
Stops the spin animation.
virtual QSize sizeHint() const
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. Setting the delay to a value larger than 40 slows the animati...
SWIFT_GUI_EXPORT swift::gui::CGuiApplication * sGui
Single instance of GUI application object.
Free functions in swift::misc.
void setAlphaF(float alpha)
bool isEmpty() const const
bool removeOne(const AT &t)
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
void killTimer(Qt::TimerId id)
void setObjectName(QAnyStringView name)
int startTimer(int interval, Qt::TimerType timerType)
void drawRoundedRect(const QRect &rect, qreal xRadius, qreal yRadius, Qt::SizeMode mode)
void setBrush(QColor color)
void setPen(Qt::PenStyle style)
void setRenderHint(QPainter::RenderHint hint, bool on)
void translate(const QPoint &offset)
QPoint center() const const
QRect boundingRect() const const
#define SWIFT_AUDIT_X(COND, WHERE, WHAT)
A weaker kind of verify.