#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)