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 +++ 8 files changed, 74 insertions(+), 8 deletions(-) (limited to 'include') 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; }; -- cgit 1.5.1