From 86ae71f674354c8b440ac78595ab6e2554554e8e Mon Sep 17 00:00:00 2001 From: Date: Thu, 14 Dec 2017 00:25:06 +0100 Subject: [PATCH] fixed compiling --- src/application.cpp | 2 ++ src/commandmanager.cpp | 42 +++++++++++++++++++++------------------- src/commandmanager.hpp | 2 +- src/widgets/notebook.cpp | 5 +++++ src/widgets/notebook.hpp | 1 + src/widgets/window.cpp | 6 ++---- src/widgets/window.hpp | 4 +++- src/windowmanager.cpp | 32 +++++++++++++++++++++--------- src/windowmanager.hpp | 12 ++++++------ 9 files changed, 65 insertions(+), 41 deletions(-) diff --git a/src/application.cpp b/src/application.cpp index 46f0c9577..9ae0b6cc4 100644 --- a/src/application.cpp +++ b/src/application.cpp @@ -22,6 +22,8 @@ Application::Application() logging::init(); SettingsManager::getInstance().load(); + this->windowManager.initMainWindow(); + // Initialize everything we need this->emoteManager.loadGlobalEmotes(); diff --git a/src/commandmanager.cpp b/src/commandmanager.cpp index 4bcaf78a4..1d545ad10 100644 --- a/src/commandmanager.cpp +++ b/src/commandmanager.cpp @@ -4,37 +4,39 @@ namespace chatterino { void CommandManager::execCommand(QString command) { - if (command == "selectr") { - selectSplitRelative(1, 0); - } - if (command == "selectl") { - selectSplitRelative(-1, 0); - } - if (command == "selectu") { - selectSplitRelative(0, -1); - } - if (command == "selectd") { - selectSplitRelative(0, 1); - } +// if (command == "selectr") { +// selectSplitRelative(false, 1); +// } +// if (command == "selectl") { +// selectSplitRelative(false, -1); +// } +// if (command == "selectu") { +// selectSplitRelative(true, -1); +// } +// if (command == "selectd") { +// selectSplitRelative(true, 1); +// } if (command == "mover") { - moveSplitRelative(1, 0); + moveSplitRelative(false, 1); } if (command == "movel") { - moveSplitRelative(-1, 0); + moveSplitRelative(false, -1); } if (command == "moveu") { - moveSplitRelative(0, -1); + moveSplitRelative(true, -1); } if (command == "moved") { - moveSplitRelative(0, 1); + moveSplitRelative(true, 1); } } -void CommandManager::selectSplitRelative(int dx, int dy) -{ - WindowManager::instance->getCurrentWindow().getNotebook().getSelectedPage(); -} +//void CommandManager::selectSplitRelative(bool vertical, int offset) +//{ +// SplitContainer *container = WindowManager::instance-> +// +// if (vertical) +//} void CommandManager::moveSplitRelative(int dx, int dy) { diff --git a/src/commandmanager.hpp b/src/commandmanager.hpp index 13c28aa57..92ef7896a 100644 --- a/src/commandmanager.hpp +++ b/src/commandmanager.hpp @@ -9,7 +9,7 @@ public: CommandManager() = delete; void execCommand(QString command); - void selectSplitRelative(int dx, int dy); + // void selectSplitRelative(int dx, int dy); void moveSplitRelative(int dx, int dy); }; } diff --git a/src/widgets/notebook.cpp b/src/widgets/notebook.cpp index 19b41f85d..aa068787d 100644 --- a/src/widgets/notebook.cpp +++ b/src/widgets/notebook.cpp @@ -107,6 +107,11 @@ void Notebook::select(SplitContainer *page) this->performLayout(); } +int Notebook::tabCount() +{ + return this->pages.size(); +} + SplitContainer *Notebook::tabAt(QPoint point, int &index) { int i = 0; diff --git a/src/widgets/notebook.hpp b/src/widgets/notebook.hpp index f1fc7617f..93582422a 100644 --- a/src/widgets/notebook.hpp +++ b/src/widgets/notebook.hpp @@ -39,6 +39,7 @@ public: void performLayout(bool animate = true); + int tabCount(); SplitContainer *tabAt(QPoint point, int &index); void rearrangePage(SplitContainer *page, int index); diff --git a/src/widgets/window.cpp b/src/widgets/window.cpp index f98dfc049..8de0ae4fb 100644 --- a/src/widgets/window.cpp +++ b/src/widgets/window.cpp @@ -66,10 +66,6 @@ Window::Window(ChannelManager &_channelManager, ColorScheme &_colorScheme, } } -Window::~Window() -{ -} - void Window::repaintVisibleChatWidgets(Channel *channel) { auto *page = this->notebook.getSelectedPage(); @@ -128,6 +124,8 @@ void Window::closeEvent(QCloseEvent *) { // Save closing window position // this->windowGeometry = this->geometry(); + + this->closed(); } void Window::refreshTheme() diff --git a/src/widgets/window.hpp b/src/widgets/window.hpp index 12b1b5452..e1ea34e0a 100644 --- a/src/widgets/window.hpp +++ b/src/widgets/window.hpp @@ -9,6 +9,7 @@ //#endif #include +#include #include #include @@ -27,7 +28,6 @@ class Window : public BaseWidget public: explicit Window(ChannelManager &_channelManager, ColorScheme &_colorScheme, CompletionManager &_completionManager, bool isMainWindow); - ~Window(); void repaintVisibleChatWidgets(Channel *channel = nullptr); @@ -39,6 +39,8 @@ public: Notebook &getNotebook(); + boost::signals2::signal closed; + protected: virtual void closeEvent(QCloseEvent *event) override; diff --git a/src/windowmanager.cpp b/src/windowmanager.cpp index a26c1b104..93c511d61 100644 --- a/src/windowmanager.cpp +++ b/src/windowmanager.cpp @@ -20,6 +20,12 @@ WindowManager::WindowManager(ChannelManager &_channelManager, ColorScheme &_colo WindowManager::instance = this; } +void WindowManager::initMainWindow() +{ + this->selectedWindow = this->mainWindow = + new widgets::Window(this->channelManager, this->colorScheme, this->completionManager, true); +} + static const std::string &getSettingsPath() { static std::string path = (Path::getAppdataPath() + "uilayout.json").toStdString(); @@ -53,18 +59,12 @@ void WindowManager::repaintGifEmotes() widgets::Window &WindowManager::getMainWindow() { - std::lock_guard lock(this->windowMutex); - - if (this->mainWindow == nullptr) { - this->mainWindow = new widgets::Window(this->channelManager, this->colorScheme, - this->completionManager, true); - } - return *this->mainWindow; } -widgets::Window &WindowManager::getCurrentWindow() +widgets::Window &WindowManager::getSelectedWindow() { + return *this->selectedWindow; } widgets::Window &WindowManager::createWindow() @@ -72,7 +72,6 @@ widgets::Window &WindowManager::createWindow() auto *window = new widgets::Window(this->channelManager, this->colorScheme, this->completionManager, false); - std::lock_guard lock(this->windowMutex); window->loadDefaults(); this->windows.push_back(window); @@ -80,6 +79,21 @@ widgets::Window &WindowManager::createWindow() return *window; } +int WindowManager::windowCount() +{ + return this->windows.size(); +} + +widgets::Window *WindowManager::windowAt(int index) +{ + if (index < 0 || index >= this->windows.size()) { + return nullptr; + } + qDebug() << "getting window at bad index" << index; + + return this->windows.at(index); +} + void WindowManager::load() { const auto &settingsPath = getSettingsPath(); diff --git a/src/windowmanager.hpp b/src/windowmanager.hpp index 78b569c85..b819103e5 100644 --- a/src/windowmanager.hpp +++ b/src/windowmanager.hpp @@ -2,8 +2,6 @@ #include "widgets/window.hpp" -#include - namespace chatterino { class ChannelManager; @@ -25,13 +23,16 @@ public: void layoutVisibleChatWidgets(Channel *channel = nullptr); void repaintVisibleChatWidgets(Channel *channel = nullptr); void repaintGifEmotes(); + void initMainWindow(); // void updateAll(); widgets::Window &getMainWindow(); - widgets::Window &getCurrentWindow(); - + widgets::Window &getSelectedWindow(); widgets::Window &createWindow(); + int windowCount(); + widgets::Window *windowAt(int index); + void load(); void save(); @@ -39,11 +40,10 @@ public: boost::signals2::signal layout; private: - std::mutex windowMutex; std::vector windows; - // TODO(pajlada): Store as a value instead of a pointer widgets::Window *mainWindow = nullptr; + widgets::Window *selectedWindow = nullptr; }; } // namespace chatterino