mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-20 04:25:42 +08:00
refs #855, load indicator timeout
* id for each displayed indicator * timeout function can time out particular id
This commit is contained in:
committed by
Mathew Sutcliffe
parent
7d9b721b87
commit
6a1130100e
@@ -46,7 +46,7 @@ namespace BlackGui
|
|||||||
return m_displayedWhenStopped;
|
return m_displayedWhenStopped;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CLoadIndicator::startAnimation(bool processEvents)
|
int CLoadIndicator::startAnimation(int timeoutMs, bool processEvents)
|
||||||
{
|
{
|
||||||
this->m_angle = 0;
|
this->m_angle = 0;
|
||||||
this->show();
|
this->show();
|
||||||
@@ -56,10 +56,29 @@ namespace BlackGui
|
|||||||
{
|
{
|
||||||
sGui->processEventsToRefreshGui();
|
sGui->processEventsToRefreshGui();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const int stopId = this->m_currentId++; // copy
|
||||||
|
if (timeoutMs > 0)
|
||||||
|
{
|
||||||
|
QTimer::singleShot(timeoutMs, this, [this, stopId]
|
||||||
|
{
|
||||||
|
// only timeout myself id
|
||||||
|
this->stopAnimation(stopId);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
this->m_pendingIds.push_back(stopId);
|
||||||
|
return stopId;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CLoadIndicator::stopAnimation()
|
void CLoadIndicator::stopAnimation(int indicatorId)
|
||||||
{
|
{
|
||||||
|
if (indicatorId > 0)
|
||||||
|
{
|
||||||
|
this->m_pendingIds.removeOne(indicatorId);
|
||||||
|
// if others pending do not stop
|
||||||
|
if (!this->m_pendingIds.isEmpty()) { return; }
|
||||||
|
}
|
||||||
|
this->m_pendingIds.clear();
|
||||||
if (this->m_timerId != -1) { killTimer(this->m_timerId); }
|
if (this->m_timerId != -1) { killTimer(this->m_timerId); }
|
||||||
this->m_timerId = -1;
|
this->m_timerId = -1;
|
||||||
this->hide();
|
this->hide();
|
||||||
@@ -70,8 +89,8 @@ namespace BlackGui
|
|||||||
void CLoadIndicator::setAnimationDelay(int delay)
|
void CLoadIndicator::setAnimationDelay(int delay)
|
||||||
{
|
{
|
||||||
this->m_delayMs = delay;
|
this->m_delayMs = delay;
|
||||||
if (this->m_timerId != -1) { killTimer(this->m_timerId); }
|
if (this->m_timerId != -1) { this->killTimer(this->m_timerId); }
|
||||||
this->m_timerId = startTimer(this->m_delayMs);
|
this->m_timerId = this->startTimer(this->m_delayMs);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CLoadIndicator::setColor(const QColor &color)
|
void CLoadIndicator::setColor(const QColor &color)
|
||||||
@@ -93,9 +112,8 @@ namespace BlackGui
|
|||||||
void CLoadIndicator::timerEvent(QTimerEvent *event)
|
void CLoadIndicator::timerEvent(QTimerEvent *event)
|
||||||
{
|
{
|
||||||
Q_UNUSED(event);
|
Q_UNUSED(event);
|
||||||
m_angle = (m_angle + 30) % 360;
|
this->m_angle = (this->m_angle + 30) % 360;
|
||||||
update();
|
this->update();
|
||||||
emit updatedAnimation();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CLoadIndicator::paintEvent(QPaintEvent *event)
|
void CLoadIndicator::paintEvent(QPaintEvent *event)
|
||||||
|
|||||||
@@ -21,6 +21,7 @@
|
|||||||
#include <QSize>
|
#include <QSize>
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
#include <Qt>
|
#include <Qt>
|
||||||
|
#include <QList>
|
||||||
|
|
||||||
class QPaintEvent;
|
class QPaintEvent;
|
||||||
class QPainter;
|
class QPainter;
|
||||||
@@ -44,7 +45,7 @@ namespace BlackGui
|
|||||||
//! Returns the delay between animation steps.
|
//! Returns the delay between animation steps.
|
||||||
//! \return The number of milliseconds between animation steps. By default, the animation delay is set to 40 milliseconds.
|
//! \return The number of milliseconds between animation steps. By default, the animation delay is set to 40 milliseconds.
|
||||||
//! \sa setAnimationDelay
|
//! \sa setAnimationDelay
|
||||||
int animationDelay() const { return m_delayMs; }
|
int getAnimationDelayTimeMs() const { return m_delayMs; }
|
||||||
|
|
||||||
//! Returns a Boolean value indicating whether the component is currently animated.
|
//! Returns a Boolean value indicating whether the component is currently animated.
|
||||||
//! \return Animation state.
|
//! \return Animation state.
|
||||||
@@ -72,18 +73,14 @@ namespace BlackGui
|
|||||||
//! Center this load indicator
|
//! Center this load indicator
|
||||||
void centerLoadIndicator(const QPoint &middle);
|
void centerLoadIndicator(const QPoint &middle);
|
||||||
|
|
||||||
signals:
|
|
||||||
//! Animation has been updated
|
|
||||||
void updatedAnimation();
|
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
//! Starts the spin animation.
|
//! Starts the spin animation.
|
||||||
//! \sa stopAnimation isAnimated
|
//! \sa stopAnimation isAnimated
|
||||||
void startAnimation(bool processEvents = false);
|
int startAnimation(int timeoutMs = -1, bool processEvents = false);
|
||||||
|
|
||||||
//! Stops the spin animation.
|
//! Stops the spin animation.
|
||||||
//! \sa startAnimation isAnimated
|
//! \sa startAnimation isAnimated
|
||||||
void stopAnimation();
|
void stopAnimation(int indicatorId = -1);
|
||||||
|
|
||||||
//! Sets the delay between animation steps.
|
//! Sets the delay between animation steps.
|
||||||
//! Setting the \a delay to a value larger than 40 slows the animation, while setting the \a delay to a smaller value speeds it up.
|
//! Setting the \a delay to a value larger than 40 slows the animation, while setting the \a delay to a smaller value speeds it up.
|
||||||
@@ -114,6 +111,8 @@ namespace BlackGui
|
|||||||
int m_angle = 0;
|
int m_angle = 0;
|
||||||
int m_timerId = -1;
|
int m_timerId = -1;
|
||||||
int m_delayMs = 1000;
|
int m_delayMs = 1000;
|
||||||
|
int m_currentId = 1; //!< id indicating request starting this indicator
|
||||||
|
QList<int> m_pendingIds; //!< ids not finished yet
|
||||||
bool m_displayedWhenStopped = false;
|
bool m_displayedWhenStopped = false;
|
||||||
QColor m_color = Qt::blue;
|
QColor m_color = Qt::blue;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user