Merge branch 'master' into separate_search_panel
authorSami Rämö <sami.ramo@ixonos.com>
Wed, 1 Sep 2010 10:15:01 +0000 (13:15 +0300)
committerSami Rämö <sami.ramo@ixonos.com>
Wed, 1 Sep 2010 10:15:01 +0000 (13:15 +0300)
Conflicts:
src/src.pro

14 files changed:
debian/changelog
src/src.pro
src/ui/extendedlistitem.cpp
src/ui/extendedlistitemdelegate.cpp
src/ui/friendlistitem.cpp
src/ui/listcommon.h
src/ui/listitem.cpp
src/ui/textmodifier.cpp [new file with mode: 0644]
src/ui/textmodifier.h [new file with mode: 0644]
src/ui/userinfo.cpp
src/ui/userinfo.h
tests/ui/friendlistitem/friendlistitem.pro
tests/ui/friendlistitem/testfriendlistitem.cpp
tests/ui/friendlistview/friendlistview.pro

index a86d93c..d4f9d45 100644 (file)
@@ -15,6 +15,7 @@ situare (2.0-2) unstable; urgency=low
     - Error messages from routing service are not shown
     - Error messages from location search are not shown
     - Text length cutting in user panel
+    - Area under panel can be clicked
 
  -- Jussi Laitinen <jussi.laitinen@ixonos.com>  Thu, 30 Aug 2010 10:50:00 +0300
 
index 2c72823..1cf0da4 100644 (file)
@@ -81,7 +81,8 @@ SOURCES += main.cpp \
     ui/routewaypointlistitem.cpp \
     ui/routewaypointlistview.cpp \
     user/user.cpp \
-    ui/locationsearchpanel.cpp
+    ui/locationsearchpanel.cpp \
+    ui/textmodifier.cpp
 HEADERS += application.h \
     common.h \
     coordinates/geocoordinate.h \
@@ -164,7 +165,8 @@ HEADERS += application.h \
     ui/routewaypointlistitem.h \
     ui/routewaypointlistview.h \
     user/user.h \
-    ui/locationsearchpanel.h
+    ui/locationsearchpanel.h \
+    ui/textmodifier.h
 QT += network \
     webkit
 DEFINES += QT_NO_DEBUG_OUTPUT
index 6d6e1f8..1ecb362 100644 (file)
@@ -26,6 +26,7 @@
 #include "../common.h"
 #include "extendedlistitemstore.h"
 #include "listcommon.h"
+#include "textmodifier.h"
 
 #include "extendedlistitem.h"
 
@@ -56,10 +57,17 @@ void ExtendedListItem::addSubItem(const QString &text, const QPixmap &icon)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    ExtendedListItemStore *itemStore = new ExtendedListItemStore(text);
+    QPixmap p = QPixmap(ICON_WIDTH, ICON_HEIGHT);
+    QPainter painter(&p);
+    painter.setFont(NOKIA_FONT_SMALL);
+    QFontMetrics textMetrics = painter.fontMetrics();
+
+    QString expandedText = TextModifier::splitLongWords(textMetrics, text, m_subItemTextWidth);
+
+    ExtendedListItemStore *itemStore = new ExtendedListItemStore(expandedText);
     itemStore->setIcon(icon);
     itemStore->setShortenedText(shortenText(text, m_subItemTextWidth, ListItem::TEXT_SIZE_SMALL));
-    itemStore->setTextRect(calculateExpandedTextRect(text));
+    itemStore->setTextRect(calculateExpandedTextRect(expandedText));
 
     m_subItemStoreList->append(itemStore);
 }
@@ -74,16 +82,26 @@ QRect ExtendedListItem::boundingRect(const QString &text)
 
     QFontMetrics textMetrics = painter.fontMetrics();
     QRect textRect;
