Finish up singleton refactoring into one giant class

This commit is contained in:
Rasmus Karlsson
2018-04-28 15:20:18 +02:00
parent 9426a9d633
commit 2f195891cd
34 changed files with 221 additions and 184 deletions
+4 -5
View File
@@ -75,10 +75,9 @@ ChannelView::ChannelView(BaseWidget *parent)
this->goToBottom->getLabel().setText("More messages below");
this->goToBottom->setVisible(false);
this->managedConnections.emplace_back(
singletons::FontManager::getInstance().fontChanged.connect([this] {
this->layoutMessages(); //
}));
this->managedConnections.emplace_back(app->fonts->fontChanged.connect([this] {
this->layoutMessages(); //
}));
connect(goToBottom, &RippleEffectLabel::clicked, this, [=] {
QTimer::singleShot(180, [=] {
@@ -514,7 +513,7 @@ messages::MessageElement::Flags ChannelView::getFlags() const
if (split->getModerationMode()) {
flags = (MessageElement::Flags)(flags | MessageElement::ModeratorTools);
}
if (this->channel == TwitchServer::getInstance().mentionsChannel) {
if (this->channel == app->twitch.server->mentionsChannel) {
flags = (MessageElement::Flags)(flags | MessageElement::ChannelName);
}
}
+16 -10
View File
@@ -1,4 +1,6 @@
#include "label.hpp"
#include "application.hpp"
#include "singletons/fontmanager.hpp"
#include <QPainter>
@@ -9,8 +11,11 @@ namespace widgets {
Label::Label(BaseWidget *parent)
: BaseWidget(parent)
{
singletons::FontManager::getInstance().fontChanged.connect(
[this]() { this->scaleChangedEvent(this->getScale()); });
auto app = getApp();
app->fonts->fontChanged.connect([=]() {
this->scaleChangedEvent(this->getScale()); //
});
}
const QString &Label::getText() const
@@ -37,8 +42,9 @@ void Label::setFontStyle(FontStyle style)
void Label::scaleChangedEvent(float scale)
{
QFontMetrics metrics =
singletons::FontManager::getInstance().getFontMetrics(this->fontStyle, scale);
auto app = getApp();
QFontMetrics metrics = app->fonts->getFontMetrics(this->fontStyle, scale);
this->preferedSize = QSize(metrics.width(this->text), metrics.height());
@@ -57,13 +63,13 @@ QSize Label::minimumSizeHint() const
void Label::paintEvent(QPaintEvent *)
{
QPainter painter(this);
painter.setFont(singletons::FontManager::getInstance().getFont(
this->fontStyle, this->getScale() / painter.device()->devicePixelRatioF()));
auto app = getApp();
int width = singletons::FontManager::getInstance()
.getFontMetrics(this->fontStyle, this->getScale())
.width(this->text);
QPainter painter(this);
painter.setFont(app->fonts->getFont(this->fontStyle,
this->getScale() / painter.device()->devicePixelRatioF()));
int width = app->fonts->getFontMetrics(this->fontStyle, this->getScale()).width(this->text);
int flags = Qt::TextSingleLine;
+11 -7
View File
@@ -1,4 +1,6 @@
#include "widgets/helper/splitheader.hpp"
#include "application.hpp"
#include "providers/twitch/twitchchannel.hpp"
#include "providers/twitch/twitchserver.hpp"
#include "singletons/resourcemanager.hpp"
@@ -28,17 +30,16 @@ SplitHeader::SplitHeader(Split *_split)
: BaseWidget(_split)
, split(_split)
{
auto app = getApp();
this->setMouseTracking(true);
singletons::ResourceManager &resourceManager = singletons::ResourceManager::getInstance();
util::LayoutCreator<SplitHeader> layoutCreator(this);
auto layout = layoutCreator.emplace<QHBoxLayout>().withoutMargin();
{
// dropdown label
auto dropdown = layout.emplace<RippleEffectButton>(this).assign(&this->dropdownButton);
dropdown->setMouseTracking(true);
dropdown->setPixmap(resourceManager.splitHeaderContext->getPixmap());
dropdown->setPixmap(app->resources->splitHeaderContext->getPixmap());
this->addDropdownItems(dropdown.getElement());
QObject::connect(dropdown.getElement(), &RippleEffectButton::clicked, this, [this] {
QTimer::singleShot(80, [&] {
@@ -197,10 +198,11 @@ void SplitHeader::updateChannelText()
void SplitHeader::updateModerationModeIcon()
{
singletons::ResourceManager &resourceManager = singletons::ResourceManager::getInstance();
auto app = getApp();
this->moderationButton->setPixmap(this->split->getModerationMode()
? resourceManager.moderationmode_enabled->getPixmap()
: resourceManager.moderationmode_disabled->getPixmap());
? app->resources->moderationmode_enabled->getPixmap()
: app->resources->moderationmode_disabled->getPixmap());
bool modButtonVisible = false;
ChannelPtr channel = this->split->getChannel();
@@ -285,8 +287,10 @@ void SplitHeader::menuReloadChannelEmotes()
void SplitHeader::menuManualReconnect()
{
auto app = getApp();
// fourtf: connection
providers::twitch::TwitchServer::getInstance().connect();
app->twitch.server->connect();
}
void SplitHeader::menuShowChangelog()
+3 -4
View File
@@ -39,7 +39,6 @@ SplitInput::SplitInput(Split *_chatWidget)
void SplitInput::initLayout()
{
auto app = getApp();
auto &fontManager = singletons::FontManager::getInstance();
util::LayoutCreator<SplitInput> layoutCreator(this);
auto layout = layoutCreator.setLayoutType<QHBoxLayout>().withoutMargin().assign(&this->ui.hbox);
@@ -66,11 +65,11 @@ void SplitInput::initLayout()
// set edit font
this->ui.textEdit->setFont(
fontManager.getFont(singletons::FontManager::Type::Medium, this->getScale()));
app->fonts->getFont(singletons::FontManager::Type::Medium, this->getScale()));
this->managedConnections.emplace_back(fontManager.fontChanged.connect([this, &fontManager]() {
this->managedConnections.emplace_back(app->fonts->fontChanged.connect([=]() {
this->ui.textEdit->setFont(
fontManager.getFont(singletons::FontManager::Type::Medium, this->getScale()));
app->fonts->getFont(singletons::FontManager::Type::Medium, this->getScale()));
}));
// open emote popup
+7 -5
View File
@@ -1,5 +1,6 @@
#include "selectchanneldialog.hpp"
#include "application.hpp"
#include "providers/twitch/twitchserver.hpp"
#include "util/layoutcreator.hpp"
@@ -179,17 +180,18 @@ IndirectChannel SelectChannelDialog::getSelectedChannel() const
return this->selectedChannel;
}
auto app = getApp();
switch (this->ui.notebook->getSelectedIndex()) {
case TAB_TWITCH: {
if (this->ui.twitch.channel->isChecked()) {
return providers::twitch::TwitchServer::getInstance().getOrAddChannel(
this->ui.twitch.channelName->text());
return app->twitch.server->getOrAddChannel(this->ui.twitch.channelName->text());
} else if (this->ui.twitch.watching->isChecked()) {
return providers::twitch::TwitchServer::getInstance().watchingChannel;
return app->twitch.server->watchingChannel;
} else if (this->ui.twitch.mentions->isChecked()) {
return providers::twitch::TwitchServer::getInstance().mentionsChannel;
return app->twitch.server->mentionsChannel;
} else if (this->ui.twitch.whispers->isChecked()) {
return providers::twitch::TwitchServer::getInstance().whispersChannel;
return app->twitch.server->whispersChannel;
}
}
}
+12 -14
View File
@@ -142,35 +142,33 @@ QLayout *AppearancePage::createThemeColorChanger()
QLayout *AppearancePage::createFontChanger()
{
QHBoxLayout *layout = new QHBoxLayout;
auto app = getApp();
auto &fontManager = singletons::FontManager::getInstance();
QHBoxLayout *layout = new QHBoxLayout;
// LABEL
QLabel *label = new QLabel();
layout->addWidget(label);
auto updateFontFamilyLabel = [label, &fontManager](auto) {
label->setText(QString::fromStdString(fontManager.currentFontFamily.getValue()) + ", " +
QString::number(fontManager.currentFontSize) + "pt");
auto updateFontFamilyLabel = [=](auto) {
label->setText(QString::fromStdString(app->fonts->currentFontFamily.getValue()) + ", " +
QString::number(app->fonts->currentFontSize) + "pt");
};
fontManager.currentFontFamily.connectSimple(updateFontFamilyLabel, this->managedConnections);
fontManager.currentFontSize.connectSimple(updateFontFamilyLabel, this->managedConnections);
app->fonts->currentFontFamily.connectSimple(updateFontFamilyLabel, this->managedConnections);
app->fonts->currentFontSize.connectSimple(updateFontFamilyLabel, this->managedConnections);
// BUTTON
QPushButton *button = new QPushButton("Select");
layout->addWidget(button);
button->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Policy::Fixed);
QObject::connect(button, &QPushButton::clicked, []() {
auto &fontManager = singletons::FontManager::getInstance();
QFontDialog dialog(fontManager.getFont(singletons::FontManager::Medium, 1.));
QObject::connect(button, &QPushButton::clicked, [=]() {
QFontDialog dialog(app->fonts->getFont(singletons::FontManager::Medium, 1.));
dialog.connect(&dialog, &QFontDialog::fontSelected, [](const QFont &font) {
auto &fontManager = singletons::FontManager::getInstance();
fontManager.currentFontFamily = font.family().toStdString();
fontManager.currentFontSize = font.pointSize();
dialog.connect(&dialog, &QFontDialog::fontSelected, [=](const QFont &font) {
app->fonts->currentFontFamily = font.family().toStdString();
app->fonts->currentFontSize = font.pointSize();
});
dialog.show();
+9 -4
View File
@@ -1,4 +1,6 @@
#include "tooltipwidget.hpp"
#include "application.hpp"
#include "singletons/fontmanager.hpp"
#include "singletons/thememanager.hpp"
@@ -14,6 +16,8 @@ TooltipWidget::TooltipWidget(BaseWidget *parent)
: BaseWindow(parent)
, displayText(new QLabel())
{
auto app = getApp();
this->setStyleSheet("color: #fff; background: #000");
this->setWindowOpacity(0.8);
this->updateFont();
@@ -31,8 +35,7 @@ TooltipWidget::TooltipWidget(BaseWidget *parent)
layout->addWidget(displayText);
this->setLayout(layout);
this->fontChangedConnection =
singletons::FontManager::getInstance().fontChanged.connect([this] { this->updateFont(); });
this->fontChangedConnection = app->fonts->fontChanged.connect([this] { this->updateFont(); });
}
TooltipWidget::~TooltipWidget()
@@ -47,8 +50,10 @@ void TooltipWidget::scaleChangedEvent(float)
void TooltipWidget::updateFont()
{
this->setFont(singletons::FontManager::getInstance().getFont(
singletons::FontManager::Type::MediumSmall, this->getScale()));
auto app = getApp();
this->setFont(
app->fonts->getFont(singletons::FontManager::Type::MediumSmall, this->getScale()));
}
void TooltipWidget::setText(QString text)