refactored BaseWidget

This commit is contained in:
fourtf 2018-07-06 17:11:37 +02:00
parent 741c1f7820
commit b639604a47
31 changed files with 121 additions and 134 deletions

View file

@ -17,18 +17,19 @@ namespace chatterino {
BaseWidget::BaseWidget(QWidget *parent, Qt::WindowFlags f) BaseWidget::BaseWidget(QWidget *parent, Qt::WindowFlags f)
: QWidget(parent, f) : QWidget(parent, f)
{ {
this->init(); this->theme = getApp()->themes;
}
BaseWidget::~BaseWidget() this->signalHolder_.managedConnect(this->theme->updated, [this]() {
{ this->themeChangedEvent();
this->themeConnection.disconnect();
this->update();
});
} }
float BaseWidget::getScale() const float BaseWidget::getScale() const
{ {
if (this->overrideScale) { if (this->overrideScale_) {
return this->overrideScale.get(); return this->overrideScale_.get();
} }
BaseWidget *baseWidget = dynamic_cast<BaseWidget *>(this->window()); BaseWidget *baseWidget = dynamic_cast<BaseWidget *>(this->window());
@ -37,33 +38,44 @@ float BaseWidget::getScale() const
return 1.f; 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<float> value) void BaseWidget::setOverrideScale(boost::optional<float> value)
{ {
this->overrideScale = value; this->overrideScale_ = value;
this->setScale(this->getScale()); this->setScale(this->getScale());
} }
boost::optional<float> BaseWidget::getOverrideScale() const boost::optional<float> BaseWidget::getOverrideScale() const
{ {
return this->overrideScale; return this->overrideScale_;
} }
QSize BaseWidget::getScaleIndependantSize() const QSize BaseWidget::getScaleIndependantSize() const
{ {
return this->scaleIndependantSize; return this->scaleIndependantSize_;
} }
int BaseWidget::getScaleIndependantWidth() const int BaseWidget::getScaleIndependantWidth() const
{ {
return this->scaleIndependantSize.width(); return this->scaleIndependantSize_.width();
} }
int BaseWidget::getScaleIndependantHeight() const int BaseWidget::getScaleIndependantHeight() const
{ {
return this->scaleIndependantSize.height(); return this->scaleIndependantSize_.height();
} }
void BaseWidget::setScaleIndependantSize(int width, int height) void BaseWidget::setScaleIndependantSize(int width, int height)
@ -73,7 +85,7 @@ void BaseWidget::setScaleIndependantSize(int width, int height)
void BaseWidget::setScaleIndependantSize(QSize size) void BaseWidget::setScaleIndependantSize(QSize size)
{ {
this->scaleIndependantSize = size; this->scaleIndependantSize_ = size;
if (size.width() > 0) { if (size.width() > 0) {
this->setFixedWidth((int)(size.width() * this->getScale())); this->setFixedWidth((int)(size.width() * this->getScale()));
@ -85,24 +97,12 @@ void BaseWidget::setScaleIndependantSize(QSize size)
void BaseWidget::setScaleIndependantWidth(int value) void BaseWidget::setScaleIndependantWidth(int value)
{ {
this->setScaleIndependantSize(QSize(value, this->scaleIndependantSize.height())); this->setScaleIndependantSize(QSize(value, this->scaleIndependantSize_.height()));
} }
void BaseWidget::setScaleIndependantHeight(int value) void BaseWidget::setScaleIndependantHeight(int value)
{ {
this->setScaleIndependantSize(QSize(this->scaleIndependantSize.height(), 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();
});
} }
void BaseWidget::childEvent(QChildEvent *event) void BaseWidget::childEvent(QChildEvent *event)
@ -111,12 +111,12 @@ void BaseWidget::childEvent(QChildEvent *event)
BaseWidget *widget = dynamic_cast<BaseWidget *>(event->child()); BaseWidget *widget = dynamic_cast<BaseWidget *>(event->child());
if (widget != nullptr) { if (widget != nullptr) {
this->widgets.push_back(widget); this->widgets_.push_back(widget);
} }
} else if (event->removed()) { } 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()) { if (*it == event->child()) {
this->widgets.erase(it); this->widgets_.erase(it);
break; break;
} }
} }
@ -126,25 +126,14 @@ void BaseWidget::childEvent(QChildEvent *event)
void BaseWidget::showEvent(QShowEvent *) void BaseWidget::showEvent(QShowEvent *)
{ {
this->setScale(this->getScale()); this->setScale(this->getScale());
this->themeRefreshEvent(); this->themeChangedEvent();
}
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::scaleChangedEvent(float newDpi) void BaseWidget::scaleChangedEvent(float newDpi)
{ {
} }
void BaseWidget::themeRefreshEvent() void BaseWidget::themeChangedEvent()
{ {
// Do any color scheme updates here // Do any color scheme updates here
} }

View file

@ -3,6 +3,7 @@
#include <QWidget> #include <QWidget>
#include <boost/optional.hpp> #include <boost/optional.hpp>
#include <pajlada/signals/signal.hpp> #include <pajlada/signals/signal.hpp>
#include <pajlada/signals/signalholder.hpp>
namespace chatterino { namespace chatterino {
@ -15,7 +16,6 @@ class BaseWidget : public QWidget
public: public:
explicit BaseWidget(QWidget *parent, Qt::WindowFlags f = Qt::WindowFlags()); explicit BaseWidget(QWidget *parent, Qt::WindowFlags f = Qt::WindowFlags());
virtual ~BaseWidget() override;
virtual float getScale() const; virtual float getScale() const;
pajlada::Signals::Signal<float> scaleChanged; pajlada::Signals::Signal<float> scaleChanged;
@ -32,26 +32,24 @@ public:
void setScaleIndependantHeight(int value); void setScaleIndependantHeight(int value);
protected: protected:
void childEvent(QChildEvent *) override; virtual void childEvent(QChildEvent *) override;
virtual void showEvent(QShowEvent *) override;
virtual void scaleChangedEvent(float newScale); virtual void scaleChangedEvent(float newScale);
virtual void themeRefreshEvent(); virtual void themeChangedEvent();
virtual void showEvent(QShowEvent *) override;
void setScale(float value); void setScale(float value);
Theme *themeManager; Theme *theme;
private: private:
void init(); float scale_ = 1.f;
float scale = 1.f; boost::optional<float> overrideScale_ = boost::none;
boost::optional<float> overrideScale = boost::none; QSize scaleIndependantSize_;
QSize scaleIndependantSize;
std::vector<BaseWidget *> widgets; std::vector<BaseWidget *> widgets_;
pajlada::Signals::Connection themeConnection; pajlada::Signals::SignalHolder signalHolder_;
friend class BaseWindow; friend class BaseWindow;
}; };

View file

@ -66,7 +66,7 @@ BaseWindow::BaseWindow(QWidget *parent, Flags _flags)
float BaseWindow::getScale() const float BaseWindow::getScale() const
{ {
return this->getOverrideScale().value_or(this->scale); return this->getOverrideScale().value_or(this->scale_);
} }
BaseWindow::Flags BaseWindow::getFlags() BaseWindow::Flags BaseWindow::getFlags()
@ -212,28 +212,28 @@ bool BaseWindow::hasCustomWindowFrame()
#endif #endif
} }
void BaseWindow::themeRefreshEvent() void BaseWindow::themeChangedEvent()
{ {
if (this->hasCustomWindowFrame()) { if (this->hasCustomWindowFrame()) {
QPalette palette; QPalette palette;
palette.setColor(QPalette::Background, QColor(0, 0, 0, 0)); 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); this->setPalette(palette);
if (this->ui_.titleLabel) { if (this->ui_.titleLabel) {
QPalette palette_title; QPalette palette_title;
palette_title.setColor(QPalette::Foreground, palette_title.setColor(QPalette::Foreground,
this->themeManager->isLightTheme() ? "#333" : "#ccc"); this->theme->isLightTheme() ? "#333" : "#ccc");
this->ui_.titleLabel->setPalette(palette_title); this->ui_.titleLabel->setPalette(palette_title);
} }
for (RippleEffectButton *button : this->ui_.buttons) { for (RippleEffectButton *button : this->ui_.buttons) {
button->setMouseEffectColor(this->themeManager->window.text); button->setMouseEffectColor(this->theme->window.text);
} }
} else { } else {
QPalette palette; QPalette palette;
palette.setColor(QPalette::Background, this->themeManager->window.background); palette.setColor(QPalette::Background, this->theme->window.background);
palette.setColor(QPalette::Foreground, this->themeManager->window.text); palette.setColor(QPalette::Foreground, this->theme->window.text);
this->setPalette(palette); this->setPalette(palette);
} }
} }
@ -541,7 +541,7 @@ void BaseWindow::drawCustomWindowFrame(QPainter &painter)
if (this->hasCustomWindowFrame()) { if (this->hasCustomWindowFrame()) {
QPainter painter(this); 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); painter.fillRect(QRect(0, 1, this->width() - 0, this->height() - 0), bg);
} }

