Skip to content

Commit

Permalink
Add basic color scheme handling
Browse files Browse the repository at this point in the history
  • Loading branch information
pajlada committed Jul 2, 2017
1 parent c5c2718 commit ddf886e
Show file tree
Hide file tree
Showing 13 changed files with 84 additions and 40 deletions.
3 changes: 2 additions & 1 deletion chatterino.pro
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
2 changes: 1 addition & 1 deletion src/colorscheme.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 0 additions & 1 deletion src/colorscheme.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ class ColorScheme
const int HighlightColorCount = 3;
QColor HighlightColors[3];

void init(WindowManager &windowManager);
void normalizeColor(QColor &color);

void update();
Expand Down
39 changes: 39 additions & 0 deletions src/widgets/basewidget.cpp
Original file line number Diff line number Diff line change
@@ -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
21 changes: 8 additions & 13 deletions src/widgets/basewidget.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#pragma once

#include "colorscheme.hpp"

#include <QWidget>

namespace chatterino {
Expand All @@ -15,19 +13,16 @@ class BaseWidget : public QWidget
Q_OBJECT

public:
explicit BaseWidget(ColorScheme &_colorScheme, QWidget *parent)
: QWidget(parent)
, colorScheme(_colorScheme)
{
}

explicit BaseWidget(BaseWidget *parent)
: QWidget(parent)
, colorScheme(parent->colorScheme)
{
}
explicit BaseWidget(ColorScheme &_colorScheme, QWidget *parent);

explicit BaseWidget(BaseWidget *parent);

ColorScheme &colorScheme;

private:
void init();

virtual void refreshTheme();
};

} // namespace widgets
Expand Down
2 changes: 1 addition & 1 deletion src/widgets/chatwidget.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class ChatWidget : public BaseWidget
void giveFocus();

protected:
void paintEvent(QPaintEvent *) override;
virtual void paintEvent(QPaintEvent *) override;

private:
ChannelManager &channelManager;
Expand Down
23 changes: 12 additions & 11 deletions src/widgets/chatwidgetheader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ ChatWidgetHeader::ChatWidgetHeader(ChatWidget *_chatWidget)
{
this->setFixedHeight(32);

this->updateColors();
this->refreshTheme();

this->updateChannelText();

this->setLayout(&this->hbox);
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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()
{
}
Expand Down
5 changes: 2 additions & 3 deletions src/widgets/chatwidgetheader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -62,6 +59,8 @@ class ChatWidgetHeader : public BaseWidget
void leftButtonClicked();
void rightButtonClicked();

virtual void refreshTheme() override;

public slots:
void menuMoveSplit();
void menuReloadChannelEmotes();
Expand Down
3 changes: 2 additions & 1 deletion src/widgets/chatwidgetinput.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ class ChatWidgetInput : public BaseWidget
QLabel textLengthLabel;
ChatWidgetHeaderButton emotesLabel;

virtual void refreshTheme() override;

private slots:
void refreshTheme();
void setMessageLengthVisisble(bool value)
{
textLengthLabel.setHidden(!value);
Expand Down
6 changes: 3 additions & 3 deletions src/widgets/chatwidgetview.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ class ChatWidgetView : public BaseWidget
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);
Expand Down
13 changes: 9 additions & 4 deletions src/widgets/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
2 changes: 2 additions & 0 deletions src/widgets/mainwindow.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ class MainWindow : public BaseWidget
virtual void closeEvent(QCloseEvent *event) override;

private:
virtual void refreshTheme() override;

ChannelManager &channelManager;
ColorScheme &colorScheme;

Expand Down
4 changes: 3 additions & 1 deletion src/widgets/notebookpagedroppreview.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "widgets/notebookpagedroppreview.hpp"
#include "colorscheme.hpp"

#include <QDebug>
#include <QPainter>
Expand All @@ -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 *)
Expand Down

0 comments on commit ddf886e

Please sign in to comment.