Added ListItem, ListItemDelegate, ListView classes.
authorJussi Laitinen <jupe@l3l7588.ixonos.local>
Mon, 5 Jul 2010 13:32:09 +0000 (16:32 +0300)
committerJussi Laitinen <jupe@l3l7588.ixonos.local>
Mon, 5 Jul 2010 13:32:09 +0000 (16:32 +0300)
16 files changed:
src/src.pro
src/ui/friendlistitem.cpp
src/ui/friendlistitem.h
src/ui/friendlistitemdelegate.cpp [new file with mode: 0644]
src/ui/friendlistitemdelegate.h [new file with mode: 0644]
src/ui/listitem.cpp [new file with mode: 0644]
src/ui/listitem.h [new file with mode: 0644]
src/ui/listitemdelegate.cpp [new file with mode: 0644]
src/ui/listitemdelegate.h [new file with mode: 0644]
src/ui/listview.cpp [new file with mode: 0644]
src/ui/listview.h [new file with mode: 0644]
tests/ui/friendlist/friendlist.pro
tests/ui/listitem/listitem.pro [new file with mode: 0644]
tests/ui/listitem/testlistitem.cpp [new file with mode: 0644]
tests/ui/listview/listview.pro [new file with mode: 0644]
tests/ui/listview/testlistview.cpp [new file with mode: 0644]

index 577dca8..87c3a12 100644 (file)
@@ -53,7 +53,11 @@ SOURCES += main.cpp \
     ui/zoombuttonpanel.cpp \
     user/user.cpp \
     ui/fullscreenbutton.cpp \
-    engine/mce.cpp
+    engine/mce.cpp \
+    ui/listview.cpp \
+    ui/listitem.cpp \
+    ui/listitemdelegate.cpp \
+    ui/friendlistitemdelegate.cpp
 HEADERS += common.h \
     engine/engine.h \
     facebookservice/facebookauthentication.h \
@@ -104,7 +108,11 @@ HEADERS += common.h \
     ui/zoombuttonpanel.h \
     user/user.h \
     ui/fullscreenbutton.h \
-    engine/mce.h
+    engine/mce.h \
+    ui/listview.h \
+    ui/listitem.h \
+    ui/listitemdelegate.h \
+    ui/friendlistitemdelegate.h
 QT += network \
     webkit
 
index 24e6dd5..d835d65 100644 (file)
@@ -67,103 +67,65 @@ const int CAR_DISTANCE = 500;       ///< Car distance limit for distance icon
 const int AEROPLANE_DISTANCE = 5000;///< Aeroplane distance limit for distance icon
 
 FriendListItem::FriendListItem(QWidget *parent)
-    : QWidget(parent)
+    : ListItem(parent)
     , m_expanded(false)
     , m_user(0)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    QVBoxLayout *layout = new QVBoxLayout(this);
-    layout->setContentsMargins(MARGIN, 0, MARGIN*2, MARGIN*2);
-    layout->setSpacing(0);
-    setLayout(layout);
-
-    QHBoxLayout *topLayout = new QHBoxLayout();
-    topLayout->setMargin(0);
-    topLayout->setSpacing(0);
-
-    QVBoxLayout *distanceLayout = new QVBoxLayout();
-    distanceLayout->setMargin(0);
-    distanceLayout->setSpacing(0);
-
-    QHBoxLayout *bottomLayout = new QHBoxLayout();
-    bottomLayout->setMargin(0);
-    bottomLayout->setSpacing(0);
-
-    QFormLayout *infoLayout = new QFormLayout();
-    infoLayout->setMargin(0);
-    infoLayout->setSpacing(0);
-    infoLayout->setLabelAlignment(Qt::AlignTop);
-
-    QLabel *clockLabel = new QLabel();
-    clockLabel->setPixmap(QPixmap(":/res/images/clock.png"));
-    clockLabel->setContentsMargins(0, 0, MARGIN, 0);
-    clockLabel->setFixedSize(ICON_WIDTH + MARGIN, ICON_HEIGHT);
-    QLabel *envelopeLabel = new QLabel();
-    envelopeLabel->setPixmap(QPixmap(":/res/images/envelope.png"));
-    envelopeLabel->setContentsMargins(0, 0, MARGIN, 0);
-    envelopeLabel->setFixedSize(ICON_WIDTH + MARGIN, ICON_HEIGHT);
-    QLabel *compassLabel = new QLabel();
-    compassLabel->setPixmap(QPixmap(":/res/images/compass.png"));
-    compassLabel->setContentsMargins(0, 0, MARGIN, 0);
-    compassLabel->setFixedSize(ICON_WIDTH + MARGIN, ICON_HEIGHT);
-
-    m_nameLabel = new QLabel();
-    m_nameLabel->setFixedHeight(IMAGE_HEIGHT);
-
-    m_distanceTextLabel = new QLabel();
-    m_distanceTextLabel->setFixedHeight(ICON_HEIGHT);
-
-    m_distanceImageLabel = new QLabel();
-    m_distanceImageLabel->setFixedSize(ICON_WIDTH, ICON_HEIGHT);
-
-    m_findButton = new ImageButton(this);
-
-    m_updatedLabel = new QLabel();
-    m_updatedLabel->setWordWrap(true);
-    m_statusTextLabel = new QLabel();
-    m_statusTextLabel->setWordWrap(true);
-    m_locationLabel = new QLabel();
-    m_locationLabel->setWordWrap(true);
-
-    distanceLayout->addWidget(m_distanceImageLabel, 0, Qt::AlignRight);
-    distanceLayout->addWidget(m_distanceTextLabel, 0, Qt::AlignRight);
-
-    infoLayout->addRow(envelopeLabel, m_statusTextLabel);
-    infoLayout->addRow(compassLabel, m_locationLabel);
-    infoLayout->addRow(clockLabel, m_updatedLabel);
-
-    topLayout->addWidget(m_findButton);
-    topLayout->addWidget(m_nameLabel, 1);
-    topLayout->addLayout(distanceLayout);
-
-    bottomLayout->addSpacing(IMAGE_WIDTH);
-    bottomLayout->addLayout(infoLayout);
-
-    layout->addLayout(topLayout, 0);
-    layout->addLayout(bottomLayout, 1);
-
-    setMinimumSize(BACKGROUND_WIDTH, ITEM_MIN_HEIGHT);
-    setMaximumWidth(BACKGROUND_WIDTH);
-
-    setFont(NOKIA_FONT_SMALL);
-    m_nameLabel->setFont(NOKIA_FONT_NORMAL);
-    QPalette itemPalette = palette();
-    itemPalette.setColor(QPalette::Foreground, COLOR_GRAY);
-    setPalette(itemPalette);
-    QPalette namePalette = m_nameLabel->palette();
-    namePalette.setColor(QPalette::Foreground, Qt::white);
-    m_nameLabel->setPalette(namePalette);
-
-    m_backgroundTopImage.load(":/res/images/list_item_top.png");
-    m_backgroundMiddleImage.load(":/res/images/list_item_middle.png");
-    m_backgroundBottomImage.load(":/res/images/list_item_bottom.png");
-
-    connect(m_findButton, SIGNAL(clicked()),
-        this, SLOT(findButtonClicked()));
+//    m_distanceTextLabel = new QLabel();
+//    m_distanceTextLabel->setFixedHeight(ICON_HEIGHT);
+
+//    m_distanceImageLabel = new QLabel();
+//    m_distanceImageLabel->setFixedSize(ICON_WIDTH, ICON_HEIGHT);
+
+//    m_findButton = new ImageButton(this);
+
+//    m_updatedLabel = new QLabel();
+//    m_updatedLabel->setWordWrap(true);
+//    m_statusTextLabel = new QLabel();
+//    m_statusTextLabel->setWordWrap(true);
+//    m_locationLabel = new QLabel();
+//    m_locationLabel->setWordWrap(true);
+
+//    distanceLayout->addWidget(m_distanceImageLabel, 0, Qt::AlignRight);
+//    distanceLayout->addWidget(m_distanceTextLabel, 0, Qt::AlignRight);
+
+//    infoLayout->addRow(envelopeLabel, m_statusTextLabel);
+//    infoLayout->addRow(compassLabel, m_locationLabel);
+//    infoLayout->addRow(clockLabel, m_updatedLabel);
+
+//    topLayout->addWidget(m_findButton);
+//    topLayout->addWidget(m_nameLabel, 1);
+//    topLayout->addLayout(distanceLayout);
+
+//    bottomLayout->addSpacing(IMAGE_WIDTH);
+//    bottomLayout->addLayout(infoLayout);
+
+//    layout->addLayout(topLayout, 0);
+//    layout->addLayout(bottomLayout, 1);
+
+//    setMinimumSize(BACKGROUND_WIDTH, ITEM_MIN_HEIGHT);
+//    setMaximumWidth(BACKGROUND_WIDTH);
+
+//    setFont(NOKIA_FONT_SMALL);
+//    m_nameLabel->setFont(NOKIA_FONT_NORMAL);
+//    QPalette itemPalette = palette();
+//    itemPalette.setColor(QPalette::Foreground, COLOR_GRAY);
+//    setPalette(itemPalette);
+//    QPalette namePalette = m_nameLabel->palette();
+//    namePalette.setColor(QPalette::Foreground, Qt::white);
+//    m_nameLabel->setPalette(namePalette);
+
+//    m_backgroundTopImage.load(":/res/images/list_item_top.png");
+//    m_backgroundMiddleImage.load(":/res/images/list_item_middle.png");
+//    m_backgroundBottomImage.load(":/res/images/list_item_bottom.png");
+
+//    connect(m_findButton, SIGNAL(clicked()),
+//        this, SLOT(findButtonClicked()));
 }
 