View file

@ -65,7 +65,7 @@ protected:
virtual void resizeEvent(QResizeEvent *) override; virtual void resizeEvent(QResizeEvent *) override;
virtual void closeEvent(QCloseEvent *) override; virtual void closeEvent(QCloseEvent *) override;
virtual void themeRefreshEvent() override; virtual void themeChangedEvent() override;
virtual bool event(QEvent *event) override; virtual bool event(QEvent *event) override;
virtual void wheelEvent(QWheelEvent *event) override; virtual void wheelEvent(QWheelEvent *event) override;

View file

@ -27,7 +27,7 @@ public:
void setHasOffset(bool hasOffset); void setHasOffset(bool hasOffset);
protected: protected:
virtual void scaleChangedEvent(float scale) override; virtual void scaleChangedEvent(float scale_) override;
virtual void paintEvent(QPaintEvent *) override; virtual void paintEvent(QPaintEvent *) override;
virtual QSize sizeHint() const override; virtual QSize sizeHint() const override;

View file

@ -375,7 +375,7 @@ void Notebook::paintEvent(QPaintEvent *event)
QPainter painter(this); QPainter painter(this);
painter.fillRect(0, this->lineY, this->width(), (int)(3 * this->getScale()), painter.fillRect(0, this->lineY, this->width(), (int)(3 * this->getScale()),
this->themeManager->tabs.bottomLine); this->theme->tabs.bottomLine);
} }
NotebookButton *Notebook::getAddButton() NotebookButton *Notebook::getAddButton()

