summaryrefslogtreecommitdiffstats
path: root/weather
diff options
context:
space:
mode:
authorLuiz Agostini <luiz.agostini@openbossa.org>2009-11-05 13:23:54 -0300
committerLuiz Agostini <luiz.agostini@openbossa.org>2009-11-05 18:56:59 -0300
commit1ffac662c25835b22f4e3d879ee6a289909c638c (patch)
tree51656525455ebe6b252192a1506db96ce0b28a78 /weather
parent31d9ea4246c894a95e172755afd449a6707d4cb0 (diff)
Weather: basic carroussel enhancement.
Signed-off-by: Luiz Agostini <luiz.agostini@openbossa.org>
Diffstat (limited to 'weather')
-rw-r--r--weather/carroussel.h33
-rw-r--r--weather/citycarroussel.h8
2 files changed, 30 insertions, 11 deletions
diff --git a/weather/carroussel.h b/weather/carroussel.h
index f345826..796fd60 100644
--- a/weather/carroussel.h
+++ b/weather/carroussel.h
@@ -33,21 +33,26 @@
#define __CARROUSSEL_H__
#include <QList>
+#include <QDebug>
+
template<class T> class Carroussel
{
public:
Carroussel() : m_pos(0) {}
- ~Carroussel() { qDeleteAll(m_list); }
+ ~Carroussel() {}
int count() const { return m_list.count(); }
int pos() const { return m_pos; }
void move(int offset) { m_pos = getIndex(m_pos + offset); }
- int add(T *item);
- T *operator[](int aIdx) { return m_list[getIndex(aIdx + m_pos)]; }
+ int add(const T &item);
+ void remove(int idx);
+ T &operator[](int aIdx) { return m_list[getIndex(aIdx + m_pos)]; }
+ const T &operator[](int aIdx) const { return m_list[getIndex(aIdx + m_pos)]; }
+ void reset(const QList<T> &list, int newPos);
private:
int m_pos;
- QList<T*> m_list;
- int getIndex(int idx);
+ QList<T> m_list;
+ int getIndex(int idx) const;
int getCarrousselIndex(int idx);
};
@@ -83,14 +88,28 @@ private:
// Carroussel
-template<class T> int Carroussel<T>::add(T *item)
+template<class T> int Carroussel<T>::add(const T &item)
{
int idx = m_list.count() - m_pos;
m_list.append(item);
return idx <= m_list.count() / 2 ? idx : idx - m_list.count();
}
-template<class T> int Carroussel<T>::getIndex(int idx)
+template<class T> void Carroussel<T>::remove(int idx)
+{
+ idx = getIndex(m_pos + idx);
+ qDebug() << idx << m_pos << m_list.count();
+ m_list.removeAt(idx);
+ m_pos = getIndex(idx < m_pos ? m_pos - 1 : m_pos);
+}
+
+template<class T> void Carroussel<T>::reset(const QList<T> &list, int newPos)
+{
+ m_list = list;
+ m_pos = getIndex(newPos);
+}
+
+template<class T> int Carroussel<T>::getIndex(int idx) const
{
if (m_list.count() == 0)
return 0;
diff --git a/weather/citycarroussel.h b/weather/citycarroussel.h
index 0083b13..41d9a46 100644
--- a/weather/citycarroussel.h
+++ b/weather/citycarroussel.h
@@ -141,10 +141,10 @@ public slots:
private:
friend class CityCarrousselGesture;
- Carroussel<CityForecastData> m_data;
- Carroussel<ForecastBackground> m_background;
- Carroussel<QGraphicsTextItem> m_texts;
- Carroussel<CityInfoDisplay> m_cityInfo;
+ Carroussel<CityForecastData*> m_data;
+ Carroussel<ForecastBackground*> m_background;
+ Carroussel<QGraphicsTextItem*> m_texts;
+ Carroussel<CityInfoDisplay*> m_cityInfo;
CarrousselGroup m_carroussel;
QSharedPointer<ForecastView> m_view;