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:
parent
f3d5b4bb57
commit
d7f5068fbf
|
@ -25,7 +25,6 @@
|
||||||
#include "content/spinner.h"
|
#include "content/spinner.h"
|
||||||
|
|
||||||
#include "../misc/style.h"
|
#include "../misc/style.h"
|
||||||
#include "../misc/smileypack.h"
|
|
||||||
#include "../misc/settings.h"
|
#include "../misc/settings.h"
|
||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
@ -86,7 +85,7 @@ ChatLog::~ChatLog()
|
||||||
|
|
||||||
ChatMessage* ChatLog::addChatMessage(const QString& sender, const QString &msg, bool self, bool alert)
|
ChatMessage* ChatLog::addChatMessage(const QString& sender, const QString &msg, bool self, bool alert)
|
||||||
{
|
{
|
||||||
QString txt = SmileyPack::getInstance().smileyfied(msg);
|
QString txt = msg;
|
||||||
if(alert)
|
if(alert)
|
||||||
txt = "<div class=alert>" + txt + "</div>";
|
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);
|
ChatMessage* line = new ChatMessage(scene, msg);
|
||||||
line->addColumn(new Text(""), ColumnFormat(NAME_COL_WIDTH, ColumnFormat::FixedSize, ColumnFormat::Right));
|
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->addColumn(new Spinner(QSizeF(16, 16)), ColumnFormat(TIME_COL_WIDTH, ColumnFormat::FixedSize, ColumnFormat::Right));
|
||||||
line->setAsAction();
|
line->setAsAction();
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
#include "text.h"
|
#include "text.h"
|
||||||
|
|
||||||
#include "../customtextdocument.h"
|
#include "../customtextdocument.h"
|
||||||
|
#include "src/misc/smileypack.h"
|
||||||
|
|
||||||
#include <QFontMetrics>
|
#include <QFontMetrics>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
|
@ -50,11 +51,10 @@ Text::~Text()
|
||||||
|
|
||||||
void Text::setText(const QString& txt)
|
void Text::setText(const QString& txt)
|
||||||
{
|
{
|
||||||
text = txt;
|
text = SmileyPack::getInstance().smileyfied(toHtmlChars(txt));
|
||||||
|
|
||||||
detectAnchors();
|
detectAnchors();
|
||||||
|
detectQuotes();
|
||||||
text.replace("\n", " <br/>");
|
|
||||||
|
|
||||||
ensureIntegrity();
|
ensureIntegrity();
|
||||||
freeResources();
|
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("^[ ]*>.*").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)
|
QString Text::toHtmlChars(const QString &str)
|
||||||
{
|
{
|
||||||
static QList<QPair<QString, QString>> replaceList = {{"&","&"}, {">",">"}, {"<","<"}};
|
static QList<QPair<QString, QString>> replaceList = {{"&","&"}, {">",">"}, {"<","<"}};
|
||||||
|
|
|
@ -62,6 +62,7 @@ protected:
|
||||||
int cursorFromPos(QPointF scenePos) const;
|
int cursorFromPos(QPointF scenePos) const;
|
||||||
|
|
||||||
void detectAnchors();
|
void detectAnchors();
|
||||||
|
void detectQuotes();
|
||||||
QString toHtmlChars(const QString& str);
|
QString toHtmlChars(const QString& str);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user