Added listcommon.h file. listview
authorJussi Laitinen <jupe@l3l7588.ixonos.local>
Fri, 9 Jul 2010 08:03:49 +0000 (11:03 +0300)
committerJussi Laitinen <jupe@l3l7588.ixonos.local>
Fri, 9 Jul 2010 08:03:49 +0000 (11:03 +0300)
13 files changed:
src/src.pro
src/ui/friendlistitem.cpp
src/ui/friendlistitem.h
src/ui/friendlistitemdelegate.cpp
src/ui/friendlistitemdelegate.h
src/ui/listcommon.h [new file with mode: 0644]
src/ui/listitem.cpp
src/ui/listitem.h
src/ui/listitemdelegate.cpp
src/ui/listitemdelegate.h
src/ui/listview.cpp
src/ui/listview.h
tests/ui/listview/listview.pro

index 7bea9d2..f2e74d7 100644 (file)
@@ -112,7 +112,8 @@ HEADERS += common.h \
     ui/listview.h \
     ui/listitem.h \
     ui/listitemdelegate.h \
-    ui/friendlistitemdelegate.h
+    ui/friendlistitemdelegate.h \
+    ui/listcommon.h
 QT += network \
     webkit
 
index 6fc0d30..1be6a57 100644 (file)
 #include "../user/user.h"
 #include "imagebutton.h"
 #include "../common.h"
-
-const int ITEM_WIDTH = 368;
-const int ICON_HEIGHT = 24;     ///< Icon height
-const int ICON_WIDTH = 24;       ///< Icon width
-const int IMAGE_HEIGHT = 64; ///< Friend image height
-const int IMAGE_WIDTH = 64;  ///< Friend image width
-const int ITEM_MIN_HEIGHT = 141; ///< Minimum height for item
-const int MARGIN = 5;   ///< Icon margin
-const int MOUSE_PRESS_AREA_WIDTH = 20;  ///< Area width for item height toggling
-const int MOUSE_PRESS_AREA_HEIGHT = 20; ///< Area height for item height toggling
-
-/**
-* @var NAME_LABEL_MAX_WIDTH
-*
-* @brief Name label's maximum width
-*/
-const int NAME_LABEL_MAX_WIDTH = ITEM_WIDTH - 3*MARGIN - IMAGE_WIDTH;
-
-/**
-* @var LABEL_MAX_WIDTH
-*
-* @brief All label's maximum width
-*/
-const int LABEL_MAX_WIDTH = ITEM_WIDTH - 3 * MARGIN - IMAGE_WIDTH - MARGIN - ICON_WIDTH - MARGIN;
+#include "listcommon.h"
 
 const int WALK_DISTANCE = 5;        ///< Walk distance limit for distance icon
 const int CAR_DISTANCE = 500;       ///< Car distance limit for distance icon
 const int AEROPLANE_DISTANCE = 5000;///< Aeroplane distance limit for distance icon
 
 FriendListItem::FriendListItem()
-    : m_expanded(false)
+    : m_selected(false)
     , m_user(0)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    setData(Qt::SizeHintRole, QSize(ITEM_WIDTH, ITEM_MIN_HEIGHT));
