2017-06-11 09:31:45 +02:00
|
|
|
#include "windowmanager.hpp"
|
2018-01-05 02:56:18 +01:00
|
|
|
#include "debug/log.hpp"
|
2017-12-31 22:58:35 +01:00
|
|
|
#include "singletons/fontmanager.hpp"
|
2017-12-31 00:50:07 +01:00
|
|
|
#include "singletons/thememanager.hpp"
|
2017-01-15 16:38:30 +01:00
|
|
|
|
2017-01-28 22:35:23 +01:00
|
|
|
#include <QDebug>
|
|
|
|
|
2017-01-18 21:30:23 +01:00
|
|
|
namespace chatterino {
|
2017-12-31 22:58:35 +01:00
|
|
|
namespace singletons {
|
2018-01-05 02:56:18 +01:00
|
|
|
|
2017-12-31 00:50:07 +01:00
|
|
|
WindowManager &WindowManager::getInstance()
|
|
|
|
{
|
|
|
|
static WindowManager instance(ThemeManager::getInstance());
|
|
|
|
return instance;
|
|
|
|
}
|
2017-04-13 19:25:33 +02:00
|
|
|
|
2017-12-31 00:50:07 +01:00
|
|
|
WindowManager::WindowManager(ThemeManager &_themeManager)
|
|
|
|
: themeManager(_themeManager)
|
2017-04-13 19:25:33 +02:00
|
|
|
{
|
2017-12-31 00:50:07 +01:00
|
|
|
_themeManager.repaintVisibleChatWidgets.connect([this] { this->repaintVisibleChatWidgets(); });
|
2017-04-13 19:25:33 +02:00
|
|
|
}
|
2017-01-18 21:30:23 +01:00
|
|
|
|
2017-12-14 00:25:06 +01:00
|
|
|
void WindowManager::initMainWindow()
|
|
|
|
{
|
2017-12-31 00:50:07 +01:00
|
|
|
this->selectedWindow = this->mainWindow = new widgets::Window("main", this->themeManager, true);
|
2017-12-14 00:25:06 +01:00
|
|
|
}
|
|
|
|
|
2017-04-12 17:46:44 +02:00
|
|
|
void WindowManager::layoutVisibleChatWidgets(Channel *channel)
|
2017-01-15 16:38:30 +01:00
|
|
|
{
|
2018-01-01 23:29:54 +01:00
|
|
|
this->layout(channel);
|
2017-01-16 03:15:07 +01:00
|
|
|
}
|
|
|
|
|
2017-04-12 17:46:44 +02:00
|
|
|
void WindowManager::repaintVisibleChatWidgets(Channel *channel)
|
2017-01-16 03:15:07 +01:00
|
|
|
{
|
2017-06-13 21:13:58 +02:00
|
|
|
if (this->mainWindow != nullptr) {
|
|
|
|
this->mainWindow->repaintVisibleChatWidgets(channel);
|
2017-01-26 04:26:40 +01:00
|
|
|
}
|
2017-01-15 16:38:30 +01:00
|
|
|
}
|
2017-01-26 21:04:01 +01:00
|
|
|
|
2017-04-12 17:46:44 +02:00
|
|
|
void WindowManager::repaintGifEmotes()
|
2017-02-07 00:03:15 +01:00
|
|
|
{
|
2017-09-17 02:13:57 +02:00
|
|
|
this->repaintGifs();
|
2017-02-07 00:03:15 +01:00
|
|
|
}
|
|
|
|
|
2017-09-16 00:05:06 +02:00
|
|
|
// void WindowManager::updateAll()
|
|
|
|
//{
|
|
|
|
// if (this->mainWindow != nullptr) {
|
|
|
|
// this->mainWindow->update();
|
|
|
|
// }
|
|
|
|
//}
|
2017-02-02 01:23:26 +01:00
|
|
|
|
2017-11-12 17:21:50 +01:00
|
|
|
widgets::Window &WindowManager::getMainWindow()
|
2017-04-13 19:25:33 +02:00
|
|
|
{
|
2017-06-13 21:13:58 +02:00
|
|
|
return *this->mainWindow;
|
2017-04-13 19:25:33 +02:00
|
|
|
}
|
|
|
|
|
2017-12-14 00:25:06 +01:00
|
|
|
widgets::Window &WindowManager::getSelectedWindow()
|
2017-11-12 17:21:50 +01:00
|
|
|
{
|
2017-12-14 00:25:06 +01:00
|
|
|
return *this->selectedWindow;
|
2017-11-12 17:21:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
widgets::Window &WindowManager::createWindow()
|
|
|
|
{
|
2017-12-31 00:50:07 +01:00
|
|
|
auto *window = new widgets::Window("external", this->themeManager, false);
|
2017-12-26 15:08:36 +01:00
|
|
|
window->getNotebook().addNewPage();
|
2017-11-12 17:21:50 +01:00
|
|
|
|
|
|
|
this->windows.push_back(window);
|
|
|
|
|
|
|
|
return *window;
|
|
|
|
}
|
|
|
|
|
2017-12-14 00:25:06 +01:00
|
|
|
int WindowManager::windowCount()
|
|
|
|
{
|
|
|
|
return this->windows.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
widgets::Window *WindowManager::windowAt(int index)
|
|
|
|
{
|
2017-12-23 23:24:35 +01:00
|
|
|
if (index < 0 || (size_t)index >= this->windows.size()) {
|
2017-12-14 00:25:06 +01:00
|
|
|
return nullptr;
|
|
|
|
}
|
2018-01-05 02:56:18 +01:00
|
|
|
debug::Log("getting window at bad index {}", index);
|
2017-12-14 00:25:06 +01:00
|
|
|
|
|
|
|
return this->windows.at(index);
|
|
|
|
}
|
|
|
|
|
2017-04-12 17:46:44 +02:00
|
|
|
void WindowManager::save()
|
2017-01-26 21:04:01 +01:00
|
|
|
{
|
2017-12-22 14:44:31 +01:00
|
|
|
assert(this->mainWindow);
|
2017-01-28 22:35:23 +01:00
|
|
|
|
2017-12-22 14:44:31 +01:00
|
|
|
this->mainWindow->save();
|
2017-01-28 22:35:23 +01:00
|
|
|
|
2017-12-22 14:44:31 +01:00
|
|
|
for (widgets::Window *window : this->windows) {
|
|
|
|
window->save();
|
2017-01-28 22:35:23 +01:00
|
|
|
}
|
2017-01-26 21:04:01 +01:00
|
|
|
}
|
2017-01-28 22:35:23 +01:00
|
|
|
|
2018-01-05 02:56:18 +01:00
|
|
|
} // namespace singletons
|
2017-04-14 17:52:22 +02:00
|
|
|
} // namespace chatterino
|