View file

@ -50,7 +50,7 @@ public:
void performLayout(bool animate = false); void performLayout(bool animate = false);
protected: protected:
virtual void scaleChangedEvent(float scale) override; virtual void scaleChangedEvent(float scale_) override;
virtual void resizeEvent(QResizeEvent *) override; virtual void resizeEvent(QResizeEvent *) override;
virtual void paintEvent(QPaintEvent *) override; virtual void paintEvent(QPaintEvent *) override;

View file

@ -217,7 +217,7 @@ void Scrollbar::paintEvent(QPaintEvent *)
int xOffset = mouseOver ? 0 : width() - int(4 * this->getScale()); int xOffset = mouseOver ? 0 : width() - int(4 * this->getScale());
QPainter painter(this); 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), // painter.fillRect(QRect(xOffset, 0, width(), this->buttonHeight),
// this->themeManager->ScrollbarArrow); // this->themeManager->ScrollbarArrow);
@ -229,11 +229,11 @@ void Scrollbar::paintEvent(QPaintEvent *)
// mouse over thumb // mouse over thumb
if (this->mouseDownIndex_ == 2) { if (this->mouseDownIndex_ == 2) {
painter.fillRect(this->thumbRect_, this->themeManager->scrollbars.thumbSelected); painter.fillRect(this->thumbRect_, this->theme->scrollbars.thumbSelected);
} }
// mouse not over thumb // mouse not over thumb
else { else {
painter.fillRect(this->thumbRect_, this->themeManager->scrollbars.thumb); painter.fillRect(this->thumbRect_, this->theme->scrollbars.thumb);
} }
// draw highlights // draw highlights

View file

@ -62,7 +62,7 @@ void TooltipWidget::raise()
} }
#endif #endif
void TooltipWidget::themeRefreshEvent() void TooltipWidget::themeChangedEvent()
{ {
this->setStyleSheet("color: #fff; background: #000"); this->setStyleSheet("color: #fff; background: #000");
} }

View file

@ -27,7 +27,7 @@ public:
protected: protected:
void changeEvent(QEvent *) override; void changeEvent(QEvent *) override;
void leaveEvent(QEvent *) override; void leaveEvent(QEvent *) override;
void themeRefreshEvent() override; void themeChangedEvent() override;
void scaleChangedEvent(float) override; void scaleChangedEvent(float) override;
private: private:

