From b639604a475bbca1420c81a9b297810dd93300c3 Mon Sep 17 00:00:00 2001 From: fourtf Date: Fri, 6 Jul 2018 17:11:37 +0200 Subject: [PATCH] refactored BaseWidget --- src/widgets/BaseWidget.cpp | 77 +++++++++------------ src/widgets/BaseWidget.hpp | 22 +++--- src/widgets/BaseWindow.cpp | 16 ++--- src/widgets/BaseWindow.hpp | 2 +- src/widgets/Label.hpp | 2 +- src/widgets/Notebook.cpp | 2 +- src/widgets/Notebook.hpp | 2 +- src/widgets/Scrollbar.cpp | 6 +- src/widgets/TooltipWidget.cpp | 2 +- src/widgets/TooltipWidget.hpp | 2 +- src/widgets/dialogs/SelectChannelDialog.cpp | 6 +- src/widgets/dialogs/SelectChannelDialog.hpp | 2 +- src/widgets/dialogs/SettingsDialog.cpp | 4 +- src/widgets/dialogs/SettingsDialog.hpp | 2 +- src/widgets/dialogs/UserInfoPopup.cpp | 4 +- src/widgets/dialogs/UserInfoPopup.hpp | 2 +- src/widgets/helper/ChannelView.cpp | 6 +- src/widgets/helper/ChannelView.hpp | 2 +- src/widgets/helper/NotebookButton.cpp | 12 ++-- src/widgets/helper/NotebookButton.hpp | 2 +- src/widgets/helper/NotebookTab.cpp | 14 ++-- src/widgets/helper/NotebookTab.hpp | 2 +- src/widgets/helper/RippleEffectButton.cpp | 2 +- src/widgets/helper/TitlebarButton.cpp | 6 +- src/widgets/splits/Split.cpp | 6 +- src/widgets/splits/SplitContainer.cpp | 10 +-- src/widgets/splits/SplitHeader.cpp | 16 ++--- src/widgets/splits/SplitHeader.hpp | 2 +- src/widgets/splits/SplitInput.cpp | 16 ++--- src/widgets/splits/SplitInput.hpp | 4 +- src/widgets/splits/SplitOverlay.cpp | 2 +- 31 files changed, 121 insertions(+), 134 deletions(-) diff --git a/src/widgets/BaseWidget.cpp b/src/widgets/BaseWidget.cpp index 1b21e3e46..818d951a8 100644 --- a/src/widgets/BaseWidget.cpp +++ b/src/widgets/BaseWidget.cpp @@ -17,18 +17,19 @@ namespace chatterino { BaseWidget::BaseWidget(QWidget *parent, Qt::WindowFlags f) : QWidget(parent, f) { - this->init(); -} + this->theme = getApp()->themes; -BaseWidget::~BaseWidget() -{ - this->themeConnection.disconnect(); + this->signalHolder_.managedConnect(this->theme->updated, [this]() { + this->themeChangedEvent(); + + this->update(); + }); } float BaseWidget::getScale() const { - if (this->overrideScale) { - return this->overrideScale.get(); + if (this->overrideScale_) { + return this->overrideScale_.get(); } BaseWidget *baseWidget = dynamic_cast(this->window()); @@ -37,33 +38,44 @@ float BaseWidget::getScale() const return 1.f; } - return baseWidget->scale; + return baseWidget->scale_; +} + +void BaseWidget::setScale(float value) +{ + // update scale value + this->scale_ = value; + + this->scaleChangedEvent(this->getScale()); + this->scaleChanged.invoke(this->getScale()); + + this->setScaleIndependantSize(this->getScaleIndependantSize()); } void BaseWidget::setOverrideScale(boost::optional value) { - this->overrideScale = value; + this->overrideScale_ = value; this->setScale(this->getScale()); } boost::optional BaseWidget::getOverrideScale() const { - return this->overrideScale; + return this->overrideScale_; } QSize BaseWidget::getScaleIndependantSize() const { - return this->scaleIndependantSize; + return this->scaleIndependantSize_; } int BaseWidget::getScaleIndependantWidth() const { - return this->scaleIndependantSize.width(); + return this->scaleIndependantSize_.width(); } int BaseWidget::getScaleIndependantHeight() const { - return this->scaleIndependantSize.height(); + return this->scaleIndependantSize_.height(); } void BaseWidget::setScaleIndependantSize(int width, int height) @@ -73,7 +85,7 @@ void BaseWidget::setScaleIndependantSize(int width, int height) void BaseWidget::setScaleIndependantSize(QSize size) { - this->scaleIndependantSize = size; + this->scaleIndependantSize_ = size; if (size.width() > 0) { this->setFixedWidth((int)(size.width() * this->getScale())); @@ -85,24 +97,12 @@ void BaseWidget::setScaleIndependantSize(QSize size) void BaseWidget::setScaleIndependantWidth(int value) { - this->setScaleIndependantSize(QSize(value, this->scaleIndependantSize.height())); + this->setScaleIndependantSize(QSize(value, this->scaleIndependantSize_.height())); } void BaseWidget::setScaleIndependantHeight(int value) { - this->setScaleIndependantSize(QSize(this->scaleIndependantSize.height(), value)); -} - -void BaseWidget::init() -{ - auto app = getApp(); - this->themeManager = app->themes; - - this->themeConnection = this->themeManager->updated.connect([this]() { - this->themeRefreshEvent(); - - this->update(); - }); + this->setScaleIndependantSize(QSize(this->scaleIndependantSize_.height(), value)); } void BaseWidget::childEvent(QChildEvent *event) @@ -111,12 +111,12 @@ void BaseWidget::childEvent(QChildEvent *event) BaseWidget *widget = dynamic_cast(event->child()); if (widget != nullptr) { - this->widgets.push_back(widget); + this->widgets_.push_back(widget); } } else if (event->removed()) { - for (auto it = this->widgets.begin(); it != this->widgets.end(); it++) { + for (auto it = this->widgets_.begin(); it != this->widgets_.end(); it++) { if (*it == event->child()) { - this->widgets.erase(it); + this->widgets_.erase(it); break; } } @@ -126,25 +126,14 @@ void BaseWidget::childEvent(QChildEvent *event) void BaseWidget::showEvent(QShowEvent *) { this->setScale(this->getScale()); - this->themeRefreshEvent(); -} - -void BaseWidget::setScale(float value) -{ - // update scale value - this->scale = value; - - this->scaleChangedEvent(this->getScale()); - this->scaleChanged.invoke(this->getScale()); - - this->setScaleIndependantSize(this->getScaleIndependantSize()); + this->themeChangedEvent(); } void BaseWidget::scaleChangedEvent(float newDpi) { } -void BaseWidget::themeRefreshEvent() +void BaseWidget::themeChangedEvent() { // Do any color scheme updates here } diff --git a/src/widgets/BaseWidget.hpp b/src/widgets/BaseWidget.hpp index 0e00f5e55..ebdbe6532 100644 --- a/src/widgets/BaseWidget.hpp +++ b/src/widgets/BaseWidget.hpp @@ -3,6 +3,7 @@ #include #include #include +#include namespace chatterino { @@ -15,7 +16,6 @@ class BaseWidget : public QWidget public: explicit BaseWidget(QWidget *parent, Qt::WindowFlags f = Qt::WindowFlags()); - virtual ~BaseWidget() override; virtual float getScale() const; pajlada::Signals::Signal scaleChanged; @@ -32,26 +32,24 @@ public: void setScaleIndependantHeight(int value); protected: - void childEvent(QChildEvent *) override; + virtual void childEvent(QChildEvent *) override; + virtual void showEvent(QShowEvent *) override; virtual void scaleChangedEvent(float newScale); - virtual void themeRefreshEvent(); - - virtual void showEvent(QShowEvent *) override; + virtual void themeChangedEvent(); void setScale(float value); - Theme *themeManager; + Theme *theme; private: - void init(); - float scale = 1.f; - boost::optional overrideScale = boost::none; - QSize scaleIndependantSize; + float scale_ = 1.f; + boost::optional overrideScale_ = boost::none; + QSize scaleIndependantSize_; - std::vector widgets; + std::vector widgets_; - pajlada::Signals::Connection themeConnection; + pajlada::Signals::SignalHolder signalHolder_; friend class BaseWindow; }; diff --git a/src/widgets/BaseWindow.cpp b/src/widgets/BaseWindow.cpp index e4c27b090..f67938128 100644 --- a/src/widgets/BaseWindow.cpp +++ b/src/widgets/BaseWindow.cpp @@ -66,7 +66,7 @@ BaseWindow::BaseWindow(QWidget *parent, Flags _flags) float BaseWindow::getScale() const { - return this->getOverrideScale().value_or(this->scale); + return this->getOverrideScale().value_or(this->scale_); } BaseWindow::Flags BaseWindow::getFlags() @@ -212,28 +212,28 @@ bool BaseWindow::hasCustomWindowFrame() #endif } -void BaseWindow::themeRefreshEvent() +void BaseWindow::themeChangedEvent() { if (this->hasCustomWindowFrame()) { QPalette palette; palette.setColor(QPalette::Background, QColor(0, 0, 0, 0)); - palette.setColor(QPalette::Foreground, this->themeManager->window.text); + palette.setColor(QPalette::Foreground, this->theme->window.text); this->setPalette(palette); if (this->ui_.titleLabel) { QPalette palette_title; palette_title.setColor(QPalette::Foreground, - this->themeManager->isLightTheme() ? "#333" : "#ccc"); + this->theme->isLightTheme() ? "#333" : "#ccc"); this->ui_.titleLabel->setPalette(palette_title); } for (RippleEffectButton *button : this->ui_.buttons) { - button->setMouseEffectColor(this->themeManager->window.text); + button->setMouseEffectColor(this->theme->window.text); } } else { QPalette palette; - palette.setColor(QPalette::Background, this->themeManager->window.background); - palette.setColor(QPalette::Foreground, this->themeManager->window.text); + palette.setColor(QPalette::Background, this->theme->window.background); + palette.setColor(QPalette::Foreground, this->theme->window.text); this->setPalette(palette); } } @@ -541,7 +541,7 @@ void BaseWindow::drawCustomWindowFrame(QPainter &painter) if (this->hasCustomWindowFrame()) { QPainter painter(this); - QColor bg = this->overrideBackgroundColor_.value_or(this->themeManager->window.background); + QColor bg = this->overrideBackgroundColor_.value_or(this->theme->window.background); painter.fillRect(QRect(0, 1, this->width() - 0, this->height() - 0), bg); } diff --git a/src/widgets/BaseWindow.hpp b/src/widgets/BaseWindow.hpp index 5baf88b69..205b9cff8 100644 --- a/src/widgets/BaseWindow.hpp +++ b/src/widgets/BaseWindow.hpp @@ -65,7 +65,7 @@ protected: virtual void resizeEvent(QResizeEvent *) override; virtual void closeEvent(QCloseEvent *) override; - virtual void themeRefreshEvent() override; + virtual void themeChangedEvent() override; virtual bool event(QEvent *event) override; virtual void wheelEvent(QWheelEvent *event) override; diff --git a/src/widgets/Label.hpp b/src/widgets/Label.hpp index be20b7a6c..0ca8d2dec 100644 --- a/src/widgets/Label.hpp +++ b/src/widgets/Label.hpp @@ -27,7 +27,7 @@ public: void setHasOffset(bool hasOffset); protected: - virtual void scaleChangedEvent(float scale) override; + virtual void scaleChangedEvent(float scale_) override; virtual void paintEvent(QPaintEvent *) override; virtual QSize sizeHint() const override; diff --git a/src/widgets/Notebook.cpp b/src/widgets/Notebook.cpp index 921173d67..5902b7d48 100644 --- a/src/widgets/Notebook.cpp +++ b/src/widgets/Notebook.cpp @@ -375,7 +375,7 @@ void Notebook::paintEvent(QPaintEvent *event) QPainter painter(this); painter.fillRect(0, this->lineY, this->width(), (int)(3 * this->getScale()), - this->themeManager->tabs.bottomLine); + this->theme->tabs.bottomLine); } NotebookButton *Notebook::getAddButton() diff --git a/src/widgets/Notebook.hpp b/src/widgets/Notebook.hpp index 224f5aa7b..a7dd96761 100644 --- a/src/widgets/Notebook.hpp +++ b/src/widgets/Notebook.hpp @@ -50,7 +50,7 @@ public: void performLayout(bool animate = false); protected: - virtual void scaleChangedEvent(float scale) override; + virtual void scaleChangedEvent(float scale_) override; virtual void resizeEvent(QResizeEvent *) override; virtual void paintEvent(QPaintEvent *) override; diff --git a/src/widgets/Scrollbar.cpp b/src/widgets/Scrollbar.cpp index 0e656ad58..37efde61e 100644 --- a/src/widgets/Scrollbar.cpp +++ b/src/widgets/Scrollbar.cpp @@ -217,7 +217,7 @@ void Scrollbar::paintEvent(QPaintEvent *) int xOffset = mouseOver ? 0 : width() - int(4 * this->getScale()); QPainter painter(this); - painter.fillRect(rect(), this->themeManager->scrollbars.background); + painter.fillRect(rect(), this->theme->scrollbars.background); // painter.fillRect(QRect(xOffset, 0, width(), this->buttonHeight), // this->themeManager->ScrollbarArrow); @@ -229,11 +229,11 @@ void Scrollbar::paintEvent(QPaintEvent *) // mouse over thumb if (this->mouseDownIndex_ == 2) { - painter.fillRect(this->thumbRect_, this->themeManager->scrollbars.thumbSelected); + painter.fillRect(this->thumbRect_, this->theme->scrollbars.thumbSelected); } // mouse not over thumb else { - painter.fillRect(this->thumbRect_, this->themeManager->scrollbars.thumb); + painter.fillRect(this->thumbRect_, this->theme->scrollbars.thumb); } // draw highlights diff --git a/src/widgets/TooltipWidget.cpp b/src/widgets/TooltipWidget.cpp index 310eccc11..1dda62b0e 100644 --- a/src/widgets/TooltipWidget.cpp +++ b/src/widgets/TooltipWidget.cpp @@ -62,7 +62,7 @@ void TooltipWidget::raise() } #endif -void TooltipWidget::themeRefreshEvent() +void TooltipWidget::themeChangedEvent() { this->setStyleSheet("color: #fff; background: #000"); } diff --git a/src/widgets/TooltipWidget.hpp b/src/widgets/TooltipWidget.hpp index ac452e726..410c39139 100644 --- a/src/widgets/TooltipWidget.hpp +++ b/src/widgets/TooltipWidget.hpp @@ -27,7 +27,7 @@ public: protected: void changeEvent(QEvent *) override; void leaveEvent(QEvent *) override; - void themeRefreshEvent() override; + void themeChangedEvent() override; void scaleChangedEvent(float) override; private: diff --git a/src/widgets/dialogs/SelectChannelDialog.cpp b/src/widgets/dialogs/SelectChannelDialog.cpp index 9da44f1cb..9007eaf9d 100644 --- a/src/widgets/dialogs/SelectChannelDialog.cpp +++ b/src/widgets/dialogs/SelectChannelDialog.cpp @@ -267,11 +267,11 @@ void SelectChannelDialog::closeEvent(QCloseEvent *) this->closed.invoke(); } -void SelectChannelDialog::themeRefreshEvent() +void SelectChannelDialog::themeChangedEvent() { - BaseWindow::themeRefreshEvent(); + BaseWindow::themeChangedEvent(); - if (this->themeManager->isLightTheme()) { + if (this->theme->isLightTheme()) { this->setStyleSheet("QRadioButton { color: #000 } QLabel { color: #000 }"); } else { this->setStyleSheet("QRadioButton { color: #fff } QLabel { color: #fff }"); diff --git a/src/widgets/dialogs/SelectChannelDialog.hpp b/src/widgets/dialogs/SelectChannelDialog.hpp index c48e921ca..eadd7a290 100644 --- a/src/widgets/dialogs/SelectChannelDialog.hpp +++ b/src/widgets/dialogs/SelectChannelDialog.hpp @@ -24,7 +24,7 @@ public: protected: virtual void closeEvent(QCloseEvent *) override; - virtual void themeRefreshEvent() override; + virtual void themeChangedEvent() override; private: class EventFilter : public QObject diff --git a/src/widgets/dialogs/SettingsDialog.cpp b/src/widgets/dialogs/SettingsDialog.cpp index 4925c2896..81b421760 100644 --- a/src/widgets/dialogs/SettingsDialog.cpp +++ b/src/widgets/dialogs/SettingsDialog.cpp @@ -175,9 +175,9 @@ void SettingsDialog::scaleChangedEvent(float newDpi) this->ui_.tabContainerContainer->setFixedWidth(int(200 * newDpi)); } -void SettingsDialog::themeRefreshEvent() +void SettingsDialog::themeChangedEvent() { - BaseWindow::themeRefreshEvent(); + BaseWindow::themeChangedEvent(); QPalette palette; palette.setColor(QPalette::Background, QColor("#444")); diff --git a/src/widgets/dialogs/SettingsDialog.hpp b/src/widgets/dialogs/SettingsDialog.hpp index 066ab4983..58d50b872 100644 --- a/src/widgets/dialogs/SettingsDialog.hpp +++ b/src/widgets/dialogs/SettingsDialog.hpp @@ -29,7 +29,7 @@ public: protected: virtual void scaleChangedEvent(float newDpi) override; - virtual void themeRefreshEvent() override; + virtual void themeChangedEvent() override; private: void refresh(); diff --git a/src/widgets/dialogs/UserInfoPopup.cpp b/src/widgets/dialogs/UserInfoPopup.cpp index 6163bceca..efae603bf 100644 --- a/src/widgets/dialogs/UserInfoPopup.cpp +++ b/src/widgets/dialogs/UserInfoPopup.cpp @@ -158,9 +158,9 @@ UserInfoPopup::UserInfoPopup() this->installEvents(); } -void UserInfoPopup::themeRefreshEvent() +void UserInfoPopup::themeChangedEvent() { - BaseWindow::themeRefreshEvent(); + BaseWindow::themeChangedEvent(); this->setStyleSheet("background: #333"); } diff --git a/src/widgets/dialogs/UserInfoPopup.hpp b/src/widgets/dialogs/UserInfoPopup.hpp index 711fda3c4..10909be4a 100644 --- a/src/widgets/dialogs/UserInfoPopup.hpp +++ b/src/widgets/dialogs/UserInfoPopup.hpp @@ -21,7 +21,7 @@ public: void setData(const QString &name, const ChannelPtr &channel); protected: - virtual void themeRefreshEvent() override; + virtual void themeChangedEvent() override; private: bool isMod_; diff --git a/src/widgets/helper/ChannelView.cpp b/src/widgets/helper/ChannelView.cpp index c7ee9a968..8442e34ff 100644 --- a/src/widgets/helper/ChannelView.cpp +++ b/src/widgets/helper/ChannelView.cpp @@ -131,9 +131,9 @@ ChannelView::~ChannelView() { } -void ChannelView::themeRefreshEvent() +void ChannelView::themeChangedEvent() { - BaseWidget::themeRefreshEvent(); + BaseWidget::themeChangedEvent(); this->layoutMessages(); } @@ -575,7 +575,7 @@ void ChannelView::paintEvent(QPaintEvent * /*event*/) QPainter painter(this); - painter.fillRect(rect(), this->themeManager->splits.background); + painter.fillRect(rect(), this->theme->splits.background); // draw messages this->drawMessages(painter); diff --git a/src/widgets/helper/ChannelView.hpp b/src/widgets/helper/ChannelView.hpp index f115156de..6a114001b 100644 --- a/src/widgets/helper/ChannelView.hpp +++ b/src/widgets/helper/ChannelView.hpp @@ -53,7 +53,7 @@ public: pajlada::Signals::Signal linkClicked; protected: - void themeRefreshEvent() override; + void themeChangedEvent() override; void resizeEvent(QResizeEvent *) override; diff --git a/src/widgets/helper/NotebookButton.cpp b/src/widgets/helper/NotebookButton.cpp index 9d51dc242..009d9ad17 100644 --- a/src/widgets/helper/NotebookButton.cpp +++ b/src/widgets/helper/NotebookButton.cpp @@ -32,9 +32,9 @@ NotebookButton::Icon NotebookButton::getIcon() const return this->icon_; } -void NotebookButton::themeRefreshEvent() +void NotebookButton::themeChangedEvent() { - this->setMouseEffectColor(this->themeManager->tabs.regular.text); + this->setMouseEffectColor(this->theme->tabs.regular.text); } void NotebookButton::paintEvent(QPaintEvent *event) @@ -45,11 +45,11 @@ void NotebookButton::paintEvent(QPaintEvent *event) QColor foreground; if (mouseDown_ || mouseOver_) { - background = this->themeManager->tabs.regular.backgrounds.hover.color(); - foreground = this->themeManager->tabs.regular.text; + background = this->theme->tabs.regular.backgrounds.hover.color(); + foreground = this->theme->tabs.regular.text; } else { - background = this->themeManager->tabs.regular.backgrounds.regular.color(); - foreground = this->themeManager->tabs.regular.text; + background = this->theme->tabs.regular.backgrounds.regular.color(); + foreground = this->theme->tabs.regular.text; } painter.setPen(Qt::NoPen); diff --git a/src/widgets/helper/NotebookButton.hpp b/src/widgets/helper/NotebookButton.hpp index 91a87e488..01504ad8d 100644 --- a/src/widgets/helper/NotebookButton.hpp +++ b/src/widgets/helper/NotebookButton.hpp @@ -21,7 +21,7 @@ public: Icon getIcon() const; protected: - virtual void themeRefreshEvent() override; + virtual void themeChangedEvent() override; virtual void paintEvent(QPaintEvent *) override; virtual void mouseReleaseEvent(QMouseEvent *) override; virtual void dragEnterEvent(QDragEnterEvent *) override; diff --git a/src/widgets/helper/NotebookTab.cpp b/src/widgets/helper/NotebookTab.cpp index 9efb54e60..46bf3993e 100644 --- a/src/widgets/helper/NotebookTab.cpp +++ b/src/widgets/helper/NotebookTab.cpp @@ -64,12 +64,12 @@ NotebookTab::NotebookTab(Notebook *notebook) // }); } -void NotebookTab::themeRefreshEvent() +void NotebookTab::themeChangedEvent() { this->update(); // this->setMouseEffectColor(QColor("#999")); - this->setMouseEffectColor(this->themeManager->tabs.regular.text); + this->setMouseEffectColor(this->theme->tabs.regular.text); } void NotebookTab::updateSize() @@ -222,16 +222,16 @@ void NotebookTab::paintEvent(QPaintEvent *) // select the right tab colors Theme::TabColors colors; - Theme::TabColors regular = this->themeManager->tabs.regular; + Theme::TabColors regular = this->theme->tabs.regular; if (this->selected_) { - colors = this->themeManager->tabs.selected; + colors = this->theme->tabs.selected; } else if (this->highlightState_ == HighlightState::Highlighted) { - colors = this->themeManager->tabs.highlighted; + colors = this->theme->tabs.highlighted; } else if (this->highlightState_ == HighlightState::NewMessage) { - colors = this->themeManager->tabs.newMessage; + colors = this->theme->tabs.newMessage; } else { - colors = this->themeManager->tabs.regular; + colors = this->theme->tabs.regular; } bool windowFocused = this->window() == QApplication::activeWindow(); diff --git a/src/widgets/helper/NotebookTab.hpp b/src/widgets/helper/NotebookTab.hpp index 5b6070fcf..ff6249a9c 100644 --- a/src/widgets/helper/NotebookTab.hpp +++ b/src/widgets/helper/NotebookTab.hpp @@ -47,7 +47,7 @@ public: void hideTabXChanged(bool); protected: - virtual void themeRefreshEvent() override; + virtual void themeChangedEvent() override; virtual void paintEvent(QPaintEvent *) override; diff --git a/src/widgets/helper/RippleEffectButton.cpp b/src/widgets/helper/RippleEffectButton.cpp index 31fc4ffc4..fd2e1ae67 100644 --- a/src/widgets/helper/RippleEffectButton.cpp +++ b/src/widgets/helper/RippleEffectButton.cpp @@ -121,7 +121,7 @@ void RippleEffectButton::fancyPaint(QPainter &painter) if (this->mouseEffectColor_) { c = this->mouseEffectColor_.get(); } else { - c = this->themeManager->isLightTheme() ? QColor(0, 0, 0) : QColor(255, 255, 255); + c = this->theme->isLightTheme() ? QColor(0, 0, 0) : QColor(255, 255, 255); } if (this->hoverMultiplier_ > 0) { diff --git a/src/widgets/helper/TitlebarButton.cpp b/src/widgets/helper/TitlebarButton.cpp index 5abc177da..820d33e14 100644 --- a/src/widgets/helper/TitlebarButton.cpp +++ b/src/widgets/helper/TitlebarButton.cpp @@ -26,8 +26,8 @@ void TitleBarButton::paintEvent(QPaintEvent *event) painter.setOpacity(this->getCurrentDimAmount()); - QColor color = this->themeManager->window.text; - QColor background = this->themeManager->window.background; + QColor color = this->theme->window.text; + QColor background = this->theme->window.background; int xD = this->height() / 3; int centerX = this->width() / 2; @@ -50,7 +50,7 @@ void TitleBarButton::paintEvent(QPaintEvent *event) painter.drawRect(centerX - xD / 2 + xD2, xD, xD3, xD3); painter.fillRect(centerX - xD / 2, xD + xD2, xD3, xD3, - this->themeManager->window.background); + this->theme->window.background); painter.drawRect(centerX - xD / 2, xD + xD2, xD3, xD3); break; } diff --git a/src/widgets/splits/Split.cpp b/src/widgets/splits/Split.cpp index 1a04bcefe..2262ff096 100644 --- a/src/widgets/splits/Split.cpp +++ b/src/widgets/splits/Split.cpp @@ -286,7 +286,7 @@ void Split::paintEvent(QPaintEvent *) // color the background of the chat QPainter painter(this); - painter.fillRect(this->rect(), this->themeManager->splits.background); + painter.fillRect(this->rect(), this->theme->splits.background); } void Split::mouseMoveEvent(QMouseEvent *event) @@ -446,7 +446,7 @@ void Split::doOpenViewerList() QList labelList; for (auto &x : labels) { auto label = new QListWidgetItem(x); - label->setBackgroundColor(this->themeManager->splits.header.background); + label->setBackgroundColor(this->theme->splits.header.background); labelList.append(label); } auto loadingLabel = new QLabel("Loading..."); @@ -503,7 +503,7 @@ void Split::doOpenViewerList() dockVbox->addWidget(resultList); resultList->hide(); - multiWidget->setStyleSheet(this->themeManager->splits.input.styleSheet); + multiWidget->setStyleSheet(this->theme->splits.input.styleSheet); multiWidget->setLayout(dockVbox); viewerDock->setWidget(multiWidget); viewerDock->show(); diff --git a/src/widgets/splits/SplitContainer.cpp b/src/widgets/splits/SplitContainer.cpp index af3ef1c0c..5073ac066 100644 --- a/src/widgets/splits/SplitContainer.cpp +++ b/src/widgets/splits/SplitContainer.cpp @@ -400,9 +400,9 @@ void SplitContainer::paintEvent(QPaintEvent *) QPainter painter(this); if (this->splits.size() == 0) { - painter.fillRect(rect(), this->themeManager->splits.background); + painter.fillRect(rect(), this->theme->splits.background); - painter.setPen(this->themeManager->splits.header.text); + painter.setPen(this->theme->splits.header.text); QString text = "Click to add a split"; @@ -445,7 +445,7 @@ void SplitContainer::paintEvent(QPaintEvent *) int s = std::min(dropRect.rect.width(), dropRect.rect.height()) - 12; - if (this->themeManager->isLightTheme()) { + if (this->theme->isLightTheme()) { painter.setPen(QColor(0, 0, 0)); } else { painter.setPen(QColor(255, 255, 255)); @@ -457,8 +457,8 @@ void SplitContainer::paintEvent(QPaintEvent *) } QBrush accentColor = (QApplication::activeWindow() == this->window() - ? this->themeManager->tabs.selected.backgrounds.regular - : this->themeManager->tabs.selected.backgrounds.unfocused); + ? this->theme->tabs.selected.backgrounds.regular + : this->theme->tabs.selected.backgrounds.unfocused); painter.fillRect(0, 0, width(), 1, accentColor); } diff --git a/src/widgets/splits/SplitHeader.cpp b/src/widgets/splits/SplitHeader.cpp index 66c6a1e9d..ab0e36a9b 100644 --- a/src/widgets/splits/SplitHeader.cpp +++ b/src/widgets/splits/SplitHeader.cpp @@ -28,8 +28,8 @@ SplitHeader::SplitHeader(Split *_split) : BaseWidget(_split) , split(_split) { - this->split->focused.connect([this]() { this->themeRefreshEvent(); }); - this->split->focusLost.connect([this]() { this->themeRefreshEvent(); }); + this->split->focused.connect([this]() { this->themeChangedEvent(); }); + this->split->focusLost.connect([this]() { this->themeChangedEvent(); }); auto app = getApp(); @@ -374,8 +374,8 @@ void SplitHeader::paintEvent(QPaintEvent *) { QPainter painter(this); - painter.fillRect(rect(), this->themeManager->splits.header.background); - painter.setPen(this->themeManager->splits.header.border); + painter.fillRect(rect(), this->theme->splits.header.background); + painter.setPen(this->theme->splits.header.border); painter.drawRect(0, 0, width() - 1, height() - 1); } @@ -468,17 +468,17 @@ void SplitHeader::rightButtonClicked() { } -void SplitHeader::themeRefreshEvent() +void SplitHeader::themeChangedEvent() { QPalette palette; if (this->split->hasFocus()) { - palette.setColor(QPalette::Foreground, this->themeManager->splits.header.focusedText); + palette.setColor(QPalette::Foreground, this->theme->splits.header.focusedText); } else { - palette.setColor(QPalette::Foreground, this->themeManager->splits.header.text); + palette.setColor(QPalette::Foreground, this->theme->splits.header.text); } - if (this->themeManager->isLightTheme()) { + if (this->theme->isLightTheme()) { this->dropdownButton->setPixmap(QPixmap(":/images/menu_black.png")); } else { this->dropdownButton->setPixmap(QPixmap(":/images/menu_white.png")); diff --git a/src/widgets/splits/SplitHeader.hpp b/src/widgets/splits/SplitHeader.hpp index cb4095e71..2c6907d32 100644 --- a/src/widgets/splits/SplitHeader.hpp +++ b/src/widgets/splits/SplitHeader.hpp @@ -38,7 +38,7 @@ public: protected: virtual void scaleChangedEvent(float) override; - virtual void themeRefreshEvent() override; + virtual void themeChangedEvent() override; virtual void paintEvent(QPaintEvent *) override; virtual void mousePressEvent(QMouseEvent *event) override; diff --git a/src/widgets/splits/SplitInput.cpp b/src/widgets/splits/SplitInput.cpp index f9743ed51..426244f8c 100644 --- a/src/widgets/splits/SplitInput.cpp +++ b/src/widgets/splits/SplitInput.cpp @@ -111,18 +111,18 @@ void SplitInput::scaleChangedEvent(float scale) this->ui_.textEdit->setFont(getApp()->fonts->getFont(FontStyle::ChatMedium, this->getScale())); } -void SplitInput::themeRefreshEvent() +void SplitInput::themeChangedEvent() { QPalette palette; - palette.setColor(QPalette::Foreground, this->themeManager->splits.input.text); + palette.setColor(QPalette::Foreground, this->theme->splits.input.text); this->updateEmoteButton(); this->ui_.textEditLength->setPalette(palette); - this->ui_.textEdit->setStyleSheet(this->themeManager->splits.input.styleSheet); + this->ui_.textEdit->setStyleSheet(this->theme->splits.input.styleSheet); - this->ui_.hbox->setMargin(int((this->themeManager->isLightTheme() ? 4 : 2) * this->getScale())); + this->ui_.hbox->setMargin(int((this->theme->isLightTheme() ? 4 : 2) * this->getScale())); this->ui_.emoteButton->getLabel().setStyleSheet("color: #000"); } @@ -134,7 +134,7 @@ void SplitInput::updateEmoteButton() QString text = ""; text.replace("xD", QString::number(int(12 * scale))); - if (this->themeManager->isLightTheme()) { + if (this->theme->isLightTheme()) { text.replace("emote", "emote_dark"); } @@ -322,11 +322,11 @@ void SplitInput::paintEvent(QPaintEvent *) { QPainter painter(this); - if (this->themeManager->isLightTheme()) { + if (this->theme->isLightTheme()) { int s = int(3 * this->getScale()); QRect rect = this->rect().marginsRemoved(QMargins(s, s, s, s)); - painter.fillRect(rect, this->themeManager->splits.input.background); + painter.fillRect(rect, this->theme->splits.input.background); painter.setPen(QColor("#ccc")); painter.drawRect(rect); @@ -334,7 +334,7 @@ void SplitInput::paintEvent(QPaintEvent *) int s = int(1 * this->getScale()); QRect rect = this->rect().marginsRemoved(QMargins(s, s, s, s)); - painter.fillRect(rect, this->themeManager->splits.input.background); + painter.fillRect(rect, this->theme->splits.input.background); painter.setPen(QColor("#333")); painter.drawRect(rect); diff --git a/src/widgets/splits/SplitInput.hpp b/src/widgets/splits/SplitInput.hpp index 777b126e0..491841d44 100644 --- a/src/widgets/splits/SplitInput.hpp +++ b/src/widgets/splits/SplitInput.hpp @@ -31,8 +31,8 @@ public: pajlada::Signals::Signal textChanged; protected: - virtual void scaleChangedEvent(float scale) override; - virtual void themeRefreshEvent() override; + virtual void scaleChangedEvent(float scale_) override; + virtual void themeChangedEvent() override; virtual void paintEvent(QPaintEvent *) override; virtual void resizeEvent(QResizeEvent *) override; diff --git a/src/widgets/splits/SplitOverlay.cpp b/src/widgets/splits/SplitOverlay.cpp index 718930b74..4f3ced959 100644 --- a/src/widgets/splits/SplitOverlay.cpp +++ b/src/widgets/splits/SplitOverlay.cpp @@ -91,7 +91,7 @@ SplitOverlay::SplitOverlay(Split *parent) void SplitOverlay::paintEvent(QPaintEvent *) { QPainter painter(this); - if (this->themeManager->isLightTheme()) { + if (this->theme->isLightTheme()) { painter.fillRect(this->rect(), QColor(255, 255, 255, 200)); } else { painter.fillRect(this->rect(), QColor(0, 0, 0, 150));