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. --- include/RoomInfoListItem.h | 55 +++++++++++++++++++++++++++++++++++++++--- include/TextInputWidget.h | 5 ++-- include/TimelineItem.h | 6 +++++ include/TimelineView.h | 9 +++++-- include/TopRoomBar.h | 2 +- include/UserInfoWidget.h | 1 + include/ui/LoadingIndicator.h | 1 + include/ui/OverlayWidget.h | 3 +++ resources/res.qrc | 7 +++--- resources/styles/nheko.qss | 56 +++++++++++++++++++++++++++++++++++++++++++ resources/styles/system.qss | 39 ++++++++++++++++++++++++++++++ src/ChatPage.cc | 7 +++--- src/EmojiPanel.cc | 17 +++++++------ src/LoginPage.cc | 28 +++++++++++----------- src/LogoutDialog.cc | 4 ++-- src/MainWindow.cc | 3 +-- src/RegisterPage.cc | 32 ++++++++++++------------- src/RoomInfoListItem.cc | 30 +++++++++++++---------- src/RoomList.cc | 4 +--- src/TextInputWidget.cc | 17 +++++++++---- src/TimelineItem.cc | 25 ++++++++++++------- src/TimelineView.cc | 11 ++++++++- src/TopRoomBar.cc | 2 -- src/UserInfoWidget.cc | 22 +++++++++++++---- src/UserSettingsPage.cc | 9 ++++--- src/main.cc | 16 +++++++++++++ src/ui/Badge.cc | 1 - src/ui/OverlayWidget.cc | 11 +++++++++ src/ui/TextField.cc | 2 -- 29 files changed, 328 insertions(+), 97 deletions(-) create mode 100644 resources/styles/nheko.qss create mode 100644 resources/styles/system.qss diff --git a/include/RoomInfoListItem.h b/include/RoomInfoListItem.h index a137b37f..acb1ab84 100644 --- a/include/RoomInfoListItem.h +++ b/include/RoomInfoListItem.h @@ -38,6 +38,19 @@ struct DescInfo class RoomInfoListItem : public QWidget { Q_OBJECT + Q_PROPERTY(QColor highlightedBackgroundColor READ highlightedBackgroundColor WRITE + setHighlightedBackgroundColor) + Q_PROPERTY( + QColor hoverBackgroundColor READ hoverBackgroundColor WRITE setHoverBackgroundColor) + Q_PROPERTY(QColor backgroundColor READ backgroundColor WRITE setBackgroundColor) + + Q_PROPERTY(QColor titleColor READ titleColor WRITE setTitleColor) + Q_PROPERTY(QColor subtitleColor READ subtitleColor WRITE setSubtitleColor) + + Q_PROPERTY( + QColor highlightedTitleColor READ highlightedTitleColor WRITE setHighlightedTitleColor) + Q_PROPERTY(QColor highlightedSubtitleColor READ highlightedSubtitleColor WRITE + setHighlightedSubtitleColor) public: RoomInfoListItem(QSharedPointer settings, @@ -51,13 +64,39 @@ public: void clearUnreadMessageCount(); void setState(const RoomState &state); - bool isPressed() const { return isPressed_; }; - RoomState state() const { return state_; }; - int unreadMessageCount() const { return unreadMsgCount_; }; + bool isPressed() const { return isPressed_; } + RoomState state() const { return state_; } + int unreadMessageCount() const { return unreadMsgCount_; } void setAvatar(const QImage &avatar_image); void setDescriptionMessage(const DescInfo &info); + inline QColor highlightedBackgroundColor() const { return highlightedBackgroundColor_; } + inline QColor hoverBackgroundColor() const { return hoverBackgroundColor_; } + inline QColor backgroundColor() const { return backgroundColor_; } + + inline QColor highlightedTitleColor() const { return highlightedTitleColor_; } + inline QColor highlightedSubtitleColor() const { return highlightedSubtitleColor_; } + + inline QColor titleColor() const { return titleColor_; } + inline QColor subtitleColor() const { return subtitleColor_; } + + inline void setHighlightedBackgroundColor(QColor &color) + { + highlightedBackgroundColor_ = color; + } + inline void setHoverBackgroundColor(QColor &color) { hoverBackgroundColor_ = color; } + inline void setBackgroundColor(QColor &color) { backgroundColor_ = color; } + + inline void setHighlightedTitleColor(QColor &color) { highlightedTitleColor_ = color; } + inline void setHighlightedSubtitleColor(QColor &color) + { + highlightedSubtitleColor_ = color; + } + + inline void setTitleColor(QColor &color) { titleColor_ = color; } + inline void setSubtitleColor(QColor &color) { subtitleColor_ = color; } + signals: void clicked(const QString &room_id); void leaveRoom(const QString &room_id); @@ -98,4 +137,14 @@ private: int maxHeight_; int unreadMsgCount_ = 0; + + QColor highlightedBackgroundColor_; + QColor hoverBackgroundColor_; + QColor backgroundColor_; + + QColor highlightedTitleColor_; + QColor highlightedSubtitleColor_; + + QColor titleColor_; + QColor subtitleColor_; }; diff --git a/include/TextInputWidget.h b/include/TextInputWidget.h index 70b1c213..88706e4a 100644 --- a/include/TextInputWidget.h +++ b/include/TextInputWidget.h @@ -76,7 +76,7 @@ public: public slots: void openFileSelection(); void hideUploadSpinner(); - void focusLineEdit() { input_->setFocus(); }; + void focusLineEdit() { input_->setFocus(); } private slots: void addSelectedEmoji(const QString &emoji); @@ -91,7 +91,8 @@ signals: void stoppedTyping(); protected: - void focusInEvent(QFocusEvent *event); + void focusInEvent(QFocusEvent *event) override; + void paintEvent(QPaintEvent *) override; private: void showUploadSpinner(); diff --git a/include/TimelineItem.h b/include/TimelineItem.h index 1adf574c..d90810d5 100644 --- a/include/TimelineItem.h +++ b/include/TimelineItem.h @@ -19,6 +19,9 @@ #include #include +#include +#include +#include #include "Emote.h" #include "Image.h" @@ -67,6 +70,9 @@ public: ~TimelineItem(); +protected: + void paintEvent(QPaintEvent *event) override; + private: void init(); diff --git a/include/TimelineView.h b/include/TimelineView.h index bc7c41e6..78c31e8e 100644 --- a/include/TimelineView.h +++ b/include/TimelineView.h @@ -21,6 +21,8 @@ #include #include #include +#include +#include #include "Emote.h" #include "Image.h" @@ -110,7 +112,7 @@ public slots: void addBackwardsEvents(const QString &room_id, const RoomMessages &msgs); // Whether or not the initial batch has been loaded. - bool hasLoaded() { return scroll_layout_->count() > 1 || isTimelineFinished; }; + bool hasLoaded() { return scroll_layout_->count() > 1 || isTimelineFinished; } void handleFailedMessage(int txnid); @@ -120,6 +122,9 @@ private slots: signals: void updateLastTimelineMessage(const QString &user, const DescInfo &info); +protected: + void paintEvent(QPaintEvent *event) override; + private: void init(); void addTimelineItem(TimelineItem *item, TimelineDirection direction); @@ -133,7 +138,7 @@ private: bool isPendingMessage(const QString &txnid, const QString &sender, const QString &userid); void removePendingMessage(const QString &txnid); - bool isDuplicate(const QString &event_id) { return eventIds_.contains(event_id); }; + bool isDuplicate(const QString &event_id) { return eventIds_.contains(event_id); } void handleNewUserMessage(PendingMessage msg); diff --git a/include/TopRoomBar.h b/include/TopRoomBar.h index f1e93d9d..2f65428d 100644 --- a/include/TopRoomBar.h +++ b/include/TopRoomBar.h @@ -34,7 +34,7 @@ class Menu; class OverlayModal; class RoomSettings; -static const QString URL_HTML = "\\1"; +static const QString URL_HTML = "\\1"; static const QRegExp URL_REGEX("((?:https?|ftp)://\\S+)"); class TopRoomBar : public QWidget diff --git a/include/UserInfoWidget.h b/include/UserInfoWidget.h index 111f5808..2acfedb8 100644 --- a/include/UserInfoWidget.h +++ b/include/UserInfoWidget.h @@ -44,6 +44,7 @@ signals: protected: void resizeEvent(QResizeEvent *event) override; + void paintEvent(QPaintEvent *event) override; private slots: void closeLogoutDialog(bool isLoggingOut); diff --git a/include/ui/LoadingIndicator.h b/include/ui/LoadingIndicator.h index 75920dd8..bb33fe6c 100644 --- a/include/ui/LoadingIndicator.h +++ b/include/ui/LoadingIndicator.h @@ -9,6 +9,7 @@ class LoadingIndicator : public QWidget { Q_OBJECT + Q_PROPERTY(QColor color READ color WRITE setColor) public: LoadingIndicator(QWidget *parent = 0); diff --git a/include/ui/OverlayWidget.h b/include/ui/OverlayWidget.h index 2984e469..6662479d 100644 --- a/include/ui/OverlayWidget.h +++ b/include/ui/OverlayWidget.h @@ -1,6 +1,8 @@ #pragma once #include +#include +#include #include class OverlayWidget : public QWidget @@ -15,4 +17,5 @@ protected: bool eventFilter(QObject *obj, QEvent *event) override; QRect overlayGeometry() const; + void paintEvent(QPaintEvent *event) override; }; diff --git a/resources/res.qrc b/resources/res.qrc index 55962275..9bd977a2 100644 --- a/resources/res.qrc +++ b/resources/res.qrc @@ -42,7 +42,6 @@ icons/emoji-categories/flags.png icons/emoji-categories/flags@2x.png - nheko.png @@ -62,13 +61,15 @@ nheko-32.png nheko-16.png - fonts/OpenSans/OpenSans-Regular.ttf fonts/OpenSans/OpenSans-Italic.ttf fonts/OpenSans/OpenSans-Bold.ttf fonts/OpenSans/OpenSans-Semibold.ttf - fonts/EmojiOne/emojione-android.ttf + + styles/system.qss + styles/nheko.qss + diff --git a/resources/styles/nheko.qss b/resources/styles/nheko.qss new file mode 100644 index 00000000..caaac6b9 --- /dev/null +++ b/resources/styles/nheko.qss @@ -0,0 +1,56 @@ +* { + color: #333; +} + +QLabel { + color: #333; +} + +#chatPage, #chatPage > * { background-color: white; } + +TimelineView, TimelineView > * { background-color: white; } + +QMenu, QMenu > * { background-color: white; } + +FlatButton { qproperty-foregroundColor: #333; } + +RaisedButton { qproperty-foregroundColor: white; } + +RoomInfoListItem +{ + qproperty-highlightedBackgroundColor: #38A3D8; + qproperty-hoverBackgroundColor: rgba(200, 200, 200, 128); + qproperty-backgroundColor: white; + + qproperty-titleColor: #333; + qproperty-subtitleColor: #5d6565; + + qproperty-highlightedTitleColor: white; + qproperty-highlightedSubtitleColor: white; +} + +#ChatPageLoadSpinner { + qproperty-color: #acc7dc; +} + +#FileUploadSpinner { + qproperty-color: #333; +} + +UserInfoWidget, UserInfoWidget > * { + background-color: #d6dde3; + color: #ebebeb; +} + +Avatar { + qproperty-textColor: black; + qproperty-backgroundColor: #eee; +} + +#displayNameLabel { + color: #171919; +} + +#userIdLabel { + color: #555459; +} diff --git a/resources/styles/system.qss b/resources/styles/system.qss new file mode 100644 index 00000000..2f15271f --- /dev/null +++ b/resources/styles/system.qss @@ -0,0 +1,39 @@ +OverlayWidget, OverlayWidget > * { + background-color: palette(window); +} + +#mainContent, #mainContent > * { + background-color: palette(base); +} + +TimelineView, TimelineView > *, TimelineItem, TimelineItem > * { + background-color: palette(base); +} + +FlatButton { + qproperty-foregroundColor: palette(text); +} + +RoomInfoListItem { + qproperty-highlightedBackgroundColor: palette(highlight); + qproperty-hoverBackgroundColor: palette(dark); + qproperty-backgroundColor: palette(window); + + qproperty-titleColor: palette(text); + qproperty-subtitleColor: palette(text); + + qproperty-highlightedTitleColor: palette(text); + qproperty-highlightedSubtitleColor: palette(text); +} + +LoadingIndicator { + qproperty-color: palette(text); +} + +#ChatPageLoadSpinner { + qproperty-color: #acc7dc; +} + +UserInfoWidget, UserInfoWidget > * { + background-color: palette(window); +} diff --git a/src/ChatPage.cc b/src/ChatPage.cc index 4091086b..37e05c34 100644 --- a/src/ChatPage.cc +++ b/src/ChatPage.cc @@ -49,7 +49,7 @@ ChatPage::ChatPage(QSharedPointer client, QWidget *parent) : QWidget(parent) , client_(client) { - setStyleSheet("background-color: #fff;"); + setObjectName("chatPage"); topLayout_ = new QHBoxLayout(this); topLayout_->setSpacing(0); @@ -79,7 +79,8 @@ ChatPage::ChatPage(QSharedPointer client, QWidget *parent) sideBarLayout_->addWidget(sidebarActions_); // Content - content_ = new QFrame(this); + content_ = new QFrame(this); + content_->setObjectName("mainContent"); contentLayout_ = new QVBoxLayout(content_); contentLayout_->setSpacing(0); contentLayout_->setMargin(0); @@ -544,7 +545,7 @@ ChatPage::showQuickSwitcher() new OverlayModal(MainWindow::instance(), quickSwitcher_.data()), [=](OverlayModal *modal) { modal->deleteLater(); }); quickSwitcherModal_->setDuration(0); - quickSwitcherModal_->setColor(QColor(30, 30, 30, 170)); + // quickSwitcherModal_->setColor(QColor(30, 30, 30, 170)); } QMap rooms; diff --git a/src/EmojiPanel.cc b/src/EmojiPanel.cc index 3f5f8369..82eb8afc 100644 --- a/src/EmojiPanel.cc +++ b/src/EmojiPanel.cc @@ -32,11 +32,9 @@ EmojiPanel::EmojiPanel(QWidget *parent) , animationDuration_{100} , categoryIconSize_{20} { - setStyleSheet("QWidget {background: #fff; color: #e8e8e8; border: none;}" - "QScrollBar:vertical { background-color: #fff; width: 8px; margin: 0px " - "2px 0 2px; }" - "QScrollBar::handle:vertical { background-color: #d6dde3; min-height: " - "20px; }" + setStyleSheet("QWidget {border: none;}" + "QScrollBar:vertical { width: 8px; margin: 0px 2px 0 2px; }" + "QScrollBar::handle:vertical { min-height: 20px; }" "QScrollBar::add-line:vertical { border: none; background: none; }" "QScrollBar::sub-line:vertical { border: none; background: none; }"); @@ -55,7 +53,7 @@ EmojiPanel::EmojiPanel(QWidget *parent) contentLayout->setMargin(0); auto emojiCategories = new QFrame(mainWidget); - emojiCategories->setStyleSheet("background-color: #f2f2f2"); + // emojiCategories->setStyleSheet("background-color: #f2f2f2"); auto categoriesLayout = new QHBoxLayout(emojiCategories); categoriesLayout->setSpacing(6); @@ -250,6 +248,10 @@ EmojiPanel::leaveEvent(QEvent *event) void EmojiPanel::paintEvent(QPaintEvent *event) { + Q_UNUSED(event); + + QStyleOption opt; + opt.init(this); QPainter p(this); DropShadow::draw(p, shadowMargin_, @@ -262,7 +264,8 @@ EmojiPanel::paintEvent(QPaintEvent *event) width(), height()); - QWidget::paintEvent(event); + style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this); + // QWidget::paintEvent(event); } void diff --git a/src/LoginPage.cc b/src/LoginPage.cc index 0b65f8bc..5c766b78 100644 --- a/src/LoginPage.cc +++ b/src/LoginPage.cc @@ -30,7 +30,7 @@ LoginPage::LoginPage(QSharedPointer client, QWidget *parent) , inferredServerAddress_() , client_{client} { - setStyleSheet("background-color: #fff"); + // setStyleSheet("background-color: #fff"); top_layout_ = new QVBoxLayout(); @@ -40,7 +40,7 @@ LoginPage::LoginPage(QSharedPointer client, QWidget *parent) back_button_ = new FlatButton(this); back_button_->setMinimumSize(QSize(30, 30)); - back_button_->setForegroundColor("#333333"); + // back_button_->setForegroundColor("#333333"); top_bar_layout_->addWidget(back_button_, 0, Qt::AlignLeft | Qt::AlignVCenter); top_bar_layout_->addStretch(1); @@ -75,10 +75,10 @@ LoginPage::LoginPage(QSharedPointer client, QWidget *parent) form_wrapper_->addStretch(1); matrixid_input_ = new TextField(this); - matrixid_input_->setTextColor("#333333"); + // matrixid_input_->setTextColor("#333333"); matrixid_input_->setLabel(tr("Matrix ID")); - matrixid_input_->setInkColor("#555459"); - matrixid_input_->setBackgroundColor("#fff"); + // matrixid_input_->setInkColor("#555459"); + // matrixid_input_->setBackgroundColor("#fff"); matrixid_input_->setPlaceholderText(tr("e.g @joe:matrix.org")); spinner_ = new LoadingIndicator(this); @@ -95,17 +95,17 @@ LoginPage::LoginPage(QSharedPointer client, QWidget *parent) matrixidLayout_->addWidget(matrixid_input_, 0, Qt::AlignVCenter); password_input_ = new TextField(this); - password_input_->setTextColor("#333333"); + // password_input_->setTextColor("#333333"); password_input_->setLabel(tr("Password")); - password_input_->setInkColor("#555459"); - password_input_->setBackgroundColor("#fff"); + // password_input_->setInkColor("#555459"); + // password_input_->setBackgroundColor("#fff"); password_input_->setEchoMode(QLineEdit::Password); serverInput_ = new TextField(this); - serverInput_->setTextColor("#333333"); + // serverInput_->setTextColor("#333333"); serverInput_->setLabel("Homeserver address"); - serverInput_->setInkColor("#555459"); - serverInput_->setBackgroundColor("#fff"); + // serverInput_->setInkColor("#555459"); + // serverInput_->setBackgroundColor("#fff"); serverInput_->setPlaceholderText("matrix.org"); serverInput_->hide(); @@ -121,8 +121,8 @@ LoginPage::LoginPage(QSharedPointer client, QWidget *parent) button_layout_->setContentsMargins(0, 0, 0, 30); login_button_ = new RaisedButton(tr("LOGIN"), this); - login_button_->setBackgroundColor(QColor("#333333")); - login_button_->setForegroundColor(QColor("white")); + // login_button_->setBackgroundColor(QColor("#333333")); + // login_button_->setForegroundColor(QColor("white")); login_button_->setMinimumSize(350, 65); login_button_->setFontSize(20); login_button_->setCornerRadius(3); @@ -136,7 +136,7 @@ LoginPage::LoginPage(QSharedPointer client, QWidget *parent) error_label_ = new QLabel(this); error_label_->setFont(font); - error_label_->setStyleSheet("color: #E22826"); + // error_label_->setStyleSheet("color: #E22826"); top_layout_->addLayout(top_bar_layout_); top_layout_->addStretch(1); diff --git a/src/LogoutDialog.cc b/src/LogoutDialog.cc index 7f2cdbd3..c0db1270 100644 --- a/src/LogoutDialog.cc +++ b/src/LogoutDialog.cc @@ -27,7 +27,7 @@ LogoutDialog::LogoutDialog(QWidget *parent) : QFrame(parent) { setMaximumSize(400, 400); - setStyleSheet("background-color: #fff"); + // setStyleSheet("background-color: #fff"); auto layout = new QVBoxLayout(this); layout->setSpacing(30); @@ -52,7 +52,7 @@ LogoutDialog::LogoutDialog(QWidget *parent) auto label = new QLabel(tr("Logout. Are you sure?"), this); label->setFont(font); - label->setStyleSheet("color: #333333"); + // label->setStyleSheet("color: #333333"); layout->addWidget(label); layout->addLayout(buttonLayout); diff --git a/src/MainWindow.cc b/src/MainWindow.cc index c5735b68..04b0e8e3 100644 --- a/src/MainWindow.cc +++ b/src/MainWindow.cc @@ -43,7 +43,6 @@ MainWindow::MainWindow(QWidget *parent) { setWindowTitle("nheko"); setObjectName("MainWindow"); - setStyleSheet("QWidget#MainWindow {background-color: #fff}"); restoreWindowSize(); @@ -204,9 +203,9 @@ MainWindow::showChatPage(QString userid, QString homeserver, QString token) spinner_ = QSharedPointer( new LoadingIndicator(this), [=](LoadingIndicator *indicator) { indicator->deleteLater(); }); - spinner_->setColor("#acc7dc"); spinner_->setFixedHeight(100); spinner_->setFixedWidth(100); + spinner_->setObjectName("ChatPageLoadSpinner"); spinner_->start(); } diff --git a/src/RegisterPage.cc b/src/RegisterPage.cc index 304a7dc0..01f3b28f 100644 --- a/src/RegisterPage.cc +++ b/src/RegisterPage.cc @@ -28,7 +28,7 @@ RegisterPage::RegisterPage(QSharedPointer client, QWidget *parent) : QWidget(parent) , client_(client) { - setStyleSheet("background-color: #fff"); + // setStyleSheet("background-color: #fff"); top_layout_ = new QVBoxLayout(); @@ -73,30 +73,30 @@ RegisterPage::RegisterPage(QSharedPointer client, QWidget *parent) form_wrapper_->addStretch(1); username_input_ = new TextField(); - username_input_->setTextColor("#333333"); + // username_input_->setTextColor("#333333"); username_input_->setLabel(tr("Username")); - username_input_->setInkColor("#555459"); - username_input_->setBackgroundColor("#fff"); + // username_input_->setInkColor("#555459"); + // username_input_->setBackgroundColor("#fff"); password_input_ = new TextField(); - password_input_->setTextColor("#333333"); + // password_input_->setTextColor("#333333"); password_input_->setLabel(tr("Password")); - password_input_->setInkColor("#555459"); - password_input_->setBackgroundColor("#fff"); + // password_input_->setInkColor("#555459"); + // password_input_->setBackgroundColor("#fff"); password_input_->setEchoMode(QLineEdit::Password); password_confirmation_ = new TextField(); - password_confirmation_->setTextColor("#333333"); + // password_confirmation_->setTextColor("#333333"); password_confirmation_->setLabel(tr("Password confirmation")); - password_confirmation_->setInkColor("#555459"); - password_confirmation_->setBackgroundColor("#fff"); + // password_confirmation_->setInkColor("#555459"); + // password_confirmation_->setBackgroundColor("#fff"); password_confirmation_->setEchoMode(QLineEdit::Password); server_input_ = new TextField(); - server_input_->setTextColor("#333333"); + // server_input_->setTextColor("#333333"); server_input_->setLabel(tr("Home Server")); - server_input_->setInkColor("#555459"); - server_input_->setBackgroundColor("#fff"); + // server_input_->setInkColor("#555459"); + // server_input_->setBackgroundColor("#fff"); form_layout_->addWidget(username_input_, Qt::AlignHCenter, 0); form_layout_->addWidget(password_input_, Qt::AlignHCenter, 0); @@ -112,11 +112,11 @@ RegisterPage::RegisterPage(QSharedPointer client, QWidget *parent) error_label_ = new QLabel(this); error_label_->setFont(font); - error_label_->setStyleSheet("color: #E22826"); + // error_label_->setStyleSheet("color: #E22826"); register_button_ = new RaisedButton(tr("REGISTER"), this); - register_button_->setBackgroundColor(QColor("#333333")); - register_button_->setForegroundColor(QColor("white")); + // register_button_->setBackgroundColor(QColor("#333333")); + // register_button_->setForegroundColor(QColor("white")); register_button_->setMinimumSize(350, 65); register_button_->setFontSize(conf::btn::fontSize); register_button_->setCornerRadius(conf::btn::cornerRadius); diff --git a/src/RoomInfoListItem.cc b/src/RoomInfoListItem.cc index 49b24b58..875bb506 100644 --- a/src/RoomInfoListItem.cc +++ b/src/RoomInfoListItem.cc @@ -95,18 +95,19 @@ RoomInfoListItem::paintEvent(QPaintEvent *event) p.setRenderHint(QPainter::SmoothPixmapTransform); p.setRenderHint(QPainter::Antialiasing); - if (isPressed_) - p.fillRect(rect(), QColor("#38A3D8")); - else if (underMouse()) - p.fillRect(rect(), QColor(200, 200, 200, 128)); - else - p.fillRect(rect(), QColor("#FFF")); - QFont font; font.setPixelSize(conf::fontSize); QFontMetrics metrics(font); - p.setPen(QColor("#333")); + if (isPressed_) { + p.fillRect(rect(), highlightedBackgroundColor_); + } else if (underMouse()) { + p.fillRect(rect(), hoverBackgroundColor_); + } else { + p.fillRect(rect(), backgroundColor_); + } + + // p.setPen(QColor("#333")); QRect avatarRegion(Padding, Padding, IconSize, IconSize); @@ -115,10 +116,12 @@ RoomInfoListItem::paintEvent(QPaintEvent *event) if (width() > ui::sidebar::SmallSize) { if (isPressed_) { - QPen pen(QColor("white")); + QPen pen(highlightedTitleColor_); + p.setPen(pen); + } else { + QPen pen(titleColor_); p.setPen(pen); } - font.setPixelSize(conf::roomlist::fonts::heading); p.setFont(font); @@ -130,8 +133,11 @@ RoomInfoListItem::paintEvent(QPaintEvent *event) state_.getName(), Qt::ElideRight, (width() - IconSize - 2 * Padding) * 0.8); p.drawText(QPoint(2 * Padding + IconSize, top_y), name); - if (!isPressed_) { - QPen pen(QColor("#5d6565")); + if (isPressed_) { + QPen pen(highlightedSubtitleColor_); + p.setPen(pen); + } else { + QPen pen(subtitleColor_); p.setPen(pen); } diff --git a/src/RoomList.cc b/src/RoomList.cc index a0b95748..f23b22cb 100644 --- a/src/RoomList.cc +++ b/src/RoomList.cc @@ -33,9 +33,7 @@ RoomList::RoomList(QSharedPointer client, QWidget *parent) : QWidget(parent) , client_(client) { - setStyleSheet( - "border: 1px solid #ccc; border-right: 0px solid #000; border-left: 0px solid #000;"); - + setStyleSheet("border: none;"); topLayout_ = new QVBoxLayout(this); topLayout_->setSpacing(0); topLayout_->setMargin(0); diff --git a/src/TextInputWidget.cc b/src/TextInputWidget.cc index d71769f4..829784fd 100644 --- a/src/TextInputWidget.cc +++ b/src/TextInputWidget.cc @@ -133,8 +133,8 @@ FilteredTextEdit::minimumSizeHint() const void FilteredTextEdit::submit() { - if (toPlainText().trimmed().isEmpty()) - return; + if (toPlainText().trimmed().isEmpty()) + return; if (true_history_.size() == INPUT_HISTORY_SIZE) true_history_.pop_back(); @@ -176,7 +176,6 @@ TextInputWidget::TextInputWidget(QWidget *parent) setFixedHeight(conf::textInput::height); setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); setCursor(Qt::ArrowCursor); - setStyleSheet("background-color: #fff;"); topLayout_ = new QHBoxLayout(); topLayout_->setSpacing(0); @@ -192,6 +191,7 @@ TextInputWidget::TextInputWidget(QWidget *parent) spinner_ = new LoadingIndicator(this); spinner_->setFixedHeight(32); spinner_->setFixedWidth(32); + spinner_->setObjectName("FileUploadSpinner"); spinner_->hide(); QFont font; @@ -202,7 +202,7 @@ TextInputWidget::TextInputWidget(QWidget *parent) input_->setFont(font); input_->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); input_->setPlaceholderText(tr("Write a message...")); - input_->setStyleSheet("color: #333333; border: none; padding-top: 5px; margin: 0 5px"); + input_->setStyleSheet("border: none; padding-top: 5px;"); sendMessageBtn_ = new FlatButton(this); @@ -335,3 +335,12 @@ TextInputWidget::focusInEvent(QFocusEvent *event) { input_->setFocus(event->reason()); } + +void +TextInputWidget::paintEvent(QPaintEvent *) +{ + QStyleOption opt; + opt.init(this); + QPainter p(this); + style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this); +} 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); +} diff --git a/src/TimelineView.cc b/src/TimelineView.cc index b1fb2ad0..267fbbff 100644 --- a/src/TimelineView.cc +++ b/src/TimelineView.cc @@ -399,7 +399,6 @@ TimelineView::init() const int max = scroll_area_->verticalScrollBar()->maximum(); scroll_area_->verticalScrollBar()->setValue(max); }); - top_layout_ = new QVBoxLayout(this); top_layout_->setSpacing(0); top_layout_->setMargin(0); @@ -416,6 +415,7 @@ TimelineView::init() scroll_layout_ = new QVBoxLayout(scroll_widget_); scroll_layout_->addStretch(1); scroll_layout_->setSpacing(0); + scroll_layout_->setObjectName("timelinescrollarea"); scroll_area_->setWidget(scroll_widget_); @@ -639,3 +639,12 @@ TimelineView::handleFailedMessage(int txnid) // Note: We do this even if the message has already been echoed. QTimer::singleShot(500, this, SLOT(sendNextPendingMessage())); } + +void +TimelineView::paintEvent(QPaintEvent *) +{ + QStyleOption opt; + opt.init(this); + QPainter p(this); + style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this); +} diff --git a/src/TopRoomBar.cc b/src/TopRoomBar.cc index 7bec888d..d852ae32 100644 --- a/src/TopRoomBar.cc +++ b/src/TopRoomBar.cc @@ -41,8 +41,6 @@ TopRoomBar::TopRoomBar(QWidget *parent) avatar_ = new Avatar(this); avatar_->setLetter(QChar('?')); - avatar_->setBackgroundColor(QColor("#d6dde3")); - avatar_->setTextColor(QColor("#555459")); avatar_->setSize(35); textLayout_ = new QVBoxLayout(); diff --git a/src/UserInfoWidget.cc b/src/UserInfoWidget.cc index f5f3db74..27d6cbbe 100644 --- a/src/UserInfoWidget.cc +++ b/src/UserInfoWidget.cc @@ -43,17 +43,19 @@ UserInfoWidget::UserInfoWidget(QWidget *parent) textLayout_ = new QVBoxLayout(); userAvatar_ = new Avatar(this); + userAvatar_->setObjectName("userAvatar"); userAvatar_->setLetter(QChar('?')); userAvatar_->setSize(55); - userAvatar_->setBackgroundColor("#fff"); - userAvatar_->setTextColor("#333333"); + // userAvatar_->setBackgroundColor("#fff"); + // userAvatar_->setTextColor("#333333"); QFont nameFont("Open Sans SemiBold"); nameFont.setPixelSize(conf::userInfoWidget::fonts::displayName); displayNameLabel_ = new QLabel(this); displayNameLabel_->setFont(nameFont); - displayNameLabel_->setStyleSheet("padding: 0 9px; color: #171919; margin-bottom: -10px;"); + displayNameLabel_->setObjectName("displayNameLabel"); + displayNameLabel_->setStyleSheet("padding: 0 9px; margin-bottom: -10px;"); displayNameLabel_->setAlignment(Qt::AlignLeading | Qt::AlignLeft | Qt::AlignTop); QFont useridFont("Open Sans"); @@ -61,7 +63,8 @@ UserInfoWidget::UserInfoWidget(QWidget *parent) userIdLabel_ = new QLabel(this); userIdLabel_->setFont(useridFont); - userIdLabel_->setStyleSheet("padding: 0 8px 8px 8px; color: #555459;"); + userIdLabel_->setObjectName("userIdLabel"); + userIdLabel_->setStyleSheet("padding: 0 8px 8px 8px;"); userIdLabel_->setAlignment(Qt::AlignLeading | Qt::AlignLeft | Qt::AlignVCenter); avatarLayout_->addWidget(userAvatar_); @@ -177,3 +180,14 @@ UserInfoWidget::setUserId(const QString &userid) user_id_ = userid; userIdLabel_->setText(userid); } + +void +UserInfoWidget::paintEvent(QPaintEvent *event) +{ + Q_UNUSED(event); + + QStyleOption opt; + opt.init(this); + QPainter p(this); + style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this); +} diff --git a/src/UserSettingsPage.cc b/src/UserSettingsPage.cc index 10754cfd..e53ad668 100644 --- a/src/UserSettingsPage.cc +++ b/src/UserSettingsPage.cc @@ -72,7 +72,7 @@ UserSettingsPage::UserSettingsPage(QSharedPointer settings, QWidge backBtn_->setIconSize(QSize(24, 24)); auto heading_ = new QLabel(tr("User Settings")); - heading_->setFont(QFont("Open Sans Bold", 22)); + heading_->setStyleSheet("font-weight: bold; font-size: 22px;"); topBarLayout_ = new QHBoxLayout; topBarLayout_->setSpacing(0); @@ -87,7 +87,7 @@ UserSettingsPage::UserSettingsPage(QSharedPointer settings, QWidge trayToggle_ = new Toggle(this); trayToggle_->setActiveColor(QColor("#38A3D8")); trayToggle_->setInactiveColor(QColor("gray")); - trayLabel->setFont(QFont("Open Sans", 15)); + trayLabel->setStyleSheet("font-size: 15px;"); trayOptionLayout_->addWidget(trayLabel); trayOptionLayout_->addWidget(trayToggle_, 0, Qt::AlignBottom | Qt::AlignRight); @@ -98,14 +98,13 @@ UserSettingsPage::UserSettingsPage(QSharedPointer settings, QWidge themeCombo_ = new QComboBox(this); themeCombo_->addItem("Default"); themeCombo_->addItem("System"); - themeLabel_->setFont(QFont("Open Sans", 15)); + themeLabel_->setStyleSheet("font-size: 15px;"); themeOptionLayout_->addWidget(themeLabel_); themeOptionLayout_->addWidget(themeCombo_, 0, Qt::AlignBottom | Qt::AlignRight); auto general_ = new QLabel(tr("GENERAL"), this); - general_->setFont(QFont("Open Sans Bold", 17)); - general_->setStyleSheet("color: #5d6565"); + general_->setStyleSheet("font-size: 17px; color: #5d6565"); mainLayout_ = new QVBoxLayout; mainLayout_->setSpacing(7); diff --git a/src/main.cc b/src/main.cc index 8bd77254..9ca1d5de 100644 --- a/src/main.cc +++ b/src/main.cc @@ -17,6 +17,7 @@ #include #include +#include #include #include #include @@ -72,6 +73,21 @@ main(int argc, char *argv[]) QSettings settings; + QFile stylefile; + + if (!settings.contains("user/theme")) { + settings.setValue("user/theme", "default"); + } + + if (settings.value("user/theme").toString() == "default") { + stylefile.setFileName(":/styles/styles/nheko.qss"); + } else { + stylefile.setFileName(":/styles/styles/system.qss"); + } + stylefile.open(QFile::ReadOnly); + QString stylesheet = QString(stylefile.readAll()); + + app.setStyleSheet(stylesheet); // Set the default if a value has not been set. if (settings.value("font/size").toInt() == 0) settings.setValue("font/size", 12); diff --git a/src/ui/Badge.cc b/src/ui/Badge.cc index 6e73eca0..016ed64f 100644 --- a/src/ui/Badge.cc +++ b/src/ui/Badge.cc @@ -176,7 +176,6 @@ Badge::paintEvent(QPaintEvent *) QBrush brush; brush.setStyle(Qt::SolidPattern); - brush.setColor(isEnabled() ? backgroundColor() : QColor("#cccccc")); painter.setBrush(brush); painter.setPen(Qt::NoPen); diff --git a/src/ui/OverlayWidget.cc b/src/ui/OverlayWidget.cc index c69f81f7..ccac0116 100644 --- a/src/ui/OverlayWidget.cc +++ b/src/ui/OverlayWidget.cc @@ -59,3 +59,14 @@ OverlayWidget::overlayGeometry() const return widget->rect(); } + +void +OverlayWidget::paintEvent(QPaintEvent *event) +{ + Q_UNUSED(event); + + QStyleOption opt; + opt.init(this); + QPainter p(this); + style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this); +} diff --git a/src/ui/TextField.cc b/src/ui/TextField.cc index e038f2dd..d80d6466 100644 --- a/src/ui/TextField.cc +++ b/src/ui/TextField.cc @@ -197,8 +197,6 @@ TextField::paintEvent(QPaintEvent *event) if (text().isEmpty()) { painter.setOpacity(1 - state_machine_->progress()); - // painter.fillRect(rect(), - // parentWidget()->palette().color(backgroundRole())); painter.fillRect(rect(), backgroundColor()); } -- cgit v1.2.3