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
+17 -15
View File
@@ -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;