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
+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;
}