-    QStringList rows = text.split('\n');
-
-    foreach (QString row, rows) {
-
-        QRect textRowRect = textMetrics.boundingRect(row);
-
-        if (textRowRect.width() > textRect.width())
-            textRect.setWidth(textRowRect.width());
-
-        textRect.setHeight(textRect.height() + textRowRect.height());
+    int rowHeight = textMetrics.ascent() + textMetrics.descent();
+    textRect.setSize(QSize(m_subItemTextWidth, rowHeight));
+
+    QStringList words = text.split(QRegExp("\\b"));
+    QString rowText;
+    foreach (QString word, words) {
+
+        if (word.contains("\n")) {
+            foreach (QChar c, word) {
+                if (c == '\n')
+                    textRect.setHeight(textRect.height() + rowHeight);
+            }
+            rowText.clear();
+        } else {
+            rowText.append(word);
+            if (textMetrics.width(rowText) > m_subItemTextWidth) {
+                textRect.setHeight(textRect.height() + rowHeight);
+                rowText = word.simplified();
+            }
+        }
     }
 
     return textRect;
@@ -95,13 +113,7 @@ QRect ExtendedListItem::calculateExpandedTextRect(const QString &text)
 
     const int TEXT_BOTTOM_MARGIN = 2;
 
-    QRect textRect = boundingRect(text);
-
-    int textRectFactor = textRect.width() / m_subItemTextWidth;
-    textRectFactor += textRect.height() / SUBITEM_TEXT_ROW_HEIGHT;
-
-    QRect expandedTextRect = QRect(0, 0, m_subItemTextWidth, SUBITEM_TEXT_ROW_HEIGHT
-                                   * qMax(textRectFactor, 1));
+    QRect expandedTextRect = boundingRect(text);
 
     m_normalHeight += SUBITEM_TEXT_ROW_HEIGHT + TEXT_BOTTOM_MARGIN;
     m_expandedHeight += expandedTextRect.height() + TEXT_BOTTOM_MARGIN;
index ee1b6f3..c174106 100644 (file)
@@ -81,7 +81,7 @@ void ExtendedListItemDelegate::paint(QPainter *painter, const QStyleOptionViewIt
             if (!itemStore->icon().isNull())
                 painter->drawPixmap(iconRect, itemStore->icon());
 
-            painter->drawText(subItemTextRect, Qt::TextWrapAnywhere, text);
+            painter->drawText(subItemTextRect, Qt::TextWordWrap, text);
             previousSubItemTextRectBottom = subItemTextRect.bottom() + ICON_MARGIN;
         }
     }
index ad48d3a..395b9c1 100644 (file)
@@ -104,7 +104,7 @@ void FriendListItem::setUserData(User *user)
     QRect distanceRect = distanceTextFontMetrics.boundingRect(distanceText);
 
     setData(DISTANCE_SIZE_HINT_INDEX, distanceRect);