View file

@ -267,11 +267,11 @@ void SelectChannelDialog::closeEvent(QCloseEvent *)
this->closed.invoke(); 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 }"); this->setStyleSheet("QRadioButton { color: #000 } QLabel { color: #000 }");
} else { } else {
this->setStyleSheet("QRadioButton { color: #fff } QLabel { color: #fff }"); this->setStyleSheet("QRadioButton { color: #fff } QLabel { color: #fff }");

View file

@ -24,7 +24,7 @@ public:
protected: protected:
virtual void closeEvent(QCloseEvent *) override; virtual void closeEvent(QCloseEvent *) override;
virtual void themeRefreshEvent() override; virtual void themeChangedEvent() override;
private: private:
class EventFilter : public QObject class EventFilter : public QObject

View file

@ -175,9 +175,9 @@ void SettingsDialog::scaleChangedEvent(float newDpi)
this->ui_.tabContainerContainer->setFixedWidth(int(200 * newDpi)); this->ui_.tabContainerContainer->setFixedWidth(int(200 * newDpi));
} }
void SettingsDialog::themeRefreshEvent() void SettingsDialog::themeChangedEvent()
{ {
BaseWindow::themeRefreshEvent(); BaseWindow::themeChangedEvent();
QPalette palette; QPalette palette;
palette.setColor(QPalette::Background, QColor("#444")); palette.setColor(QPalette::Background, QColor("#444"));

View file

@ -29,7 +29,7 @@ public:
protected: protected:
virtual void scaleChangedEvent(float newDpi) override; virtual void scaleChangedEvent(float newDpi) override;
virtual void themeRefreshEvent() override; virtual void themeChangedEvent() override;
private: private:
void refresh(); void refresh();

View file

@ -158,9 +158,9 @@ UserInfoPopup::UserInfoPopup()
this->installEvents(); this->installEvents();
} }
void UserInfoPopup::themeRefreshEvent() void UserInfoPopup::themeChangedEvent()
{ {
BaseWindow::themeRefreshEvent(); BaseWindow::themeChangedEvent();
this->setStyleSheet("background: #333"); this->setStyleSheet("background: #333");
} }

View file

@ -21,7 +21,7 @@ public:
void setData(const QString &name, const ChannelPtr &channel); void setData(const QString &name, const ChannelPtr &channel);
protected: protected:
virtual void themeRefreshEvent() override; virtual void themeChangedEvent() override;
private: private:
bool isMod_; bool isMod_;

View file

@ -131,9 +131,9 @@ ChannelView::~ChannelView()
{ {
} }
void ChannelView::themeRefreshEvent() void ChannelView::themeChangedEvent()
{ {
BaseWidget::themeRefreshEvent(); BaseWidget::themeChangedEvent();
this->layoutMessages(); this->layoutMessages();
} }
@ -575,7 +575,7 @@ void ChannelView::paintEvent(QPaintEvent * /*event*/)
QPainter painter(this); QPainter painter(this);
painter.fillRect(rect(), this->themeManager->splits.background); painter.fillRect(rect(), this->theme->splits.background);
// draw messages // draw messages
this->drawMessages(painter); this->drawMessages(painter);

View file

@ -53,7 +53,7 @@ public:
pajlada::Signals::Signal<const Link &> linkClicked; pajlada::Signals::Signal<const Link &> linkClicked;
protected: protected:
void themeRefreshEvent() override; void themeChangedEvent() override;
void resizeEvent(QResizeEvent *) override; void resizeEvent(QResizeEvent *) override;

View file

@ -32,9 +32,9 @@ NotebookButton::Icon NotebookButton::getIcon() const
return this->icon_; 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) void NotebookButton::paintEvent(QPaintEvent *event)
@ -45,11 +45,11 @@ void NotebookButton::paintEvent(QPaintEvent *event)
QColor foreground; QColor foreground;
if (mouseDown_ || mouseOver_) { if (mouseDown_ || mouseOver_) {
background = this->themeManager->tabs.regular.backgrounds.hover.color(); background = this->theme->tabs.regular.backgrounds.hover.color();
foreground = this->themeManager->tabs.regular.text; foreground = this->theme->tabs.regular.text;
} else { } else {
background = this->themeManager->tabs.regular.backgrounds.regular.color(); background = this->theme->tabs.regular.backgrounds.regular.color();
foreground = this->themeManager->tabs.regular.text; foreground = this->theme->tabs.regular.text;
} }
painter.setPen(Qt::NoPen); painter.setPen(Qt::NoPen);