-void FriendListItem::setData(User *user)
+void FriendListItem::setUserData(User *user)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
@@ -171,13 +133,13 @@ void FriendListItem::setData(User *user)
         m_user = user;
 
         if (!m_user->profileImage().isNull())
-            m_findButton->setButtonIcon(m_user->profileImage());
+            setData(Qt::DisplayRole, m_user->profileImage());
 
-        QString unit;
-        double value;
-        m_user->distance(value, unit);
-        m_distanceTextLabel->setText(QString::number(value) + " " + unit);
-        setDistanceIcon(value, unit);
+//        QString unit;
+//        double value;
+//        m_user->distance(value, unit);
+//        m_distanceTextLabel->setText(QString::number(value) + " " + unit);
+//        setDistanceIcon(value, unit);
 
         shortenTexts();
         setText(false);
@@ -204,8 +166,8 @@ void FriendListItem::shortenTexts()
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    QFontMetrics nameLabelMetrics = m_nameLabel->fontMetrics();
-    QFontMetrics otherLabelsMetrics = m_updatedLabel->fontMetrics();
+    QFontMetrics nameLabelMetrics = QFontMetrics(NOKIA_FONT_NORMAL);
+    QFontMetrics otherLabelsMetrics = QFontMetrics(NOKIA_FONT_SMALL);
 
     QString name = m_user->name();
     QString updated = m_user->timestamp();
@@ -248,66 +210,23 @@ void FriendListItem::setText(bool expanded)
     qDebug() << __PRETTY_FUNCTION__;
 
     if (expanded) {
-        setUpdatesEnabled(false);
-        m_nameLabel->setText(m_shortenedName);
-        m_updatedLabel->setText(m_user->timestamp());
-        m_statusTextLabel->setText(m_user->note());
-        m_locationLabel->setText(m_user->address());
-        setUpdatesEnabled(true);
+        //setUpdatesEnabled(false);
+        setData(Qt::UserRole, m_shortenedName);
+        setData(Qt::UserRole + 1, m_user->timestamp());
+        setData(Qt::UserRole + 2, m_user->note());
+        setData(Qt::UserRole + 3, m_user->address());
+        //setUpdatesEnabled(true);
     }
     else {
-        setUpdatesEnabled(false);
-        m_nameLabel->setText(m_shortenedName);
-        m_updatedLabel->setText(m_shortenedUpdated);
-        m_statusTextLabel->setText(m_shortenedStatusText);
-        m_locationLabel->setText(m_shortenedLocation);
-        setUpdatesEnabled(true);
+        //setUpdatesEnabled(false);
+        setData(Qt::UserRole, m_shortenedName);
+        setData(Qt::UserRole + 1, m_shortenedUpdated);
+        setData(Qt::UserRole + 2, m_shortenedStatusText);
+        setData(Qt::UserRole + 3, m_shortenedLocation);
+        //setUpdatesEnabled(true);
     }
 }
 