-    setTitle(shortenText(user->name(), NAME_TEXT_MAX_WIDTH - distanceRect.width() + MARGIN,
+    setTitle(shortenText(user->name(), NAME_TEXT_MAX_WIDTH - distanceRect.width() - MARGIN * 2,
                         ListItem::TEXT_SIZE_NORMAL));
     setCoordinates(user->coordinates());
 
index bc8b416..e975123 100644 (file)
@@ -48,7 +48,7 @@ const int NAME_TEXT_MAX_WIDTH = ITEM_WIDTH - 3 * MARGIN - IMAGE_WIDTH;
 const int SUBITEM_TEXT_MAX_WIDTH = ITEM_WIDTH - 3 * MARGIN - IMAGE_WIDTH - MARGIN - ICON_WIDTH
                                    - MARGIN * 2;
 
-const int SUBITEM_TEXT_ROW_HEIGHT = 22;     ///< Subitems text row height
+const int SUBITEM_TEXT_ROW_HEIGHT = 21;     ///< Subitems text row height
 
 const int TITLE_DISPLAY_INDEX = Qt::DisplayRole;
 const int AVATAR_IMAGE_INDEX = Qt::DecorationRole;
index a2f08d5..82127db 100644 (file)
@@ -24,6 +24,7 @@
 
 #include "../common.h"
 #include "listcommon.h"
+#include "textmodifier.h"
 
 #include "listitem.h"
 
@@ -78,14 +79,5 @@ QString ListItem::shortenText(const QString &text, int textWidth, TextSize textS
 
     QFontMetrics textMetrics = painter.fontMetrics();
 
-    QString shortenedText = text;
-
-    int index = shortenedText.indexOf('\n');
-
-    if (index > 0) {
-        shortenedText.truncate(index);
-        shortenedText.append("...");
-    }
-
-    return textMetrics.elidedText(shortenedText, Qt::ElideRight, textWidth);
+    return TextModifier::shortenText(textMetrics, text, textWidth);
 }
diff --git a/src/ui/textmodifier.cpp b/src/ui/textmodifier.cpp
new file mode 100644 (file)
index 0000000..b08ea8a
--- /dev/null
@@ -0,0 +1,80 @@
+/*
+   Situare - A location system for Facebook
+   Copyright (C) 2010  Ixonos Plc. Authors:
+
+       Katri Kaikkonen - katri.kaikkonen@ixonos.com
+       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 <QFontMetrics>
+#include <QStringList>
+
+#include "textmodifier.h"
+
+QString TextModifier::shortenText(const QFontMetrics fontMetrics, const QString &text,
+                                  int textMaxWidth)
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    QString copiedText = text;
+    int index = copiedText.indexOf('\n');
+
+    if (index >= 0) {
+        copiedText.truncate(index);
+        copiedText.append("...");
+    }
+
+    return fontMetrics.elidedText(copiedText, Qt::ElideRight, textMaxWidth);
+}
+
+QString TextModifier::splitWord(const QFontMetrics fontMetrics, const QString &word,
+                                int textMaxWidth)
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    QString result;
+    QString temp;
+
+    for (int i = 0; i < word.length(); i++) {
+        if (fontMetrics.width(temp.append(word.at(i))) > textMaxWidth) {
+            result.append(temp.left(temp.length() - 1));
+            result.append(" ");
+            temp.remove(0, temp.length() - 1);
+        }
+    }
+
+    result.append(temp);
+
+    return result;
+}
+
+QString TextModifier::splitLongWords(const QFontMetrics fontMetrics, const QString &text,
+                                     int textMaxWidth)
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    QStringList list;
+    list = text.split(' ');
+
+    for (int i = 0; i < list.count(); i++) {
+        if (fontMetrics.width(list.at(i)) > textMaxWidth)
+            list.replace(i, splitWord(fontMetrics, list.at(i), textMaxWidth));
+    }
+
+    return list.join(" ");
+}
diff --git a/src/ui/textmodifier.h b/src/ui/textmodifier.h
new file mode 100644 (file)
index 0000000..e206e0a
--- /dev/null
@@ -0,0 +1,77 @@
+/*
+   Situare - A location system for Facebook
+   Copyright (C) 2010  Ixonos Plc. Authors:
+
+       Katri Kaikkonen - katri.kaikkonen@ixonos.com
+       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 TEXTMODIFIER_H
+#define TEXTMODIFIER_H
+
+#include <QObject>
+
+class QFontMetrics;
+
+/**
+* @brief Contains helper methods to modify text.
+*/
+class TextModifier : public QObject
+{
+    Q_OBJECT
+public:
+    TextModifier(QObject *parent = 0);
+
+    /**
+    * @brief Shortens text to fit.
+    *
+    * Text shortening is defined by text maximum width.
+    *
+    * @param fontMetrics font metrics to use
+    * @param text text to shorten
+    * @param textMaxWidth maximum width for text
+    */
+    static QString shortenText(const QFontMetrics fontMetrics, const QString &text,
+                               int textMaxWidth);
+
+    /**
+     * @brief Splits too long word.
+     *
+     * Splits long word to several by adding extra spaces
+     *
+     * @param fontMetrics font metrics to use
+     * @param word long word to be splitted
+     * @param textMaxWidth maximum width for word
+     * @returns splitted word
+     */
+    static QString splitWord(const QFontMetrics fontMetrics, const QString &word, int textMaxWidth);
+
+    /**
+     * @brief Splits long words from text.
+     *
+     * Splits long words to several by adding extra spaces
+     *
+     * @param fontMetrics font metrics to use
+     * @param text text to be splitted
+     * @param textMaxWidth maximum width for word
+     * @returns text with long words splitted
+     */
+    static QString splitLongWords(const QFontMetrics fontMetrics, const QString &text,
+                                  int textMaxWidth);
+};
+
+#endif // TEXTMODIFIER_H
index c1d1b7f..31aaafc 100644 (file)
@@ -32,6 +32,7 @@
 
 #include "common.h"
 #include "imagebutton.h"
+#include "textmodifier.h"
 #include "user/user.h"
 
 #include "userinfo.h"
@@ -41,8 +42,8 @@ const int BACKGROUND_TOP_HEIGHT = 20;
 const int BACKGROUND_WIDTH = 368;
 const int ICON_HEIGHT = 24;
 const int ICON_WIDTH = 24;
-const int LABEL_MAX_WIDTH = 300;
 const int MARGIN = 5;
+const int LABEL_MAX_WIDTH = BACKGROUND_WIDTH - ICON_WIDTH - 5 * MARGIN;
 
 UserInfo::UserInfo(QWidget *parent)
     : QWidget(parent),
@@ -256,15 +257,8 @@ void UserInfo::setMessageText(const QString &text)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    QStringList list;
-    list = text.split(' ');
-
-    for (int i = 0; i < list.count(); i++) {
-        if (fontMetrics().width(list.at(i)) > LABEL_MAX_WIDTH)
-            list.replace(i, splitWord(list.at(i)));
-    }
-
-    m_messageText = list.join(" ");
+    m_messageText = TextModifier::splitLongWords(m_statusTextLabel->fontMetrics(), text,
+                                                 LABEL_MAX_WIDTH);
 
     setExpanded(false);
 }
@@ -281,10 +275,12 @@ void UserInfo::setExpanded(bool expanded)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    if (expanded)
+    if (expanded) {
         m_statusTextLabel->setText(m_messageText);
-    else
-        m_statusTextLabel->setText(shortenText(m_statusTextLabel, m_messageText, LABEL_MAX_WIDTH));
+    } else {
+        m_statusTextLabel->setText(TextModifier::shortenText(m_statusTextLabel->fontMetrics(),
+                                                             m_messageText, LABEL_MAX_WIDTH));
+    }
 }
 
 void UserInfo::setTime(const QString &time)
