1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

quoting support, toHtmlChars, fixes

This commit is contained in:
krepa098 2015-01-03 13:52:56 +01:00
parent f3d5b4bb57
commit d7f5068fbf
3 changed files with 25 additions and 6 deletions

View File

@ -25,7 +25,6 @@
#include "content/spinner.h"
#include "../misc/style.h"
#include "../misc/smileypack.h"
#include "../misc/settings.h"
#include <QDebug>
@ -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 = "<div class=alert>" + txt + "</div>";
@ -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("<div class=action>*" + sender + " " + SmileyPack::getInstance().smileyfied(msg) + "</div>", Style::getFont(Style::Big)), ColumnFormat(1.0, ColumnFormat::VariableSize));
line->addColumn(new Text("<div class=action>*" + sender + " " + msg + "</div>", 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();

View File

@ -17,6 +17,7 @@
#include "text.h"
#include "../customtextdocument.h"
#include "src/misc/smileypack.h"
#include <QFontMetrics>
#include <QPainter>
@ -50,11 +51,10 @@ Text::~Text()
void Text::setText(const QString& txt)
{
text = txt;
text = SmileyPack::getInstance().smileyfied(toHtmlChars(txt));
detectAnchors();
text.replace("\n", " <br/>");
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<messageLines.size();++i)
{
if (QRegExp("^[ ]*&gt;.*").exactMatch(messageLines[i]))
quotedText += "<span class=quote>" + messageLines[i] + "</span>";
else
quotedText += messageLines[i];
if (i < messageLines.size() - 1)
quotedText += "<br/>";
}
text = quotedText;
}
QString Text::toHtmlChars(const QString &str)
{
static QList<QPair<QString, QString>> replaceList = {{"&","&amp;"}, {">","&gt;"}, {"<","&lt;"}};

View File

@ -62,6 +62,7 @@ protected:
int cursorFromPos(QPointF scenePos) const;
void detectAnchors();
void detectQuotes();
QString toHtmlChars(const QString& str);
private: