From 19b526d4533841ca91209929f0d6aef6042a8eeb Mon Sep 17 00:00:00 2001 From: Max Sandholm Date: Thu, 16 Nov 2017 16:33:52 +0200 Subject: Use system color scheme (using a Qt stylesheet) #104 The color scheme of nheko obeys the default color theme of Qt (i.e. the system theme). It uses a Qt stylesheet to accomplish this, which means replacing the color theme with a custom theme would only be a matter of writing a new style sheet and loading it into the app. --- src/TimelineItem.cc | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) (limited to 'src/TimelineItem.cc') diff --git a/src/TimelineItem.cc b/src/TimelineItem.cc index efc12d42..8c21e61d 100644 --- a/src/TimelineItem.cc +++ b/src/TimelineItem.cc @@ -30,7 +30,7 @@ #include "TimelineViewManager.h" static const QRegExp URL_REGEX("((?:https?|ftp)://\\S+)"); -static const QString URL_HTML = "\\1"; +static const QString URL_HTML = "\\1"; namespace events = matrix::events; namespace msgs = matrix::events::messages; @@ -205,7 +205,7 @@ TimelineItem::TimelineItem(const events::MessageEvent &event, body.replace(URL_REGEX, URL_HTML); body.replace("\n", "
"); - body = "" + body + ""; + body = "" + body + ""; if (with_sender) { auto displayName = TimelineViewManager::displayName(event.sender()); @@ -308,7 +308,7 @@ TimelineItem::TimelineItem(const events::MessageEvent &event, void TimelineItem::generateBody(const QString &body) { - QString content(" %1 "); + QString content(" %1 "); body_ = new QLabel(this); body_->setFont(font_); @@ -332,8 +332,8 @@ TimelineItem::generateBody(const QString &userid, const QString &body) sender = userid.split(":")[0].split("@")[1]; } - QString userContent(" %1 "); - QString bodyContent(" %1 "); + QString userContent("%1"); + QString bodyContent("%1"); QFont usernameFont = font_; usernameFont.setBold(true); @@ -357,7 +357,7 @@ TimelineItem::generateBody(const QString &userid, const QString &body) void TimelineItem::generateTimestamp(const QDateTime &time) { - QString msg(" %1 "); + QString msg("%1"); QFont timestampFont; timestampFont.setPixelSize(conf::timeline::fonts::timestamp); @@ -369,6 +369,8 @@ TimelineItem::generateTimestamp(const QDateTime &time) timestamp_->setFont(timestampFont); timestamp_->setText(msg.arg(time.toString("HH:mm"))); timestamp_->setContentsMargins(0, topMargin, 0, 0); + timestamp_->setStyleSheet( + QString("font-size: %1px;").arg(conf::timeline::fonts::timestamp)); } QString @@ -399,8 +401,6 @@ TimelineItem::setupAvatarLayout(const QString &userName) userAvatar_ = new Avatar(this); userAvatar_->setLetter(QChar(userName[0]).toUpper()); - userAvatar_->setBackgroundColor(QColor("#eee")); - userAvatar_->setTextColor(QColor("black")); userAvatar_->setSize(conf::timeline::avatarSize); // TODO: The provided user name should be a UserId class @@ -467,3 +467,12 @@ TimelineItem::descriptiveTime(const QDateTime &then) } TimelineItem::~TimelineItem() {} + +void +TimelineItem::paintEvent(QPaintEvent *) +{ + QStyleOption opt; + opt.init(this); + QPainter p(this); + style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this); +} -- cgit 1.5.1