mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-13 19:49:51 +01:00
refactored windowmanager
This commit is contained in:
parent
11fed12be1
commit
d96c4a5c91
|
@ -117,7 +117,7 @@ void Channel::addMessage(std::shared_ptr<Message> message)
|
|||
|
||||
this->messageAppended(message);
|
||||
|
||||
WindowManager::repaintVisibleChatWidgets(this);
|
||||
WindowManager::getInstance().repaintVisibleChatWidgets(this);
|
||||
}
|
||||
|
||||
// private methods
|
||||
|
|
|
@ -21,7 +21,7 @@ void ColorScheme::init()
|
|||
[](const float &) { ColorScheme::getInstance().update(); });
|
||||
|
||||
ColorScheme::getInstance().updated.connect(
|
||||
[] { WindowManager::repaintVisibleChatWidgets(); });
|
||||
[] { WindowManager::getInstance().repaintVisibleChatWidgets(); });
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -172,4 +172,4 @@ void ColorScheme::normalizeColor(QColor &color)
|
|||
|
||||
// color.setHslF(color.hueF(), s, newL);
|
||||
}
|
||||
}
|
||||
} // namespace chatterino
|
||||
|
|
|
@ -58,7 +58,7 @@ public:
|
|||
|
||||
QObject::connect(&_gifUpdateTimer, &QTimer::timeout, [this] {
|
||||
_gifUpdateTimerSignal();
|
||||
WindowManager::repaintGifEmotes();
|
||||
WindowManager::getInstance().repaintGifEmotes();
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -93,6 +93,6 @@ private:
|
|||
void loadFfzEmotes();
|
||||
void loadBttvEmotes();
|
||||
};
|
||||
}
|
||||
} // namespace chatterino
|
||||
|
||||
#endif // EMOTES_H
|
||||
|
|
6
main.cpp
6
main.cpp
|
@ -31,9 +31,9 @@ int main(int argc, char *argv[])
|
|||
|
||||
ColorScheme::getInstance().init();
|
||||
|
||||
WindowManager::load();
|
||||
WindowManager::getInstance().load();
|
||||
|
||||
MainWindow &w = WindowManager::getMainWindow();
|
||||
MainWindow &w = WindowManager::getInstance().getMainWindow();
|
||||
w.show();
|
||||
|
||||
IrcManager::getInstance().connect();
|
||||
|
@ -42,7 +42,7 @@ int main(int argc, char *argv[])
|
|||
|
||||
SettingsManager::getInstance().save();
|
||||
|
||||
WindowManager::save();
|
||||
WindowManager::getInstance().save();
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
|
|
@ -93,7 +93,7 @@ void LazyLoadedImage::loadImage()
|
|||
}
|
||||
|
||||
EmoteManager::getInstance().incGeneration();
|
||||
WindowManager::layoutVisibleChatWidgets();
|
||||
WindowManager::getInstance().layoutVisibleChatWidgets();
|
||||
|
||||
reply->deleteLater();
|
||||
manager->deleteLater();
|
||||
|
@ -115,5 +115,5 @@ void LazyLoadedImage::gifUpdateTimout()
|
|||
|
||||
this->currentPixmap = this->allFrames[this->currentFrame].image;
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace messages
|
||||
} // namespace chatterino
|
||||
|
|
|
@ -152,7 +152,7 @@ void SettingsDialog::addTabs()
|
|||
|
||||
QObject::connect(slider, &QSlider::valueChanged, this, [this, &settings](int value) {
|
||||
settings.themeHue.set(value / 1000.0);
|
||||
WindowManager::updateAll();
|
||||
WindowManager::getInstance().updateAll();
|
||||
});
|
||||
|
||||
group->setLayout(form);
|
||||
|
|
|
@ -7,6 +7,13 @@
|
|||
#include <boost/property_tree/json_parser.hpp>
|
||||
|
||||
namespace chatterino {
|
||||
WindowManager WindowManager::instance;
|
||||
|
||||
WindowManager::WindowManager()
|
||||
: _windowMutex()
|
||||
, _mainWindow(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
static const std::string &getSettingsPath()
|
||||
{
|
||||
|
@ -15,38 +22,45 @@ static const std::string &getSettingsPath()
|
|||
return path;
|
||||
}
|
||||
|
||||
QMutex WindowManager::windowMutex;
|
||||
|
||||
widgets::MainWindow *WindowManager::mainWindow(nullptr);
|
||||
|
||||
void WindowManager::layoutVisibleChatWidgets(Channel *channel)
|
||||
{
|
||||
if (WindowManager::mainWindow != nullptr) {
|
||||
WindowManager::mainWindow->layoutVisibleChatWidgets(channel);
|
||||
if (_mainWindow != nullptr) {
|
||||
_mainWindow->layoutVisibleChatWidgets(channel);
|
||||
}
|
||||
}
|
||||
|
||||
void WindowManager::repaintVisibleChatWidgets(Channel *channel)
|
||||
{
|
||||
if (WindowManager::mainWindow != nullptr) {
|
||||
WindowManager::mainWindow->repaintVisibleChatWidgets(channel);
|
||||
if (_mainWindow != nullptr) {
|
||||
_mainWindow->repaintVisibleChatWidgets(channel);
|
||||
}
|
||||
}
|
||||
|
||||
void WindowManager::repaintGifEmotes()
|
||||
{
|
||||
if (WindowManager::mainWindow != nullptr) {
|
||||
WindowManager::mainWindow->repaintGifEmotes();
|
||||
if (_mainWindow != nullptr) {
|
||||
_mainWindow->repaintGifEmotes();
|
||||
}
|
||||
}
|
||||
|
||||
void WindowManager::updateAll()
|
||||
{
|
||||
if (WindowManager::mainWindow != nullptr) {
|
||||
WindowManager::mainWindow->update();
|
||||
if (_mainWindow != nullptr) {
|
||||
_mainWindow->update();
|
||||
}
|
||||
}
|
||||
|
||||
widgets::MainWindow &WindowManager::getMainWindow()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(_windowMutex);
|
||||
|
||||
if (_mainWindow == nullptr) {
|
||||
_mainWindow = new widgets::MainWindow();
|
||||
}
|
||||
|
||||
return *_mainWindow;
|
||||
}
|
||||
|
||||
void WindowManager::load()
|
||||
{
|
||||
const auto &settingsPath = getSettingsPath();
|
||||
|
@ -57,7 +71,7 @@ void WindowManager::load()
|
|||
} catch (const boost::property_tree::json_parser_error &ex) {
|
||||
qDebug() << "Error using property_tree::readJson: " << QString::fromStdString(ex.message());
|
||||
|
||||
WindowManager::getMainWindow().loadDefaults();
|
||||
getMainWindow().loadDefaults();
|
||||
|
||||
return;
|
||||
}
|
||||
|
@ -70,7 +84,7 @@ void WindowManager::load()
|
|||
const auto &type = v.second.get<std::string>("type", "unknown");
|
||||
|
||||
if (type == "main") {
|
||||
WindowManager::getMainWindow().load(v.second);
|
||||
getMainWindow().load(v.second);
|
||||
} else {
|
||||
qDebug() << "Unhandled window type: " << type.c_str();
|
||||
}
|
||||
|
@ -80,8 +94,8 @@ void WindowManager::load()
|
|||
}
|
||||
|
||||
// if the main window was not loaded properly, load defaults
|
||||
if (!WindowManager::getMainWindow().isLoaded()) {
|
||||
WindowManager::getMainWindow().loadDefaults();
|
||||
if (!getMainWindow().isLoaded()) {
|
||||
getMainWindow().loadDefaults();
|
||||
}
|
||||
|
||||
// If there are no windows, create a default main window
|
||||
|
@ -97,7 +111,7 @@ void WindowManager::save()
|
|||
|
||||
{
|
||||
// save main window
|
||||
auto child = WindowManager::getMainWindow().save();
|
||||
auto child = getMainWindow().save();
|
||||
windows.push_back(std::make_pair("", child));
|
||||
}
|
||||
|
||||
|
|
|
@ -3,40 +3,35 @@
|
|||
|
||||
#include "widgets/mainwindow.h"
|
||||
|
||||
#include <QMutex>
|
||||
#include <mutex>
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
class WindowManager
|
||||
{
|
||||
public:
|
||||
static void layoutVisibleChatWidgets(Channel *channel = NULL);
|
||||
static void repaintVisibleChatWidgets(Channel *channel = NULL);
|
||||
static void repaintGifEmotes();
|
||||
static void updateAll();
|
||||
|
||||
static widgets::MainWindow &getMainWindow()
|
||||
static WindowManager &getInstance()
|
||||
{
|
||||
windowMutex.lock();
|
||||
if (mainWindow == nullptr) {
|
||||
mainWindow = new widgets::MainWindow();
|
||||
}
|
||||
windowMutex.unlock();
|
||||
|
||||
return *mainWindow;
|
||||
return instance;
|
||||
}
|
||||
|
||||
static void load();
|
||||
static void save();
|
||||
void layoutVisibleChatWidgets(Channel *channel = nullptr);
|
||||
void repaintVisibleChatWidgets(Channel *channel = nullptr);
|
||||
void repaintGifEmotes();
|
||||
void updateAll();
|
||||
|
||||
widgets::MainWindow &getMainWindow();
|
||||
|
||||
void load();
|
||||
void save();
|
||||
|
||||
private:
|
||||
WindowManager()
|
||||
{
|
||||
}
|
||||
static WindowManager instance;
|
||||
|
||||
static QMutex windowMutex;
|
||||
WindowManager();
|
||||
|
||||
static widgets::MainWindow *mainWindow;
|
||||
std::mutex _windowMutex;
|
||||
widgets::MainWindow *_mainWindow;
|
||||
};
|
||||
|
||||
} // namespace chatterino
|
||||
|
|
Loading…
Reference in a new issue