- 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
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 \
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
#include "../common.h"
#include "extendedlistitemstore.h"
#include "listcommon.h"
+#include "textmodifier.h"
#include "extendedlistitem.h"
{
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);
}
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;
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;
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;
}
}
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());
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;
#include "../common.h"
#include "listcommon.h"
+#include "textmodifier.h"
#include "listitem.h"
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);
}
--- /dev/null
+/*
+ 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(" ");
+}
--- /dev/null
+/*
+ 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
#include "common.h"
#include "imagebutton.h"
+#include "textmodifier.h"
#include "user/user.h"
#include "userinfo.h"
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),
{
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);
}
{
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)
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)
*/
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
../../../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 \
../../../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
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)
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);
}
../../../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 \
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