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

fix(chat): cleanup chat css base style

fix chat area's inner stylesheet
note: the base font is never a bold font (respects html tags: e.g. <b>bold text</b>)

fix block colors:
* action -> blue
* alert -> red
* quote -> green
This commit is contained in:
Nils Fenner 2016-07-10 13:43:50 +02:00
parent 464daebdd7
commit 989b15e656
6 changed files with 33 additions and 40 deletions

View File

@ -61,6 +61,9 @@ ChatMessage::Ptr ChatMessage::createChatMessage(const QString &sender, const QSt
switch(type) switch(type)
{ {
case NORMAL:
text = wrapDiv(text, "msg");
break;
case ACTION: case ACTION:
senderText = "*"; senderText = "*";
text = wrapDiv(QString("%1 %2").arg(sender.toHtmlEscaped(), text), "action"); 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: case ALERT:
text = wrapDiv(text, "alert"); text = wrapDiv(text, "alert");
break; break;
default:
text = wrapDiv(text, "msg");
} }
// Note: Eliding cannot be enabled for RichText items. (QTBUG-17207) // Note: Eliding cannot be enabled for RichText items. (QTBUG-17207)

View File

@ -31,13 +31,13 @@
#include <QDesktopServices> #include <QDesktopServices>
#include <QTextFragment> #include <QTextFragment>
#include "src/widget/style.h"
Text::Text(const QString& txt, const QFont& font, bool enableElide, const QString &rwText, const QColor c) Text::Text(const QString& txt, const QFont& font, bool enableElide, const QString &rwText, const QColor c)
: rawText(rwText) : rawText(rwText)
, elide(enableElide) , elide(enableElide)
, defFont(font) , defFont(font)
, defStyleSheet(QString::fromUtf8("body{font: '%1' %2px %3;}") , defStyleSheet(Style::getStylesheet(QStringLiteral(":/ui/chatArea/innerStyle.css"), font))
.arg(font.family()).arg(font.pixelSize())
.arg(font.bold() ? "bold" : QString()))
, color(c) , color(c)
{ {
setText(txt); setText(txt);

View File

@ -29,9 +29,6 @@
CustomTextDocument::CustomTextDocument(QObject *parent) CustomTextDocument::CustomTextDocument(QObject *parent)
: QTextDocument(parent) : QTextDocument(parent)
{ {
static QString css = Style::getStylesheet(":ui/chatArea/innerStyle.css");
setDefaultStyleSheet(css);
setUndoRedoEnabled(false); setUndoRedoEnabled(false);
setUseDesignMetrics(false); setUseDesignMetrics(false);
} }

View File

@ -78,7 +78,7 @@ QStringList Style::getThemeColorNames()
QList<QColor> Style::themeColorColors = {QColor(), QColor("#004aa4"), QColor("#97ba00"), QColor("#c23716"), QColor("#4617b5")}; QList<QColor> 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); QFile file(filename);
if (!file.open(QFile::ReadOnly | QFile::Text)) if (!file.open(QFile::ReadOnly | QFile::Text))
@ -87,7 +87,7 @@ QString Style::getStylesheet(const QString &filename)
return QString(); return QString();
} }
return resolve(file.readAll()); return resolve(file.readAll(), baseFont);
} }
QColor Style::getColor(Style::ColorPalette entry) QColor Style::getColor(Style::ColorPalette entry)
@ -115,7 +115,7 @@ QFont Style::getFont(Style::Font font)
return fonts[font]; return fonts[font];
} }
QString Style::resolve(QString qss) QString Style::resolve(QString qss, const QFont& baseFont)
{ {
if (dict.isEmpty()) if (dict.isEmpty())
{ {
@ -137,13 +137,15 @@ QString Style::resolve(QString qss)
{"@themeLight", Style::getColor(Style::ThemeLight).name()}, {"@themeLight", Style::getColor(Style::ThemeLight).name()},
// fonts // fonts
{"@baseFont", QString::fromUtf8("'%1' %2px")
.arg(baseFont.family()).arg(QFontInfo(baseFont).pixelSize())},
{"@extraBig", qssifyFont(Style::getFont(Style::ExtraBig))}, {"@extraBig", qssifyFont(Style::getFont(Style::ExtraBig))},
{"@big", qssifyFont(Style::getFont(Style::Big))}, {"@big", qssifyFont(Style::getFont(Style::Big))},
{"@bigBold", qssifyFont(Style::getFont(Style::BigBold))}, {"@bigBold", qssifyFont(Style::getFont(Style::BigBold))},
{"@medium", qssifyFont(Style::getFont(Style::Medium))}, {"@medium", qssifyFont(Style::getFont(Style::Medium))},
{"@mediumBold", qssifyFont(Style::getFont(Style::MediumBold))}, {"@mediumBold", qssifyFont(Style::getFont(Style::MediumBold))},
{"@small", qssifyFont(Style::getFont(Style::Small))}, {"@small", qssifyFont(Style::getFont(Style::Small))},
{"@smallLight", qssifyFont(Style::getFont(Style::SmallLight))}, {"@smallLight", qssifyFont(Style::getFont(Style::SmallLight))}
}; };
} }

View File

@ -59,10 +59,10 @@ public:
}; };
static QStringList getThemeColorNames(); 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 QColor getColor(ColorPalette entry);
static QFont getFont(Font font); 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 repolish(QWidget* w);
static void setThemeColor(int color); static void setThemeColor(int color);
static void setThemeColor(const QColor &color); ///< Pass an invalid QColor to reset to defaults static void setThemeColor(const QColor &color); ///< Pass an invalid QColor to reset to defaults

View File

@ -1,42 +1,35 @@
body {
font: @baseFont;
}
p { p {
white-space: pre-wrap; white-space: pre-wrap;
} }
p.msg { .action {
color: @black; color: #1818FF;
font: @big; font-style: italic;
} }
p.action { .typing {
color: #1818FF; color: @mediumGreyLight;
font: @big;
font-style: italic;
} }
p.typing { .quote {
color: @mediumGreyLight; color: #279419;
font: @big;
} }
span.quote { .alert {
color: #279419; margin-left: 0px;
margin-right: 0px;
background-color: @orange;
} }
p.alert { .alert_name {
margin-left: 0px; background-color: @orange;
margin-right: 0px; font: @bigBold;
color: @black;
background-color: @orange;
font: @big;
}
p.alert_name {
color: @black;
background-color: @orange;
font: @bigBold;
} }
a { a {
color: blue; color: blue;
} }