refs #855, load indicator timeout

* id for each displayed indicator
* timeout function can time out particular id
This commit is contained in:
Klaus Basan
2017-01-07 02:14:54 +01:00
committed by Mathew Sutcliffe
parent 7d9b721b87
commit 6a1130100e
2 changed files with 31 additions and 14 deletions

View File

@@ -46,7 +46,7 @@ namespace BlackGui
return m_displayedWhenStopped;
}
void CLoadIndicator::startAnimation(bool processEvents)
int CLoadIndicator::startAnimation(int timeoutMs, bool processEvents)
{
this->m_angle = 0;
this->show();
@@ -56,10 +56,29 @@ namespace BlackGui
{
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); }
this->m_timerId = -1;
this->hide();
@@ -70,8 +89,8 @@ namespace BlackGui
void CLoadIndicator::setAnimationDelay(int delay)
{
this->m_delayMs = delay;
if (this->m_timerId != -1) { killTimer(this->m_timerId); }
this->m_timerId = startTimer(this->m_delayMs);
if (this->m_timerId != -1) { this->killTimer(this->m_timerId); }
this->m_timerId = this->startTimer(this->m_delayMs);
}
void CLoadIndicator::setColor(const QColor &color)
@@ -93,9 +112,8 @@ namespace BlackGui
void CLoadIndicator::timerEvent(QTimerEvent *event)
{
Q_UNUSED(event);
m_angle = (m_angle + 30) % 360;
update();
emit updatedAnimation();
this->m_angle = (this->m_angle + 30) % 360;
this->update();
}
void CLoadIndicator::paintEvent(QPaintEvent *event)

View File

@@ -21,6 +21,7 @@
#include <QSize>
#include <QWidget>
#include <Qt>
#include <QList>
class QPaintEvent;
class QPainter;
@@ -44,7 +45,7 @@ namespace BlackGui
//! Returns the delay between animation steps.
//! \return The number of milliseconds between animation steps. By default, the animation delay is set to 40 milliseconds.
//! \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.
//! \return Animation state.
@@ -72,18 +73,14 @@ namespace BlackGui
//! Center this load indicator
void centerLoadIndicator(const QPoint &middle);
signals:
//! Animation has been updated
void updatedAnimation();
public slots:
//! Starts the spin animation.
//! \sa stopAnimation isAnimated
void startAnimation(bool processEvents = false);
int startAnimation(int timeoutMs = -1, bool processEvents = false);
//! Stops the spin animation.
//! \sa startAnimation isAnimated
void stopAnimation();
void stopAnimation(int indicatorId = -1);
//! 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.
@@ -114,6 +111,8 @@ namespace BlackGui
int m_angle = 0;
int m_timerId = -1;
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;
QColor m_color = Qt::blue;
};