From ee893c5adf531b3c216d936fba2d92eefeefe591 Mon Sep 17 00:00:00 2001 From: Max Sandholm Date: Mon, 30 Oct 2017 14:34:12 +0200 Subject: [PATCH] Stylesheet for system theme now works --- include/RoomInfoListItem.h | 27 ++++++++++++++++++++++++--- include/TimelineItem.h | 6 ++++++ include/TimelineView.h | 5 +++++ resources/styles/system.qss | 15 +++++++++++++-- src/ChatPage.cc | 2 +- src/RoomInfoListItem.cc | 6 +++--- src/TimelineItem.cc | 9 +++++++++ src/TimelineView.cc | 9 +++++++++ src/main.cc | 1 + src/ui/TextField.cc | 2 -- 10 files changed, 71 insertions(+), 11 deletions(-) diff --git a/include/RoomInfoListItem.h b/include/RoomInfoListItem.h index a137b37f..a00610fa 100644 --- a/include/RoomInfoListItem.h +++ b/include/RoomInfoListItem.h @@ -38,6 +38,15 @@ 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) public: RoomInfoListItem(QSharedPointer settings, @@ -51,13 +60,21 @@ 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 void setHighlightedBackgroundColor(QColor &color) { highlightedBackgroundColor_ = color; } + inline void setHoverBackgroundColor(QColor &color) { hoverBackgroundColor_ = color; } + inline void setBackgroundColor(QColor &color) { backgroundColor_ = color; } + signals: void clicked(const QString &room_id); void leaveRoom(const QString &room_id); @@ -98,4 +115,8 @@ private: int maxHeight_; int unreadMsgCount_ = 0; + + QColor highlightedBackgroundColor_; + QColor hoverBackgroundColor_; + QColor backgroundColor_; }; diff --git a/include/TimelineItem.h b/include/TimelineItem.h index 1adf574c..126ce584 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..09a583b1 100644 --- a/include/TimelineView.h +++ b/include/TimelineView.h @@ -21,6 +21,8 @@ #include #include #include +#include +#include #include "Emote.h" #include "Image.h" @@ -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); diff --git a/resources/styles/system.qss b/resources/styles/system.qss index f357f426..307709b9 100644 --- a/resources/styles/system.qss +++ b/resources/styles/system.qss @@ -1,2 +1,13 @@ -TimelineView { background-color: red; } -TimelineItem { background-color: rgba(255,0,0,255); } +TimelineView, TimelineView > * { + background-color: palette(base); +} + +FlatButton { + qproperty-foregroundColor: palette(text); +} + +RoomInfoListItem { + qproperty-highlightedBackgroundColor: palette(highlight); + qproperty-hoverBackgroundColor: palette(dark); + qproperty-backgroundColor: palette(window); +} diff --git a/src/ChatPage.cc b/src/ChatPage.cc index 42e09df4..814ddad2 100644 --- a/src/ChatPage.cc +++ b/src/ChatPage.cc @@ -54,7 +54,7 @@ ChatPage::ChatPage(QSharedPointer client, QWidget *parent) topLayout_->setMargin(0); auto splitter = new Splitter(this); - splitter->setHandleWidth(1); + splitter->setHandleWidth(0); topLayout_->addWidget(splitter); diff --git a/src/RoomInfoListItem.cc b/src/RoomInfoListItem.cc index b3e360b0..5937e0bd 100644 --- a/src/RoomInfoListItem.cc +++ b/src/RoomInfoListItem.cc @@ -96,11 +96,11 @@ RoomInfoListItem::paintEvent(QPaintEvent *event) p.setRenderHint(QPainter::Antialiasing); if (isPressed_) - p.fillRect(rect(), palette().color(QPalette::Highlight)); + p.fillRect(rect(), highlightedBackgroundColor_); else if (underMouse()) - p.fillRect(rect(), palette().color(QPalette::Dark)); + p.fillRect(rect(), hoverBackgroundColor_); else - p.fillRect(rect(), palette().color(QPalette::Window)); + p.fillRect(rect(), backgroundColor_); QFont font; font.setPixelSize(conf::fontSize); diff --git a/src/TimelineItem.cc b/src/TimelineItem.cc index c7949044..cdaeac15 100644 --- a/src/TimelineItem.cc +++ b/src/TimelineItem.cc @@ -468,3 +468,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 761fe015..4025fc36 100644 --- a/src/TimelineView.cc +++ b/src/TimelineView.cc @@ -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/main.cc b/src/main.cc index f800c9ae..7daaeefa 100644 --- a/src/main.cc +++ b/src/main.cc @@ -22,6 +22,7 @@ #include #include #include +#include #include "MainWindow.h" 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()); }