diff --git a/src/chatlog/chatmessage.cpp b/src/chatlog/chatmessage.cpp index 864351a28..75823a625 100644 --- a/src/chatlog/chatmessage.cpp +++ b/src/chatlog/chatmessage.cpp @@ -61,6 +61,9 @@ ChatMessage::Ptr ChatMessage::createChatMessage(const QString &sender, const QSt switch(type) { + case NORMAL: + text = wrapDiv(text, "msg"); + break; case ACTION: senderText = "*"; text = wrapDiv(QString("%1 %2").arg(sender.toHtmlEscaped(), text), "action"); @@ -69,8 +72,6 @@ ChatMessage::Ptr ChatMessage::createChatMessage(const QString &sender, const QSt case ALERT: text = wrapDiv(text, "alert"); break; - default: - text = wrapDiv(text, "msg"); } // Note: Eliding cannot be enabled for RichText items. (QTBUG-17207) diff --git a/src/chatlog/content/text.cpp b/src/chatlog/content/text.cpp index d3272f185..d23309f46 100644 --- a/src/chatlog/content/text.cpp +++ b/src/chatlog/content/text.cpp @@ -31,13 +31,13 @@ #include #include +#include "src/widget/style.h" + Text::Text(const QString& txt, const QFont& font, bool enableElide, const QString &rwText, const QColor c) : rawText(rwText) , elide(enableElide) , defFont(font) - , defStyleSheet(QString::fromUtf8("body{font: '%1' %2px %3;}") - .arg(font.family()).arg(font.pixelSize()) - .arg(font.bold() ? "bold" : QString())) + , defStyleSheet(Style::getStylesheet(QStringLiteral(":/ui/chatArea/innerStyle.css"), font)) , color(c) { setText(txt); diff --git a/src/chatlog/customtextdocument.cpp b/src/chatlog/customtextdocument.cpp index dd7143887..c4261b4ea 100644 --- a/src/chatlog/customtextdocument.cpp +++ b/src/chatlog/customtextdocument.cpp @@ -29,9 +29,6 @@ CustomTextDocument::CustomTextDocument(QObject *parent) : QTextDocument(parent) { - static QString css = Style::getStylesheet(":ui/chatArea/innerStyle.css"); - - setDefaultStyleSheet(css); setUndoRedoEnabled(false); setUseDesignMetrics(false); } diff --git a/src/widget/style.cpp b/src/widget/style.cpp index 57f47a8c6..369790c11 100644 --- a/src/widget/style.cpp +++ b/src/widget/style.cpp @@ -78,7 +78,7 @@ QStringList Style::getThemeColorNames() QList Style::themeColorColors = {QColor(), QColor("#004aa4"), QColor("#97ba00"), QColor("#c23716"), QColor("#4617b5")}; -QString Style::getStylesheet(const QString &filename) +QString Style::getStylesheet(const QString &filename, const QFont& baseFont) { QFile file(filename); if (!file.open(QFile::ReadOnly | QFile::Text)) @@ -87,7 +87,7 @@ QString Style::getStylesheet(const QString &filename) return QString(); } - return resolve(file.readAll()); + return resolve(file.readAll(), baseFont); } QColor Style::getColor(Style::ColorPalette entry) @@ -115,7 +115,7 @@ QFont Style::getFont(Style::Font font) return fonts[font]; } -QString Style::resolve(QString qss) +QString Style::resolve(QString qss, const QFont& baseFont) { if (dict.isEmpty()) { @@ -137,13 +137,15 @@ QString Style::resolve(QString qss) {"@themeLight", Style::getColor(Style::ThemeLight).name()}, // fonts + {"@baseFont", QString::fromUtf8("'%1' %2px") + .arg(baseFont.family()).arg(QFontInfo(baseFont).pixelSize())}, {"@extraBig", qssifyFont(Style::getFont(Style::ExtraBig))}, {"@big", qssifyFont(Style::getFont(Style::Big))}, {"@bigBold", qssifyFont(Style::getFont(Style::BigBold))}, {"@medium", qssifyFont(Style::getFont(Style::Medium))}, {"@mediumBold", qssifyFont(Style::getFont(Style::MediumBold))}, {"@small", qssifyFont(Style::getFont(Style::Small))}, - {"@smallLight", qssifyFont(Style::getFont(Style::SmallLight))}, + {"@smallLight", qssifyFont(Style::getFont(Style::SmallLight))} }; } diff --git a/src/widget/style.h b/src/widget/style.h index 6b4cb236d..f34fcb88f 100644 --- a/src/widget/style.h +++ b/src/widget/style.h @@ -59,10 +59,10 @@ public: }; static QStringList getThemeColorNames(); - static QString getStylesheet(const QString& filename); + static QString getStylesheet(const QString& filename, const QFont& baseFont = QFont()); static QColor getColor(ColorPalette entry); static QFont getFont(Font font); - static QString resolve(QString qss); + static QString resolve(QString qss, const QFont& baseFont = QFont()); static void repolish(QWidget* w); static void setThemeColor(int color); static void setThemeColor(const QColor &color); ///< Pass an invalid QColor to reset to defaults diff --git a/ui/chatArea/innerStyle.css b/ui/chatArea/innerStyle.css index 15495dc82..bc1ef8f92 100644 --- a/ui/chatArea/innerStyle.css +++ b/ui/chatArea/innerStyle.css @@ -1,42 +1,35 @@ +body { + font: @baseFont; +} + p { - white-space: pre-wrap; + white-space: pre-wrap; } -p.msg { - color: @black; - font: @big; +.action { + color: #1818FF; + font-style: italic; } -p.action { - color: #1818FF; - font: @big; - font-style: italic; +.typing { + color: @mediumGreyLight; } -p.typing { - color: @mediumGreyLight; - font: @big; +.quote { + color: #279419; } -span.quote { - color: #279419; +.alert { + margin-left: 0px; + margin-right: 0px; + background-color: @orange; } -p.alert { - margin-left: 0px; - margin-right: 0px; - color: @black; - background-color: @orange; - font: @big; -} - -p.alert_name { - color: @black; - background-color: @orange; - font: @bigBold; +.alert_name { + background-color: @orange; + font: @bigBold; } a { color: blue; } -