2 Situare - A location system for Facebook
3 Copyright (C) 2010 Ixonos Plc. Authors:
5 Katri Kaikkonen - katri.kaikkonen@ixonos.com
6 Jussi Laitinen - jussi.laitinen@ixonos.com
8 Situare is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License
10 version 2 as published by the Free Software Foundation.
12 Situare is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with Situare; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
24 #include <QFontMetrics>
25 #include <QStringList>
27 #include "textmodifier.h"
29 QString TextModifier::shortenText(const QFontMetrics fontMetrics, const QString &text,
32 qDebug() << __PRETTY_FUNCTION__;
34 QString copiedText = text;
35 int index = copiedText.indexOf('\n');
38 copiedText.truncate(index);
39 copiedText.append("...");
42 return fontMetrics.elidedText(copiedText, Qt::ElideRight, textMaxWidth);
45 QString TextModifier::splitWord(const QFontMetrics fontMetrics, const QString &word,
48 qDebug() << __PRETTY_FUNCTION__;
53 for (int i = 0; i < word.length(); i++) {
54 if (fontMetrics.width(temp.append(word.at(i))) > textMaxWidth) {
55 result.append(temp.left(temp.length() - 1));
57 temp.remove(0, temp.length() - 1);
66 QString TextModifier::splitLongWords(const QFontMetrics fontMetrics, const QString &text,
69 qDebug() << __PRETTY_FUNCTION__;
72 list = text.split(' ');
74 for (int i = 0; i < list.count(); i++) {
75 if (fontMetrics.width(list.at(i)) > textMaxWidth)
76 list.replace(i, splitWord(fontMetrics, list.at(i), textMaxWidth));
79 return list.join(" ");