+    setData(ITEM_SIZE_HINT_INDEX, QSize(ITEM_WIDTH, ITEM_MIN_HEIGHT));
 }
 
 void FriendListItem::calculateTextRects()
 {
-    QPixmap p = QPixmap(10, 10);
+    qDebug() << __PRETTY_FUNCTION__;
+
+    //Dummy value to get painter font metrics.
+    QPixmap p = QPixmap(ICON_WIDTH, ICON_HEIGHT);
     QPainter painter(&p);
     painter.setFont(NOKIA_FONT_SMALL);
     QFontMetrics smallFontMetrics = painter.fontMetrics();
@@ -85,39 +65,25 @@ void FriendListItem::calculateTextRects()
     QRect updatedRect = smallFontMetrics.boundingRect(m_user->timestamp());
     QRect locationRect = smallFontMetrics.boundingRect(m_user->address());
 
+    int statusTextRectFactor = statusTextRect.width() / LABEL_MAX_WIDTH;
+    statusTextRectFactor++;
+    m_statusTextRect = QRect(0, 0, LABEL_MAX_WIDTH, ICON_HEIGHT * statusTextRectFactor);
+    int updatedRectFactor = updatedRect.width() / LABEL_MAX_WIDTH;
+    updatedRectFactor++;
+    m_updatedRect = QRect(0, 0, LABEL_MAX_WIDTH, ICON_HEIGHT * updatedRectFactor);
+    int locationRectFactor = locationRect.width() / LABEL_MAX_WIDTH;
+    locationRectFactor++;
+    m_locationRect = QRect(0, 0, LABEL_MAX_WIDTH, ICON_HEIGHT * locationRectFactor);
 
-    qDebug() << m_shortenedStatusText;
-
-    int statusTextFactor = statusTextRect.width() / LABEL_MAX_WIDTH;
-    statusTextFactor++;
-    m_statusTextRect = QRect(0, 0, LABEL_MAX_WIDTH, 24 * statusTextFactor);
-    int updatedFactor = updatedRect.width() / LABEL_MAX_WIDTH;
-    updatedFactor++;
-    m_updatedRect = QRect(0, 0, LABEL_MAX_WIDTH, 24 * updatedFactor);
-    int locationFactor = locationRect.width() / LABEL_MAX_WIDTH;
-    locationFactor++;
-    m_locationRect = QRect(0, 0, LABEL_MAX_WIDTH, 24 * locationFactor);
-
-    qDebug() << statusTextRect;
-    qDebug() << updatedRect;
-    qDebug() << locationRect;
-
-    qDebug() << m_statusTextRect;
-    qDebug() << m_updatedRect;
-    qDebug() << m_locationRect;
-
-    qWarning() << statusTextRect.width() << statusTextRect.height();
-    qWarning() << m_statusTextRect.width() << m_statusTextRect.height();
+    m_expandedHeight = ITEM_MIN_HEIGHT + ((statusTextRectFactor + updatedRectFactor +
+                                           locationRectFactor - 3) * ICON_HEIGHT);
 
-    m_expandedHeight = ITEM_MIN_HEIGHT + ((statusTextFactor + updatedFactor + locationFactor - 3) *
-                                          ICON_HEIGHT);
-
-    setData(Qt::SizeHintRole + 1, distanceRect);
+    setData(DISTANCE_SIZE_HINT_INDEX, distanceRect);
 }
 
 QPointF FriendListItem::coordinates()
 {
-    qWarning() << __PRETTY_FUNCTION__;
+    qDebug() << __PRETTY_FUNCTION__;
 
     return m_user->coordinates();
 }
@@ -131,6 +97,8 @@ void FriendListItem::setId(const QString &id)
 
 QString FriendListItem::id() const
 {
+    qDebug() << __PRETTY_FUNCTION__;
+
     return ListItem::id();
 }
 
@@ -144,13 +112,13 @@ void FriendListItem::setUserData(User *user)
         setId(m_user->userId());
 
         if (!m_user->profileImage().isNull())
-            setData(Qt::DecorationRole, m_user->profileImage());
+            setData(AVATAR_IMAGE_INDEX, m_user->profileImage());
 
         QString unit;
         double value;
         m_user->distance(value, unit);
         m_distanceText = QString::number(value) + " " + unit;
-        setData(Qt::UserRole + 3, m_distanceText);
+        setData(DISTANCE_TEXT_DISPLAY_INDEX, m_distanceText);
         setDistanceIcon(value, unit);
 
         shortenTexts();
@@ -161,6 +129,8 @@ void FriendListItem::setUserData(User *user)
 
 void FriendListItem::setDistanceIcon(double value, const QString &unit)
 {
+    qDebug() << __PRETTY_FUNCTION__;
+
     QPixmap distanceImage;
 
     if ((unit == "m") || (value < WALK_DISTANCE))
@@ -172,17 +142,15 @@ void FriendListItem::setDistanceIcon(double value, const QString &unit)
     else
         distanceImage.load(":/res/images/rocket_icon_gray.png");
 
-    qDebug() << __PRETTY_FUNCTION__ << distanceImage.isNull();
-
-    setData(Qt::UserRole + 4, distanceImage);
+    setData(DISTANCE_IMAGE_INDEX, distanceImage);
 }
 
 void FriendListItem::shortenTexts()
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    QPixmap p = QPixmap(10, 10);
-
+    //Dummy value to get painter font metrics.
+    QPixmap p = QPixmap(ICON_WIDTH, ICON_HEIGHT);
     QPainter painter(&p);
     painter.setFont(NOKIA_FONT_NORMAL);
     QFontMetrics nameLabelMetrics = painter.fontMetrics();