@@ -300,43 +296,8 @@ void UserInfo::setUserName(const QString &name)
 
     m_userName = name;
 
-    m_nameLabel->setText(shortenText(m_nameLabel, m_userName, LABEL_MAX_WIDTH));
-}
-
-QString UserInfo::shortenText(const QLabel *label, const QString &text, int textMaxWidth)
-{
-    qDebug() << __PRETTY_FUNCTION__;
-
-    QFontMetrics labelMetrics = label->fontMetrics();
-    QString copiedText = text;
-    int index = copiedText.indexOf('\n');
-
-    if (index >= 0) {
-        copiedText.truncate(index);
-        copiedText.append("...");
-    }
-
-    return labelMetrics.elidedText(copiedText, Qt::ElideRight, textMaxWidth);
-}
-
-QString UserInfo::splitWord(const QString &word) const
-{
-    qDebug() << __PRETTY_FUNCTION__;
-
-    QString result;
-    QString temp;
-
-    for (int i = 0; i < word.length(); i++) {
-        if (fontMetrics().width(temp.append(word.at(i))) > LABEL_MAX_WIDTH) {
-            result.append(temp.left(temp.length() - 1));
-            result.append(" ");
-            temp.remove(0, temp.length() - 1);
-        }
-    }
-
-    result.append(temp);
-
-    return result;
+    m_nameLabel->setText(TextModifier::shortenText(m_nameLabel->fontMetrics(), m_userName,
+                                                   LABEL_MAX_WIDTH));
 }
 
 void UserInfo::updateLocationDialogFinished(int reason)
index e6553e6..a7b52c9 100644 (file)
@@ -155,26 +155,6 @@ private:
      */
     void setExpanded(bool expanded);
 
