From ddf886eaf151cb73ac493766e7d95bce05f56b66 Mon Sep 17 00:00:00 2001 From: Rasmus Karlsson Date: Sun, 2 Jul 2017 14:28:37 +0200 Subject: [PATCH] Add basic color scheme handling Fix #59 --- chatterino.pro | 3 +- src/colorscheme.cpp | 2 +- src/colorscheme.hpp | 1 - src/widgets/basewidget.cpp | 39 +++++++++++++++++++++++++ src/widgets/basewidget.hpp | 19 +++++------- src/widgets/chatwidget.hpp | 2 +- src/widgets/chatwidgetheader.cpp | 23 ++++++++------- src/widgets/chatwidgetheader.hpp | 5 ++-- src/widgets/chatwidgetinput.hpp | 3 +- src/widgets/chatwidgetview.hpp | 6 ++-- src/widgets/mainwindow.cpp | 13 ++++++--- src/widgets/mainwindow.hpp | 2 ++ src/widgets/notebookpagedroppreview.cpp | 4 ++- 13 files changed, 83 insertions(+), 39 deletions(-) create mode 100644 src/widgets/basewidget.cpp diff --git a/chatterino.pro b/chatterino.pro index 36e3ff1e8..22922e9b2 100644 --- a/chatterino.pro +++ b/chatterino.pro @@ -93,7 +93,8 @@ SOURCES += \ src/twitch/twitchuser.cpp \ src/ircaccount.cpp \ src/widgets/accountpopup.cpp \ - src/messagefactory.cpp + src/messagefactory.cpp \ + src/widgets/basewidget.cpp HEADERS += \ src/asyncexec.hpp \ diff --git a/src/colorscheme.cpp b/src/colorscheme.cpp index fe433d672..00e66427d 100644 --- a/src/colorscheme.cpp +++ b/src/colorscheme.cpp @@ -118,7 +118,7 @@ void ColorScheme::setColors(double hue, double multiplier) "border:" + TabSelectedBackground.name() + ";" + "color:" + Text.name() + ";" + "selection-background-color:" + TabSelectedBackground.name(); - updated(); + this->updated(); } void ColorScheme::fillLookupTableValues(double (&array)[360], double from, double to, diff --git a/src/colorscheme.hpp b/src/colorscheme.hpp index 7f4fd89d4..ad8ccae9f 100644 --- a/src/colorscheme.hpp +++ b/src/colorscheme.hpp @@ -68,7 +68,6 @@ public: const int HighlightColorCount = 3; QColor HighlightColors[3]; - void init(WindowManager &windowManager); void normalizeColor(QColor &color); void update(); diff --git a/src/widgets/basewidget.cpp b/src/widgets/basewidget.cpp new file mode 100644 index 000000000..ea2b46356 --- /dev/null +++ b/src/widgets/basewidget.cpp @@ -0,0 +1,39 @@ +#include "widgets/basewidget.hpp" +#include "colorscheme.hpp" + +#include +#include + +namespace chatterino { +namespace widgets { + +BaseWidget::BaseWidget(ColorScheme &_colorScheme, QWidget *parent) + : QWidget(parent) + , colorScheme(_colorScheme) +{ + this->init(); +} + +BaseWidget::BaseWidget(BaseWidget *parent) + : QWidget(parent) + , colorScheme(parent->colorScheme) +{ + this->init(); +} + +void BaseWidget::init() +{ + this->colorScheme.updated.connect([this]() { + this->refreshTheme(); + + this->update(); + }); +} + +void BaseWidget::refreshTheme() +{ + // Do any color scheme updates here +} + +} // namespace widgets +} // namespace chatterino diff --git a/src/widgets/basewidget.hpp b/src/widgets/basewidget.hpp index c98a211ba..e2322e40a 100644 --- a/src/widgets/basewidget.hpp +++ b/src/widgets/basewidget.hpp @@ -1,7 +1,5 @@ #pragma once -#include "colorscheme.hpp" - #include namespace chatterino { @@ -15,19 +13,16 @@ class BaseWidget : public QWidget Q_OBJECT public: - explicit BaseWidget(ColorScheme &_colorScheme, QWidget *parent) - : QWidget(parent) - , colorScheme(_colorScheme) - { - } + explicit BaseWidget(ColorScheme &_colorScheme, QWidget *parent); - explicit BaseWidget(BaseWidget *parent) - : QWidget(parent) - , colorScheme(parent->colorScheme) - { - } + explicit BaseWidget(BaseWidget *parent); ColorScheme &colorScheme; + +private: + void init(); + + virtual void refreshTheme(); }; } // namespace widgets diff --git a/src/widgets/chatwidget.hpp b/src/widgets/chatwidget.hpp index 60230c0a3..250d7ab04 100644 --- a/src/widgets/chatwidget.hpp +++ b/src/widgets/chatwidget.hpp @@ -57,7 +57,7 @@ public: void giveFocus(); protected: - void paintEvent(QPaintEvent *) override; + virtual void paintEvent(QPaintEvent *) override; private: ChannelManager &channelManager; diff --git a/src/widgets/chatwidgetheader.cpp b/src/widgets/chatwidgetheader.cpp index 490225d6a..37db522b7 100644 --- a/src/widgets/chatwidgetheader.cpp +++ b/src/widgets/chatwidgetheader.cpp @@ -21,7 +21,8 @@ ChatWidgetHeader::ChatWidgetHeader(ChatWidget *_chatWidget) { this->setFixedHeight(32); - this->updateColors(); + this->refreshTheme(); + this->updateChannelText(); this->setLayout(&this->hbox); @@ -67,16 +68,6 @@ ChatWidgetHeader::ChatWidgetHeader(ChatWidget *_chatWidget) this->rightLabel.getLabel().setText("ayy"); } -void ChatWidgetHeader::updateColors() -{ - QPalette palette; - palette.setColor(QPalette::Foreground, this->colorScheme.Text); - - this->leftLabel.setPalette(palette); - this->channelNameLabel.setPalette(palette); - this->rightLabel.setPalette(palette); -} - void ChatWidgetHeader::updateChannelText() { const QString &c = this->chatWidget->getChannelName(); @@ -151,6 +142,16 @@ void ChatWidgetHeader::rightButtonClicked() { } +void ChatWidgetHeader::refreshTheme() +{ + QPalette palette; + palette.setColor(QPalette::Foreground, this->colorScheme.Text); + + this->leftLabel.setPalette(palette); + this->channelNameLabel.setPalette(palette); + this->rightLabel.setPalette(palette); +} + void ChatWidgetHeader::menuMoveSplit() { } diff --git a/src/widgets/chatwidgetheader.hpp b/src/widgets/chatwidgetheader.hpp index b880df0ca..8ce3ca740 100644 --- a/src/widgets/chatwidgetheader.hpp +++ b/src/widgets/chatwidgetheader.hpp @@ -28,9 +28,6 @@ class ChatWidgetHeader : public BaseWidget public: explicit ChatWidgetHeader(ChatWidget *_chatWidget); - // Update palette from global color scheme - void updateColors(); - // Update channel text from chat widget void updateChannelText(); @@ -62,6 +59,8 @@ private: void leftButtonClicked(); void rightButtonClicked(); + virtual void refreshTheme() override; + public slots: void menuMoveSplit(); void menuReloadChannelEmotes(); diff --git a/src/widgets/chatwidgetinput.hpp b/src/widgets/chatwidgetinput.hpp index 1c5d300ab..f7fb9e5de 100644 --- a/src/widgets/chatwidgetinput.hpp +++ b/src/widgets/chatwidgetinput.hpp @@ -39,8 +39,9 @@ private: QLabel textLengthLabel; ChatWidgetHeaderButton emotesLabel; + virtual void refreshTheme() override; + private slots: - void refreshTheme(); void setMessageLengthVisisble(bool value) { textLengthLabel.setHidden(!value); diff --git a/src/widgets/chatwidgetview.hpp b/src/widgets/chatwidgetview.hpp index f22ea6ed5..ea927a758 100644 --- a/src/widgets/chatwidgetview.hpp +++ b/src/widgets/chatwidgetview.hpp @@ -35,9 +35,9 @@ protected: virtual void paintEvent(QPaintEvent *) override; virtual void wheelEvent(QWheelEvent *event) override; - void mouseMoveEvent(QMouseEvent *event) override; - void mousePressEvent(QMouseEvent *event) override; - void mouseReleaseEvent(QMouseEvent *event) override; + virtual void mouseMoveEvent(QMouseEvent *event) override; + virtual void mousePressEvent(QMouseEvent *event) override; + virtual void mouseReleaseEvent(QMouseEvent *event) override; bool tryGetMessageAt(QPoint p, std::shared_ptr &message, QPoint &relativePos); diff --git a/src/widgets/mainwindow.cpp b/src/widgets/mainwindow.cpp index 97704131a..3e96f3c7d 100644 --- a/src/widgets/mainwindow.cpp +++ b/src/widgets/mainwindow.cpp @@ -43,9 +43,7 @@ MainWindow::MainWindow(ChannelManager &_channelManager, ColorScheme &_colorSchem layout->setMargin(0); // } - QPalette palette; - palette.setColor(QPalette::Background, this->colorScheme.TabPanelBackground); - setPalette(palette); + this->refreshTheme(); if (this->windowGeometry->isFilled()) { // Load geometry from settings file @@ -160,11 +158,18 @@ Notebook &MainWindow::getNotebook() return this->notebook; } -void MainWindow::closeEvent(QCloseEvent *event) +void MainWindow::closeEvent(QCloseEvent *) { // Save closing window position this->windowGeometry = this->geometry(); } +void MainWindow::refreshTheme() +{ + QPalette palette; + palette.setColor(QPalette::Background, this->colorScheme.TabPanelBackground); + this->setPalette(palette); +} + } // namespace widgets } // namespace chatterino diff --git a/src/widgets/mainwindow.hpp b/src/widgets/mainwindow.hpp index 2da4aa9e7..2a722ab51 100644 --- a/src/widgets/mainwindow.hpp +++ b/src/widgets/mainwindow.hpp @@ -44,6 +44,8 @@ protected: virtual void closeEvent(QCloseEvent *event) override; private: + virtual void refreshTheme() override; + ChannelManager &channelManager; ColorScheme &colorScheme; diff --git a/src/widgets/notebookpagedroppreview.cpp b/src/widgets/notebookpagedroppreview.cpp index a278a8ff8..580398615 100644 --- a/src/widgets/notebookpagedroppreview.cpp +++ b/src/widgets/notebookpagedroppreview.cpp @@ -1,4 +1,5 @@ #include "widgets/notebookpagedroppreview.hpp" +#include "colorscheme.hpp" #include #include @@ -18,7 +19,8 @@ void NotebookPageDropPreview::paintEvent(QPaintEvent *) { QPainter painter(this); - painter.fillRect(8, 8, width() - 17, height() - 17, this->colorScheme.DropPreviewBackground); + painter.fillRect(8, 8, this->width() - 17, this->height() - 17, + this->colorScheme.DropPreviewBackground); } void NotebookPageDropPreview::hideEvent(QHideEvent *)