@@ -216,7 +184,7 @@ void FriendListItem::shortenTexts()
         location.append("...");
     }
 
-    int distanceLabelWidth = otherLabelsMetrics.width(m_distanceText) + 5;
+    int distanceLabelWidth = otherLabelsMetrics.width(m_distanceText) + MARGIN;
     m_shortenedName = nameLabelMetrics.elidedText(name, Qt::ElideRight, NAME_LABEL_MAX_WIDTH
                                                   - distanceLabelWidth);
     m_shortenedStatusText = otherLabelsMetrics.elidedText(statusText, Qt::ElideRight,
@@ -224,82 +192,54 @@ void FriendListItem::shortenTexts()
     m_shortenedUpdated = otherLabelsMetrics.elidedText(updated, Qt::ElideRight, LABEL_MAX_WIDTH);
     m_shortenedLocation = otherLabelsMetrics.elidedText(location, Qt::ElideRight, LABEL_MAX_WIDTH);
 
-    setData(Qt::SizeHintRole + 4, QRect(0, 0, distanceLabelWidth, 24));
-
-    qWarning() << m_shortenedStatusText;
-}
-
-QString FriendListItem::elideText(int width, const QString &text)
-{
-    QFontMetrics otherLabelsMetrics = QFontMetrics(NOKIA_FONT_SMALL);
-    int widthSum = 0;
-    QString t = text;
-
-    for (int i = 0; i < text.size(); ++i) {
-        QChar c = text.at(i);
-
-        widthSum += otherLabelsMetrics.width(c);
-
-        if (widthSum > width) {
-            t.truncate(i - 3);
-            t.append("...");
-            break;
-        }
-    }
-
-    return t;
+    setData(NAME_DISPLAY_INDEX, m_shortenedName);
 }
 
 void FriendListItem::setText(bool expanded)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    setData(Qt::DisplayRole, m_shortenedName);
-
     if (expanded) {
-        setData(Qt::UserRole, m_user->note());
-        setData(Qt::UserRole + 1, m_user->timestamp());
-        setData(Qt::UserRole + 2, m_user->address());
+        setData(STATUS_TEXT_DISPLAY_INDEX, m_user->note());
+        setData(LOCATION_DISPLAY_INDEX, m_user->address());
+        setData(UPDATED_DISPLAY_INDEX, m_user->timestamp());
+
+        setData(STATUS_TEXT_SIZE_HINT_INDEX, m_statusTextRect);
+        setData(LOCATION_SIZE_HINT_INDEX, m_locationRect);
+        setData(UPDATED_SIZE_HINT_INDEX, m_updatedRect);
 
-        setData(Qt::SizeHintRole + 2, m_statusTextRect);
-        setData(Qt::SizeHintRole + 3, m_updatedRect);
-        setData(Qt::SizeHintRole + 4, m_locationRect);
     }
     else {
-        setData(Qt::UserRole, m_shortenedStatusText);
-        setData(Qt::UserRole + 1, m_shortenedUpdated);
-        setData(Qt::UserRole + 2, m_shortenedLocation);
+        setData(STATUS_TEXT_DISPLAY_INDEX, m_shortenedStatusText);
+        setData(LOCATION_DISPLAY_INDEX, m_shortenedLocation);
+        setData(UPDATED_DISPLAY_INDEX, m_shortenedUpdated);
 
-        setData(Qt::SizeHintRole + 2, QRect(0, 0, LABEL_MAX_WIDTH, ICON_HEIGHT));
-        setData(Qt::SizeHintRole + 3, QRect(0, 0, LABEL_MAX_WIDTH, ICON_HEIGHT));
-        setData(Qt::SizeHintRole + 4, QRect(0, 0, LABEL_MAX_WIDTH, ICON_HEIGHT));
+        setData(STATUS_TEXT_SIZE_HINT_INDEX, QRect(0, 0, LABEL_MAX_WIDTH, ICON_HEIGHT));
+        setData(LOCATION_SIZE_HINT_INDEX, QRect(0, 0, LABEL_MAX_WIDTH, ICON_HEIGHT));
+        setData(UPDATED_SIZE_HINT_INDEX, QRect(0, 0, LABEL_MAX_WIDTH, ICON_HEIGHT));
     }
 }
 