View file

@ -21,7 +21,7 @@ public:
Icon getIcon() const; Icon getIcon() const;
protected: protected:
virtual void themeRefreshEvent() override; virtual void themeChangedEvent() override;
virtual void paintEvent(QPaintEvent *) override; virtual void paintEvent(QPaintEvent *) override;
virtual void mouseReleaseEvent(QMouseEvent *) override; virtual void mouseReleaseEvent(QMouseEvent *) override;
virtual void dragEnterEvent(QDragEnterEvent *) override; virtual void dragEnterEvent(QDragEnterEvent *) override;

View file

@ -64,12 +64,12 @@ NotebookTab::NotebookTab(Notebook *notebook)
// }); // });
} }
void NotebookTab::themeRefreshEvent() void NotebookTab::themeChangedEvent()
{ {
this->update(); this->update();
// this->setMouseEffectColor(QColor("#999")); // this->setMouseEffectColor(QColor("#999"));
this->setMouseEffectColor(this->themeManager->tabs.regular.text); this->setMouseEffectColor(this->theme->tabs.regular.text);
} }
void NotebookTab::updateSize() void NotebookTab::updateSize()
@ -222,16 +222,16 @@ void NotebookTab::paintEvent(QPaintEvent *)
// select the right tab colors // select the right tab colors
Theme::TabColors colors; Theme::TabColors colors;
Theme::TabColors regular = this->themeManager->tabs.regular; Theme::TabColors regular = this->theme->tabs.regular;
if (this->selected_) { if (this->selected_) {
colors = this->themeManager->tabs.selected; colors = this->theme->tabs.selected;
} else if (this->highlightState_ == HighlightState::Highlighted) { } else if (this->highlightState_ == HighlightState::Highlighted) {
colors = this->themeManager->tabs.highlighted; colors = this->theme->tabs.highlighted;
} else if (this->highlightState_ == HighlightState::NewMessage) { } else if (this->highlightState_ == HighlightState::NewMessage) {
colors = this->themeManager->tabs.newMessage; colors = this->theme->tabs.newMessage;
} else { } else {
colors = this->themeManager->tabs.regular; colors = this->theme->tabs.regular;
} }
bool windowFocused = this->window() == QApplication::activeWindow(); bool windowFocused = this->window() == QApplication::activeWindow();

View file

@ -47,7 +47,7 @@ public:
void hideTabXChanged(bool); void hideTabXChanged(bool);
protected: protected:
virtual void themeRefreshEvent() override; virtual void themeChangedEvent() override;
virtual void paintEvent(QPaintEvent *) override; virtual void paintEvent(QPaintEvent *) override;

View file

@ -121,7 +121,7 @@ void RippleEffectButton::fancyPaint(QPainter &painter)
if (this->mouseEffectColor_) { if (this->mouseEffectColor_) {
c = this->mouseEffectColor_.get(); c = this->mouseEffectColor_.get();
} else { } 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) { if (this->hoverMultiplier_ > 0) {

View file

@ -26,8 +26,8 @@ void TitleBarButton::paintEvent(QPaintEvent *event)
painter.setOpacity(this->getCurrentDimAmount()); painter.setOpacity(this->getCurrentDimAmount());
QColor color = this->themeManager->window.text; QColor color = this->theme->window.text;
QColor background = this->themeManager->window.background; QColor background = this->theme->window.background;
int xD = this->height() / 3; int xD = this->height() / 3;
int centerX = this->width() / 2; int centerX = this->width() / 2;
@ -50,7 +50,7 @@ void TitleBarButton::paintEvent(QPaintEvent *event)
painter.drawRect(centerX - xD / 2 + xD2, xD, xD3, xD3); painter.drawRect(centerX - xD / 2 + xD2, xD, xD3, xD3);
painter.fillRect(centerX - xD / 2, xD + xD2, 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); painter.drawRect(centerX - xD / 2, xD + xD2, xD3, xD3);
break; break;
} }

View file