-    /**
-     * @brief Elides long text
-     *
-     * @param label get the fontmetrics from the label
-     * @param text long text to be shortened
-     * @param textMaxWidth label width
-     * @returns shortened text
-     */
-    QString shortenText(const QLabel *label, const QString &text, int textMaxWidth);
-
-    /**
-     * @brief Split too long words.
-     *
-     * Splits long word to several by adding extra spaces
-     *
-     * @param word long word to be splitted
-     * @returns splitted word
-     */
-    QString splitWord(const QString &word) const;
-
 private slots:
     /**
      * @brief Slot for collapse user info
index 7422912..5197e61 100644 (file)
@@ -9,7 +9,8 @@ HEADERS += ../../../src/ui/friendlistitem.h \
     ../../../src/coordinates/scenecoordinate.h \
     ../../../src/coordinates/geocoordinate.h \
     ../../../src/ui/extendedlistitemstore.h \
-    ../../../src/ui/extendedlistitem.h
+    ../../../src/ui/extendedlistitem.h \
+    ../../../src/ui/textmodifier.h
 SOURCES += ../../../src/ui/friendlistitem.cpp \
     ../../../src/ui/listitem.cpp \
     ../../../src/user/user.cpp \
@@ -17,5 +18,6 @@ SOURCES += ../../../src/ui/friendlistitem.cpp \
     ../../../src/coordinates/scenecoordinate.cpp \
     ../../../src/coordinates/geocoordinate.cpp \
     ../../../src/ui/extendedlistitemstore.cpp \
-    ../../../src/ui/extendedlistitem.cpp
+    ../../../src/ui/extendedlistitem.cpp \
+    ../../../src/ui/textmodifier.cpp
 RESOURCES += ../../../images.qrc
index 6b8a887..8158416 100644 (file)
@@ -92,7 +92,7 @@ void TestFriendListItem::setUserData()
 
 void TestFriendListItem::toggleSelection()
 {
-    QCOMPARE(friendListItem->data(ITEM_SIZE_HINT_INDEX).toSize(), QSize(368, 142));
+    QCOMPARE(friendListItem->data(ITEM_SIZE_HINT_INDEX).toSize(), QSize(368, 139));
 
     QList<ExtendedListItemStore *> *subItems = (QList<ExtendedListItemStore *> *)
                                                (friendListItem->data(SUBITEM_STORE_INDEX)
@@ -107,7 +107,7 @@ void TestFriendListItem::toggleSelection()
     QCOMPARE(friendListItem->data(ITEM_EXPANDED_INDEX).toBool(), true);
 
     friendListItem->toggleSelection();
-    QCOMPARE(friendListItem->data(ITEM_SIZE_HINT_INDEX).toSize(), QSize(368, 142));
+    QCOMPARE(friendListItem->data(ITEM_SIZE_HINT_INDEX).toSize(), QSize(368, 139));
     QCOMPARE(friendListItem->data(ITEM_EXPANDED_INDEX).toBool(), false);
 }
 
index 4e72e5f..a008a7c 100644 (file)
@@ -10,7 +10,8 @@ HEADERS += ../../../src/ui/listview.h \
     ../../../src/user/user.h \
     ../../../src/coordinates/scenecoordinate.h \
     ../../../src/coordinates/geocoordinate.h \
-    ../../../src/ui/friendlistview.h
+    ../../../src/ui/friendlistview.h \
+    ../../../src/ui/textmodifier.h
 SOURCES += ../../../src/ui/listview.cpp \
     ../../../src/ui/listitem.cpp \
     ../../../src/ui/extendedlistitem.cpp \
@@ -20,5 +21,6 @@ SOURCES += ../../../src/ui/listview.cpp \
     testfriendlistview.cpp \
     ../../../src/coordinates/scenecoordinate.cpp \
     ../../../src/coordinates/geocoordinate.cpp \
-    ../../../src/ui/friendlistview.cpp
+    ../../../src/ui/friendlistview.cpp \
+    ../../../src/ui/textmodifier.cpp
 RESOURCES += ../../../images.qrc