-void FriendListItem::toggleHeight()
+bool FriendListItem::toggleSelection()
 {
-    if (m_expanded) {
-        m_expanded = false;
-        setText(false);
-        setData(Qt::SizeHintRole, QSize(ITEM_WIDTH, ITEM_MIN_HEIGHT));
-    }
-    else {
-        m_expanded = true;
-        setText(true);
-        setData(Qt::SizeHintRole, QSize(ITEM_WIDTH, m_expandedHeight));
-    }
+    qDebug() << __PRETTY_FUNCTION__;
+
+    setSelected(!m_selected);
+    return m_selected;
 }
 
-void FriendListItem::setExpanded(bool expanded)
+void FriendListItem::setSelected(bool selected)
 {
-    m_expanded = expanded;
+    qDebug() << __PRETTY_FUNCTION__;
+
+    m_selected = selected;
 
-    if (m_expanded) {
+    if (m_selected) {
         setText(true);
-        setData(Qt::SizeHintRole, QSize(ITEM_WIDTH, m_expandedHeight));
+        setData(ITEM_SIZE_HINT_INDEX, QSize(ITEM_WIDTH, m_expandedHeight));
     }
     else {
         setText(false);
-        setData(Qt::SizeHintRole, QSize(ITEM_WIDTH, ITEM_MIN_HEIGHT));
+        setData(ITEM_SIZE_HINT_INDEX, QSize(ITEM_WIDTH, ITEM_MIN_HEIGHT));
     }
 }
index f65c0bf..07962bd 100644 (file)
@@ -36,7 +36,6 @@
 */
 class FriendListItem : public ListItem
 {
-    //Q_OBJECT
 
 public:
     /**
@@ -48,7 +47,6 @@ public:
     */
     FriendListItem();
 
-
 /******************************************************************************
 * MEMBER FUNCTIONS AND SLOTS
 ******************************************************************************/
@@ -60,8 +58,8 @@ public:
     */
     void setUserData(User *user);
 
-    void toggleHeight();
-    void setExpanded(bool expanded);
+    bool toggleSelection();
+    void setSelected(bool expanded);
 
     void setId(const QString &id);
     QString id() const;
@@ -92,31 +90,13 @@ private:
     */
     void shortenTexts();
 
-    QString elideText(int width, const QString &text);
-
     void calculateTextRects();
-//private slots:
-//    /**
-//    * @brief Slot for find button click
-//    */
-//    void findButtonClicked();
-
-/******************************************************************************
-* SIGNALS
-******************************************************************************/
-//signals:
-//    /**
-//    * @brief Signal for finding friend.
-//    *
-//    * @param coordinates friend's geo coordinates
-//    */
-//    void findFriend(const QPointF &coordinates);
 
 /******************************************************************************
 * DATA MEMBERS
 ******************************************************************************/
 private:
-    bool m_expanded;                ///< Item expanded state
+    bool m_selected;                ///< Item selected state
     QPoint m_mousePosition;         ///< Current mouse press position
     QRect m_locationRect;
     QRect m_statusTextRect;
index 77605e9..c1c1a21 100644 (file)
@@ -1,34 +1,30 @@
+/*
+   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 <QDebug>
 #include <QPainter>
 
 #include "friendlistitemdelegate.h"
 #include "../common.h"
-
-const int BACKGROUND_BOTTOM_HEIGHT = 15;
-const int BACKGROUND_TOP_HEIGHT = 20;
-const int BACKGROUND_WIDTH = 368;
-const int ICON_HEIGHT = 24;     ///< Icon height
-const int ICON_WIDTH = 24;       ///< Icon width
-const int IMAGE_HEIGHT = 64; ///< Friend image height
-const int IMAGE_WIDTH = 64;  ///< Friend image width
-const int ITEM_MIN_HEIGHT = 141; ///< Minimum height for item
-const int MARGIN = 5;   ///< Icon margin
-const int MOUSE_PRESS_AREA_WIDTH = 20;  ///< Area width for item height toggling
-const int MOUSE_PRESS_AREA_HEIGHT = 20; ///< Area height for item height toggling
-
-/**
-* @var NAME_LABEL_MAX_WIDTH
-*
-* @brief Name label's maximum width
-*/
-const int NAME_LABEL_MAX_WIDTH = BACKGROUND_WIDTH - 3*MARGIN - IMAGE_WIDTH;
-
-/**
-* @var LABEL_MAX_WIDTH
-*
-* @brief All label's maximum width
-*/
-const int LABEL_MAX_WIDTH = BACKGROUND_WIDTH - 3 * MARGIN - IMAGE_WIDTH - MARGIN - ICON_WIDTH;
+#include "listcommon.h"
 
 FriendListItemDelegate::FriendListItemDelegate()
 {
@@ -49,45 +45,46 @@ void FriendListItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem
     painter->setPen(COLOR_GRAY);
     painter->setFont(NOKIA_FONT_SMALL);
 
-    QString statusText = index.data(Qt::UserRole).toString();
-    QString address = index.data(Qt::UserRole + 1).toString();
-    QString timestamp = index.data(Qt::UserRole + 2).toString();
-    QString distance = index.data(Qt::UserRole + 3).toString();
-    QPixmap distanceIcon = QPixmap(qvariant_cast<QPixmap>(index.data(Qt::UserRole + 4)));
+    QString statusText = index.data(STATUS_TEXT_DISPLAY_INDEX).toString();
+    QString location = index.data(LOCATION_DISPLAY_INDEX).toString();
+    QString updated = index.data(UPDATED_DISPLAY_INDEX).toString();
+    QString distance = index.data(DISTANCE_TEXT_DISPLAY_INDEX).toString();
+    QPixmap distanceIcon = QPixmap(qvariant_cast<QPixmap>(index.data(DISTANCE_IMAGE_INDEX)));
 
     QRect itemRect = option.rect;
 
-    QPoint distanceIconPoint = QPoint(BACKGROUND_WIDTH - ICON_WIDTH - 15, itemRect.top() + 5);
-    QRect distanceRect = index.data(Qt::SizeHintRole + 1).toRect();
-    distanceRect.translate(BACKGROUND_WIDTH - distanceRect.width() - 5, itemRect.top() + ICON_HEIGHT + 10);
+    QPoint distanceIconPoint = QPoint(ITEM_WIDTH - ICON_WIDTH - 3*MARGIN, itemRect.top() + MARGIN);
+    QRect distanceRect = index.data(DISTANCE_SIZE_HINT_INDEX).toRect();
+    distanceRect.translate(ITEM_WIDTH - distanceRect.width() - 2*MARGIN,
+                           itemRect.top() + ICON_HEIGHT + 2*MARGIN);
 
     painter->drawPixmap(distanceIconPoint, distanceIcon);
     painter->drawText(distanceRect, Qt::TextSingleLine, distance);
 
-    QRect envelopeRect = QRect(itemRect.left() + IMAGE_WIDTH + 15, itemRect.top() + IMAGE_HEIGHT - 10,
-                               ICON_WIDTH, ICON_HEIGHT);
-    QRect statusTextRect = index.data(Qt::SizeHintRole + 2).toRect();
-    statusTextRect.translate(envelopeRect.right() + 5, envelopeRect.top());
+    QRect envelopeRect = QRect(itemRect.left() + IMAGE_WIDTH + 3*MARGIN,
+                               itemRect.top() + IMAGE_HEIGHT - 2*MARGIN, ICON_WIDTH, ICON_HEIGHT);
+    QRect statusTextRect = index.data(STATUS_TEXT_SIZE_HINT_INDEX).toRect();
+    statusTextRect.translate(envelopeRect.right() + MARGIN, envelopeRect.top());
 
     painter->drawPixmap(envelopeRect, m_envelopeImage);
     painter->drawText(statusTextRect, Qt::TextWrapAnywhere, statusText);
 
 
-    QRect compassRect = QRect(envelopeRect.left(), statusTextRect.bottom() + 2, ICON_WIDTH,
-                              ICON_HEIGHT);
-    QRect locationRect = index.data(Qt::SizeHintRole + 3).toRect();
-    locationRect.translate(compassRect.right() + 5, compassRect.top());
+    QRect compassRect = QRect(envelopeRect.left(), statusTextRect.bottom() + ICON_MARGIN,
+                              ICON_WIDTH, ICON_HEIGHT);
+    QRect locationRect = index.data(LOCATION_SIZE_HINT_INDEX).toRect();
+    locationRect.translate(compassRect.right() + MARGIN, compassRect.top());
 
     painter->drawPixmap(compassRect, m_compassImage);
-    painter->drawText(locationRect, Qt::TextWrapAnywhere, address);
-
+    painter->drawText(locationRect, Qt::TextWrapAnywhere, location);
 
-    QRect clockRect = QRect(envelopeRect.left(), locationRect.bottom() + 2, ICON_WIDTH, ICON_HEIGHT);
-    QRect timestampRect = index.data(Qt::SizeHintRole + 4).toRect();
-    timestampRect.translate(clockRect.right() + 5, clockRect.top());
+    QRect clockRect = QRect(envelopeRect.left(), locationRect.bottom() + ICON_MARGIN, ICON_WIDTH,
+                            ICON_HEIGHT);
+    QRect updatedRect = index.data(UPDATED_SIZE_HINT_INDEX).toRect();
+    updatedRect.translate(clockRect.right() + MARGIN, clockRect.top());
 
     painter->drawPixmap(clockRect, m_clockImage);
-    painter->drawText(timestampRect, Qt::TextWrapAnywhere, timestamp);
+    painter->drawText(updatedRect, Qt::TextWrapAnywhere, updated);
 }
 
 QSize FriendListItemDelegate::sizeHint(const QStyleOptionViewItem &option,
index dba1000..1e07a1c 100644 (file)
@@ -1,3 +1,24 @@
+/*
+   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.
+*/
+
 #ifndef FRIENDLISTITEMDELEGATE_H
 #define FRIENDLISTITEMDELEGATE_H
 
diff --git a/src/ui/listcommon.h b/src/ui/listcommon.h
new file mode 100644 (file)
index 0000000..17338cc
--- /dev/null
@@ -0,0 +1,65 @@
+/*
+   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.
+*/
+
+#ifndef LISTCOMMON_H
+#define LISTCOMMON_H
+
+#include <Qt>
+
+const int ITEM_WIDTH = 368;     ///< Item minimum width
+const int ICON_HEIGHT = 24;     ///< Icon height
+const int ICON_MARGIN = 2;      ///< Icon margin
+const int ICON_WIDTH = 24;      ///< Icon width
+const int IMAGE_HEIGHT = 64;    ///< Friend image height
+const int IMAGE_WIDTH = 64;     ///< Friend image width
+const int ITEM_MIN_HEIGHT = 141;///< Minimum height for item
+const int MARGIN = 5;           ///< Text and image margin
+
+/**
+* @var NAME_LABEL_MAX_WIDTH
+*
+* @brief Name label's maximum width
+*/
+const int NAME_LABEL_MAX_WIDTH = ITEM_WIDTH - 3*MARGIN - IMAGE_WIDTH;
+
+/**
+* @var LABEL_MAX_WIDTH
+*
+* @brief All label's maximum width
+*/
+const int LABEL_MAX_WIDTH = ITEM_WIDTH - 3 * MARGIN - IMAGE_WIDTH - MARGIN - ICON_WIDTH - MARGIN*2;
+
+const int NAME_DISPLAY_INDEX = Qt::DisplayRole;
+const int AVATAR_IMAGE_INDEX = Qt::DecorationRole;
+
+const int ITEM_SIZE_HINT_INDEX = Qt::SizeHintRole;
+const int DISTANCE_SIZE_HINT_INDEX = Qt::SizeHintRole + 1;
+const int STATUS_TEXT_SIZE_HINT_INDEX = Qt::SizeHintRole + 2;
+const int LOCATION_SIZE_HINT_INDEX = Qt::SizeHintRole + 3;
+const int UPDATED_SIZE_HINT_INDEX = Qt::SizeHintRole + 4;
+
+const int STATUS_TEXT_DISPLAY_INDEX = Qt::UserRole;
+const int LOCATION_DISPLAY_INDEX = Qt::UserRole + 1;
+const int UPDATED_DISPLAY_INDEX = Qt::UserRole + 2;
+const int DISTANCE_TEXT_DISPLAY_INDEX = Qt::UserRole + 3;
+const int DISTANCE_IMAGE_INDEX = Qt::UserRole + 4;
+
+#endif // LISTCOMMON_H
index b273f89..16e397a 100644 (file)
@@ -1,3 +1,24 @@
+/*
+   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 <QDebug>
 
 #include "listitem.h"
index 128de46..f05f67d 100644 (file)
@@ -1,3 +1,24 @@
+/*
+   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.
+*/
+
 #ifndef LISTITEM_H
 #define LISTITEM_H
 
@@ -14,8 +35,8 @@ public:
     QString name() const;
     void setImage(const QPixmap &image);
     void setName(const QString &neame);
-    virtual void toggleHeight() = 0;
-    virtual void setExpanded(bool expanded) = 0;
+    virtual bool toggleSelection() = 0;
+    virtual void setSelected(bool selected) = 0;
     virtual QString id() const;
     virtual void setId(const QString &id);
     virtual QPointF coordinates() = 0;
index fabff3a..ae93581 100644 (file)
@@ -1,17 +1,36 @@
+/*
+   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 <QPainter>
 #include <QDebug>
 
 #include "listitemdelegate.h"
 #include "listitem.h"
 #include "../common.h"
+#include "listcommon.h"
 #include "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
+const int NAME_TOP_MARGIN = 40;
 
 ListItemDelegate::ListItemDelegate(QWidget *parent) :
     QStyledItemDelegate(parent)
@@ -28,18 +47,18 @@ void ListItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &opti
 {
     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();
+    QPixmap image = QPixmap(qvariant_cast<QPixmap>(index.data(AVATAR_IMAGE_INDEX)));
+    QString name = index.data(NAME_DISPLAY_INDEX).toString();
+    QSize size = index.data(ITEM_SIZE_HINT_INDEX).toSize();
 
     QRect itemRect = option.rect;
 
-    QRect topRect = QRect(itemRect.left(), itemRect.top(), BACKGROUND_WIDTH,
+    QRect topRect = QRect(itemRect.left(), itemRect.top(), ITEM_WIDTH,
                           BACKGROUND_TOP_HEIGHT);
-    QRect middleRect = QRect(itemRect.left(), topRect.bottom(), BACKGROUND_WIDTH,
+    QRect middleRect = QRect(itemRect.left(), topRect.bottom(), ITEM_WIDTH,
                              size.height() - BACKGROUND_TOP_HEIGHT
                              - BACKGROUND_BOTTOM_HEIGHT);
-    QRect bottomRect = QRect(topRect.left(), middleRect.bottom(), BACKGROUND_WIDTH,
+    QRect bottomRect = QRect(topRect.left(), middleRect.bottom(), ITEM_WIDTH,
                              BACKGROUND_BOTTOM_HEIGHT);
 
     painter->drawPixmap(topRect, m_backgroundTopImage);
@@ -50,8 +69,8 @@ void ListItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &opti
 
     painter->setPen(Qt::white);
     painter->setFont(NOKIA_FONT_NORMAL);
-    painter->drawText(itemRect.topLeft() + QPoint(MARGIN*2 + IMAGE_WIDTH + MARGIN,
-                                                  MARGIN + 35), name);
+    painter->drawText(itemRect.topLeft() + QPoint(MARGIN*2 + IMAGE_WIDTH + MARGIN, NAME_TOP_MARGIN),
+                      name);
 }
 
 QSize ListItemDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
index 4f24222..f7dbceb 100644 (file)
@@ -1,3 +1,24 @@
+/*
+   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.
+*/
+
 #ifndef LISTITEMDELEGATE_H
 #define LISTITEMDELEGATE_H
 
index c1ddaf1..ac3bd75 100644 (file)
@@ -1,3 +1,24 @@
+/*
+   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 <QDebug>
 
 #include "listitem.h"
@@ -21,28 +42,28 @@ void ListView::addListItem(const QString &key, ListItem *item)
     if (!m_listItems.contains(key)) {
         addItem(item);
         m_listItems.insert(key, item);
-        qDebug() << __PRETTY_FUNCTION__ << key << " lisattiin";
     }
-    else
-        qDebug() << __PRETTY_FUNCTION__ << key << " ei lisatty";
 }
 
 void ListView::addListItemToView(ListItem *item)
 {
+    qDebug() << __PRETTY_FUNCTION__;
+
     addItem(item);
 }
 
 void ListView::clearList()
 {
+    qDebug() << __PRETTY_FUNCTION__;
+
     m_listItems.clear();
     clear();
-
-    qDebug() << __PRETTY_FUNCTION__ << count();
-    qDebug() << __PRETTY_FUNCTION__ << m_listItems.count();
 }
 
 void ListView::clearUnused(const QStringList &userIDs)
 {
+    qDebug() << __PRETTY_FUNCTION__;
+
     foreach (QString key, m_listItems.keys()) {
         if (!userIDs.contains(key)) {
             ListItem *item = m_listItems.take(key);
@@ -52,24 +73,26 @@ void ListView::clearUnused(const QStringList &userIDs)
             }
         }
     }
-    qDebug() << __PRETTY_FUNCTION__ << count();
-    qDebug() << __PRETTY_FUNCTION__ << m_listItems.count();
 }
 
 void ListView::clearFilter()
 {
+    qDebug() << __PRETTY_FUNCTION__;
+
     foreach (ListItem *item, m_listItems)
         setItemHidden(item, false);
 }
 
 bool ListView::contains(const QString &userID)
 {
+    qDebug() << __PRETTY_FUNCTION__;
+
     return m_listItems.contains(userID);
 }
 
 void ListView::filter(const QList<QString> &userIDs)
 {
-    qDebug() << __PRETTY_FUNCTION__ << m_listItems.count();
+    qDebug() << __PRETTY_FUNCTION__;
 
     foreach (ListItem *item, m_listItems) {
         if (userIDs.contains(item->id()))
@@ -81,6 +104,8 @@ void ListView::filter(const QList<QString> &userIDs)
 
 ListItem *ListView::takeListItemFromView(const QString &userID)
 {
+    qDebug() << __PRETTY_FUNCTION__;
+
     ListItem *item = listItem(userID);
     takeItem(row(item));
     return item;
@@ -88,29 +113,34 @@ ListItem *ListView::takeListItemFromView(const QString &userID)
 
 void ListView::listItemClicked(QListWidgetItem *item)
 {
-    qWarning() << __PRETTY_FUNCTION__;
+    qDebug() << __PRETTY_FUNCTION__;
 
     ListItem *currentItem = static_cast<ListItem*>(item);
 
     if (currentItem) {
 
         if (previousItem == currentItem) {
-            currentItem->toggleHeight();
-        }
-        else {
+            bool expanded = currentItem->toggleSelection();
+
+            if (expanded)
+                emit listItemClicked(currentItem->coordinates());
+
+        } else {
             if (previousItem)
-                previousItem->setExpanded(false);
+                previousItem->setSelected(false);
 
-            currentItem->setExpanded(true);
+            currentItem->setSelected(true);
+            emit listItemClicked(currentItem->coordinates());
         }
 
         previousItem = currentItem;
 
-        emit listItemClicked(currentItem->coordinates());
     }
 }
 
 ListItem *ListView::listItem(const QString &userID)
 {
+    qDebug() << __PRETTY_FUNCTION__;
+
     return static_cast<ListItem*>(m_listItems.value(userID));
 }
index 48b17ac..3eab7a2 100644 (file)
@@ -1,3 +1,24 @@
+/*
+   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.
+*/
+
 #ifndef LISTVIEW_H
 #define LISTVIEW_H
 
index 20db633..1db413d 100644 (file)
@@ -1,5 +1,5 @@
 CONFIG += qtestlib
-#DEFINES += QT_NO_DEBUG_OUTPUT
+DEFINES += QT_NO_DEBUG_OUTPUT
 INCLUDEPATH += . \
     ../../../src/
 HEADERS += ../../../src/ui/listview.h \