@ -286,7 +286,7 @@ void Split::paintEvent(QPaintEvent *)
// color the background of the chat // color the background of the chat
QPainter painter(this); QPainter painter(this);
painter.fillRect(this->rect(), this->themeManager->splits.background); painter.fillRect(this->rect(), this->theme->splits.background);
} }
void Split::mouseMoveEvent(QMouseEvent *event) void Split::mouseMoveEvent(QMouseEvent *event)
@ -446,7 +446,7 @@ void Split::doOpenViewerList()
QList<QListWidgetItem *> labelList; QList<QListWidgetItem *> labelList;
for (auto &x : labels) { for (auto &x : labels) {
auto label = new QListWidgetItem(x); auto label = new QListWidgetItem(x);
label->setBackgroundColor(this->themeManager->splits.header.background); label->setBackgroundColor(this->theme->splits.header.background);
labelList.append(label); labelList.append(label);
} }
auto loadingLabel = new QLabel("Loading..."); auto loadingLabel = new QLabel("Loading...");
@ -503,7 +503,7 @@ void Split::doOpenViewerList()
dockVbox->addWidget(resultList); dockVbox->addWidget(resultList);
resultList->hide(); resultList->hide();
multiWidget->setStyleSheet(this->themeManager->splits.input.styleSheet); multiWidget->setStyleSheet(this->theme->splits.input.styleSheet);
multiWidget->setLayout(dockVbox); multiWidget->setLayout(dockVbox);
viewerDock->setWidget(multiWidget); viewerDock->setWidget(multiWidget);
viewerDock->show(); viewerDock->show();

View file

@ -400,9 +400,9 @@ void SplitContainer::paintEvent(QPaintEvent *)
QPainter painter(this); QPainter painter(this);
if (this->splits.size() == 0) { 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"; QString text = "Click to add a split";
@ -445,7 +445,7 @@ void SplitContainer::paintEvent(QPaintEvent *)
int s = std::min<int>(dropRect.rect.width(), dropRect.rect.height()) - 12; int s = std::min<int>(dropRect.rect.width(), dropRect.rect.height()) - 12;
if (this->themeManager->isLightTheme()) { if (this->theme->isLightTheme()) {
painter.setPen(QColor(0, 0, 0)); painter.setPen(QColor(0, 0, 0));
} else { } else {
painter.setPen(QColor(255, 255, 255)); painter.setPen(QColor(255, 255, 255));
@ -457,8 +457,8 @@ void SplitContainer::paintEvent(QPaintEvent *)
} }
QBrush accentColor = (QApplication::activeWindow() == this->window() QBrush accentColor = (QApplication::activeWindow() == this->window()
? this->themeManager->tabs.selected.backgrounds.regular ? this->theme->tabs.selected.backgrounds.regular
: this->themeManager->tabs.selected.backgrounds.unfocused); : this->theme->tabs.selected.backgrounds.unfocused);
painter.fillRect(0, 0, width(), 1, accentColor); painter.fillRect(0, 0, width(), 1, accentColor);
} }

View file

