From d7f5068fbfa09f638e96fe2c79561dabf5155da9 Mon Sep 17 00:00:00 2001 From: krepa098 Date: Sat, 3 Jan 2015 13:52:56 +0100 Subject: [PATCH] quoting support, toHtmlChars, fixes --- src/chatlog/chatlog.cpp | 5 ++--- src/chatlog/content/text.cpp | 25 ++++++++++++++++++++++--- src/chatlog/content/text.h | 1 + 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/src/chatlog/chatlog.cpp b/src/chatlog/chatlog.cpp index 5c41d51f6..ef877ea0a 100644 --- a/src/chatlog/chatlog.cpp +++ b/src/chatlog/chatlog.cpp @@ -25,7 +25,6 @@ #include "content/spinner.h" #include "../misc/style.h" -#include "../misc/smileypack.h" #include "../misc/settings.h" #include @@ -86,7 +85,7 @@ ChatLog::~ChatLog() ChatMessage* ChatLog::addChatMessage(const QString& sender, const QString &msg, bool self, bool alert) { - QString txt = SmileyPack::getInstance().smileyfied(msg); + QString txt = msg; if(alert) txt = "
" + txt + "
"; @@ -119,7 +118,7 @@ ChatMessage *ChatLog::addChatAction(const QString &sender, const QString &msg) { ChatMessage* line = new ChatMessage(scene, msg); line->addColumn(new Text(""), ColumnFormat(NAME_COL_WIDTH, ColumnFormat::FixedSize, ColumnFormat::Right)); - line->addColumn(new Text("
*" + sender + " " + SmileyPack::getInstance().smileyfied(msg) + "
", Style::getFont(Style::Big)), ColumnFormat(1.0, ColumnFormat::VariableSize)); + line->addColumn(new Text("
*" + sender + " " + msg + "
", Style::getFont(Style::Big)), ColumnFormat(1.0, ColumnFormat::VariableSize)); line->addColumn(new Spinner(QSizeF(16, 16)), ColumnFormat(TIME_COL_WIDTH, ColumnFormat::FixedSize, ColumnFormat::Right)); line->setAsAction(); diff --git a/src/chatlog/content/text.cpp b/src/chatlog/content/text.cpp index b8783066b..c07a453cf 100644 --- a/src/chatlog/content/text.cpp +++ b/src/chatlog/content/text.cpp @@ -17,6 +17,7 @@ #include "text.h" #include "../customtextdocument.h" +#include "src/misc/smileypack.h" #include #include @@ -50,11 +51,10 @@ Text::~Text() void Text::setText(const QString& txt) { - text = txt; + text = SmileyPack::getInstance().smileyfied(toHtmlChars(txt)); detectAnchors(); - - text.replace("\n", "
"); + detectQuotes(); ensureIntegrity(); freeResources(); @@ -287,6 +287,25 @@ void Text::detectAnchors() } } +void Text::detectQuotes() +{ + // detect text quotes + QStringList messageLines = text.split("\n"); + QString quotedText; + for (int i=0;i"; + else + quotedText += messageLines[i]; + + if (i < messageLines.size() - 1) + quotedText += "
"; + } + + text = quotedText; +} + QString Text::toHtmlChars(const QString &str) { static QList> replaceList = {{"&","&"}, {">",">"}, {"<","<"}}; diff --git a/src/chatlog/content/text.h b/src/chatlog/content/text.h index 8ef17499b..ef1deee67 100644 --- a/src/chatlog/content/text.h +++ b/src/chatlog/content/text.h @@ -62,6 +62,7 @@ protected: int cursorFromPos(QPointF scenePos) const; void detectAnchors(); + void detectQuotes(); QString toHtmlChars(const QString& str); private: