ui/routingpanel.cpp \
ui/routewaypointlistitem.cpp \
ui/routewaypointlistview.cpp \
- user/user.cpp
+ user/user.cpp \
+ ui/textmodifier.cpp
HEADERS += application.h \
common.h \
coordinates/geocoordinate.h \
ui/routingpanel.h \
ui/routewaypointlistitem.h \
ui/routewaypointlistview.h \
- user/user.h
+ user/user.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->setShortenedText(shortenText(expandedText, m_subItemTextWidth,
+ ListItem::TEXT_SIZE_SMALL));
+ itemStore->setTextRect(calculateExpandedTextRect(expandedText));
m_subItemStoreList->append(itemStore);
}
QRect ExtendedListItem::boundingRect(const QString &text)
{
- qDebug() << __PRETTY_FUNCTION__;
+ qWarning() << __PRETTY_FUNCTION__ << text;
QPixmap p = QPixmap(ICON_WIDTH, ICON_HEIGHT);
QPainter painter(&p);
QFontMetrics textMetrics = painter.fontMetrics();
QRect textRect;
- QStringList rows = text.split('\n');
-
- foreach (QString row, rows) {
+ textRect.setSize(QSize(m_subItemTextWidth, textMetrics.height()));
- QRect textRowRect = textMetrics.boundingRect(row);
-
- if (textRowRect.width() > textRect.width())
- textRect.setWidth(textRowRect.width());
+ QStringList rows = text.split('\n');
+ for (int i = 1; i < rows.count(); ++i) {
+ qWarning() << "jep";
+ QRect textRowRect = textMetrics.boundingRect(rows.at(i));
textRect.setHeight(textRect.height() + textRowRect.height());
}
+ QStringList words = text.split(" ");
+ QString rowText;
+ for (int i = 0; i < words.count(); ++i) {
+ if (i == words.count() -1)
+ rowText.append(words.at(i));
+ else
+ rowText.append(words.at(i) + " ");
+ if (textMetrics.width(rowText) > m_subItemTextWidth) {
+ textRect.setHeight(textRect.height() + textMetrics.height());
+ rowText = words.at(i);
+ qWarning() << "hep";
+ }
+ }
+
+ //textRect.setHeight(textRect.height() + 5);
+// qWarning() << textRect.width() << textRect.height();
return textRect;
}
const int TEXT_BOTTOM_MARGIN = 2;
QRect textRect = boundingRect(text);
+ QRect expandedTextRect = textRect;
+// int textRectFactor = textRect.width() / m_subItemTextWidth;
+// textRectFactor += textRect.height() / SUBITEM_TEXT_ROW_HEIGHT;
- 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 = QRect(0, 0, m_subItemTextWidth, SUBITEM_TEXT_ROW_HEIGHT
+// * qMax(textRectFactor, 1));
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,
+ QString nameTemp = QString("Pitka nimi pitka nimi pitka nimi");
+ setTitle(shortenText(nameTemp, NAME_TEXT_MAX_WIDTH - distanceRect.width() - MARGIN * 2,
ListItem::TEXT_SIZE_NORMAL));
setCoordinates(user->coordinates());
clearSubItems();
- addSubItem(user->note(), QPixmap(":/res/images/envelope.png"));
+ QString noteTemp = QString("Joillakin lehdillä on tosi tarkat rajat painon kanssa, ja emme "
+ "menneet Playboyn pyytämiin koekuvauksiinkaan, kun he sanoivat, "
+ "että se on ainoa mahdollisuus. Jos on esim. liian ruskettunut, "
+ "niin he karsivat saman tien pois. Nain jälkikäteen ajatellen minua "
+ "on jäänyt harmittamaan, ettemme menneet koekuvaukseen kun kerran "
+ "pyydettiin! Kun Julia pääsi kyseisen lehden Grapevine-sivulle "
+ "vuonna 2003, meille molemmille jäi kytemään ajatus jatkosta. "
+ "Olemme ihmetelleet, miksi Suomen lehdistö sivuutti asian vain "
+ "nopeasti. Vaikka kyseessä ei ollutkaan monen kuvan kuvasarja "
+ "Juliasta, hän silti poseerasi varsinaisessa Playboy-lehdessä.");
+ QString noteTemp2 = QString("hei\nhei\nhei\nhei\nhei\nhei\nhei\nhei\nhei\nhei\nhei\nhei\n"
+ "hei\nhei\nhei\nhei\nhei\nhei\nhei\nhei\nhei\nhei\nhei\nhei");
+
+ static int index = 0;
+
+// if (index % 2)
+ addSubItem(noteTemp, QPixmap(":/res/images/envelope.png"));
+// else
+// addSubItem(noteTemp2, QPixmap(":/res/images/envelope.png"));
addSubItem(user->address(), QPixmap(":/res/images/compass.png"));
addSubItem(user->timestamp(), QPixmap(":/res/images/clock.png"));
+
+ index++;
}
qDebug() << __PRETTY_FUNCTION__;
QStringList newUserIDs;
+ static int count = 0;
foreach (User *user, friendList) {
FriendListItem *item = 0;
}
newUserIDs.append(user->userId());
+
+ count++;
+ if (count >= 1)
+ break;
}
m_friendListView->clearUnused(newUserIDs);
#include "../common.h"
#include "listcommon.h"
+#include "textmodifier.h"
#include "listitem.h"
QFontMetrics textMetrics = painter.fontMetrics();
- QString shortenedText = text;
+ return TextModifier::shortenText(textMetrics, text, textWidth);
- int index = shortenedText.indexOf('\n');
+// QFontMetrics textMetrics = painter.fontMetrics();
- if (index > 0) {
- shortenedText.truncate(index);
- shortenedText.append("...");
- }
+// QString shortenedText = text;
- return textMetrics.elidedText(shortenedText, Qt::ElideRight, textWidth);
+// int index = shortenedText.indexOf('\n');
+
+// if (index > 0) {
+// shortenedText.truncate(index);
+// shortenedText.append("...");
+// }
+
+// return textMetrics.elidedText(shortenedText, Qt::ElideRight, textWidth);
}
--- /dev/null
+#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
+#ifndef TEXTMODIFIER_H
+#define TEXTMODIFIER_H
+
+#include <QObject>
+
+class QFontMetrics;
+
+class TextModifier : public QObject
+{
+ Q_OBJECT
+public:
+ TextModifier(QObject *parent = 0);
+
+ static QString shortenText(const QFontMetrics fontMetrics, const QString &text,
+ int textMaxWidth);
+
+ static QString splitWord(const QFontMetrics fontMetrics, const QString &word, int textMaxWidth);
+
+ static QString splitLongWords(const QFontMetrics fontMetrics, const QString &text,
+ int textMaxWidth);
+};
+
+#endif // TEXTMODIFIER_H