@ -28,8 +28,8 @@ SplitHeader::SplitHeader(Split *_split)
: BaseWidget(_split) : BaseWidget(_split)
, split(_split) , split(_split)
{ {
this->split->focused.connect([this]() { this->themeRefreshEvent(); }); this->split->focused.connect([this]() { this->themeChangedEvent(); });
this->split->focusLost.connect([this]() { this->themeRefreshEvent(); }); this->split->focusLost.connect([this]() { this->themeChangedEvent(); });
auto app = getApp(); auto app = getApp();
@ -374,8 +374,8 @@ void SplitHeader::paintEvent(QPaintEvent *)
{ {
QPainter painter(this); QPainter painter(this);
painter.fillRect(rect(), this->themeManager->splits.header.background); painter.fillRect(rect(), this->theme->splits.header.background);
painter.setPen(this->themeManager->splits.header.border); painter.setPen(this->theme->splits.header.border);
painter.drawRect(0, 0, width() - 1, height() - 1); painter.drawRect(0, 0, width() - 1, height() - 1);
} }
@ -468,17 +468,17 @@ void SplitHeader::rightButtonClicked()
{ {
} }
void SplitHeader::themeRefreshEvent() void SplitHeader::themeChangedEvent()
{ {
QPalette palette; QPalette palette;
if (this->split->hasFocus()) { if (this->split->hasFocus()) {
palette.setColor(QPalette::Foreground, this->themeManager->splits.header.focusedText); palette.setColor(QPalette::Foreground, this->theme->splits.header.focusedText);
} else { } 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")); this->dropdownButton->setPixmap(QPixmap(":/images/menu_black.png"));
} else { } else {
this->dropdownButton->setPixmap(QPixmap(":/images/menu_white.png")); this->dropdownButton->setPixmap(QPixmap(":/images/menu_white.png"));

View file

@ -38,7 +38,7 @@ public:
protected: protected:
virtual void scaleChangedEvent(float) override; virtual void scaleChangedEvent(float) override;
virtual void themeRefreshEvent() override; virtual void themeChangedEvent() override;
virtual void paintEvent(QPaintEvent *) override; virtual void paintEvent(QPaintEvent *) override;
virtual void mousePressEvent(QMouseEvent *event) override; virtual void mousePressEvent(QMouseEvent *event) override;

View file

@ -111,18 +111,18 @@ void SplitInput::scaleChangedEvent(float scale)
this->ui_.textEdit->setFont(getApp()->fonts->getFont(FontStyle::ChatMedium, this->getScale())); this->ui_.textEdit->setFont(getApp()->fonts->getFont(FontStyle::ChatMedium, this->getScale()));
} }
void SplitInput::themeRefreshEvent() void SplitInput::themeChangedEvent()
{ {
QPalette palette; QPalette palette;
palette.setColor(QPalette::Foreground, this->themeManager->splits.input.text); palette.setColor(QPalette::Foreground, this->theme->splits.input.text);
this->updateEmoteButton(); this->updateEmoteButton();
this->ui_.textEditLength->setPalette(palette); 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"); this->ui_.emoteButton->getLabel().setStyleSheet("color: #000");
} }
@ -134,7 +134,7 @@ void SplitInput::updateEmoteButton()
QString text = "<img src=':/images/emote.svg' width='xD' height='xD' />"; QString text = "<img src=':/images/emote.svg' width='xD' height='xD' />";
text.replace("xD", QString::number(int(12 * scale))); text.replace("xD", QString::number(int(12 * scale)));
if (this->themeManager->isLightTheme()) { if (this->theme->isLightTheme()) {
text.replace("emote", "emote_dark"); text.replace("emote", "emote_dark");
} }
@ -322,11 +322,11 @@ void SplitInput::paintEvent(QPaintEvent *)
{ {
QPainter painter(this); QPainter painter(this);
if (this->themeManager->isLightTheme()) { if (this->theme->isLightTheme()) {
int s = int(3 * this->getScale()); int s = int(3 * this->getScale());
QRect rect = this->rect().marginsRemoved(QMargins(s, s, s, s)); 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.setPen(QColor("#ccc"));
painter.drawRect(rect); painter.drawRect(rect);
@ -334,7 +334,7 @@ void SplitInput::paintEvent(QPaintEvent *)
int s = int(1 * this->getScale()); int s = int(1 * this->getScale());
QRect rect = this->rect().marginsRemoved(QMargins(s, s, s, s)); 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.setPen(QColor("#333"));
painter.drawRect(rect); painter.drawRect(rect);

View file

@ -31,8 +31,8 @@ public:
pajlada::Signals::Signal<const QString &> textChanged; pajlada::Signals::Signal<const QString &> textChanged;
protected: protected:
virtual void scaleChangedEvent(float scale) override; virtual void scaleChangedEvent(float scale_) override;
virtual void themeRefreshEvent() override; virtual void themeChangedEvent() override;
virtual void paintEvent(QPaintEvent *) override; virtual void paintEvent(QPaintEvent *) override;
virtual void resizeEvent(QResizeEvent *) override; virtual void resizeEvent(QResizeEvent *) override;

View file

@ -91,7 +91,7 @@ SplitOverlay::SplitOverlay(Split *parent)
void SplitOverlay::paintEvent(QPaintEvent *) void SplitOverlay::paintEvent(QPaintEvent *)
{ {
QPainter painter(this); QPainter painter(this);
if (this->themeManager->isLightTheme()) { if (this->theme->isLightTheme()) {
painter.fillRect(this->rect(), QColor(255, 255, 255, 200)); painter.fillRect(this->rect(), QColor(255, 255, 255, 200));
} else { } else {
painter.fillRect(this->rect(), QColor(0, 0, 0, 150)); painter.fillRect(this->rect(), QColor(0, 0, 0, 150));