summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLuiz Agostini <luiz.agostini@openbossa.org>2009-11-13 14:28:31 -0300
committerLuiz Agostini <luiz.agostini@openbossa.org>2009-11-13 15:42:02 -0300
commit93a769d08aa3642cb131b930e3fb9250e94ac9d6 (patch)
tree4b6bd8eb1a36e173b1a8a2546a2207f0fe520661
parentd5d15204b6ab248c75064a043a0754dab3b383f0 (diff)
Weather: adjusting rain animation.
Signed-off-by: Luiz Agostini <luiz.agostini@openbossa.org>
-rw-r--r--weather/forecastrain.cpp37
1 files changed, 20 insertions, 17 deletions
diff --git a/weather/forecastrain.cpp b/weather/forecastrain.cpp
index 442d548..81f3175 100644
--- a/weather/forecastrain.cpp
+++ b/weather/forecastrain.cpp
@@ -54,14 +54,15 @@ ForecastRain::ForecastRain(RainType type, QGraphicsItem *parent)
: QGraphicsItem(parent)
, m_animation(this, "progress")
{
- for (int i = Light; i <= type; ++i) {
+ for (int i = Light; i <= Heavy; ++i) {
QGraphicsPixmapItem *item = new QGraphicsPixmapItem(RainItemArray[i].pic(), this);
item->setPos(0.0, -20.0);
+ item->hide();
m_items.append(item);
}
m_animation.setStartValue(0.0);
- m_animation.setEndValue(qreal(m_items.count() + 1));
- m_animation.setDuration(1000);
+ m_animation.setEndValue(3.0);
+ m_animation.setDuration(type == Light ? 3000 : type == Medium ? 2000 : 1000);
m_animation.setLoopCount(-1);
}
@@ -74,17 +75,15 @@ int ForecastRain::loadImages()
void ForecastRain::start()
{
- if (m_items.count() > 1) {
- switch (m_animation.state()) {
- case QAbstractAnimation::Stopped:
- m_animation.start();
- break;
- case QAbstractAnimation::Paused:
- m_animation.resume();
- break;
- default:
- break;
- }
+ switch (m_animation.state()) {
+ case QAbstractAnimation::Stopped:
+ m_animation.start();
+ break;
+ case QAbstractAnimation::Paused:
+ m_animation.resume();
+ break;
+ default:
+ break;
}
}
@@ -110,10 +109,14 @@ void ForecastRain::setProgress(qreal progress)
{
m_progress = progress;
for (int i = 0; i < m_items.count(); ++i) {
- const qreal opacity = progress < i ? 0.0
- : progress < i + 1 ? progress - qreal(i)
- : progress < i + 2 ? progress - qreal(i + 1)
+
+ qreal x = progress + i - 1;
+ x = x < 0 ? 3.0 + x : x > 3.0 ? x - 3.0 : x;
+ const qreal opacity = x <= 1.0 ? x
+ : x <= 2.0 ? 2.0 - x
: 0.0;
m_items[i]->setOpacity(opacity);
+ if ((opacity != 0.0) != m_items[i]->isVisible())
+ m_items[i]->setVisible(opacity != 0.0);
}
}