Add basic color scheme handling

Fix #59
This commit is contained in:
Rasmus Karlsson 2017-07-02 14:28:37 +02:00
parent c5c2718dc0
commit ddf886eaf1
13 changed files with 83 additions and 39 deletions

View file

@ -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 \

View file

@ -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,

View file

@ -68,7 +68,6 @@ public:
const int HighlightColorCount = 3;
QColor HighlightColors[3];
void init(WindowManager &windowManager);
void normalizeColor(QColor &color);
void update();

View file

@ -0,0 +1,39 @@
#include "widgets/basewidget.hpp"
#include "colorscheme.hpp"
#include <QDebug>
#include <boost/signals2.hpp>
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

View file

@ -1,7 +1,5 @@
#pragma once
#include "colorscheme.hpp"
#include <QWidget>
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

View file

@ -57,7 +57,7 @@ public:
void giveFocus();
protected:
void paintEvent(QPaintEvent *) override;
virtual void paintEvent(QPaintEvent *) override;
private:
ChannelManager &channelManager;

View file

@ -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()
{
}

View file

@ -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();

View file

@ -39,8 +39,9 @@ private:
QLabel textLengthLabel;
ChatWidgetHeaderButton emotesLabel;
virtual void refreshTheme() override;
private slots:
void refreshTheme();
void setMessageLengthVisisble(bool value)
{
textLengthLabel.setHidden(!value);

View file

@ -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<messages::MessageRef> &message,
QPoint &relativePos);

View file

@ -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

View file

@ -44,6 +44,8 @@ protected:
virtual void closeEvent(QCloseEvent *event) override;
private:
virtual void refreshTheme() override;
ChannelManager &channelManager;
ColorScheme &colorScheme;

View file

@ -1,4 +1,5 @@
#include "widgets/notebookpagedroppreview.hpp"
#include "colorscheme.hpp"
#include <QDebug>
#include <QPainter>
@ -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 *)