Perform initial refactoring work

Things that were once singletons are no longer singletons, but are
instead stored in the "Application" singleton

Some singletons still remain, and some renaming/renamespacing is left
This commit is contained in:
Rasmus Karlsson
2018-04-27 22:11:19 +02:00
parent 32b6417a55
commit ae26b835b6
78 changed files with 850 additions and 773 deletions
+14 -17
View File
@@ -1,4 +1,6 @@
#include "widgets/accountpopup.hpp"
#include "application.hpp"
#include "channel.hpp"
#include "credentials.hpp"
#include "singletons/accountmanager.hpp"
@@ -23,6 +25,8 @@ AccountPopupWidget::AccountPopupWidget(ChannelPtr _channel)
, ui(new Ui::AccountPopup)
, channel(_channel)
{
auto app = getApp();
this->ui->setupUi(this);
this->setStayInScreenRect(true);
@@ -33,15 +37,11 @@ AccountPopupWidget::AccountPopupWidget(ChannelPtr _channel)
this->resize(0, 0);
auto &accountManager = singletons::AccountManager::getInstance();
connect(this, &AccountPopupWidget::refreshButtons, this,
&AccountPopupWidget::actuallyRefreshButtons, Qt::QueuedConnection);
accountManager.Twitch.userChanged.connect([this] {
singletons::AccountManager &accountManager = singletons::AccountManager::getInstance();
auto currentTwitchUser = accountManager.Twitch.getCurrent();
app->accounts->Twitch.userChanged.connect([=] {
auto currentTwitchUser = app->accounts->Twitch.getCurrent();
if (!currentTwitchUser) {
// No twitch user set (should never happen)
return;
@@ -53,8 +53,6 @@ AccountPopupWidget::AccountPopupWidget(ChannelPtr _channel)
this->loggedInUser.refreshUserType(this->channel, true);
});
singletons::SettingManager &settings = singletons::SettingManager::getInstance();
for (auto button : this->ui->profileLayout->findChildren<QPushButton *>()) {
button->setFocusProxy(this);
}
@@ -129,19 +127,19 @@ AccountPopupWidget::AccountPopupWidget(ChannelPtr _channel)
}
});
QObject::connect(this->ui->disableHighlights, &QPushButton::clicked, this, [=, &settings]() {
QString str = settings.highlightUserBlacklist;
QObject::connect(this->ui->disableHighlights, &QPushButton::clicked, this, [=]() {
QString str = app->settings->highlightUserBlacklist;
str.append(this->ui->lblUsername->text() + "\n");
settings.highlightUserBlacklist = str;
app->settings->highlightUserBlacklist = str;
this->ui->disableHighlights->hide();
this->ui->enableHighlights->show();
});
QObject::connect(this->ui->enableHighlights, &QPushButton::clicked, this, [=, &settings]() {
QString str = settings.highlightUserBlacklist;
QObject::connect(this->ui->enableHighlights, &QPushButton::clicked, this, [=]() {
QString str = app->settings->highlightUserBlacklist;
QStringList list = str.split("\n");
list.removeAll(this->ui->lblUsername->text());
settings.highlightUserBlacklist = list.join("\n");
app->settings->highlightUserBlacklist = list.join("\n");
this->ui->enableHighlights->hide();
this->ui->disableHighlights->show();
});
@@ -279,8 +277,7 @@ void AccountPopupWidget::sendCommand(QPushButton *button, QString command)
void AccountPopupWidget::refreshLayouts()
{
singletons::AccountManager &accountManager = singletons::AccountManager::getInstance();
auto currentTwitchUser = accountManager.Twitch.getCurrent();
auto currentTwitchUser = getApp()->accounts->Twitch.getCurrent();
if (!currentTwitchUser) {
// No twitch user set (should never happen)
return;
@@ -378,7 +375,7 @@ void AccountPopupWidget::showEvent(QShowEvent *)
this->refreshLayouts();
QString blacklisted = singletons::SettingManager::getInstance().highlightUserBlacklist;
QString blacklisted = getApp()->settings->highlightUserBlacklist;
QStringList list = blacklisted.split("\n", QString::SkipEmptyParts);
if (list.contains(this->ui->lblUsername->text(), Qt::CaseInsensitive)) {
this->ui->disableHighlights->hide();
+12 -8
View File
@@ -1,4 +1,6 @@
#include "accountswitchwidget.hpp"
#include "application.hpp"
#include "const.hpp"
#include "singletons/accountmanager.hpp"
@@ -8,22 +10,22 @@ namespace widgets {
AccountSwitchWidget::AccountSwitchWidget(QWidget *parent)
: QListWidget(parent)
{
singletons::AccountManager &accountManager = singletons::AccountManager::getInstance();
auto app = getApp();
this->addItem(ANONYMOUS_USERNAME_LABEL);
for (const auto &userName : accountManager.Twitch.getUsernames()) {
for (const auto &userName : app->accounts->Twitch.getUsernames()) {
this->addItem(userName);
}
accountManager.Twitch.userListUpdated.connect([this, &accountManager]() {
app->accounts->Twitch.userListUpdated.connect([=]() {
this->blockSignals(true);
this->clear();
this->addItem(ANONYMOUS_USERNAME_LABEL);
for (const auto &userName : accountManager.Twitch.getUsernames()) {
for (const auto &userName : app->accounts->Twitch.getUsernames()) {
this->addItem(userName);
}
@@ -34,13 +36,13 @@ AccountSwitchWidget::AccountSwitchWidget(QWidget *parent)
this->refreshSelection();
QObject::connect(this, &QListWidget::clicked, [this, &accountManager] {
QObject::connect(this, &QListWidget::clicked, [=] {
if (!this->selectedItems().isEmpty()) {
QString newUsername = this->currentItem()->text();
if (newUsername.compare(ANONYMOUS_USERNAME_LABEL, Qt::CaseInsensitive) == 0) {
accountManager.Twitch.currentUsername = "";
app->accounts->Twitch.currentUsername = "";
} else {
accountManager.Twitch.currentUsername = newUsername.toStdString();
app->accounts->Twitch.currentUsername = newUsername.toStdString();
}
}
});
@@ -57,7 +59,9 @@ void AccountSwitchWidget::refreshSelection()
// Select the currently logged in user
if (this->count() > 0) {
auto currentUser = singletons::AccountManager::getInstance().Twitch.getCurrent();
auto app = getApp();
auto currentUser = app->accounts->Twitch.getCurrent();
if (currentUser->isAnon()) {
this->setCurrentRow(0);
+3 -1
View File
@@ -1,5 +1,7 @@
#include "attachedwindow.hpp"
#include "application.hpp"
#include <QTimer>
#include <QVBoxLayout>
@@ -22,7 +24,7 @@ AttachedWindow::AttachedWindow(void *_target, int _yOffset)
layout->setMargin(0);
this->setLayout(layout);
auto *split = new Split(singletons::ThemeManager::getInstance(), this);
auto *split = new Split(this);
this->ui.split = split;
split->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::MinimumExpanding);
layout->addWidget(split);
+7 -10
View File
@@ -1,4 +1,6 @@
#include "widgets/basewidget.hpp"
#include "application.hpp"
#include "debug/log.hpp"
#include "singletons/settingsmanager.hpp"
#include "singletons/thememanager.hpp"
@@ -12,16 +14,8 @@
namespace chatterino {
namespace widgets {
BaseWidget::BaseWidget(singletons::ThemeManager &_themeManager, QWidget *parent, Qt::WindowFlags f)
BaseWidget::BaseWidget(QWidget *parent, Qt::WindowFlags f)
: QWidget(parent, f)
, themeManager(_themeManager)
{
this->init();
}
BaseWidget::BaseWidget(BaseWidget *parent, Qt::WindowFlags f)
: QWidget(parent, f)
, themeManager(singletons::ThemeManager::getInstance())
{
this->init();
}
@@ -87,7 +81,10 @@ void BaseWidget::setScaleIndependantHeight(int value)
void BaseWidget::init()
{
this->themeConnection = this->themeManager.updated.connect([this]() {
auto app = getApp();
this->themeManager = app->themes;
this->themeConnection = this->themeManager->updated.connect([this]() {
this->themeRefreshEvent();
this->update();
+3 -5
View File
@@ -17,13 +17,9 @@ class BaseWidget : public QWidget
Q_OBJECT
public:
explicit BaseWidget(singletons::ThemeManager &_themeManager, QWidget *parent,
Qt::WindowFlags f = Qt::WindowFlags());
explicit BaseWidget(BaseWidget *parent, Qt::WindowFlags f = Qt::WindowFlags());
explicit BaseWidget(QWidget *parent, Qt::WindowFlags f = Qt::WindowFlags());
virtual ~BaseWidget();
singletons::ThemeManager &themeManager;
float getScale() const;
pajlada::Signals::Signal<float> scaleChanged;
@@ -45,6 +41,8 @@ protected:
void setScale(float value);
singletons::ThemeManager *themeManager;
private:
void init();
float scale = 1.f;
+11 -23
View File
@@ -1,5 +1,6 @@
#include "basewindow.hpp"
#include "application.hpp"
#include "debug/log.hpp"
#include "singletons/settingsmanager.hpp"
#include "util/nativeeventhelper.hpp"
@@ -31,23 +32,8 @@
namespace chatterino {
namespace widgets {
BaseWindow::BaseWindow(singletons::ThemeManager &_themeManager, QWidget *parent,
bool _enableCustomFrame)
: BaseWidget(_themeManager, parent, Qt::Window)
, enableCustomFrame(_enableCustomFrame)
{
this->init();
}
BaseWindow::BaseWindow(BaseWidget *parent, bool _enableCustomFrame)
: BaseWidget(parent, Qt::Window)
, enableCustomFrame(_enableCustomFrame)
{
this->init();
}
BaseWindow::BaseWindow(QWidget *parent, bool _enableCustomFrame)
: BaseWidget(singletons::ThemeManager::getInstance(), parent, Qt::Window)
: BaseWidget(parent, Qt::Window)
, enableCustomFrame(_enableCustomFrame)
{
this->init();
@@ -55,6 +41,8 @@ BaseWindow::BaseWindow(QWidget *parent, bool _enableCustomFrame)
void BaseWindow::init()
{
auto app = getApp();
this->setWindowIcon(QIcon(":/images/icon.png"));
#ifdef USEWINSDK
@@ -127,7 +115,7 @@ void BaseWindow::init()
}
#endif
if (singletons::SettingManager::getInstance().windowTopMost.getValue()) {
if (app->settings->windowTopMost.getValue()) {
this->setWindowFlags(this->windowFlags() | Qt::WindowStaysOnTopHint);
}
}
@@ -167,21 +155,21 @@ void BaseWindow::themeRefreshEvent()
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->themeManager->window.text);
this->setPalette(palette);
QPalette palette_title;
palette_title.setColor(QPalette::Foreground,
this->themeManager.isLightTheme() ? "#333" : "#ccc");
this->themeManager->isLightTheme() ? "#333" : "#ccc");
this->ui.titleLabel->setPalette(palette_title);
for (RippleEffectButton *button : this->ui.buttons) {
button->setMouseEffectColor(this->themeManager.window.text);
button->setMouseEffectColor(this->themeManager->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->themeManager->window.background);
palette.setColor(QPalette::Foreground, this->themeManager->window.text);
this->setPalette(palette);
}
}
@@ -430,7 +418,7 @@ void BaseWindow::paintEvent(QPaintEvent *event)
// bool windowFocused = this->window() == QApplication::activeWindow();
painter.fillRect(QRect(0, 1, this->width() - 0, this->height() - 0),
this->themeManager.window.background);
this->themeManager->window.background);
}
}
-3
View File
@@ -19,9 +19,6 @@ class BaseWindow : public BaseWidget
Q_OBJECT
public:
explicit BaseWindow(singletons::ThemeManager &_themeManager, QWidget *parent,
bool enableCustomFrame = false);
explicit BaseWindow(BaseWidget *parent, bool enableCustomFrame = false);
explicit BaseWindow(QWidget *parent = nullptr, bool enableCustomFrame = false);
QWidget *getLayoutContainer();
+12 -11
View File
@@ -1,21 +1,22 @@
#include "emotepopup.hpp"
#include <QHBoxLayout>
#include <QTabWidget>
#include "application.hpp"
#include "messages/messagebuilder.hpp"
#include "providers/twitch/twitchchannel.hpp"
#include "singletons/accountmanager.hpp"
#include "widgets/notebook.hpp"
#include <QHBoxLayout>
#include <QTabWidget>
using namespace chatterino::providers::twitch;
using namespace chatterino::messages;
namespace chatterino {
namespace widgets {
EmotePopup::EmotePopup(singletons::ThemeManager &themeManager)
: BaseWindow(themeManager, nullptr, true)
EmotePopup::EmotePopup()
: BaseWindow(nullptr, true)
{
this->viewEmotes = new ChannelView();
this->viewEmojis = new ChannelView();
@@ -80,16 +81,16 @@ void EmotePopup::loadChannel(ChannelPtr _channel)
emoteChannel->addMessage(builder2.getMessage());
};
singletons::EmoteManager &emoteManager = singletons::EmoteManager::getInstance();
auto app = getApp();
QString userID = singletons::AccountManager::getInstance().Twitch.getCurrent()->getUserId();
QString userID = app->accounts->Twitch.getCurrent()->getUserId();
addEmotes(emoteManager.twitchAccountEmotes[userID.toStdString()].emotes,
addEmotes(app->emotes->twitchAccountEmotes[userID.toStdString()].emotes,
"Twitch Account Emotes", "Twitch Account Emote");
addEmotes(emoteManager.bttvGlobalEmotes, "BetterTTV Global Emotes", "BetterTTV Global Emote");
addEmotes(app->emotes->bttvGlobalEmotes, "BetterTTV Global Emotes", "BetterTTV Global Emote");
addEmotes(*channel->bttvChannelEmotes.get(), "BetterTTV Channel Emotes",
"BetterTTV Channel Emote");
addEmotes(emoteManager.ffzGlobalEmotes, "FrankerFaceZ Global Emotes",
addEmotes(app->emotes->ffzGlobalEmotes, "FrankerFaceZ Global Emotes",
"FrankerFaceZ Global Emote");
addEmotes(*channel->ffzChannelEmotes.get(), "FrankerFaceZ Channel Emotes",
"FrankerFaceZ Channel Emote");
@@ -99,7 +100,7 @@ void EmotePopup::loadChannel(ChannelPtr _channel)
void EmotePopup::loadEmojis()
{
auto &emojis = singletons::EmoteManager::getInstance().getEmojis();
auto &emojis = getApp()->emotes->getEmojis();
ChannelPtr emojiChannel(new Channel("", Channel::None));
+1 -1
View File
@@ -12,7 +12,7 @@ namespace widgets {
class EmotePopup : public BaseWindow
{
public:
explicit EmotePopup(singletons::ThemeManager &);
EmotePopup();
void loadChannel(ChannelPtr channel);
void loadEmojis();
+47 -28
View File
@@ -1,4 +1,6 @@
#include "channelview.hpp"
#include "application.hpp"
#include "debug/log.hpp"
#include "messages/layouts/messagelayout.hpp"
#include "messages/limitedqueuesnapshot.hpp"
@@ -38,14 +40,17 @@ ChannelView::ChannelView(BaseWidget *parent)
, scrollBar(this)
, userPopupWidget(std::shared_ptr<TwitchChannel>())
{
auto app = getApp();
#ifndef Q_OS_MAC
// this->setAttribute(Qt::WA_OpaquePaintEvent);
#endif
this->setMouseTracking(true);
QObject::connect(&singletons::SettingManager::getInstance(),
&singletons::SettingManager::wordFlagsChanged, this,
&ChannelView::wordFlagsChanged);
this->managedConnections.emplace_back(app->settings->wordFlagsChanged.connect([=] {
this->layoutMessages();
this->update();
}));
this->scrollBar.getCurrentValueChanged().connect([this] {
// Whenever the scrollbar value has been changed, re-render the ChatWidgetView
@@ -56,10 +61,10 @@ ChannelView::ChannelView(BaseWidget *parent)
this->queueUpdate();
});
singletons::WindowManager &windowManager = singletons::WindowManager::getInstance();
this->repaintGifsConnection = windowManager.repaintGifs.connect([&] { this->queueUpdate(); });
this->layoutConnection = windowManager.layout.connect([&](Channel *channel) {
this->repaintGifsConnection = app->windows->repaintGifs.connect([&] {
this->queueUpdate(); //
});
this->layoutConnection = app->windows->layout.connect([&](Channel *channel) {
if (channel == nullptr || this->channel.get() == channel) {
this->layoutMessages();
}
@@ -75,10 +80,10 @@ ChannelView::ChannelView(BaseWidget *parent)
this->layoutMessages(); //
}));
connect(goToBottom, &RippleEffectLabel::clicked, this, [this] {
QTimer::singleShot(180, [this] {
this->scrollBar.scrollToBottom(singletons::SettingManager::getInstance()
.enableSmoothScrollingNewMessages.getValue());
connect(goToBottom, &RippleEffectLabel::clicked, this, [=] {
QTimer::singleShot(180, [=] {
this->scrollBar.scrollToBottom(
app->settings->enableSmoothScrollingNewMessages.getValue());
});
});
@@ -100,8 +105,11 @@ ChannelView::ChannelView(BaseWidget *parent)
this->scrollBar.resize(this->scrollBar.width(), this->height() + 1);
singletons::SettingManager::getInstance().showLastMessageIndicator.connect(
[this](auto, auto) { this->update(); }, this->managedConnections);
app->settings->showLastMessageIndicator.connect(
[this](auto, auto) {
this->update(); //
},
this->managedConnections);
this->layoutCooldown = new QTimer(this);
this->layoutCooldown->setSingleShot(true);
@@ -117,9 +125,6 @@ ChannelView::ChannelView(BaseWidget *parent)
ChannelView::~ChannelView()
{
QObject::disconnect(&singletons::SettingManager::getInstance(),
&singletons::SettingManager::wordFlagsChanged, this,
&ChannelView::wordFlagsChanged);
this->messageAppendedConnection.disconnect();
this->messageRemovedConnection.disconnect();
this->repaintGifsConnection.disconnect();
@@ -161,6 +166,8 @@ void ChannelView::layoutMessages()
void ChannelView::actuallyLayoutMessages()
{
auto app = getApp();
// BENCH(timer)
auto messagesSnapshot = this->getMessagesSnapshot();
@@ -238,9 +245,8 @@ void ChannelView::actuallyLayoutMessages()
// Perhaps also if the user scrolled with the scrollwheel in this ChatWidget in the last 0.2
// seconds or something
if (this->enableScrollingToBottom && this->showingLatestMessages && showScrollbar) {
this->scrollBar.scrollToBottom(
this->messageWasAdded &&
singletons::SettingManager::getInstance().enableSmoothScrollingNewMessages.getValue());
this->scrollBar.scrollToBottom(this->messageWasAdded &&
app->settings->enableSmoothScrollingNewMessages.getValue());
this->messageWasAdded = false;
}
@@ -494,11 +500,13 @@ void ChannelView::setSelection(const SelectionItem &start, const SelectionItem &
messages::MessageElement::Flags ChannelView::getFlags() const
{
auto app = getApp();
if (this->overrideFlags) {
return this->overrideFlags.get();
}
MessageElement::Flags flags = singletons::SettingManager::getInstance().getWordFlags();
MessageElement::Flags flags = app->settings->getWordFlags();
Split *split = dynamic_cast<Split *>(this->parentWidget());
@@ -520,7 +528,7 @@ void ChannelView::paintEvent(QPaintEvent * /*event*/)
QPainter painter(this);
painter.fillRect(rect(), this->themeManager.splits.background);
painter.fillRect(rect(), this->themeManager->splits.background);
// draw messages
this->drawMessages(painter);
@@ -532,6 +540,8 @@ void ChannelView::paintEvent(QPaintEvent * /*event*/)
// overlay when a message is disabled
void ChannelView::drawMessages(QPainter &painter)
{
auto app = getApp();
auto messagesSnapshot = this->getMessagesSnapshot();
size_t start = this->scrollBar.getCurrentValue();
@@ -550,7 +560,7 @@ void ChannelView::drawMessages(QPainter &painter)
messages::MessageLayout *layout = messagesSnapshot[i].get();
bool isLastMessage = false;
if (singletons::SettingManager::getInstance().showLastMessageIndicator) {
if (app->settings->showLastMessageIndicator) {
isLastMessage = this->lastReadMessage.get() == layout;
}
@@ -599,7 +609,9 @@ void ChannelView::drawMessages(QPainter &painter)
void ChannelView::wheelEvent(QWheelEvent *event)
{
if (this->scrollBar.isVisible()) {
float mouseMultiplier = singletons::SettingManager::getInstance().mouseScrollMultiplier;
auto app = getApp();
float mouseMultiplier = app->settings->mouseScrollMultiplier;
float desired = this->scrollBar.getDesiredValue();
float delta = event->delta() * 1.5 * mouseMultiplier;
@@ -677,7 +689,9 @@ void ChannelView::mouseMoveEvent(QMouseEvent *event)
return;
}
if (singletons::SettingManager::getInstance().pauseChatHover.getValue()) {
auto app = getApp();
if (app->settings->pauseChatHover.getValue()) {
this->pause(300);
}
@@ -745,7 +759,9 @@ void ChannelView::mousePressEvent(QMouseEvent *event)
return;
}
if (singletons::SettingManager::getInstance().linksDoubleClickOnly.getValue()) {
auto app = getApp();
if (app->settings->linksDoubleClickOnly.getValue()) {
this->pause(200);
}
@@ -808,6 +824,8 @@ void ChannelView::mouseReleaseEvent(QMouseEvent *event)
return;
}
auto app = getApp();
if (this->selecting) {
this->paused = false;
}
@@ -852,8 +870,7 @@ void ChannelView::mouseReleaseEvent(QMouseEvent *event)
}
auto &link = hoverLayoutElement->getLink();
if (event->button() != Qt::LeftButton ||
!singletons::SettingManager::getInstance().linksDoubleClickOnly) {
if (event->button() != Qt::LeftButton || !app->settings->linksDoubleClickOnly) {
this->handleLinkClick(event, link, layout.get());
}
@@ -862,7 +879,9 @@ void ChannelView::mouseReleaseEvent(QMouseEvent *event)
void ChannelView::mouseDoubleClickEvent(QMouseEvent *event)
{
if (singletons::SettingManager::getInstance().linksDoubleClickOnly) {
auto app = getApp();
if (app->settings->linksDoubleClickOnly) {
std::shared_ptr<messages::MessageLayout> layout;
QPoint relativePos;
int messageIndex;
+1 -1
View File
@@ -20,7 +20,7 @@ void NotebookPageDropPreview::paintEvent(QPaintEvent *)
QPainter painter(this);
painter.fillRect(8, 8, this->width() - 17, this->height() - 17,
this->themeManager.splits.dropPreview);
this->themeManager->splits.dropPreview);
}
void NotebookPageDropPreview::hideEvent(QHideEvent *)
+5 -5
View File
@@ -22,7 +22,7 @@ NotebookButton::NotebookButton(BaseWidget *parent)
void NotebookButton::themeRefreshEvent()
{
this->setMouseEffectColor(this->themeManager.tabs.regular.text);
this->setMouseEffectColor(this->themeManager->tabs.regular.text);
}
void NotebookButton::paintEvent(QPaintEvent *)
@@ -33,11 +33,11 @@ void NotebookButton::paintEvent(QPaintEvent *)
QColor foreground;
if (mouseDown || mouseOver) {
background = this->themeManager.tabs.regular.backgrounds.hover.color();
foreground = this->themeManager.tabs.regular.text;
background = this->themeManager->tabs.regular.backgrounds.hover.color();
foreground = this->themeManager->tabs.regular.text;
} else {
background = this->themeManager.tabs.regular.backgrounds.regular.color();
foreground = this->themeManager.tabs.regular.text;
background = this->themeManager->tabs.regular.backgrounds.regular.color();
foreground = this->themeManager->tabs.regular.text;
}
painter.setPen(Qt::NoPen);
+41 -27
View File
@@ -1,4 +1,6 @@
#include "widgets/helper/notebooktab.hpp"
#include "application.hpp"
#include "common.hpp"
#include "debug/log.hpp"
#include "singletons/settingsmanager.hpp"
@@ -23,12 +25,14 @@ NotebookTab2::NotebookTab2(Notebook2 *_notebook)
, notebook(_notebook)
, menu(this)
{
auto app = getApp();
this->setAcceptDrops(true);
this->positionChangedAnimation.setEasingCurve(QEasingCurve(QEasingCurve::InCubic));
singletons::SettingManager::getInstance().hideTabX.connect(
boost::bind(&NotebookTab2::hideTabXChanged, this, _1), this->managedConnections);
app->settings->hideTabX.connect(boost::bind(&NotebookTab2::hideTabXChanged, this, _1),
this->managedConnections);
this->setMouseTracking(true);
@@ -77,12 +81,13 @@ void NotebookTab2::themeRefreshEvent()
void NotebookTab2::updateSize()
{
auto app = getApp();
float scale = getScale();
int width;
QFontMetrics metrics(this->font());
if (singletons::SettingManager::getInstance().hideTabX) {
if (app->settings->hideTabX) {
width = (int)((metrics.width(this->title) + 16 /*+ 16*/) * scale);
} else {
width = (int)((metrics.width(this->title) + 8 + 24 /*+ 16*/) * scale);
@@ -173,7 +178,7 @@ void NotebookTab2::moveAnimated(QPoint pos, bool animated)
void NotebookTab2::paintEvent(QPaintEvent *)
{
singletons::SettingManager &settingManager = singletons::SettingManager::getInstance();
auto app = getApp();
QPainter painter(this);
float scale = this->getScale();
@@ -182,16 +187,16 @@ void NotebookTab2::paintEvent(QPaintEvent *)
// select the right tab colors
singletons::ThemeManager::TabColors colors;
singletons::ThemeManager::TabColors regular = this->themeManager.tabs.regular;
singletons::ThemeManager::TabColors regular = this->themeManager->tabs.regular;
if (this->selected) {
colors = this->themeManager.tabs.selected;
colors = this->themeManager->tabs.selected;
} else if (this->highlightState == HighlightState::Highlighted) {
colors = this->themeManager.tabs.highlighted;
colors = this->themeManager->tabs.highlighted;
} else if (this->highlightState == HighlightState::NewMessage) {
colors = this->themeManager.tabs.newMessage;
colors = this->themeManager->tabs.newMessage;
} else {
colors = this->themeManager.tabs.regular;
colors = this->themeManager->tabs.regular;
}
bool windowFocused = this->window() == QApplication::activeWindow();
@@ -248,7 +253,7 @@ void NotebookTab2::paintEvent(QPaintEvent *)
painter.setPen(colors.text);
// set area for text
int rectW = (settingManager.hideTabX ? 0 : static_cast<int>(16) * scale);
int rectW = (app->settings->hideTabX ? 0 : static_cast<int>(16) * scale);
QRect rect(0, 0, this->width() - rectW, height);
// draw text
@@ -269,7 +274,7 @@ void NotebookTab2::paintEvent(QPaintEvent *)
}
// draw close x
if (!settingManager.hideTabX && (mouseOver || selected)) {
if (!app->settings->hideTabX && (mouseOver || selected)) {
QRect xRect = this->getXRect();
if (!xRect.isNull()) {
if (mouseOverX) {
@@ -315,7 +320,7 @@ void NotebookTab2::mouseReleaseEvent(QMouseEvent *event)
this->notebook->removePage(this->page);
}
} else {
if (!singletons::SettingManager::getInstance().hideTabX && this->mouseDownX &&
if (!getApp()->settings->hideTabX && this->mouseDownX &&
this->getXRect().contains(event->pos())) {
this->mouseDownX = false;
@@ -350,8 +355,9 @@ void NotebookTab2::dragEnterEvent(QDragEnterEvent *)
void NotebookTab2::mouseMoveEvent(QMouseEvent *event)
{
if (!singletons::SettingManager::getInstance().hideTabX &&
this->notebook->getAllowUserTabManagement()) //
auto app = getApp();
if (!app->settings->hideTabX && this->notebook->getAllowUserTabManagement()) //
{
bool overX = this->getXRect().contains(event->pos());
@@ -397,12 +403,14 @@ NotebookTab::NotebookTab(Notebook *_notebook)
, notebook(_notebook)
, menu(this)
{
auto app = getApp();
this->setAcceptDrops(true);
this->positionChangedAnimation.setEasingCurve(QEasingCurve(QEasingCurve::InCubic));
singletons::SettingManager::getInstance().hideTabX.connect(
boost::bind(&NotebookTab::hideTabXChanged, this, _1), this->managedConnections);
app->settings->hideTabX.connect(boost::bind(&NotebookTab::hideTabXChanged, this, _1),
this->managedConnections);
this->setMouseTracking(true);
@@ -449,11 +457,13 @@ void NotebookTab::themeRefreshEvent()
void NotebookTab::updateSize()
{
auto app = getApp();
float scale = getScale();
int width;
if (singletons::SettingManager::getInstance().hideTabX) {
if (app->settings->hideTabX) {
width = (int)((fontMetrics().width(this->title) + 16 /*+ 16*/) * scale);
} else {
width = (int)((fontMetrics().width(this->title) + 8 + 24 /*+ 16*/) * scale);
@@ -544,7 +554,7 @@ void NotebookTab::moveAnimated(QPoint pos, bool animated)
void NotebookTab::paintEvent(QPaintEvent *)
{
singletons::SettingManager &settingManager = singletons::SettingManager::getInstance();
auto app = getApp();
QPainter painter(this);
float scale = this->getScale();
@@ -553,16 +563,16 @@ void NotebookTab::paintEvent(QPaintEvent *)
// select the right tab colors
singletons::ThemeManager::TabColors colors;
singletons::ThemeManager::TabColors regular = this->themeManager.tabs.regular;
singletons::ThemeManager::TabColors regular = this->themeManager->tabs.regular;
if (this->selected) {
colors = this->themeManager.tabs.selected;
colors = this->themeManager->tabs.selected;
} else if (this->highlightState == HighlightState::Highlighted) {
colors = this->themeManager.tabs.highlighted;
colors = this->themeManager->tabs.highlighted;
} else if (this->highlightState == HighlightState::NewMessage) {
colors = this->themeManager.tabs.newMessage;
colors = this->themeManager->tabs.newMessage;
} else {
colors = this->themeManager.tabs.regular;
colors = this->themeManager->tabs.regular;
}
bool windowFocused = this->window() == QApplication::activeWindow();
@@ -619,7 +629,7 @@ void NotebookTab::paintEvent(QPaintEvent *)
painter.setPen(colors.text);
// set area for text
int rectW = (settingManager.hideTabX ? 0 : static_cast<int>(16) * scale);
int rectW = (app->settings->hideTabX ? 0 : static_cast<int>(16) * scale);
QRect rect(0, 0, this->width() - rectW, height);
// draw text
@@ -640,7 +650,7 @@ void NotebookTab::paintEvent(QPaintEvent *)
}
// draw close x
if (!settingManager.hideTabX && (mouseOver || selected)) {
if (!app->settings->hideTabX && (mouseOver || selected)) {
QRect xRect = this->getXRect();
if (mouseOverX) {
painter.fillRect(xRect, QColor(0, 0, 0, 64));
@@ -675,6 +685,8 @@ void NotebookTab::mousePressEvent(QMouseEvent *event)
void NotebookTab::mouseReleaseEvent(QMouseEvent *event)
{
auto app = getApp();
this->mouseDown = false;
if (event->button() == Qt::MiddleButton) {
@@ -682,7 +694,7 @@ void NotebookTab::mouseReleaseEvent(QMouseEvent *event)
this->notebook->removePage(this->page);
}
} else {
if (!singletons::SettingManager::getInstance().hideTabX && this->mouseDownX &&
if (!app->settings->hideTabX && this->mouseDownX &&
this->getXRect().contains(event->pos())) {
this->mouseDownX = false;
@@ -715,7 +727,9 @@ void NotebookTab::dragEnterEvent(QDragEnterEvent *)
void NotebookTab::mouseMoveEvent(QMouseEvent *event)
{
if (!singletons::SettingManager::getInstance().hideTabX) {
auto app = getApp();
if (!app->settings->hideTabX) {
bool overX = this->getXRect().contains(event->pos());
if (overX != this->mouseOverX) {
+1 -1
View File
@@ -64,7 +64,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->themeManager->isLightTheme() ? QColor(0, 0, 0) : QColor(255, 255, 255);
}
if (this->hoverMultiplier > 0) {
+3 -3
View File
@@ -218,8 +218,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->themeManager->splits.header.background);
painter.setPen(this->themeManager->splits.header.border);
painter.drawRect(0, 0, width() - 1, height() - 1);
}
@@ -268,7 +268,7 @@ void SplitHeader::rightButtonClicked()
void SplitHeader::themeRefreshEvent()
{
QPalette palette;
palette.setColor(QPalette::Foreground, this->themeManager.splits.header.text);
palette.setColor(QPalette::Foreground, this->themeManager->splits.header.text);
// this->dropdownButton->setPalette(palette);
this->titleLabel->setPalette(palette);
+18 -13
View File
@@ -1,4 +1,6 @@
#include "widgets/helper/splitinput.hpp"
#include "application.hpp"
#include "singletons/commandmanager.hpp"
#include "singletons/ircmanager.hpp"
#include "singletons/settingsmanager.hpp"
@@ -36,6 +38,7 @@ SplitInput::SplitInput(Split *_chatWidget)
void SplitInput::initLayout()
{
auto app = getApp();
auto &fontManager = singletons::FontManager::getInstance();
util::LayoutCreator<SplitInput> layoutCreator(this);
@@ -73,7 +76,7 @@ void SplitInput::initLayout()
// open emote popup
QObject::connect(this->ui.emoteButton, &RippleEffectLabel::clicked, [this] {
if (!this->emotePopup) {
this->emotePopup = std::make_unique<EmotePopup>(this->themeManager);
this->emotePopup = std::make_unique<EmotePopup>();
this->emotePopup->linkClicked.connect([this](const messages::Link &link) {
if (link.type == messages::Link::InsertText) {
this->insertText(link.value + " ");
@@ -95,7 +98,7 @@ void SplitInput::initLayout()
});
// textEditLength visibility
singletons::SettingManager::getInstance().showMessageLength.connect(
app->settings->showMessageLength.connect(
[this](const bool &value, auto) { this->ui.textEditLength->setHidden(!value); },
this->managedConnections);
}
@@ -117,18 +120,20 @@ void SplitInput::themeRefreshEvent()
{
QPalette palette;
palette.setColor(QPalette::Foreground, this->themeManager.splits.input.text);
palette.setColor(QPalette::Foreground, this->themeManager->splits.input.text);
this->ui.textEditLength->setPalette(palette);
this->ui.textEdit->setStyleSheet(this->themeManager.splits.input.styleSheet);
this->ui.textEdit->setStyleSheet(this->themeManager->splits.input.styleSheet);
this->ui.hbox->setMargin((this->themeManager.isLightTheme() ? 4 : 2) * this->getScale());
this->ui.hbox->setMargin((this->themeManager->isLightTheme() ? 4 : 2) * this->getScale());
}
void SplitInput::installKeyPressedEvent()
{
this->ui.textEdit->keyPressed.connect([this](QKeyEvent *event) {
auto app = getApp();
this->ui.textEdit->keyPressed.connect([this, app](QKeyEvent *event) {
if (event->key() == Qt::Key_Enter || event->key() == Qt::Key_Return) {
auto c = this->chatWidget->getChannel();
if (c == nullptr) {
@@ -136,8 +141,7 @@ void SplitInput::installKeyPressedEvent()
}
QString message = ui.textEdit->toPlainText();
QString sendMessage =
singletons::CommandManager::getInstance().execCommand(message, c, false);
QString sendMessage = app->commands->execCommand(message, c, false);
sendMessage = sendMessage.replace('\n', ' ');
c->sendMessage(sendMessage);
@@ -278,6 +282,8 @@ void SplitInput::insertText(const QString &text)
void SplitInput::editTextChanged()
{
auto app = getApp();
// set textLengthLabel value
QString text = this->ui.textEdit->toPlainText();
@@ -287,8 +293,7 @@ void SplitInput::editTextChanged()
static QRegularExpression spaceRegex("\\s\\s+");
text = text.replace(spaceRegex, " ");
text = singletons::CommandManager::getInstance().execCommand(
text, this->chatWidget->getChannel(), true);
text = app->commands->execCommand(text, this->chatWidget->getChannel(), true);
QString labelText;
@@ -305,10 +310,10 @@ void SplitInput::paintEvent(QPaintEvent *)
{
QPainter painter(this);
painter.fillRect(this->rect(), this->themeManager.splits.input.background);
painter.fillRect(this->rect(), this->themeManager->splits.input.background);
QPen pen(this->themeManager.splits.input.border);
if (this->themeManager.isLightTheme()) {
QPen pen(this->themeManager->splits.input.border);
if (this->themeManager->isLightTheme()) {
pen.setWidth((int)(6 * this->getScale()));
}
painter.setPen(pen);
+3 -3
View File
@@ -25,8 +25,8 @@ void TitleBarButton::paintEvent(QPaintEvent *)
{
QPainter painter(this);
QColor color = this->themeManager.window.text;
QColor background = this->themeManager.window.background;
QColor color = this->themeManager->window.text;
QColor background = this->themeManager->window.background;
int xD = this->height() / 3;
int centerX = this->width() / 2;
@@ -49,7 +49,7 @@ void TitleBarButton::paintEvent(QPaintEvent *)
painter.drawRect(centerX - xD / 2 + xD2, xD, xD3, xD3);
painter.fillRect(centerX - xD / 2, xD + xD2, xD3, xD3,
this->themeManager.window.background);
this->themeManager->window.background);
painter.drawRect(centerX - xD / 2, xD + xD2, xD3, xD3);
break;
}
+1 -1
View File
@@ -50,7 +50,7 @@ void LogInWithCredentials(const std::string &userID, const std::string &username
pajlada::Settings::Setting<std::string>::set("/accounts/uid" + userID + "/oauthToken",
oauthToken);
singletons::AccountManager::getInstance().Twitch.reloadUsers();
getApp()->accounts->Twitch.reloadUsers();
messageBox.exec();
}
+20 -16
View File
@@ -1,4 +1,6 @@
#include "widgets/notebook.hpp"
#include "application.hpp"
#include "debug/log.hpp"
#include "singletons/thememanager.hpp"
#include "singletons/windowmanager.hpp"
@@ -24,7 +26,7 @@ namespace chatterino {
namespace widgets {
Notebook2::Notebook2(QWidget *parent)
: BaseWidget(singletons::ThemeManager::getInstance(), parent)
: BaseWidget(parent)
, addButton(this)
{
this->addButton.setHidden(true);
@@ -258,7 +260,7 @@ void Notebook2::resizeEvent(QResizeEvent *)
void Notebook2::performLayout(bool animated)
{
singletons::SettingManager &settings = singletons::SettingManager::getInstance();
auto app = getApp();
int xStart = (int)(2 * this->getScale());
@@ -269,13 +271,13 @@ void Notebook2::performLayout(bool animated)
// bool customFrame = false;
// if (!this->showButtons || settings.hidePreferencesButton || customFrame) {
// if (!this->showButtons || app->settings->hidePreferencesButton || customFrame) {
// this->settingsButton.hide();
// } else {
// this->settingsButton.show();
// x += settingsButton.width();
// }
// if (!this->showButtons || settings.hideUserButton || customFrame) {
// if (!this->showButtons || app->settings->hideUserButton || customFrame) {
// this->userButton.hide();
// } else {
// this->userButton.move(x, 0);
@@ -284,7 +286,7 @@ void Notebook2::performLayout(bool animated)
// }
// if (customFrame || !this->showButtons ||
// (settings.hideUserButton && settings.hidePreferencesButton)) {
// (app->settings->hideUserButton && app->settings->hidePreferencesButton)) {
// x += (int)(scale * 2);
// }
@@ -342,7 +344,7 @@ void Notebook2::paintEvent(QPaintEvent *event)
QPainter painter(this);
painter.fillRect(0, this->lineY, this->width(), (int)(1 * this->getScale()),
this->themeManager.tabs.bottomLine);
this->themeManager->tabs.bottomLine);
}
NotebookTab2 *Notebook2::getTabFromPage(QWidget *page)
@@ -366,6 +368,8 @@ Notebook::Notebook(Window *parent, bool _showButtons)
, showButtons(_showButtons)
, closeConfirmDialog(this)
{
auto app = getApp();
this->connect(&this->settingsButton, SIGNAL(clicked()), this, SLOT(settingsButtonClicked()));
this->connect(&this->userButton, SIGNAL(clicked()), this, SLOT(usersButtonClicked()));
this->connect(&this->addButton, SIGNAL(clicked()), this, SLOT(addPageButtonClicked()));
@@ -375,10 +379,8 @@ Notebook::Notebook(Window *parent, bool _showButtons)
this->userButton.move(24, 0);
this->userButton.icon = NotebookButton::IconUser;
auto &settingsManager = singletons::SettingManager::getInstance();
settingsManager.hidePreferencesButton.connectSimple([this](auto) { this->performLayout(); });
settingsManager.hideUserButton.connectSimple([this](auto) { this->performLayout(); });
app->settings->hidePreferencesButton.connectSimple([this](auto) { this->performLayout(); });
app->settings->hideUserButton.connectSimple([this](auto) { this->performLayout(); });
closeConfirmDialog.setText("Are you sure you want to close this tab?");
closeConfirmDialog.setIcon(QMessageBox::Icon::Question);
@@ -568,19 +570,19 @@ void Notebook::previousTab()
void Notebook::performLayout(bool animated)
{
singletons::SettingManager &settings = singletons::SettingManager::getInstance();
auto app = getApp();
int x = 0, y = 0;
float scale = this->getScale();
bool customFrame = this->parentWindow->hasCustomWindowFrame();
if (!this->showButtons || settings.hidePreferencesButton || customFrame) {
if (!this->showButtons || app->settings->hidePreferencesButton || customFrame) {
this->settingsButton.hide();
} else {
this->settingsButton.show();
x += settingsButton.width();
}
if (!this->showButtons || settings.hideUserButton || customFrame) {
if (!this->showButtons || app->settings->hideUserButton || customFrame) {
this->userButton.hide();
} else {
this->userButton.move(x, 0);
@@ -589,7 +591,7 @@ void Notebook::performLayout(bool animated)
}
if (customFrame || !this->showButtons ||
(settings.hideUserButton && settings.hidePreferencesButton)) {
(app->settings->hideUserButton && app->settings->hidePreferencesButton)) {
x += (int)(scale * 2);
}
@@ -654,12 +656,14 @@ void Notebook::scaleChangedEvent(float)
void Notebook::settingsButtonClicked()
{
singletons::WindowManager::getInstance().showSettingsDialog();
auto app = getApp();
app->windows->showSettingsDialog();
}
void Notebook::usersButtonClicked()
{
singletons::WindowManager::getInstance().showAccountSelectPopup(
auto app = getApp();
app->windows->showAccountSelectPopup(
this->mapToGlobal(this->userButton.rect().bottomRight()));
}
+12 -9
View File
@@ -1,4 +1,6 @@
#include "widgets/scrollbar.hpp"
#include "application.hpp"
#include "singletons/thememanager.hpp"
#include "widgets/helper/channelview.hpp"
@@ -6,6 +8,7 @@
#include <QMouseEvent>
#include <QPainter>
#include <QTimer>
#include <cmath>
#define MIN_THUMB_HEIGHT 10
@@ -16,7 +19,6 @@ namespace widgets {
Scrollbar::Scrollbar(ChannelView *parent)
: BaseWidget(parent)
, currentValueAnimation(this, "currentValue")
, smoothScrollingSetting(singletons::SettingManager::getInstance().enableSmoothScrolling)
{
resize((int)(16 * this->getScale()), 100);
this->currentValueAnimation.setDuration(150);
@@ -92,7 +94,8 @@ void Scrollbar::setSmallChange(qreal value)
void Scrollbar::setDesiredValue(qreal value, bool animated)
{
animated &= this->smoothScrollingSetting.getValue();
auto app = getApp();
animated &= app->settings->enableSmoothScrolling.getValue();
value = std::max(this->minimum, std::min(this->maximum - this->largeChange, value));
if (this->desiredValue + this->smoothScrollingOffset != value) {
@@ -197,23 +200,23 @@ void Scrollbar::paintEvent(QPaintEvent *)
int xOffset = mouseOver ? 0 : width() - (int)(4 * this->getScale());
QPainter painter(this);
// painter.fillRect(rect(), this->themeManager.ScrollbarBG);
// painter.fillRect(rect(), this->themeManager->ScrollbarBG);
// painter.fillRect(QRect(xOffset, 0, width(), this->buttonHeight),
// this->themeManager.ScrollbarArrow);
// this->themeManager->ScrollbarArrow);
// painter.fillRect(QRect(xOffset, height() - this->buttonHeight, width(),
// this->buttonHeight),
// this->themeManager.ScrollbarArrow);
// this->themeManager->ScrollbarArrow);
this->thumbRect.setX(xOffset);
// mouse over thumb
if (this->mouseDownIndex == 2) {
painter.fillRect(this->thumbRect, this->themeManager.scrollbars.thumbSelected);
painter.fillRect(this->thumbRect, this->themeManager->scrollbars.thumbSelected);
}
// mouse not over thumb
else {
painter.fillRect(this->thumbRect, this->themeManager.scrollbars.thumb);
painter.fillRect(this->thumbRect, this->themeManager->scrollbars.thumb);
}
// draw highlights
@@ -235,10 +238,10 @@ void Scrollbar::paintEvent(QPaintEvent *)
if (!highlight.isNull()) {
if (highlight.getStyle() == ScrollbarHighlight::Default) {
painter.fillRect(w / 8 * 3, (int)y, w / 4, highlightHeight,
this->themeManager.tabs.selected.backgrounds.regular.color());
this->themeManager->tabs.selected.backgrounds.regular.color());
} else {
painter.fillRect(0, (int)y, w, 1,
this->themeManager.tabs.selected.backgrounds.regular.color());
this->themeManager->tabs.selected.backgrounds.regular.color());
}
}
-2
View File
@@ -88,8 +88,6 @@ private:
pajlada::Signals::NoArgSignal currentValueChanged;
pajlada::Settings::Setting<bool> &smoothScrollingSetting;
void updateScroll();
};
+1 -1
View File
@@ -266,7 +266,7 @@ void SelectChannelDialog::themeRefreshEvent()
{
BaseWindow::themeRefreshEvent();
if (this->themeManager.isLightTheme()) {
if (this->themeManager->isLightTheme()) {
this->setStyleSheet("QRadioButton { color: #000 } QLabel { color: #000 }");
} else {
this->setStyleSheet("QRadioButton { color: #fff } QLabel { color: #fff }");
+4 -4
View File
@@ -1,4 +1,6 @@
#include "widgets/settingsdialog.hpp"
#include "application.hpp"
#include "util/layoutcreator.hpp"
#include "widgets/helper/settingsdialogtab.hpp"
#include "widgets/settingspages/aboutpage.hpp"
@@ -150,7 +152,7 @@ void SettingsDialog::refresh()
{
// this->ui.accountSwitchWidget->refresh();
singletons::SettingManager::getInstance().saveSnapshot();
getApp()->settings->saveSnapshot();
}
void SettingsDialog::scaleChangedEvent(float newDpi)
@@ -209,13 +211,11 @@ void SettingsDialog::okButtonClicked()
void SettingsDialog::cancelButtonClicked()
{
auto &settings = singletons::SettingManager::getInstance();
for (auto &tab : this->tabs) {
tab->getSettingsPage()->cancel();
}
settings.recallSnapshot();
getApp()->settings->recallSnapshot();
this->close();
}
+5 -4
View File
@@ -1,13 +1,14 @@
#include "accountspage.hpp"
#include <QDialogButtonBox>
#include <QVBoxLayout>
#include "application.hpp"
#include "const.hpp"
#include "singletons/accountmanager.hpp"
#include "util/layoutcreator.hpp"
#include "widgets/logindialog.hpp"
#include <QDialogButtonBox>
#include <QVBoxLayout>
namespace chatterino {
namespace widgets {
namespace settingspages {
@@ -39,7 +40,7 @@ AccountsPage::AccountsPage()
return;
}
singletons::AccountManager::getInstance().Twitch.removeUser(selectedUser);
getApp()->accounts->Twitch.removeUser(selectedUser);
});
}
+29 -25
View File
@@ -1,5 +1,9 @@
#include "appearancepage.hpp"
#include "application.hpp"
#include "util/layoutcreator.hpp"
#include "util/removescrollareabackground.hpp"
#include <QFontDialog>
#include <QFormLayout>
#include <QGroupBox>
@@ -9,9 +13,6 @@
#include <QSlider>
#include <QVBoxLayout>
#include "util/layoutcreator.hpp"
#include "util/removescrollareabackground.hpp"
#define THEME_ITEMS "White", "Light", "Dark", "Black"
#define TAB_X "Show close button"
@@ -34,7 +35,7 @@ namespace settingspages {
AppearancePage::AppearancePage()
: SettingsPage("Look", ":/images/theme.svg")
{
singletons::SettingManager &settings = singletons::SettingManager::getInstance();
auto app = getApp();
util::LayoutCreator<AppearancePage> layoutCreator(this);
auto scroll = layoutCreator.emplace<QScrollArea>();
@@ -49,50 +50,52 @@ AppearancePage::AppearancePage()
auto form = application.emplace<QFormLayout>();
// clang-format off
form->addRow("Theme:", this->createComboBox({THEME_ITEMS}, singletons::ThemeManager::getInstance().themeName));
form->addRow("Theme:", this->createComboBox({THEME_ITEMS}, app->themes->themeName));
form->addRow("Theme color:", this->createThemeColorChanger());
form->addRow("Font:", this->createFontChanger());
form->addRow("Tabs:", this->createCheckBox(TAB_X, settings.hideTabX));
form->addRow("Tabs:", this->createCheckBox(TAB_X, app->settings->hideTabX));
#ifndef USEWINSDK
form->addRow("", this->createCheckBox(TAB_PREF, settings.hidePreferencesButton));
form->addRow("", this->createCheckBox(TAB_USER, settings.hideUserButton));
form->addRow("", this->createCheckBox(TAB_PREF, app->settings->hidePreferencesButton));
form->addRow("", this->createCheckBox(TAB_USER, app->settings->hideUserButton));
#endif
form->addRow("Scrolling:", this->createCheckBox(SCROLL_SMOOTH, settings.enableSmoothScrolling));
form->addRow("", this->createCheckBox(SCROLL_NEWMSG, settings.enableSmoothScrollingNewMessages));
form->addRow("Scrolling:", this->createCheckBox(SCROLL_SMOOTH, app->settings->enableSmoothScrolling));
form->addRow("", this->createCheckBox(SCROLL_NEWMSG, app->settings->enableSmoothScrollingNewMessages));
// clang-format on
}
auto messages = layout.emplace<QGroupBox>("Messages").emplace<QVBoxLayout>();
{
messages.append(this->createCheckBox("Show timestamp", settings.showTimestamps));
messages.append(this->createCheckBox("Show timestamp", app->settings->showTimestamps));
auto tbox = messages.emplace<QHBoxLayout>().withoutMargin();
{
tbox.emplace<QLabel>("timestamp format (a = am/pm):");
tbox.append(this->createComboBox({TIMESTAMP_FORMATS}, settings.timestampFormat));
tbox.append(this->createComboBox({TIMESTAMP_FORMATS}, app->settings->timestampFormat));
tbox->addStretch(1);
}
messages.append(this->createCheckBox("Show badges", settings.showBadges));
auto checkbox = this->createCheckBox("Seperate messages", settings.seperateMessages);
messages.append(this->createCheckBox("Show badges", app->settings->showBadges));
auto checkbox = this->createCheckBox("Seperate messages", app->settings->seperateMessages);
checkbox->setEnabled(false);
messages.append(checkbox);
messages.append(
this->createCheckBox("Show message length while typing", settings.showMessageLength));
messages.append(this->createCheckBox("Show message length while typing",
app->settings->showMessageLength));
messages.append(this->createCheckBox(LAST_MSG, settings.showLastMessageIndicator));
messages.append(this->createCheckBox(LAST_MSG, app->settings->showLastMessageIndicator));
}
auto emotes = layout.emplace<QGroupBox>("Emotes").setLayoutType<QVBoxLayout>();
{
emotes.append(this->createCheckBox("Enable Twitch emotes", settings.enableTwitchEmotes));
emotes.append(
this->createCheckBox("Enable BetterTTV emotes for Twitch", settings.enableBttvEmotes));
this->createCheckBox("Enable Twitch emotes", app->settings->enableTwitchEmotes));
emotes.append(this->createCheckBox("Enable BetterTTV emotes for Twitch",
app->settings->enableBttvEmotes));
emotes.append(this->createCheckBox("Enable FrankerFaceZ emotes for Twitch",
settings.enableFfzEmotes));
emotes.append(this->createCheckBox("Enable emojis", settings.enableEmojis));
emotes.append(this->createCheckBox("Enable animations", settings.enableGifAnimations));
app->settings->enableFfzEmotes));
emotes.append(this->createCheckBox("Enable emojis", app->settings->enableEmojis));
emotes.append(
this->createCheckBox("Enable animations", app->settings->enableGifAnimations));
}
layout->addStretch(1);
@@ -100,9 +103,10 @@ AppearancePage::AppearancePage()
QLayout *AppearancePage::createThemeColorChanger()
{
auto app = getApp();
QHBoxLayout *layout = new QHBoxLayout;
auto &themeHue = singletons::ThemeManager::getInstance().themeHue;
auto &themeHue = app->themes->themeHue;
// SLIDER
QSlider *slider = new QSlider(Qt::Horizontal);
@@ -115,9 +119,9 @@ QLayout *AppearancePage::createThemeColorChanger()
button->setFlat(true);
button->setFixedWidth(64);
auto setButtonColor = [button](int value) mutable {
auto setButtonColor = [button, app](int value) mutable {
double newValue = value / 100.0;
singletons::ThemeManager::getInstance().themeHue.setValue(newValue);
app->themes->themeHue.setValue(newValue);
QPalette pal = button->palette();
QColor color;
+17 -13
View File
@@ -1,12 +1,13 @@
#include "behaviourpage.hpp"
#include "application.hpp"
#include "util/layoutcreator.hpp"
#include <QFormLayout>
#include <QGroupBox>
#include <QLabel>
#include <QVBoxLayout>
#include <util/layoutcreator.hpp>
#define WINDOW_TOPMOST "Window always on top (requires restart)"
#define INPUT_EMPTY "Hide input box when empty"
#define PAUSE_HOVERING "When hovering"
@@ -20,20 +21,21 @@ namespace settingspages {
BehaviourPage::BehaviourPage()
: SettingsPage("Feel", ":/images/behave.svg")
{
singletons::SettingManager &settings = singletons::SettingManager::getInstance();
auto app = getApp();
util::LayoutCreator<BehaviourPage> layoutCreator(this);
auto layout = layoutCreator.setLayoutType<QVBoxLayout>();
auto form = layout.emplace<QFormLayout>().withoutMargin();
{
form->addRow("Window:", this->createCheckBox(WINDOW_TOPMOST, settings.windowTopMost));
form->addRow("Messages:", this->createCheckBox(INPUT_EMPTY, settings.hideEmptyInput));
form->addRow("Pause chat:", this->createCheckBox(PAUSE_HOVERING, settings.pauseChatHover));
form->addRow("Window:", this->createCheckBox(WINDOW_TOPMOST, app->settings->windowTopMost));
form->addRow("Messages:", this->createCheckBox(INPUT_EMPTY, app->settings->hideEmptyInput));
form->addRow("Pause chat:",
this->createCheckBox(PAUSE_HOVERING, app->settings->pauseChatHover));
form->addRow("Mouse scroll speed:", this->createMouseScrollSlider());
form->addRow("Links:", this->createCheckBox("Open links only on double click",
settings.linksDoubleClickOnly));
app->settings->linksDoubleClickOnly));
}
layout->addSpacing(16);
@@ -43,17 +45,18 @@ BehaviourPage::BehaviourPage()
auto groupLayout = group.setLayoutType<QFormLayout>();
groupLayout->addRow(
LIMIT_CHATTERS_FOR_SMALLER_STREAMERS,
this->createCheckBox("", settings.onlyFetchChattersForSmallerStreamers));
this->createCheckBox("", app->settings->onlyFetchChattersForSmallerStreamers));
groupLayout->addRow("What viewer count counts as a \"smaller streamer\"",
this->createSpinBox(settings.smallStreamerLimit, 10, 50000));
this->createSpinBox(app->settings->smallStreamerLimit, 10, 50000));
}
{
auto group = layout.emplace<QGroupBox>("Misc");
auto groupLayout = group.setLayoutType<QVBoxLayout>();
groupLayout.append(this->createCheckBox("Show whispers inline", settings.inlineWhispers));
groupLayout.append(
this->createCheckBox("Show whispers inline", app->settings->inlineWhispers));
}
layout->addStretch(1);
@@ -61,16 +64,17 @@ BehaviourPage::BehaviourPage()
QSlider *BehaviourPage::createMouseScrollSlider()
{
auto app = getApp();
auto slider = new QSlider(Qt::Horizontal);
float currentValue = singletons::SettingManager::getInstance().mouseScrollMultiplier;
float currentValue = app->settings->mouseScrollMultiplier;
int sliderValue = ((currentValue - 0.1f) / 2.f) * 99.f;
slider->setValue(sliderValue);
QObject::connect(slider, &QSlider::valueChanged, [](int newValue) {
QObject::connect(slider, &QSlider::valueChanged, [=](int newValue) {
float mul = static_cast<float>(newValue) / 99.f;
float newSliderValue = (mul * 2.1f) + 0.1f;
singletons::SettingManager::getInstance().mouseScrollMultiplier = newSliderValue;
app->settings->mouseScrollMultiplier = newSliderValue;
});
return slider;
+10 -9
View File
@@ -1,11 +1,12 @@
#include "commandpage.hpp"
#include "application.hpp"
#include "singletons/commandmanager.hpp"
#include "util/layoutcreator.hpp"
#include <QLabel>
#include <QTextEdit>
#include "singletons/commandmanager.hpp"
#include "util/layoutcreator.hpp"
// clang-format off
#define TEXT "One command per line.\n"\
"\"/cmd example command\" will print \"example command\" when you type /cmd in chat.\n"\
@@ -34,27 +35,27 @@ CommandPage::CommandPage()
QTextEdit *CommandPage::getCommandsTextEdit()
{
singletons::CommandManager &commandManager = singletons::CommandManager::getInstance();
auto app = getApp();
// cancel
QStringList currentCommands = commandManager.getCommands();
QStringList currentCommands = app->commands->getCommands();
this->onCancel.connect(
[currentCommands, &commandManager] { commandManager.setCommands(currentCommands); });
[currentCommands, app] { app->commands->setCommands(currentCommands); });
// create text edit
QTextEdit *textEdit = new QTextEdit;
textEdit->setPlainText(QString(commandManager.getCommands().join('\n')));
textEdit->setPlainText(QString(app->commands->getCommands().join('\n')));
QObject::connect(textEdit, &QTextEdit::textChanged,
[this] { this->commandsEditTimer.start(200); });
QObject::connect(&this->commandsEditTimer, &QTimer::timeout, [textEdit, &commandManager] {
QObject::connect(&this->commandsEditTimer, &QTimer::timeout, [textEdit, app] {
QString text = textEdit->toPlainText();
QStringList lines = text.split(QRegularExpression("(\r?\n|\r\n?)"));
commandManager.setCommands(lines);
app->commands->setCommands(lines);
});
return textEdit;
@@ -1,5 +1,6 @@
#include "externaltoolspage.hpp"
#include "application.hpp"
#include "util/layoutcreator.hpp"
#include <QGroupBox>
@@ -13,17 +14,21 @@ namespace settingspages {
ExternalToolsPage::ExternalToolsPage()
: SettingsPage("External tools", "")
{
singletons::SettingManager &settings = singletons::SettingManager::getInstance();
auto app = getApp();
util::LayoutCreator<ExternalToolsPage> layoutCreator(this);
auto layout = layoutCreator.setLayoutType<QVBoxLayout>();
{
auto group = layout.emplace<QGroupBox>("Streamlink");
auto groupLayout = group.setLayoutType<QFormLayout>();
groupLayout->addRow("Streamlink path:", this->createLineEdit(settings.streamlinkPath));
groupLayout->addRow("Prefered quality:",
this->createComboBox({STREAMLINK_QUALITY}, settings.preferredQuality));
groupLayout->addRow("Additional options:", this->createLineEdit(settings.streamlinkOpts));
groupLayout->addRow("Streamlink path:",
this->createLineEdit(app->settings->streamlinkPath));
groupLayout->addRow(
"Prefered quality:",
this->createComboBox({STREAMLINK_QUALITY}, app->settings->preferredQuality));
groupLayout->addRow("Additional options:",
this->createLineEdit(app->settings->streamlinkOpts));
}
layout->addStretch(1);
+43 -42
View File
@@ -1,5 +1,11 @@
#include "highlightingpage.hpp"
#include "application.hpp"
#include "debug/log.hpp"
#include "singletons/settingsmanager.hpp"
#include "util/layoutcreator.hpp"
#include "util/standarditemhelper.hpp"
#include <QFileDialog>
#include <QListWidget>
#include <QPushButton>
@@ -8,11 +14,6 @@
#include <QTableView>
#include <QTextEdit>
#include "debug/log.hpp"
#include "singletons/settingsmanager.hpp"
#include "util/layoutcreator.hpp"
#include "util/standarditemhelper.hpp"
#define ENABLE_HIGHLIGHTS "Enable Highlighting"
#define HIGHLIGHT_MSG "Highlight messages containing your name"
#define PLAY_SOUND "Play sound when your name is mentioned"
@@ -26,13 +27,13 @@ namespace settingspages {
HighlightingPage::HighlightingPage()
: SettingsPage("Highlights", ":/images/notifications.svg")
{
singletons::SettingManager &settings = singletons::SettingManager::getInstance();
auto app = getApp();
util::LayoutCreator<HighlightingPage> layoutCreator(this);
auto layout = layoutCreator.emplace<QVBoxLayout>().withoutMargin();
{
// GENERAL
layout.append(this->createCheckBox(ENABLE_HIGHLIGHTS, settings.enableHighlights));
layout.append(this->createCheckBox(ENABLE_HIGHLIGHTS, app->settings->enableHighlights));
// TABS
auto tabs = layout.emplace<QTabWidget>();
@@ -56,17 +57,17 @@ HighlightingPage::HighlightingPage()
yourName->setData(QBrush("#666"), Qt::ForegroundRole);
yourName->setFlags(yourName->flags() | Qt::ItemIsUserCheckable |
Qt::ItemIsUserCheckable);
yourName->setData(settings.enableHighlightsSelf ? 2 : 0, Qt::CheckStateRole);
yourName->setData(app->settings->enableHighlightsSelf ? 2 : 0, Qt::CheckStateRole);
model->appendRow(
{yourName,
util::boolItem(settings.enableHighlightTaskbar.getValue(), true, false),
util::boolItem(settings.enableHighlightSound.getValue(), true, false),
util::boolItem(app->settings->enableHighlightTaskbar.getValue(), true, false),
util::boolItem(app->settings->enableHighlightSound.getValue(), true, false),
util::emptyItem()});
// highlight phrases
// fourtf: could crash
for (const messages::HighlightPhrase &phrase :
settings.highlightProperties.getValue()) {
app->settings->highlightProperties.getValue()) {
model->appendRow({util::stringItem(phrase.key), util::boolItem(phrase.alert),
util::boolItem(phrase.sound), util::boolItem(phrase.regex)});
}
@@ -79,26 +80,26 @@ HighlightingPage::HighlightingPage()
auto buttons = highlights.emplace<QHBoxLayout>();
QObject::connect(model, &QStandardItemModel::dataChanged,
[model](const QModelIndex &topLeft, const QModelIndex &bottomRight,
const QVector<int> &roles) {
std::vector<messages::HighlightPhrase> phrases;
for (int i = 1; i < model->rowCount(); i++) {
phrases.push_back(messages::HighlightPhrase{
model->item(i, 0)->data(Qt::DisplayRole).toString(),
model->item(i, 1)->data(Qt::CheckStateRole).toBool(),
model->item(i, 2)->data(Qt::CheckStateRole).toBool(),
model->item(i, 3)->data(Qt::CheckStateRole).toBool()});
}
auto &settings = singletons::SettingManager::getInstance();
settings.highlightProperties.setValue(phrases);
settings.enableHighlightsSelf.setValue(
model->item(0, 0)->data(Qt::CheckStateRole).toBool());
settings.enableHighlightTaskbar.setValue(
model->item(0, 1)->data(Qt::CheckStateRole).toBool());
settings.enableHighlightSound.setValue(
model->item(0, 2)->data(Qt::CheckStateRole).toBool());
});
QObject::connect(
model, &QStandardItemModel::dataChanged,
[model, app](const QModelIndex &topLeft, const QModelIndex &bottomRight,
const QVector<int> &roles) {
std::vector<messages::HighlightPhrase> phrases;
for (int i = 1; i < model->rowCount(); i++) {
phrases.push_back(messages::HighlightPhrase{
model->item(i, 0)->data(Qt::DisplayRole).toString(),
model->item(i, 1)->data(Qt::CheckStateRole).toBool(),
model->item(i, 2)->data(Qt::CheckStateRole).toBool(),
model->item(i, 3)->data(Qt::CheckStateRole).toBool()});
}
app->settings->highlightProperties.setValue(phrases);
app->settings->enableHighlightsSelf.setValue(
model->item(0, 0)->data(Qt::CheckStateRole).toBool());
app->settings->enableHighlightTaskbar.setValue(
model->item(0, 1)->data(Qt::CheckStateRole).toBool());
app->settings->enableHighlightSound.setValue(
model->item(0, 2)->data(Qt::CheckStateRole).toBool());
});
auto add = buttons.emplace<QPushButton>("Add");
QObject::connect(*add, &QPushButton::clicked, [model, view] {
@@ -138,13 +139,13 @@ HighlightingPage::HighlightingPage()
[this] { this->disabledUsersChangedTimer.start(200); });
QObject::connect(
&this->disabledUsersChangedTimer, &QTimer::timeout, this, [text, &settings]() {
&this->disabledUsersChangedTimer, &QTimer::timeout, this, [text, app]() {
QStringList list = text->toPlainText().split("\n", QString::SkipEmptyParts);
list.removeDuplicates();
settings.highlightUserBlacklist = list.join("\n") + "\n";
app->settings->highlightUserBlacklist = list.join("\n") + "\n";
});
settings.highlightUserBlacklist.connect([=](const QString &str, auto) {
app->settings->highlightUserBlacklist.connect([=](const QString &str, auto) {
text->setPlainText(str); //
});
}
@@ -153,17 +154,17 @@ HighlightingPage::HighlightingPage()
// MISC
auto customSound = layout.emplace<QHBoxLayout>().withoutMargin();
{
customSound.append(this->createCheckBox("Custom sound", settings.customHighlightSound));
customSound.append(
this->createCheckBox("Custom sound", app->settings->customHighlightSound));
auto selectFile = customSound.emplace<QPushButton>("Select custom sound file");
QObject::connect(selectFile.getElement(), &QPushButton::clicked, this,
[&settings, this] {
auto fileName = QFileDialog::getOpenFileName(
this, tr("Open Sound"), "", tr("Audio Files (*.mp3 *.wav)"));
settings.pathHighlightSound = fileName;
});
QObject::connect(selectFile.getElement(), &QPushButton::clicked, this, [this, app] {
auto fileName = QFileDialog::getOpenFileName(this, tr("Open Sound"), "",
tr("Audio Files (*.mp3 *.wav)"));
app->settings->pathHighlightSound = fileName;
});
}
layout.append(createCheckBox(ALWAYS_PLAY, settings.highlightAlwaysPlaySound));
layout.append(createCheckBox(ALWAYS_PLAY, app->settings->highlightAlwaysPlaySound));
}
// ---- misc
@@ -1,5 +1,6 @@
#include "ignoremessagespage.hpp"
#include "application.hpp"
#include "util/layoutcreator.hpp"
#include <QLabel>
@@ -12,22 +13,22 @@ namespace settingspages {
IgnoreMessagesPage::IgnoreMessagesPage()
: SettingsPage("Ignore Messages", "")
{
singletons::SettingManager &settings = singletons::SettingManager::getInstance();
auto app = getApp();
util::LayoutCreator<IgnoreMessagesPage> layoutCreator(this);
auto layout = layoutCreator.setLayoutType<QVBoxLayout>();
layout.emplace<QLabel>("Ignored keywords:");
QTextEdit *textEdit = layout.emplace<QTextEdit>().getElement();
textEdit->setPlainText(settings.ignoredKeywords);
textEdit->setPlainText(app->settings->ignoredKeywords);
QObject::connect(textEdit, &QTextEdit::textChanged,
[this] { this->keywordsUpdated.start(200); });
QObject::connect(&this->keywordsUpdated, &QTimer::timeout, [textEdit, &settings] {
QObject::connect(&this->keywordsUpdated, &QTimer::timeout, [textEdit, app] {
QString text = textEdit->toPlainText();
settings.ignoredKeywords = text;
app->settings->ignoredKeywords = text;
});
// ---- misc
@@ -1,5 +1,6 @@
#include "ignoreuserspage.hpp"
#include "application.hpp"
#include "singletons/settingsmanager.hpp"
#include "util/layoutcreator.hpp"
@@ -21,14 +22,15 @@ namespace settingspages {
IgnoreUsersPage::IgnoreUsersPage()
: SettingsPage("Ignores", "")
{
singletons::SettingManager &settings = singletons::SettingManager::getInstance();
auto app = getApp();
util::LayoutCreator<IgnoreUsersPage> layoutCreator(this);
auto layout = layoutCreator.setLayoutType<QVBoxLayout>();
auto group = layout.emplace<QGroupBox>("Ignored users").setLayoutType<QVBoxLayout>();
{
group.append(
this->createCheckBox("Enable twitch ignored users", settings.enableTwitchIgnoredUsers));
group.append(this->createCheckBox("Enable twitch ignored users",
app->settings->enableTwitchIgnoredUsers));
auto anyways = group.emplace<QHBoxLayout>().withoutMargin();
{
+6 -4
View File
@@ -1,4 +1,6 @@
#include "logspage.hpp"
#include "application.hpp"
#include "singletons/pathmanager.hpp"
#include <QFormLayout>
@@ -23,12 +25,12 @@ inline QString CreateLink(const QString &url, bool file = false)
LogsPage::LogsPage()
: SettingsPage("Logs", "")
{
singletons::SettingManager &settings = singletons::SettingManager::getInstance();
auto app = getApp();
util::LayoutCreator<LogsPage> layoutCreator(this);
auto layout = layoutCreator.emplace<QVBoxLayout>().withoutMargin();
singletons::PathManager &pathManager = singletons::PathManager::getInstance();
auto logPath = pathManager.logsFolderPath;
auto logPath = app->paths->logsFolderPath;
auto created = layout.emplace<QLabel>();
created->setText("Logs are saved to " + CreateLink(logPath, true));
@@ -36,7 +38,7 @@ LogsPage::LogsPage()
created->setTextInteractionFlags(Qt::TextBrowserInteraction | Qt::LinksAccessibleByKeyboard |
Qt::LinksAccessibleByKeyboard);
created->setOpenExternalLinks(true);
layout.append(this->createCheckBox("Enable logging", settings.enableLogging));
layout.append(this->createCheckBox("Enable logging", app->settings->enableLogging));
layout->addStretch(1);
}
+11 -11
View File
@@ -1,5 +1,9 @@
#include "moderationpage.hpp"
#include "application.hpp"
#include "singletons/pathmanager.hpp"
#include "util/layoutcreator.hpp"
#include <QGroupBox>
#include <QHBoxLayout>
#include <QLabel>
@@ -8,9 +12,6 @@
#include <QTextEdit>
#include <QVBoxLayout>
#include "singletons/pathmanager.hpp"
#include "util/layoutcreator.hpp"
namespace chatterino {
namespace widgets {
namespace settingspages {
@@ -28,14 +29,13 @@ inline QString CreateLink(const QString &url, bool file = false)
ModerationPage::ModerationPage()
: SettingsPage("Moderation", "")
{
singletons::SettingManager &settings = singletons::SettingManager::getInstance();
singletons::PathManager &pathManager = singletons::PathManager::getInstance();
auto app = getApp();
util::LayoutCreator<ModerationPage> layoutCreator(this);
auto layout = layoutCreator.setLayoutType<QVBoxLayout>();
{
// Logs (copied from LoggingMananger)
auto logPath = pathManager.logsFolderPath;
auto logPath = app->paths->logsFolderPath;
auto created = layout.emplace<QLabel>();
created->setText("Logs are saved to " + CreateLink(logPath, true));
@@ -44,7 +44,7 @@ ModerationPage::ModerationPage()
Qt::LinksAccessibleByKeyboard |
Qt::LinksAccessibleByKeyboard);
created->setOpenExternalLinks(true);
layout.append(this->createCheckBox("Enable logging", settings.enableLogging));
layout.append(this->createCheckBox("Enable logging", app->settings->enableLogging));
layout->addStretch(1);
// Logs end
@@ -58,7 +58,7 @@ ModerationPage::ModerationPage()
auto form = layout.emplace<QFormLayout>();
{
form->addRow("Action on timed out messages (unimplemented):",
this->createComboBox({"Disable", "Hide"}, settings.timeoutAction));
this->createComboBox({"Disable", "Hide"}, app->settings->timeoutAction));
}
auto modButtons =
@@ -71,13 +71,13 @@ ModerationPage::ModerationPage()
auto text = modButtons.emplace<QTextEdit>().getElement();
text->setPlainText(settings.moderationActions);
text->setPlainText(app->settings->moderationActions);
QObject::connect(text, &QTextEdit::textChanged, this,
[this] { this->itemsChangedTimer.start(200); });
QObject::connect(&this->itemsChangedTimer, &QTimer::timeout, this, [text, &settings]() {
settings.moderationActions = text->toPlainText();
QObject::connect(&this->itemsChangedTimer, &QTimer::timeout, this, [text, app]() {
app->settings->moderationActions = text->toPlainText();
});
}
}
@@ -1,5 +1,6 @@
#include "specialchannelspage.hpp"
#include "application.hpp"
#include "singletons/settingsmanager.hpp"
#include "util/layoutcreator.hpp"
@@ -14,7 +15,8 @@ namespace settingspages {
SpecialChannelsPage::SpecialChannelsPage()
: SettingsPage("Special channels", "")
{
singletons::SettingManager &settings = singletons::SettingManager::getInstance();
auto app = getApp();
util::LayoutCreator<SpecialChannelsPage> layoutCreator(this);
auto layout = layoutCreator.setLayoutType<QVBoxLayout>();
+16 -21
View File
@@ -1,4 +1,6 @@
#include "widgets/split.hpp"
#include "application.hpp"
#include "providers/twitch/emotevalue.hpp"
#include "providers/twitch/twitchchannel.hpp"
#include "providers/twitch/twitchmessagebuilder.hpp"
@@ -36,19 +38,8 @@ using namespace chatterino::messages;
namespace chatterino {
namespace widgets {
Split::Split(SplitContainer *parent)
: Split((BaseWidget *)parent)
{
this->container = parent;
}
Split::Split(BaseWidget *widget)
: Split(widget->themeManager, widget)
{
}
Split::Split(singletons::ThemeManager &manager, QWidget *parent)
: BaseWidget(manager, parent)
Split::Split(QWidget *parent)
: BaseWidget(parent)
, container(nullptr)
, channel(Channel::getEmpty())
, vbox(this)
@@ -56,6 +47,8 @@ Split::Split(singletons::ThemeManager &manager, QWidget *parent)
, view(this)
, input(this)
{
auto app = getApp();
this->setMouseTracking(true);
this->vbox.setSpacing(0);
@@ -97,8 +90,8 @@ Split::Split(singletons::ThemeManager &manager, QWidget *parent)
}
});
this->input.textChanged.connect([this](const QString &newText) {
if (!singletons::SettingManager::getInstance().hideEmptyInput) {
this->input.textChanged.connect([=](const QString &newText) {
if (!app->settings->hideEmptyInput) {
return;
}
@@ -109,14 +102,15 @@ Split::Split(singletons::ThemeManager &manager, QWidget *parent)
}
});
singletons::SettingManager::getInstance().hideEmptyInput.connect(
app->settings->hideEmptyInput.connect(
[this](const bool &hideEmptyInput, auto) {
if (hideEmptyInput && this->input.getInputText().length() == 0) {
this->input.hide();
} else {
this->input.show();
}
});
},
this->managedConnections);
this->header.updateModerationModeIcon();
@@ -260,7 +254,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->themeManager->splits.background);
}
void Split::mouseMoveEvent(QMouseEvent *event)
@@ -328,7 +322,8 @@ void Split::doChangeChannel()
void Split::doPopup()
{
Window &window = singletons::WindowManager::getInstance().createWindow(Window::Popup);
auto app = getApp();
Window &window = app->windows->createWindow(Window::Popup);
Split *split =
new Split(static_cast<SplitContainer *>(window.getNotebook().getOrAddSelectedPage()));
@@ -397,7 +392,7 @@ void Split::doOpenViewerList()
QList<QListWidgetItem *> labelList;
for (auto &x : labels) {
auto label = new QListWidgetItem(x);
label->setBackgroundColor(this->themeManager.splits.header.background);
label->setBackgroundColor(this->themeManager->splits.header.background);
labelList.append(label);
}
auto loadingLabel = new QLabel("Loading...");
@@ -454,7 +449,7 @@ void Split::doOpenViewerList()
dockVbox->addWidget(resultList);
resultList->hide();
multiWidget->setStyleSheet(this->themeManager.splits.input.styleSheet);
multiWidget->setStyleSheet(this->themeManager->splits.input.styleSheet);
multiWidget->setLayout(dockVbox);
viewerDock->setWidget(multiWidget);
viewerDock->show();
+3 -3
View File
@@ -43,9 +43,7 @@ class Split : public BaseWidget
Q_OBJECT
public:
explicit Split(SplitContainer *parent);
explicit Split(BaseWidget *widget);
explicit Split(singletons::ThemeManager &manager, QWidget *parent);
explicit Split(QWidget *parent);
~Split() override;
pajlada::Signals::NoArgSignal channelChanged;
@@ -103,6 +101,8 @@ private:
pajlada::Signals::Connection usermodeChangedConnection;
pajlada::Signals::Connection indirectChannelChangedConnection;
std::vector<pajlada::Signals::ScopedConnection> managedConnections;
void doOpenAccountPopupWidget(AccountPopupWidget *widget, QString user);
void channelNameUpdated(const QString &newChannelName);
void handleModifiers(QEvent *event, Qt::KeyboardModifiers modifiers);
+6 -6
View File
@@ -27,7 +27,7 @@ Split *SplitContainer::draggingSplit = nullptr;
std::pair<int, int> SplitContainer::dropPosition = std::pair<int, int>(-1, -1);
SplitContainer::SplitContainer(Notebook *parent, NotebookTab *_tab)
: BaseWidget(parent->themeManager, parent)
: BaseWidget(parent)
, tab(_tab)
, dropPreview(this)
{
@@ -450,9 +450,9 @@ void SplitContainer::paintEvent(QPaintEvent *)
QPainter painter(this);
if (this->ui.hbox.count() == 0) {
painter.fillRect(rect(), this->themeManager.splits.background);
painter.fillRect(rect(), this->themeManager->splits.background);
painter.setPen(this->themeManager.splits.header.text);
painter.setPen(this->themeManager->splits.header.text);
QString text = "Click to add a <split>";
@@ -467,12 +467,12 @@ void SplitContainer::paintEvent(QPaintEvent *)
painter.drawText(rect(), text, QTextOption(Qt::AlignCenter));
} else {
painter.fillRect(rect(), this->themeManager.splits.messageSeperator);
painter.fillRect(rect(), this->themeManager->splits.messageSeperator);
}
QBrush accentColor = (QApplication::activeWindow() == this->window()
? this->themeManager.tabs.selected.backgrounds.regular
: this->themeManager.tabs.selected.backgrounds.unfocused);
? this->themeManager->tabs.selected.backgrounds.regular
: this->themeManager->tabs.selected.backgrounds.unfocused);
painter.fillRect(0, 0, width(), 1, accentColor);
}
+22 -20
View File
@@ -1,4 +1,6 @@
#include "widgets/window.hpp"
#include "application.hpp"
#include "singletons/accountmanager.hpp"
#include "singletons/ircmanager.hpp"
#include "singletons/settingsmanager.hpp"
@@ -21,33 +23,32 @@
namespace chatterino {
namespace widgets {
Window::Window(singletons::ThemeManager &_themeManager, WindowType _type)
: BaseWindow(_themeManager, nullptr, true)
Window::Window(WindowType _type)
: BaseWindow(nullptr, true)
, type(_type)
, dpi(this->getScale())
, notebook(this, !this->hasCustomWindowFrame())
{
singletons::AccountManager::getInstance().Twitch.currentUsername.connect(
[this](const std::string &newUsername, auto) {
if (newUsername.empty()) {
this->refreshWindowTitle("Not logged in");
} else {
this->refreshWindowTitle(QString::fromStdString(newUsername));
}
});
auto app = getApp();
app->accounts->Twitch.currentUsername.connect([this](const std::string &newUsername, auto) {
if (newUsername.empty()) {
this->refreshWindowTitle("Not logged in");
} else {
this->refreshWindowTitle(QString::fromStdString(newUsername));
}
});
if (this->hasCustomWindowFrame() && _type == Window::Main) {
this->addTitleBarButton(TitleBarButton::Settings, [] {
singletons::WindowManager::getInstance().showSettingsDialog();
this->addTitleBarButton(TitleBarButton::Settings, [app] {
app->windows->showSettingsDialog(); //
});
auto user = this->addTitleBarLabel([] {
singletons::WindowManager::getInstance().showAccountSelectPopup(QCursor::pos());
auto user = this->addTitleBarLabel([app] {
app->windows->showAccountSelectPopup(QCursor::pos()); //
});
singletons::AccountManager::getInstance().Twitch.userChanged.connect([user] {
user->getLabel().setText(
singletons::AccountManager::getInstance().Twitch.getCurrent()->getUserName());
});
app->accounts->Twitch.userChanged.connect(
[=] { user->getLabel().setText(app->accounts->Twitch.getCurrent()->getUserName()); });
}
if (_type == Window::Main) {
@@ -161,8 +162,9 @@ bool Window::event(QEvent *e)
void Window::closeEvent(QCloseEvent *event)
{
if (this->type == Window::Main) {
singletons::WindowManager::getInstance().save();
singletons::WindowManager::getInstance().closeAll();
auto app = getApp();
app->windows->save();
app->windows->closeAll();
}
this->closed.invoke();
+1 -1
View File
@@ -25,7 +25,7 @@ class Window : public BaseWindow
public:
enum WindowType { Main, Popup, Attached };
explicit Window(singletons::ThemeManager &_themeManager, WindowType type);
explicit Window(WindowType type);
void repaintVisibleChatWidgets(Channel *channel = nullptr);