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:
@@ -1,4 +1,6 @@
|
||||
#include "messages/image.hpp"
|
||||
|
||||
#include "application.hpp"
|
||||
#include "singletons/emotemanager.hpp"
|
||||
#include "singletons/ircmanager.hpp"
|
||||
#include "singletons/windowmanager.hpp"
|
||||
@@ -123,7 +125,7 @@ void Image::loadImage()
|
||||
if (this->allFrames.size() > 1) {
|
||||
if (!this->animated) {
|
||||
util::postToThread([this] {
|
||||
singletons::EmoteManager::getInstance().getGifUpdateSignal().connect([=]() {
|
||||
getApp()->emotes->getGifUpdateSignal().connect([=]() {
|
||||
this->gifUpdateTimout();
|
||||
}); // For some reason when Boost signal is in
|
||||
// thread scope and thread deletes the signal
|
||||
@@ -145,9 +147,10 @@ void Image::loadImage()
|
||||
loadedEventQueued = true;
|
||||
|
||||
QTimer::singleShot(500, [] {
|
||||
singletons::EmoteManager::getInstance().incGeneration();
|
||||
getApp()->emotes->incGeneration();
|
||||
|
||||
singletons::WindowManager::getInstance().layoutVisibleChatWidgets();
|
||||
auto app = getApp();
|
||||
app->windows->layoutVisibleChatWidgets();
|
||||
loadedEventQueued = false;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
#include "messages/layouts/messagelayout.hpp"
|
||||
|
||||
#include "application.hpp"
|
||||
#include "singletons/emotemanager.hpp"
|
||||
#include "singletons/settingsmanager.hpp"
|
||||
|
||||
@@ -45,7 +47,7 @@ int MessageLayout::getHeight() const
|
||||
// return true if redraw is required
|
||||
bool MessageLayout::layout(int width, float scale, MessageElement::Flags flags)
|
||||
{
|
||||
auto &emoteManager = singletons::EmoteManager::getInstance();
|
||||
auto app = getApp();
|
||||
|
||||
bool layoutRequired = false;
|
||||
|
||||
@@ -55,9 +57,9 @@ bool MessageLayout::layout(int width, float scale, MessageElement::Flags flags)
|
||||
this->currentLayoutWidth = width;
|
||||
|
||||
// check if emotes changed
|
||||
bool imagesChanged = this->emoteGeneration != emoteManager.getGeneration();
|
||||
bool imagesChanged = this->emoteGeneration != app->emotes->getGeneration();
|
||||
layoutRequired |= imagesChanged;
|
||||
this->emoteGeneration = emoteManager.getGeneration();
|
||||
this->emoteGeneration = app->emotes->getGeneration();
|
||||
|
||||
// check if text changed
|
||||
bool textChanged =
|
||||
@@ -66,14 +68,12 @@ bool MessageLayout::layout(int width, float scale, MessageElement::Flags flags)
|
||||
this->fontGeneration = singletons::FontManager::getInstance().getGeneration();
|
||||
|
||||
// check if work mask changed
|
||||
bool wordMaskChanged = this->currentWordFlags !=
|
||||
flags; // singletons::SettingManager::getInstance().getWordTypeMask();
|
||||
bool wordMaskChanged = this->currentWordFlags != flags; // app->settings->getWordTypeMask();
|
||||
layoutRequired |= wordMaskChanged;
|
||||
this->currentWordFlags = flags; // singletons::SettingManager::getInstance().getWordTypeMask();
|
||||
this->currentWordFlags = flags; // app->settings->getWordTypeMask();
|
||||
|
||||
// check if timestamp format changed
|
||||
bool timestampFormatChanged =
|
||||
this->timestampFormat != singletons::SettingManager::getInstance().timestampFormat;
|
||||
bool timestampFormatChanged = this->timestampFormat != app->settings->timestampFormat;
|
||||
|
||||
layoutRequired |= timestampFormatChanged;
|
||||
|
||||
@@ -128,8 +128,8 @@ void MessageLayout::actuallyLayout(int width, MessageElement::Flags flags)
|
||||
void MessageLayout::paint(QPainter &painter, int y, int messageIndex, Selection &selection,
|
||||
bool isLastReadMessage, bool isWindowFocused)
|
||||
{
|
||||
auto app = getApp();
|
||||
QPixmap *pixmap = this->buffer.get();
|
||||
singletons::ThemeManager &themeManager = singletons::ThemeManager::getInstance();
|
||||
|
||||
// create new buffer if required
|
||||
if (!pixmap) {
|
||||
@@ -160,7 +160,8 @@ void MessageLayout::paint(QPainter &painter, int y, int messageIndex, Selection
|
||||
|
||||
// draw disabled
|
||||
if (this->message->flags.HasFlag(Message::Disabled)) {
|
||||
painter.fillRect(0, y, pixmap->width(), pixmap->height(), themeManager.messages.disabled);
|
||||
painter.fillRect(0, y, pixmap->width(), pixmap->height(),
|
||||
app->themes->messages.disabled);
|
||||
}
|
||||
|
||||
// draw selection
|
||||
@@ -170,8 +171,9 @@ void MessageLayout::paint(QPainter &painter, int y, int messageIndex, Selection
|
||||
|
||||
// draw last read message line
|
||||
if (isLastReadMessage) {
|
||||
QColor color = isWindowFocused ? themeManager.tabs.selected.backgrounds.regular.color()
|
||||
: themeManager.tabs.selected.backgrounds.unfocused.color();
|
||||
QColor color = isWindowFocused
|
||||
? app->themes->tabs.selected.backgrounds.regular.color()
|
||||
: app->themes->tabs.selected.backgrounds.unfocused.color();
|
||||
|
||||
QBrush brush(color, Qt::VerPattern);
|
||||
|
||||
@@ -184,7 +186,7 @@ void MessageLayout::paint(QPainter &painter, int y, int messageIndex, Selection
|
||||
|
||||
void MessageLayout::updateBuffer(QPixmap *buffer, int messageIndex, Selection &selection)
|
||||
{
|
||||
singletons::ThemeManager &themeManager = singletons::ThemeManager::getInstance();
|
||||
auto app = getApp();
|
||||
|
||||
QPainter painter(buffer);
|
||||
|
||||
@@ -192,8 +194,8 @@ void MessageLayout::updateBuffer(QPixmap *buffer, int messageIndex, Selection &s
|
||||
|
||||
// draw background
|
||||
painter.fillRect(buffer->rect(), this->message->flags & Message::Highlighted
|
||||
? themeManager.messages.backgrounds.highlighted
|
||||
: themeManager.messages.backgrounds.regular);
|
||||
? app->themes->messages.backgrounds.highlighted
|
||||
: app->themes->messages.backgrounds.regular);
|
||||
|
||||
// draw message
|
||||
this->container.paintElements(painter);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "messagelayoutcontainer.hpp"
|
||||
|
||||
#include "application.hpp"
|
||||
#include "messagelayoutelement.hpp"
|
||||
#include "messages/selection.hpp"
|
||||
#include "singletons/settingsmanager.hpp"
|
||||
@@ -210,8 +211,8 @@ void MessageLayoutContainer::paintAnimatedElements(QPainter &painter, int yOffse
|
||||
void MessageLayoutContainer::paintSelection(QPainter &painter, int messageIndex,
|
||||
Selection &selection, int yOffset)
|
||||
{
|
||||
singletons::ThemeManager &themeManager = singletons::ThemeManager::getInstance();
|
||||
QColor selectionColor = themeManager.messages.selection;
|
||||
auto app = getApp();
|
||||
QColor selectionColor = app->themes->messages.selection;
|
||||
|
||||
// don't draw anything
|
||||
if (selection.selectionMin.messageIndex > messageIndex ||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "messages/layouts/messagelayoutelement.hpp"
|
||||
#include "application.hpp"
|
||||
#include "messages/messageelement.hpp"
|
||||
#include "util/debugcount.hpp"
|
||||
|
||||
@@ -239,9 +240,11 @@ int TextIconLayoutElement::getSelectionIndexCount()
|
||||
|
||||
void TextIconLayoutElement::paint(QPainter &painter)
|
||||
{
|
||||
auto app = getApp();
|
||||
|
||||
QFont font = singletons::FontManager::getInstance().getFont(FontStyle::Tiny, this->scale);
|
||||
|
||||
painter.setPen(singletons::ThemeManager::getInstance().messages.textColors.system);
|
||||
painter.setPen(app->themes->messages.textColors.system);
|
||||
painter.setFont(font);
|
||||
|
||||
QTextOption option;
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
#include "messages/messageelement.hpp"
|
||||
|
||||
#include "application.hpp"
|
||||
#include "messages/layouts/messagelayoutcontainer.hpp"
|
||||
#include "messages/layouts/messagelayoutelement.hpp"
|
||||
#include "singletons/settingsmanager.hpp"
|
||||
@@ -95,7 +97,7 @@ void EmoteElement::addToContainer(MessageLayoutContainer &container, MessageElem
|
||||
return;
|
||||
}
|
||||
|
||||
int quality = singletons::SettingManager::getInstance().preferredEmoteQuality;
|
||||
int quality = getApp()->settings->preferredEmoteQuality;
|
||||
|
||||
Image *_image;
|
||||
if (quality == 3 && this->data.image3x != nullptr) {
|
||||
@@ -134,16 +136,16 @@ TextElement::TextElement(const QString &text, MessageElement::Flags flags,
|
||||
|
||||
void TextElement::addToContainer(MessageLayoutContainer &container, MessageElement::Flags _flags)
|
||||
{
|
||||
auto app = getApp();
|
||||
|
||||
if (_flags & this->getFlags()) {
|
||||
QFontMetrics &metrics = singletons::FontManager::getInstance().getFontMetrics(
|
||||
this->style, container.getScale());
|
||||
singletons::ThemeManager &themeManager =
|
||||
singletons::ThemeManager::ThemeManager::getInstance();
|
||||
|
||||
for (Word &word : this->words) {
|
||||
auto getTextLayoutElement = [&](QString text, int width, bool trailingSpace) {
|
||||
QColor color = this->color.getColor(themeManager);
|
||||
themeManager.normalizeColor(color);
|
||||
QColor color = this->color.getColor(*app->themes);
|
||||
app->themes->normalizeColor(color);
|
||||
|
||||
auto e = (new TextLayoutElement(*this, text, QSize(width, metrics.height()), color,
|
||||
this->style, container.getScale()))
|
||||
@@ -225,8 +227,9 @@ void TimestampElement::addToContainer(MessageLayoutContainer &container,
|
||||
MessageElement::Flags _flags)
|
||||
{
|
||||
if (_flags & this->getFlags()) {
|
||||
if (singletons::SettingManager::getInstance().timestampFormat != this->format) {
|
||||
this->format = singletons::SettingManager::getInstance().timestampFormat.getValue();
|
||||
auto app = getApp();
|
||||
if (app->settings->timestampFormat != this->format) {
|
||||
this->format = app->settings->timestampFormat.getValue();
|
||||
this->element.reset(this->formatTime(this->time));
|
||||
}
|
||||
|
||||
@@ -238,8 +241,7 @@ TextElement *TimestampElement::formatTime(const QTime &time)
|
||||
{
|
||||
static QLocale locale("en_US");
|
||||
|
||||
QString format =
|
||||
locale.toString(time, singletons::SettingManager::getInstance().timestampFormat);
|
||||
QString format = locale.toString(time, getApp()->settings->timestampFormat);
|
||||
|
||||
return new TextElement(format, Flags::Timestamp, MessageColor::System, FontStyle::Medium);
|
||||
}
|
||||
@@ -256,8 +258,7 @@ void TwitchModerationElement::addToContainer(MessageLayoutContainer &container,
|
||||
if (_flags & MessageElement::ModeratorTools) {
|
||||
QSize size((int)(container.getScale() * 16), (int)(container.getScale() * 16));
|
||||
|
||||
for (const singletons::ModerationAction &m :
|
||||
singletons::SettingManager::getInstance().getModerationActions()) {
|
||||
for (const singletons::ModerationAction &m : getApp()->settings->getModerationActions()) {
|
||||
if (m.isImage()) {
|
||||
container.addElement((new ImageLayoutElement(*this, m.getImage(), size))
|
||||
->setLink(Link(Link::UserAction, m.getAction())));
|
||||
|
||||
Reference in New Issue
Block a user