diff options
author | Luiz Agostini <luiz.agostini@openbossa.org> | 2009-11-05 21:42:23 -0300 |
---|---|---|
committer | Luiz Agostini <luiz.agostini@openbossa.org> | 2009-11-05 21:42:23 -0300 |
commit | a851eb64f0dc8420276f5fcc689d6941fdacd072 (patch) | |
tree | 5585f7354c68de23ed94692558f56d1c26bdd616 /weather | |
parent | c15229b32adc5f691d5c9fe5743da392b1be0037 (diff) |
Weather: list minimum count.
Signed-off-by: Luiz Agostini <luiz.agostini@openbossa.org>
Diffstat (limited to 'weather')
-rw-r--r-- | weather/citylist.cpp | 49 | ||||
-rw-r--r-- | weather/citylist.h | 7 | ||||
-rw-r--r-- | weather/pixmapbutton.h | 4 |
3 files changed, 46 insertions, 14 deletions
diff --git a/weather/citylist.cpp b/weather/citylist.cpp index 1f4875b..63380e8 100644 --- a/weather/citylist.cpp +++ b/weather/citylist.cpp @@ -22,6 +22,7 @@ #define CITY_NAME_FONT_SIZE (Settings::scaleHeight(50.0)) static const int maxVisibleItems = 6; +static const int minListCount = 3; static inline qreal getCenterVerticalPos(QGraphicsItem *parent, QGraphicsItem *item) { @@ -190,7 +191,7 @@ void CityListText::paint(QPainter *painter, const QStyleOptionGraphicsItem *opt, // CityListItem -CityListItem::CityListItem(const ForecastData &data, CityContentList *list) +CityListItem::CityListItem(const ForecastData &data, CityContentList *list, bool deleteVisible) : ContentListItem(0) , m_height(ITEM_BACKGROUND.height()) , m_data(data) @@ -201,6 +202,8 @@ CityListItem::CityListItem(const ForecastData &data, CityContentList *list) , m_text(new CityListText(m_data.cityName(), this)) { m_delete->setPos(ITEM_BUTTON_LEFT, getCenterVerticalPos(m_delete)); + m_delete->setVisible(deleteVisible); + m_delete->setOpacity(deleteVisible ? 1.0 : 0.0); m_check->setPos(ITEM_CHECK_LEFT, getCenterVerticalPos(m_check)); m_check->hide(); m_text->setPos(TEXT_LEFT, getCenterVerticalPos(m_text)); @@ -225,29 +228,32 @@ qreal CityListItem::contentHeight() const return m_height; } +QAbstractAnimation *CityListItem::getButtonAnimation(bool hide) +{ + return getFadeAnimation(m_delete, hide, 150); +} + QAbstractAnimation *CityListItem::getShowAnimation() { - return getFadeAnimation(false, 150); + return getFadeAnimation(this, false, 150); } QAbstractAnimation *CityListItem::getHideAnimation() { - return getFadeAnimation(true, 150); + return getFadeAnimation(this, true, 150); } -QAbstractAnimation *CityListItem::getFadeAnimation(bool hide, int msecs) +template<class T>QAbstractAnimation *CityListItem::getFadeAnimation(T *target, bool hide, int msecs) { - - setOpacity(hide ? 1.0 : 0.0); - show(); - - QPropertyAnimation* lResult = new QPropertyAnimation(this, "opacity"); + target->setOpacity(hide ? 1.0 : 0.0); + target->show(); + QPropertyAnimation* lResult = new QPropertyAnimation(target, "opacity"); lResult->setEasingCurve(QEasingCurve::OutExpo); lResult->setStartValue(hide ? 1.0 : 0.0); lResult->setEndValue(hide ? 0.0 : 1.0); lResult->setDuration(msecs); if (hide) - connect(lResult, SIGNAL(finished()), this, SLOT(doHide())); + connect(lResult, SIGNAL(finished()), target, SLOT(doHide())); return lResult; } @@ -260,14 +266,14 @@ CityContentList::CityContentList(QList<ForecastData> &contentList, QObject *hold { QList<ContentListItem*> items; foreach (const ForecastData &data, m_contentList) - items.append(new CityListItem(data, this)); + items.append(new CityListItem(data, this, m_contentList.count() > minListCount)); appendItems(items); } void CityContentList::addForecast(const ForecastData &data) { m_contentList.append(data); - addItem(new CityListItem(data, this)); + addItem(new CityListItem(data, this, m_contentList.count() > minListCount)); } void CityContentList::select(const QString &selected) @@ -300,6 +306,14 @@ QAbstractAnimation *CityContentList::getInsertAnimation(int idx, qreal height) } + if (itemCount() == minListCount) { + for (int i = 0; i < minListCount; ++i) { + CityListItem *item = static_cast<CityListItem*>(getItem(i)); + if (item) + list.append(item->getButtonAnimation(false)); + } + } + return createCompoundAnimation(list); } @@ -331,6 +345,17 @@ QAbstractAnimation *CityContentList::getRemoveAnimation(int idx) } } + if (itemCount() == minListCount + 1) { + for (int i = 0; i <= minListCount; ++i) { + if (i != idx) { + CityListItem *item = static_cast<CityListItem*>(getItem(i)); + if (item) + list.append(item->getButtonAnimation(true)); + + } + } + } + m_contentList.removeAt(idx); diff --git a/weather/citylist.h b/weather/citylist.h index 5fd1e00..3d93806 100644 --- a/weather/citylist.h +++ b/weather/citylist.h @@ -66,7 +66,7 @@ class CityListItem : public ContentListItem Q_OBJECT Q_PROPERTY(qreal opacity READ opacity WRITE setOpacity); public: - CityListItem(const ForecastData &data, CityContentList *list); + CityListItem(const ForecastData &data, CityContentList *list, bool deleteVisible); void select(bool selected); const ForecastData &data() const { return m_data; } @@ -75,6 +75,8 @@ public: QAbstractAnimation *getShowAnimation(); QAbstractAnimation *getHideAnimation(); + QAbstractAnimation *getButtonAnimation(bool hide); + private slots: void removeFromList(); @@ -88,7 +90,7 @@ private: PixmapButton * const m_delete; CityListText * const m_text; - QAbstractAnimation *getFadeAnimation(bool hide, int msecs); + template<class T> static QAbstractAnimation *getFadeAnimation(T *target, bool hide, int msecs); private slots: void doHide() { hide(); } @@ -120,6 +122,7 @@ private: qreal getTop() { return pos().y(); } void setTop(qreal top) { setPos(pos().x(), top); } + }; // CityList diff --git a/weather/pixmapbutton.h b/weather/pixmapbutton.h index 51ed153..60c95a3 100644 --- a/weather/pixmapbutton.h +++ b/weather/pixmapbutton.h @@ -7,11 +7,15 @@ class PixmapButton: public QObject, public QGraphicsPixmapItem { Q_OBJECT + Q_PROPERTY(qreal opacity READ opacity WRITE setOpacity); public: PixmapButton(qreal minSize, const QPixmap &pixmap, QGraphicsItem *parent = 0); QRectF boundingRect() const; QPainterPath shape() const; +public slots: + void doHide() { hide(); } + signals: void clicked(); |