From d01fed92f08dfaf9ed8a54fdc275b51b22b56ba7 Mon Sep 17 00:00:00 2001 From: bodwok Date: Thu, 9 Apr 2020 15:53:02 +0300 Subject: [PATCH 1/3] fix(ui): updating friends list color at runtime --- src/widget/genericchatroomwidget.cpp | 59 +++++++++++++++++----------- src/widget/genericchatroomwidget.h | 10 +++++ 2 files changed, 47 insertions(+), 22 deletions(-) diff --git a/src/widget/genericchatroomwidget.cpp b/src/widget/genericchatroomwidget.cpp index 18804caa1..2e09f02d9 100644 --- a/src/widget/genericchatroomwidget.cpp +++ b/src/widget/genericchatroomwidget.cpp @@ -42,8 +42,10 @@ GenericChatroomWidget::GenericChatroomWidget(bool compact, QWidget* parent) statusMessageLabel = new CroppingLabel(this); statusMessageLabel->setTextFormat(Qt::PlainText); statusMessageLabel->setForegroundRole(QPalette::WindowText); + statusMessageLabel->setObjectName("statusMessageLabelObj"); nameLabel->setForegroundRole(QPalette::WindowText); + nameLabel->setObjectName("nameLabelObj"); Settings& s = Settings::getInstance(); connect(&s, &Settings::compactLayoutChanged, this, &GenericChatroomWidget::compactChange); @@ -123,14 +125,38 @@ void GenericChatroomWidget::setActive(bool _active) { active = _active; if (active) { - setBackgroundRole(QPalette::Light); - statusMessageLabel->setForegroundRole(QPalette::HighlightedText); - nameLabel->setForegroundRole(QPalette::HighlightedText); + currentColors.baseBackground = Style::getColor(Style::GroundBase); // When active + currentColors.statusLbl = Style::getColor(Style::StatusActive); // Color when active + currentColors.nameLbl = Style::getColor(Style::NameActive); // Color when active } else { - setBackgroundRole(QPalette::Window); - statusMessageLabel->setForegroundRole(QPalette::WindowText); - nameLabel->setForegroundRole(QPalette::WindowText); + currentColors.baseBackground = Style::getColor(Style::ThemeMedium); // Base background color + currentColors.statusLbl = Style::getColor(Style::GroundExtra); // Base color + currentColors.nameLbl = Style::getColor(Style::GroundBase); // Base color } + + changeStyle(); +} + +void GenericChatroomWidget::changeStyle() +{ + QString wgtStyle = QString("GenericChatroomWidget {" + " background-color: #%1;" // Base background color + "}" + "GenericChatroomWidget:hover {" + " background-color: #%2;" // On mouse over + "}" + "CroppingLabel#statusMessageLabelObj {" + " color: #%3;" + "}" + "CroppingLabel#nameLabelObj {" + " color: #%4;" + "}") + .arg(currentColors.baseBackground.rgba(), 0, 16) + .arg(currentColors.mouseOver.rgba(), 0, 16) + .arg(currentColors.statusLbl.rgba(), 0, 16) + .arg(currentColors.nameLbl.rgba(), 0, 16); + + setStyleSheet(wgtStyle); } void GenericChatroomWidget::setName(const QString& name) @@ -160,23 +186,12 @@ QString GenericChatroomWidget::getTitle() const void GenericChatroomWidget::reloadTheme() { - QPalette p; + currentColors.baseBackground = Style::getColor(Style::ThemeMedium); // Base background color + currentColors.mouseOver = Style::getColor(Style::ThemeLight); // On mouse over + currentColors.statusLbl = Style::getColor(Style::GroundExtra); // statusMessageLabel base color + currentColors.nameLbl = Style::getColor(Style::GroundBase); // nameLabel base color - p = statusMessageLabel->palette(); - p.setColor(QPalette::WindowText, Style::getColor(Style::GroundExtra)); // Base color - p.setColor(QPalette::HighlightedText, Style::getColor(Style::StatusActive)); // Color when active - statusMessageLabel->setPalette(p); - - p = nameLabel->palette(); - p.setColor(QPalette::WindowText, Style::getColor(Style::GroundBase)); // Base color - p.setColor(QPalette::HighlightedText, Style::getColor(Style::NameActive)); // Color when active - nameLabel->setPalette(p); - - p = palette(); - p.setColor(QPalette::Window, Style::getColor(Style::ThemeMedium)); // Base background color - p.setColor(QPalette::Highlight, Style::getColor(Style::ThemeLight)); // On mouse over - p.setColor(QPalette::Light, Style::getColor(Style::GroundBase)); // When active - setPalette(p); + changeStyle(); } void GenericChatroomWidget::activate() diff --git a/src/widget/genericchatroomwidget.h b/src/widget/genericchatroomwidget.h index b506ad4ff..5d6a85bf9 100644 --- a/src/widget/genericchatroomwidget.h +++ b/src/widget/genericchatroomwidget.h @@ -85,6 +85,16 @@ protected: MaskablePixmapWidget* avatar; CroppingLabel* statusMessageLabel; bool active; + +private: + void changeStyle(); + struct Colors{ + QColor baseBackground; + QColor mouseOver; + QColor statusLbl; + QColor nameLbl; + }; + Colors currentColors; }; #endif // GENERICCHATROOMWIDGET_H From 03124454cd223262b3d66fb9ff7cab7e44592514 Mon Sep 17 00:00:00 2001 From: bodwok Date: Wed, 15 Apr 2020 15:19:27 +0300 Subject: [PATCH 2/3] fix(ui): using a separate css file --- res.qrc | 2 + src/widget/genericchatroomwidget.cpp | 43 +++---------------- src/widget/genericchatroomwidget.h | 10 ----- .../genericChatRoomWidget.css | 21 +++++++++ .../genericChatRoomWidget.css | 21 +++++++++ 5 files changed, 49 insertions(+), 48 deletions(-) create mode 100644 themes/dark/genericChatRoomWidget/genericChatRoomWidget.css create mode 100644 themes/default/genericChatRoomWidget/genericChatRoomWidget.css diff --git a/res.qrc b/res.qrc index 0b7a562fb..35da03a5c 100644 --- a/res.qrc +++ b/res.qrc @@ -178,5 +178,7 @@ img/caps_lock.svg themes/default/contentDialog/contentDialog.css themes/default/tooliconsZone/tooliconsZone.css + themes/default/genericChatRoomWidget/genericChatRoomWidget.css + themes/dark/genericChatRoomWidget/genericChatRoomWidget.css diff --git a/src/widget/genericchatroomwidget.cpp b/src/widget/genericchatroomwidget.cpp index 2e09f02d9..fa0643f40 100644 --- a/src/widget/genericchatroomwidget.cpp +++ b/src/widget/genericchatroomwidget.cpp @@ -124,39 +124,11 @@ bool GenericChatroomWidget::isActive() void GenericChatroomWidget::setActive(bool _active) { active = _active; - if (active) { - currentColors.baseBackground = Style::getColor(Style::GroundBase); // When active - currentColors.statusLbl = Style::getColor(Style::StatusActive); // Color when active - currentColors.nameLbl = Style::getColor(Style::NameActive); // Color when active - } else { - currentColors.baseBackground = Style::getColor(Style::ThemeMedium); // Base background color - currentColors.statusLbl = Style::getColor(Style::GroundExtra); // Base color - currentColors.nameLbl = Style::getColor(Style::GroundBase); // Base color - } - changeStyle(); -} - -void GenericChatroomWidget::changeStyle() -{ - QString wgtStyle = QString("GenericChatroomWidget {" - " background-color: #%1;" // Base background color - "}" - "GenericChatroomWidget:hover {" - " background-color: #%2;" // On mouse over - "}" - "CroppingLabel#statusMessageLabelObj {" - " color: #%3;" - "}" - "CroppingLabel#nameLabelObj {" - " color: #%4;" - "}") - .arg(currentColors.baseBackground.rgba(), 0, 16) - .arg(currentColors.mouseOver.rgba(), 0, 16) - .arg(currentColors.statusLbl.rgba(), 0, 16) - .arg(currentColors.nameLbl.rgba(), 0, 16); - - setStyleSheet(wgtStyle); + setProperty("active", active); + nameLabel->setProperty("active", active); + statusMessageLabel->setProperty("active", active); + Style::repolish(this); } void GenericChatroomWidget::setName(const QString& name) @@ -186,12 +158,7 @@ QString GenericChatroomWidget::getTitle() const void GenericChatroomWidget::reloadTheme() { - currentColors.baseBackground = Style::getColor(Style::ThemeMedium); // Base background color - currentColors.mouseOver = Style::getColor(Style::ThemeLight); // On mouse over - currentColors.statusLbl = Style::getColor(Style::GroundExtra); // statusMessageLabel base color - currentColors.nameLbl = Style::getColor(Style::GroundBase); // nameLabel base color - - changeStyle(); + setStyleSheet(Style::getStylesheet("genericChatRoomWidget/genericChatRoomWidget.css")); } void GenericChatroomWidget::activate() diff --git a/src/widget/genericchatroomwidget.h b/src/widget/genericchatroomwidget.h index 5d6a85bf9..b506ad4ff 100644 --- a/src/widget/genericchatroomwidget.h +++ b/src/widget/genericchatroomwidget.h @@ -85,16 +85,6 @@ protected: MaskablePixmapWidget* avatar; CroppingLabel* statusMessageLabel; bool active; - -private: - void changeStyle(); - struct Colors{ - QColor baseBackground; - QColor mouseOver; - QColor statusLbl; - QColor nameLbl; - }; - Colors currentColors; }; #endif // GENERICCHATROOMWIDGET_H diff --git a/themes/dark/genericChatRoomWidget/genericChatRoomWidget.css b/themes/dark/genericChatRoomWidget/genericChatRoomWidget.css new file mode 100644 index 000000000..ea63997f5 --- /dev/null +++ b/themes/dark/genericChatRoomWidget/genericChatRoomWidget.css @@ -0,0 +1,21 @@ +GenericChatroomWidget { + background-color: @themeMedium; /* Base background color */ +} +GenericChatroomWidget:hover { + background-color: @themeLight; /* On mouse over */ +} +GenericChatroomWidget[active="true"] { + background-color: @groundBase; /* When active */ +} +CroppingLabel#statusMessageLabelObj { + color: @groundExtra; /* Base color */ +} +CroppingLabel#statusMessageLabelObj[active="true"] { + color: @statusActive; /* Color when active */ +} +CroppingLabel#nameLabelObj { + color: @groundExtra; /* Base color */ +} +CroppingLabel#nameLabelObj[active="true"] { + color: @nameActive; /* Color when active */ +} diff --git a/themes/default/genericChatRoomWidget/genericChatRoomWidget.css b/themes/default/genericChatRoomWidget/genericChatRoomWidget.css new file mode 100644 index 000000000..1ff6d982a --- /dev/null +++ b/themes/default/genericChatRoomWidget/genericChatRoomWidget.css @@ -0,0 +1,21 @@ +GenericChatroomWidget { + background-color: @themeMedium; /* Base background color */ +} +GenericChatroomWidget:hover { + background-color: @themeLight; /* On mouse over */ +} +GenericChatroomWidget[active="true"] { + background-color: @groundBase; /* When active */ +} +CroppingLabel#statusMessageLabelObj { + color: @groundExtra; /* Base color */ +} +CroppingLabel#statusMessageLabelObj[active="true"] { + color: @statusActive; /* Color when active */ +} +CroppingLabel#nameLabelObj { + color: @groundBase; /* Base color */ +} +CroppingLabel#nameLabelObj[active="true"] { + color: @nameActive; /* Color when active */ +} From 808b90f8ce783351f36d20165786adff5e6e4863 Mon Sep 17 00:00:00 2001 From: bodwok Date: Fri, 17 Apr 2020 14:24:31 +0300 Subject: [PATCH 3/3] style: placing files in alphabetical order --- res.qrc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/res.qrc b/res.qrc index 35da03a5c..c856c559d 100644 --- a/res.qrc +++ b/res.qrc @@ -83,6 +83,7 @@ themes/dark/emoticonWidget/dot_page_hover.svg themes/dark/emoticonWidget/emoticonWidget.css themes/dark/friendList/friendList.css + themes/dark/genericChatRoomWidget/genericChatRoomWidget.css themes/dark/msgEdit/msgEdit.css themes/dark/settings/mainHead.css themes/dark/settings/checkboxChecked.svg @@ -148,6 +149,7 @@ themes/default/emoticonWidget/dot_page_hover.svg themes/default/emoticonWidget/emoticonWidget.css themes/default/friendList/friendList.css + themes/default/genericChatRoomWidget/genericChatRoomWidget.css themes/default/msgEdit/msgEdit.css themes/default/settings/mainHead.css themes/default/statusButton/statusButton.css @@ -178,7 +180,5 @@ img/caps_lock.svg themes/default/contentDialog/contentDialog.css themes/default/tooliconsZone/tooliconsZone.css - themes/default/genericChatRoomWidget/genericChatRoomWidget.css - themes/dark/genericChatRoomWidget/genericChatRoomWidget.css