summaryrefslogtreecommitdiffstats
path: root/weather
diff options
context:
space:
mode:
authorLuiz Agostini <luiz.agostini@openbossa.org>2009-11-04 23:51:39 -0300
committerLuiz Agostini <luiz.agostini@openbossa.org>2009-11-05 00:42:10 -0300
commit16de74f980068139f68a4d6e7fbccba9402d02ea (patch)
tree6d5da94c82819e14ad15adf408a14e6af2e8c8e5 /weather
parenteb47fcf330750f2ca8492b3f612b6a40f3b6eb8a (diff)
Weather: City manager in and out animations.
Signed-off-by: Luiz Agostini <luiz.agostini@openbossa.org>
Diffstat (limited to 'weather')
-rw-r--r--weather/citymanager.cpp35
-rw-r--r--weather/citymanager.h8
-rw-r--r--weather/mainview.cpp1
3 files changed, 41 insertions, 3 deletions
diff --git a/weather/citymanager.cpp b/weather/citymanager.cpp
index c711cd5..dad7fee 100644
--- a/weather/citymanager.cpp
+++ b/weather/citymanager.cpp
@@ -33,6 +33,7 @@
#include "settings.h"
#include <QGraphicsSceneMouseEvent>
+#include <QPropertyAnimation>
static inline qreal getBottomVerticalPos(qreal &bottom, QGraphicsItem *item)
{
@@ -55,7 +56,7 @@ CityManagerContent::CityManagerContent(QList<ForecastData> &contentList, QGraphi
m_addTool->setZValue(10.0);
m_list = new CityList(contentList, this);
- m_list->setPos(0.0, getBottomVerticalPos(bottom, m_list) + m_list->initialTop());
+ m_list->setPos(0.0, getBottomVerticalPos(bottom, m_list) + m_list->initialTop() + 1);
m_list->setZValue(0.0);
connect(m_addTool, SIGNAL(newForecast(ForecastData)),
@@ -81,15 +82,21 @@ void CityManagerContent::paint(QPainter *painter,
Q_UNUSED(widget);
}
+qreal CityManagerContent::getHiddenTop()
+{
+ return m_boundingRect.height() - m_list->pos().y() - 5.0;
+}
+
// CityManager
CityManager::CityManager(QList<ForecastData> contentList, QGraphicsItem *parent)
: QGraphicsItem(parent)
, m_boundingRect(QPointF(0.0, 0.0), Settings::windowSize())
, m_contentList(contentList)
+ , m_visible(false)
{
m_content = new CityManagerContent(m_contentList, this);
- m_content->setPos(0.0, 0.0);
+ m_content->setPos(0.0, m_content->getHiddenTop());
}
QRectF CityManager::boundingRect () const
@@ -107,5 +114,27 @@ void CityManager::paint(QPainter *painter, const QStyleOptionGraphicsItem *opt,
void CityManager::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
event->accept();
- emit terminated();
+ startAnimation(false);
+}
+
+void CityManager::startAnimation(bool show)
+{
+ if (show == m_visible)
+ return;
+
+ m_visible = show;
+
+ if (m_animation)
+ m_animation->stop();
+
+ QPropertyAnimation* animation = new QPropertyAnimation(m_content, "top");
+
+ animation->setEasingCurve(QEasingCurve::OutExpo);
+ animation->setEndValue(show ? 0.0 : m_content->getHiddenTop());
+ animation->setDuration(500);
+ m_animation = animation;
+ if (!show)
+ connect(animation, SIGNAL(finished()), this, SIGNAL(terminated()));
+ m_animation->start(QAbstractAnimation::DeleteWhenStopped);
+
}
diff --git a/weather/citymanager.h b/weather/citymanager.h
index 108012f..52b7f5f 100644
--- a/weather/citymanager.h
+++ b/weather/citymanager.h
@@ -49,6 +49,8 @@ public:
QRectF boundingRect () const;
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
+ qreal getHiddenTop();
+
private:
const QRectF m_boundingRect;
AddCityTool *m_addTool;
@@ -59,6 +61,7 @@ private:
private slots:
void forecastSelected(ForecastData data);
+
};
class CityManager : public QObject, public QGraphicsItem
@@ -67,6 +70,7 @@ class CityManager : public QObject, public QGraphicsItem
Q_INTERFACES(QGraphicsItem)
public:
CityManager(QList<ForecastData> contentList, QGraphicsItem *parent = 0);
+ void showManager() { startAnimation(true); }
QRectF boundingRect () const;
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
@@ -81,6 +85,10 @@ private:
const QRectF m_boundingRect;
CityManagerContent *m_content;
QList<ForecastData> m_contentList;
+ QPointer<QAbstractAnimation> m_animation;
+ bool m_visible;
+
+ void startAnimation(bool show);
};
#endif // CITYMANAGER_H
diff --git a/weather/mainview.cpp b/weather/mainview.cpp
index 906460f..578659f 100644
--- a/weather/mainview.cpp
+++ b/weather/mainview.cpp
@@ -128,6 +128,7 @@ void MainView::cityNameClicked()
connect(m_manager, SIGNAL(terminated()), this, SLOT(closeCityManager()));
m_scene.addItem(m_manager);
m_manager->show();
+ m_manager->showManager();
}
void MainView::closeCityManager()