2017-11-12 17:21:50 +01:00
|
|
|
#include "widgets/window.hpp"
|
2017-12-31 00:50:07 +01:00
|
|
|
#include "singletons/accountmanager.hpp"
|
|
|
|
#include "singletons/channelmanager.hpp"
|
|
|
|
#include "singletons/settingsmanager.hpp"
|
|
|
|
#include "singletons/thememanager.hpp"
|
2018-01-06 20:27:26 +01:00
|
|
|
#include "widgets/helper/shortcut.hpp"
|
2017-06-11 09:31:45 +02:00
|
|
|
#include "widgets/notebook.hpp"
|
|
|
|
#include "widgets/settingsdialog.hpp"
|
2017-12-17 02:18:13 +01:00
|
|
|
#include "widgets/split.hpp"
|
2016-12-29 17:31:07 +01:00
|
|
|
|
2017-01-18 04:52:47 +01:00
|
|
|
#include <QPalette>
|
2017-05-27 15:40:42 +02:00
|
|
|
#include <QShortcut>
|
2017-04-12 17:46:44 +02:00
|
|
|
#include <QVBoxLayout>
|
2017-01-18 04:52:47 +01:00
|
|
|
|
2017-04-14 17:52:22 +02:00
|
|
|
namespace chatterino {
|
|
|
|
namespace widgets {
|
2017-01-18 21:30:23 +01:00
|
|
|
|
2018-01-02 02:15:11 +01:00
|
|
|
Window::Window(const QString &windowName, singletons::ThemeManager &_themeManager,
|
|
|
|
bool _isMainWindow)
|
2017-12-31 00:50:07 +01:00
|
|
|
: BaseWidget(_themeManager, nullptr)
|
2017-12-22 14:44:31 +01:00
|
|
|
, settingRoot(fS("/windows/{}", windowName))
|
|
|
|
, windowGeometry(this->settingRoot)
|
2017-12-23 23:24:35 +01:00
|
|
|
, dpi(this->getDpiMultiplier())
|
2017-12-31 00:50:07 +01:00
|
|
|
, themeManager(_themeManager)
|
|
|
|
, notebook(this, _isMainWindow, this->settingRoot)
|
2016-12-29 17:31:07 +01:00
|
|
|
{
|
2017-09-23 18:37:51 +02:00
|
|
|
this->initAsWindow();
|
|
|
|
|
2017-12-31 22:58:35 +01:00
|
|
|
singletons::AccountManager::getInstance().Twitch.currentUsername.connect(
|
2017-12-18 21:02:17 +01:00
|
|
|
[this](const std::string &newUsername, auto) {
|
|
|
|
if (newUsername.empty()) {
|
|
|
|
this->refreshWindowTitle("Not logged in");
|
|
|
|
} else {
|
|
|
|
this->refreshWindowTitle(QString::fromStdString(newUsername));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2017-04-12 17:46:44 +02:00
|
|
|
QVBoxLayout *layout = new QVBoxLayout(this);
|
|
|
|
|
|
|
|
// add titlebar
|
|
|
|
// if (SettingsManager::getInstance().useCustomWindowFrame.get()) {
|
|
|
|
// layout->addWidget(&_titleBar);
|
|
|
|
// }
|
|
|
|
|
2017-06-13 21:13:58 +02:00
|
|
|
layout->addWidget(&this->notebook);
|
2017-04-12 17:46:44 +02:00
|
|
|
setLayout(layout);
|
|
|
|
|
|
|
|
// set margin
|
|
|
|
// if (SettingsManager::getInstance().useCustomWindowFrame.get()) {
|
|
|
|
// layout->setMargin(1);
|
|
|
|
// } else {
|
|
|
|
layout->setMargin(0);
|
|
|
|
// }
|
2016-12-30 12:20:26 +01:00
|
|
|
|
2017-07-02 14:28:37 +02:00
|
|
|
this->refreshTheme();
|
2017-01-01 02:30:42 +01:00
|
|
|
|
2017-12-17 17:09:50 +01:00
|
|
|
this->loadGeometry();
|
2017-05-27 15:40:42 +02:00
|
|
|
|
2018-01-06 20:27:26 +01:00
|
|
|
/// Initialize program-wide hotkeys
|
|
|
|
// CTRL+P: Open Settings Dialog
|
2018-01-06 20:58:56 +01:00
|
|
|
CreateWindowShortcut(this, "CTRL+P", [] {
|
2018-01-06 20:27:26 +01:00
|
|
|
SettingsDialog::showDialog(); //
|
|
|
|
});
|
|
|
|
|
|
|
|
// CTRL+Number: Switch to n'th tab
|
2018-01-06 20:58:56 +01:00
|
|
|
CreateWindowShortcut(this, "CTRL+1", [this] { this->notebook.selectIndex(0); });
|
|
|
|
CreateWindowShortcut(this, "CTRL+2", [this] { this->notebook.selectIndex(1); });
|
|
|
|
CreateWindowShortcut(this, "CTRL+3", [this] { this->notebook.selectIndex(2); });
|
|
|
|
CreateWindowShortcut(this, "CTRL+4", [this] { this->notebook.selectIndex(3); });
|
|
|
|
CreateWindowShortcut(this, "CTRL+5", [this] { this->notebook.selectIndex(4); });
|
|
|
|
CreateWindowShortcut(this, "CTRL+6", [this] { this->notebook.selectIndex(5); });
|
|
|
|
CreateWindowShortcut(this, "CTRL+7", [this] { this->notebook.selectIndex(6); });
|
|
|
|
CreateWindowShortcut(this, "CTRL+8", [this] { this->notebook.selectIndex(7); });
|
|
|
|
CreateWindowShortcut(this, "CTRL+9", [this] { this->notebook.selectIndex(8); });
|
|
|
|
|
|
|
|
// CTRL+SHIFT+T: New tab
|
|
|
|
CreateWindowShortcut(this, "CTRL+SHIFT+T", [this] { this->notebook.addNewPage(); });
|
|
|
|
|
|
|
|
// CTRL+SHIFT+W: Close current tab
|
|
|
|
CreateWindowShortcut(this, "CTRL+SHIFT+W", [this] { this->notebook.removeCurrentPage(); });
|
2016-12-29 17:31:07 +01:00
|
|
|
}
|
|
|
|
|
2017-11-12 17:21:50 +01:00
|
|
|
void Window::repaintVisibleChatWidgets(Channel *channel)
|
2017-01-16 03:15:07 +01:00
|
|
|
{
|
2017-06-13 21:13:58 +02:00
|
|
|
auto *page = this->notebook.getSelectedPage();
|
2017-01-16 03:15:07 +01:00
|
|
|
|
2017-06-11 09:37:30 +02:00
|
|
|
if (page == nullptr) {
|
2017-01-16 03:15:07 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-11-12 17:21:50 +01:00
|
|
|
const std::vector<Split *> &widgets = page->getChatWidgets();
|
2017-01-16 03:15:07 +01:00
|
|
|
|
|
|
|
for (auto it = widgets.begin(); it != widgets.end(); ++it) {
|
2017-11-12 17:21:50 +01:00
|
|
|
Split *widget = *it;
|
2017-01-16 03:15:07 +01:00
|
|
|
|
2017-06-11 09:37:30 +02:00
|
|
|
if (channel == nullptr || channel == widget->getChannel().get()) {
|
2017-04-12 17:46:44 +02:00
|
|
|
widget->layoutMessages();
|
2017-01-16 15:06:12 +01:00
|
|
|
}
|
2017-01-16 03:15:07 +01:00
|
|
|
}
|
|
|
|
}
|
2017-01-28 22:35:23 +01:00
|
|
|
|
2017-11-12 17:21:50 +01:00
|
|
|
Notebook &Window::getNotebook()
|
2017-04-12 17:46:44 +02:00
|
|
|
{
|
2017-06-13 21:13:58 +02:00
|
|
|
return this->notebook;
|
2017-04-12 17:46:44 +02:00
|
|
|
}
|
2017-06-07 10:09:24 +02:00
|
|
|
|
2017-12-18 21:02:17 +01:00
|
|
|
void Window::refreshWindowTitle(const QString &username)
|
|
|
|
{
|
|
|
|
this->setWindowTitle(username + " - Chatterino for Twitch");
|
|
|
|
}
|
|
|
|
|
2017-11-12 17:21:50 +01:00
|
|
|
void Window::closeEvent(QCloseEvent *)
|
2017-06-26 16:41:20 +02:00
|
|
|
{
|
2017-12-17 17:09:50 +01:00
|
|
|
const QRect &geom = this->geometry();
|
|
|
|
|
|
|
|
this->windowGeometry.x = geom.x();
|
|
|
|
this->windowGeometry.y = geom.y();
|
|
|
|
this->windowGeometry.width = geom.width();
|
|
|
|
this->windowGeometry.height = geom.height();
|
2017-12-14 00:25:06 +01:00
|
|
|
|
|
|
|
this->closed();
|
2017-06-26 16:41:20 +02:00
|
|
|
}
|
|
|
|
|
2017-11-12 17:21:50 +01:00
|
|
|
void Window::refreshTheme()
|
2017-07-02 14:28:37 +02:00
|
|
|
{
|
|
|
|
QPalette palette;
|
2018-01-02 02:15:11 +01:00
|
|
|
palette.setColor(QPalette::Background,
|
|
|
|
this->themeManager.tabs.regular.backgrounds.regular.color());
|
2017-07-02 14:28:37 +02:00
|
|
|
this->setPalette(palette);
|
|
|
|
}
|
|
|
|
|
2017-12-17 17:09:50 +01:00
|
|
|
void Window::loadGeometry()
|
|
|
|
{
|
2018-01-05 03:09:44 +01:00
|
|
|
bool doSetGeometry = false;
|
|
|
|
QRect loadedGeometry;
|
2017-12-17 17:09:50 +01:00
|
|
|
if (!this->windowGeometry.x.isDefaultValue() && !this->windowGeometry.y.isDefaultValue()) {
|
2018-01-05 03:09:44 +01:00
|
|
|
loadedGeometry.setX(this->windowGeometry.x);
|
|
|
|
loadedGeometry.setY(this->windowGeometry.y);
|
|
|
|
doSetGeometry = true;
|
2017-12-17 17:09:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!this->windowGeometry.width.isDefaultValue() &&
|
|
|
|
!this->windowGeometry.height.isDefaultValue()) {
|
2018-01-05 03:09:44 +01:00
|
|
|
loadedGeometry.setWidth(this->windowGeometry.width);
|
|
|
|
loadedGeometry.setHeight(this->windowGeometry.height);
|
2017-12-17 17:09:50 +01:00
|
|
|
} else {
|
2018-01-05 03:09:44 +01:00
|
|
|
loadedGeometry.setWidth(1280);
|
|
|
|
loadedGeometry.setHeight(720);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (doSetGeometry) {
|
|
|
|
this->setGeometry(loadedGeometry);
|
|
|
|
} else {
|
|
|
|
this->resize(loadedGeometry.width(), loadedGeometry.height());
|
2017-12-17 17:09:50 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-22 14:44:31 +01:00
|
|
|
void Window::save()
|
|
|
|
{
|
|
|
|
this->notebook.save();
|
|
|
|
}
|
|
|
|
|
2017-04-14 17:52:22 +02:00
|
|
|
} // namespace widgets
|
|
|
|
} // namespace chatterino
|