-void FriendListItem::mousePressEvent(QMouseEvent *event)
-{
-    qDebug() << __PRETTY_FUNCTION__;
-
-    m_mousePosition = event->pos();
-}
-
-void FriendListItem::mouseReleaseEvent(QMouseEvent *event)
-{
-    qDebug() << __PRETTY_FUNCTION__;
-
-    if ((abs(m_mousePosition.y() - event->pos().y()) <= MOUSE_PRESS_AREA_WIDTH) &&
-        (abs(m_mousePosition.x() - event->pos().x()) <= MOUSE_PRESS_AREA_HEIGHT)) {
-        if (m_expanded) {
-            setText(false);
-            m_expanded = false;
-        }
-        else {
-            setText(true);
-            m_expanded = true;
-        }
-    }
-}
-
-void FriendListItem::paintEvent(QPaintEvent *event)
-{
-    qDebug() << __PRETTY_FUNCTION__;
-
-    Q_UNUSED(event);
-
-    QPainter painter(this);
-
-    QRect topRect = QRect(0, 0, BACKGROUND_WIDTH, BACKGROUND_TOP_HEIGHT);
-    QRect middleRect = QRect(0, topRect.bottom(), BACKGROUND_WIDTH,
-                             height() - BACKGROUND_TOP_HEIGHT - BACKGROUND_BOTTOM_HEIGHT);
-    QRect bottomRect = QRect(topRect.left(), middleRect.bottom(), BACKGROUND_WIDTH,
-                             BACKGROUND_BOTTOM_HEIGHT);
-
-    painter.drawPixmap(topRect, m_backgroundTopImage);
-    painter.drawPixmap(middleRect, m_backgroundMiddleImage);
-    painter.drawPixmap(bottomRect, m_backgroundBottomImage);
-}
-
 void FriendListItem::findButtonClicked()
 {
     qDebug() << __PRETTY_FUNCTION__;
index 46b228c..d4f4433 100644 (file)
 #include <QListWidgetItem>
 
 #include "../user/user.h"
-
-class QLabel;
-class ImageButton;
+#include "listitem.h"
 
 /**
 * @brief FriendListItem shows friend data in expandable item.
 *
 * @class FriendListItem friendlistitem.h "ui/friendlistitem.h"
 */
-class FriendListItem : public QWidget
+class FriendListItem : public ListItem
 {
     Q_OBJECT
 
@@ -50,42 +48,17 @@ public:
     */
     FriendListItem(QWidget *parent = 0);
 
-/*******************************************************************************
- * BASE CLASS INHERITED AND REIMPLEMENTED MEMBER FUNCTIONS
- ******************************************************************************/
-protected:
-    /**
-    * @brief Set current mouse position to mouse event position.
-    *
-    * @param event QMouseEvent mouse press event
-    */
-    void mousePressEvent(QMouseEvent *event);
-
-    /**
-    * @brief Call toggleHeight if mouse position is unchanged.
-    *
-    * Check if current mouse position is same as mouse release position.
-    * @param event QMouseEvent mouse release event
-    */
-    void mouseReleaseEvent(QMouseEvent *event);
-
-    /**
-    * @brief Draws stylesheet used in this class.
-    *
-    * @param event QPaintEvent
-    */
-    void paintEvent(QPaintEvent *event);
 
 /******************************************************************************
 * MEMBER FUNCTIONS AND SLOTS
 ******************************************************************************/
 public:
     /**
-    * @brief Set data for this item.
+    * @brief Set user data for this item.
     *
     * @param user User pointer
     */
-    void setData(User *user);
+    void setUserData(User *user);
 
 private:
     /**
@@ -133,22 +106,12 @@ signals:
 * DATA MEMBERS
 ******************************************************************************/
 private:
-    QPixmap m_backgroundTopImage;   ///< Top background image
-    QPixmap m_backgroundMiddleImage;   ///< Middle background image
-    QPixmap m_backgroundBottomImage;   ///< Bottom background image
     bool m_expanded;                ///< Item expanded state
-    QLabel *m_distanceImageLabel;   ///< Distance image for friend label
-    QLabel *m_distanceTextLabel;    ///< Distance text for friend label
-    ImageButton *m_findButton;      ///< Friend find button
-    QLabel *m_locationLabel;        ///< Location label
     QPoint m_mousePosition;         ///< Current mouse press position
-    QLabel *m_nameLabel;            ///< Name label
     QString m_shortenedLocation;    ///< Shortened location text
     QString m_shortenedName;        ///< Shortened name text
     QString m_shortenedStatusText;  ///< Shortened status text
     QString m_shortenedUpdated;     ///< Shortened updated text
-    QLabel *m_statusTextLabel;      ///< Status text label
-    QLabel *m_updatedLabel;         ///< Updated label
     User *m_user;                   ///< User data
 };
 
diff --git a/src/ui/friendlistitemdelegate.cpp b/src/ui/friendlistitemdelegate.cpp
new file mode 100644 (file)
index 0000000..f985b41
--- /dev/null
@@ -0,0 +1,47 @@
+#include <QDebug>
+#include <QPainter>
+
+#include "friendlistitemdelegate.h"
+
+const int IMAGE_HEIGHT = 64; ///< Friend image height
+const int IMAGE_WIDTH = 64;  ///< Friend image width
+const int ICON_HEIGHT = 24;     ///< Icon height
+const int ICON_WIDTH = 24;       ///< Icon width
+
+FriendListItemDelegate::FriendListItemDelegate()
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    m_clockImage = QPixmap(":/res/images/clock.png");
+    m_envelopeImage = QPixmap(":/res/images/envelope.png");
+    m_compassImage = QPixmap(":/res/images/compass.png");
+}
+
+void FriendListItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
+                                   const QModelIndex &index) const
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    ListItemDelegate::paint(painter, option, index);
+
+    QRect itemRect = option.rect;
+
+    QRect envelopeRect = QRect(itemRect.left() + IMAGE_WIDTH + 15, itemRect.top() + IMAGE_HEIGHT,
+                               ICON_WIDTH, ICON_HEIGHT);
+    QRect compassRect = QRect(envelopeRect.left(), envelopeRect.bottom() + 5, ICON_WIDTH,
+                              ICON_HEIGHT);
+    QRect clockRect = QRect(envelopeRect.left(), compassRect.bottom() + 5, ICON_WIDTH,
+                              ICON_HEIGHT);
+
+    painter->drawPixmap(envelopeRect, m_envelopeImage);
+    painter->drawPixmap(compassRect, m_compassImage);
+    painter->drawPixmap(clockRect, m_clockImage);
+}
+
+QSize FriendListItemDelegate::sizeHint(const QStyleOptionViewItem &option,
+                                      const QModelIndex &index) const
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    return ListItemDelegate::sizeHint(option, index);
+}
diff --git a/src/ui/friendlistitemdelegate.h b/src/ui/friendlistitemdelegate.h
new file mode 100644 (file)
index 0000000..dba1000
--- /dev/null
@@ -0,0 +1,22 @@
+#ifndef FRIENDLISTITEMDELEGATE_H
+#define FRIENDLISTITEMDELEGATE_H
+
+#include "listitemdelegate.h"
+
+class FriendListItemDelegate : public ListItemDelegate
+{
+public:
+    FriendListItemDelegate();
+
+    void paint(QPainter *painter, const QStyleOptionViewItem &option,
+               const QModelIndex &index) const;
+
+    QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const;
+
+private:
+    QPixmap m_clockImage;   ///< Top background image
+    QPixmap m_compassImage;   ///< Middle background image
+    QPixmap m_envelopeImage;   ///< Bottom background image
+};
+
+#endif // FRIENDLISTITEMDELEGATE_H
diff --git a/src/ui/listitem.cpp b/src/ui/listitem.cpp
new file mode 100644 (file)
index 0000000..389c8c9
--- /dev/null
@@ -0,0 +1,59 @@
+#include <QDebug>
+
+#include "listitem.h"
+
+ListItem::ListItem()
+    : m_expanded(false)
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    setData(Qt::SizeHintRole, QSize(368, 161));
+}
+
+QPixmap ListItem::image() const
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    return m_image;
+}
+
+QString ListItem::name() const
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    return m_name;
+}
+
+void ListItem::setImage(const QPixmap &image)
+{
+    m_image = image;
+}
+
+void ListItem::setName(const QString &name)
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    m_name = name;
+}
+
+void ListItem::toggleHeight()
+{
+    if (m_expanded) {
+        m_expanded = false;
+        setData(Qt::SizeHintRole, QSize(368, 161));
+    }
+    else {
+        m_expanded = true;
+        setData(Qt::SizeHintRole, QSize(368, 241));
+    }
+}
+
+void ListItem::setExpanded(bool expanded)
+{
+    m_expanded = expanded;
+
+    if (m_expanded)
+        setData(Qt::SizeHintRole, QSize(368, 241));
+    else
+        setData(Qt::SizeHintRole, QSize(368, 161));
+}
diff --git a/src/ui/listitem.h b/src/ui/listitem.h
new file mode 100644 (file)
index 0000000..75a7680
--- /dev/null
@@ -0,0 +1,29 @@
+#ifndef LISTITEM_H
+#define LISTITEM_H
+
+#include <QListWidgetItem>
+
+class User;
+
+class ListItem : public QListWidgetItem
+{
+public:
+    ListItem();
+
+    QPixmap image() const;
+    QString name() const;
+    void setImage(const QPixmap &image);
+    void setName(const QString &neame);
+    void toggleHeight();
+    void setExpanded(bool expanded);
+
+private:
+    bool m_expanded;
+    int m_height;
+    QPixmap m_image;
+    QString m_name;
+};
+
+Q_DECLARE_METATYPE(ListItem)
+
+#endif // LISTITEM_H
diff --git a/src/ui/listitemdelegate.cpp b/src/ui/listitemdelegate.cpp
new file mode 100644 (file)
index 0000000..7c43754
--- /dev/null
@@ -0,0 +1,63 @@
+#include <QPainter>
+#include <QDebug>
+
+#include "listitemdelegate.h"
+#include "listitem.h"
+#include "../situare/src/common.h"
+#include "../situare/src/ui/avatarimage.h"
+
+const int BACKGROUND_BOTTOM_HEIGHT = 15;
+const int BACKGROUND_TOP_HEIGHT = 20;
+const int BACKGROUND_WIDTH = 368;
+const int IMAGE_HEIGHT = 64; ///< Friend image height
+const int IMAGE_WIDTH = 64;  ///< Friend image width
+const int MARGIN = 5;   ///< Icon margin
+
+ListItemDelegate::ListItemDelegate(QWidget *parent) :
+    QStyledItemDelegate(parent)
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    m_backgroundTopImage.load(":/res/images/list_item_top.png");
+    m_backgroundMiddleImage.load(":/res/images/list_item_middle.png");
+    m_backgroundBottomImage.load(":/res/images/list_item_bottom.png");
+}
+
+void ListItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
+                        const QModelIndex &index) const
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    QPixmap image = QPixmap(qvariant_cast<QPixmap>(index.data(Qt::DecorationRole)));
+    QString name = index.data(Qt::DisplayRole).toString();
+    QSize size = index.data(Qt::SizeHintRole).toSize();
+
+    QRect itemRect = option.rect;
+
+    QRect topRect = QRect(itemRect.left(), itemRect.top(), BACKGROUND_WIDTH,
+                          BACKGROUND_TOP_HEIGHT);
+    QRect middleRect = QRect(itemRect.left(), topRect.bottom(), BACKGROUND_WIDTH,
+                             size.height() - BACKGROUND_TOP_HEIGHT
+                             - BACKGROUND_BOTTOM_HEIGHT);
+    QRect bottomRect = QRect(topRect.left(), middleRect.bottom(), BACKGROUND_WIDTH,
+                             BACKGROUND_BOTTOM_HEIGHT);
+
+    painter->drawPixmap(topRect, m_backgroundTopImage);
+    painter->drawPixmap(middleRect, m_backgroundMiddleImage);
+    painter->drawPixmap(bottomRect, m_backgroundBottomImage);
+
+    painter->drawPixmap(itemRect.left() + MARGIN*2, itemRect.top(), image);
+
+    painter->setPen(Qt::white);
+    painter->setFont(NOKIA_FONT_NORMAL);
+    painter->drawText(itemRect.topLeft() + QPoint(MARGIN*2 + IMAGE_WIDTH + MARGIN,
+                                                  MARGIN + 35), name);
+}
+
+QSize ListItemDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    return index.data(Qt::SizeHintRole).toSize();
+
+}
diff --git a/src/ui/listitemdelegate.h b/src/ui/listitemdelegate.h
new file mode 100644 (file)
index 0000000..4f24222
--- /dev/null
@@ -0,0 +1,23 @@
+#ifndef LISTITEMDELEGATE_H
+#define LISTITEMDELEGATE_H
+
+#include <QStyledItemDelegate>
+
+class ListItemDelegate : public QStyledItemDelegate
+{
+    Q_OBJECT
+public:
+    ListItemDelegate(QWidget *parent = 0);
+
+    void paint(QPainter *painter, const QStyleOptionViewItem &option,
+               const QModelIndex &index) const;
+
+    QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const;
+
+private:
+    QPixmap m_backgroundTopImage;   ///< Top background image
+    QPixmap m_backgroundMiddleImage;   ///< Middle background image
+    QPixmap m_backgroundBottomImage;   ///< Bottom background image
+};
+
+#endif // LISTITEMDELEGATE_H
diff --git a/src/ui/listview.cpp b/src/ui/listview.cpp
new file mode 100644 (file)
index 0000000..984bc80
--- /dev/null
@@ -0,0 +1,57 @@
+#include <QDebug>
+
+#include "listitem.h"
+#include "listview.h"
+
+ListView::ListView(QWidget *parent)
+    : QListWidget(parent),
+      previousItem(0)
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    connect(this, SIGNAL(itemClicked(QListWidgetItem*)),
+            this, SLOT(listItemClicked(QListWidgetItem*)));
+//    connect(this, SIGNAL(currentItemChanged(QListWidgetItem*,QListWidgetItem*)),
+//            this, SLOT(selectedChanged(QListWidgetItem*,QListWidgetItem*)));
+}
+
+void ListView::listItemClicked(QListWidgetItem *item)
+{
+    qWarning() << __PRETTY_FUNCTION__;
+
+    ListItem *currentItem = static_cast<ListItem*>(item);
+
+    if (currentItem) {
+
+        if (previousItem == currentItem) {
+            currentItem->toggleHeight();
+        }
+        else {
+            if (previousItem)
+                previousItem->setExpanded(false);
+
+            currentItem->setExpanded(true);
+        }
+
+        previousItem = currentItem;
+    }
+}
+
+void ListView::selectedChanged(QListWidgetItem *current, QListWidgetItem *previous)
+{
+    qWarning() << __PRETTY_FUNCTION__;
+
+    if (previous) {
+        ListItem *previousItem = static_cast<ListItem*>(previous);
+
+        if (previousItem)
+            previousItem->toggleHeight();
+    }
+
+    if (current) {
+        ListItem *currentItem = static_cast<ListItem*>(current);
+
+        if (currentItem)
+            currentItem->toggleHeight();
+    }
+}
diff --git a/src/ui/listview.h b/src/ui/listview.h
new file mode 100644 (file)
index 0000000..6f3c595
--- /dev/null
@@ -0,0 +1,31 @@
+#ifndef LISTVIEW_H
+#define LISTVIEW_H
+
+#include <QListWidget>
+
+class ListItem;
+
+class ListView : public QListWidget
+{
+    Q_OBJECT
+public:
+    ListView(QWidget *parent = 0);
+
+/*******************************************************************************
+ * BASE CLASS INHERITED AND REIMPLEMENTED MEMBER FUNCTIONS
+ ******************************************************************************/
+
+signals:
+
+public slots:
+
+private slots:
+    void selectedChanged(QListWidgetItem *current, QListWidgetItem *previous);
+
+    void listItemClicked(QListWidgetItem *item);
+
+private:
+    ListItem *previousItem;
+};
+
+#endif // LISTVIEW_H
index ce737c4..703e363 100644 (file)
@@ -6,11 +6,13 @@ HEADERS += ../../../src/ui/friendlistview.h \
     ../../../src/ui/friendlistitem.h \
     ../../../src/user/user.h \
     ../../../src/ui/avatarimage.h \
-    ../../../src/ui/imagebutton.h
+    ../../../src/ui/imagebutton.h \
+    ../../../src/ui/listview.h
 SOURCES += ../../../src/ui/friendlistview.cpp \
     ../../../src/ui/friendlistitem.cpp \
     ../../../src/user/user.cpp \
     ../../../src/ui/avatarimage.cpp \
     ../../../src/ui/imagebutton.cpp \
+    ../../../src/ui/listview.cpp \
     testfriendlist.cpp
 RESOURCES += ../../../images.qrc
diff --git a/tests/ui/listitem/listitem.pro b/tests/ui/listitem/listitem.pro
new file mode 100644 (file)
index 0000000..fded4d8
--- /dev/null
@@ -0,0 +1,8 @@
+CONFIG += qtestlib
+DEFINES += QT_NO_DEBUG_OUTPUT
+INCLUDEPATH += . \
+    ../../../src/
+HEADERS += ../../../src/ui/listitem.h
+SOURCES += ../../../src/ui/listitem.cpp \
+    testlistitem.cpp
+RESOURCES += ../../../images.qrc
diff --git a/tests/ui/listitem/testlistitem.cpp b/tests/ui/listitem/testlistitem.cpp
new file mode 100644 (file)
index 0000000..4e3dafe
--- /dev/null
@@ -0,0 +1,52 @@
+/*
+   Situare - A location system for Facebook
+   Copyright (C) 2010  Ixonos Plc. Authors:
+
+       Jussi Laitinen - jussi.laitinen@ixonos.com
+
+   Situare is free software; you can redistribute it and/or
+   modify it under the terms of the GNU General Public License
+   version 2 as published by the Free Software Foundation.
+
+   Situare is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with Situare; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
+   USA.
+*/
+
+#include <QtTest>
+#include <QtGui>
+
+#include "../../../src/ui/listitem.h"
+
+class TestListItem: public QObject
+{
+    Q_OBJECT
+
+private slots:
+    void cleanupTestCase();
+    void initTestCase();
+
+private:
+    ListItem *listItem;
+};
+
+void TestListItem::cleanupTestCase()
+{
+    delete listItem;
+}
+
+void TestListItem::initTestCase()
+{
+    listItem = new ListItem();
+
+    QVERIFY(listItem != 0);
+}
+
+QTEST_MAIN(TestListItem)
+#include "testlistitem.moc"
diff --git a/tests/ui/listview/listview.pro b/tests/ui/listview/listview.pro
new file mode 100644 (file)
index 0000000..b32d6d4
--- /dev/null
@@ -0,0 +1,10 @@
+CONFIG += qtestlib
+DEFINES += QT_NO_DEBUG_OUTPUT
+INCLUDEPATH += . \
+    ../../../src/
+HEADERS += ../../../src/ui/listview.h \
+    ../../../src/ui/listitem.h
+SOURCES += ../../../src/ui/listview.cpp \
+    ../../../src/ui/listitem.cpp \
+    testlistview.cpp
+RESOURCES += ../../../images.qrc
diff --git a/tests/ui/listview/testlistview.cpp b/tests/ui/listview/testlistview.cpp
new file mode 100644 (file)
index 0000000..0baf902
--- /dev/null
@@ -0,0 +1,59 @@
+/*
+   Situare - A location system for Facebook
+   Copyright (C) 2010  Ixonos Plc. Authors:
+
+       Jussi Laitinen - jussi.laitinen@ixonos.com
+
+   Situare is free software; you can redistribute it and/or
+   modify it under the terms of the GNU General Public License
+   version 2 as published by the Free Software Foundation.
+
+   Situare is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with Situare; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
+   USA.
+*/
+
+#include <QtTest>
+#include <QtGui>
+
+#include "../../../src/ui/listitem.h"
+#include "../../../src/ui/listview.h"
+
+class TestListView: public QObject
+{
+    Q_OBJECT
+
+private slots:
+    void cleanupTestCase();
+    void initTestCase();
+    void listViewAddWidget();
+
+private:
+    ListView *listView;
+};
+
+void TestListView::cleanupTestCase()
+{
+    delete listView;
+}
+
+void TestListView::initTestCase()
+{
+    listView = new ListView();
+
+    QVERIFY(listView != 0);
+}
+
+void TestListView::listViewAddWidget()
+{
+    listView->addItem(new ListItem());
+}
+
+QTEST_MAIN(TestListView)
+#include "testlistview.moc"