2017-01-18 21:30:23 +01:00
|
|
|
#include "widgets/mainwindow.h"
|
2017-01-01 02:30:42 +01:00
|
|
|
#include "colorscheme.h"
|
2017-04-12 17:46:44 +02:00
|
|
|
#include "settingsmanager.h"
|
2017-01-18 21:30:23 +01:00
|
|
|
#include "widgets/chatwidget.h"
|
|
|
|
#include "widgets/notebook.h"
|
2017-05-27 15:40:42 +02:00
|
|
|
#include "widgets/settingsdialog.h"
|
2016-12-29 17:31:07 +01:00
|
|
|
|
2017-01-28 22:35:23 +01:00
|
|
|
#include <QDebug>
|
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-28 22:35:23 +01:00
|
|
|
#include <boost/foreach.hpp>
|
2017-01-18 04:52:47 +01:00
|
|
|
|
2017-04-12 17:46:44 +02:00
|
|
|
#ifdef USEWINSDK
|
|
|
|
#include "Windows.h"
|
|
|
|
#endif
|
|
|
|
|
2017-04-14 17:52:22 +02:00
|
|
|
namespace chatterino {
|
|
|
|
namespace widgets {
|
2017-01-18 21:30:23 +01:00
|
|
|
|
2017-01-11 18:52:09 +01:00
|
|
|
MainWindow::MainWindow(QWidget *parent)
|
2017-04-12 17:46:44 +02:00
|
|
|
: QWidget(parent)
|
|
|
|
, _notebook(this)
|
|
|
|
, _loaded(false)
|
|
|
|
, _titleBar()
|
2016-12-29 17:31:07 +01:00
|
|
|
{
|
2017-04-12 17:46:44 +02:00
|
|
|
QVBoxLayout *layout = new QVBoxLayout(this);
|
|
|
|
|
|
|
|
// add titlebar
|
|
|
|
// if (SettingsManager::getInstance().useCustomWindowFrame.get()) {
|
|
|
|
// layout->addWidget(&_titleBar);
|
|
|
|
// }
|
|
|
|
|
|
|
|
layout->addWidget(&_notebook);
|
|
|
|
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-01-01 02:30:42 +01:00
|
|
|
QPalette palette;
|
2017-04-12 17:46:44 +02:00
|
|
|
palette.setColor(QPalette::Background, ColorScheme::getInstance().TabPanelBackground);
|
2017-01-01 02:30:42 +01:00
|
|
|
setPalette(palette);
|
|
|
|
|
|
|
|
resize(1280, 800);
|
2017-05-27 15:40:42 +02:00
|
|
|
|
|
|
|
// Initialize program-wide hotkeys
|
|
|
|
{
|
|
|
|
// CTRL+P: Open Settings Dialog
|
|
|
|
auto shortcut = new QShortcut(QKeySequence("CTRL+P"), this);
|
|
|
|
connect(shortcut, &QShortcut::activated, []() {
|
|
|
|
SettingsDialog::showDialog(); //
|
|
|
|
});
|
|
|
|
}
|
2016-12-29 17:31:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
MainWindow::~MainWindow()
|
|
|
|
{
|
|
|
|
}
|
2017-01-16 03:15:07 +01:00
|
|
|
|
2017-04-12 17:46:44 +02:00
|
|
|
void MainWindow::layoutVisibleChatWidgets(Channel *channel)
|
2017-01-16 03:15:07 +01:00
|
|
|
{
|
2017-04-12 17:46:44 +02:00
|
|
|
auto *page = _notebook.getSelectedPage();
|
2017-01-16 03:15:07 +01:00
|
|
|
|
|
|
|
if (page == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-01-18 04:33:30 +01:00
|
|
|
const std::vector<ChatWidget *> &widgets = page->getChatWidgets();
|
2017-01-16 03:15:07 +01:00
|
|
|
|
|
|
|
for (auto it = widgets.begin(); it != widgets.end(); ++it) {
|
|
|
|
ChatWidget *widget = *it;
|
|
|
|
|
2017-01-30 19:14:25 +01:00
|
|
|
if (channel == NULL || channel == widget->getChannel().get()) {
|
2017-04-12 17:46:44 +02:00
|
|
|
widget->layoutMessages();
|
2017-01-16 03:15:07 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-12 17:46:44 +02:00
|
|
|
void MainWindow::repaintVisibleChatWidgets(Channel *channel)
|
2017-01-16 03:15:07 +01:00
|
|
|
{
|
2017-04-12 17:46:44 +02:00
|
|
|
auto *page = _notebook.getSelectedPage();
|
2017-01-16 03:15:07 +01:00
|
|
|
|
|
|
|
if (page == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-01-18 04:33:30 +01:00
|
|
|
const std::vector<ChatWidget *> &widgets = page->getChatWidgets();
|
2017-01-16 03:15:07 +01:00
|
|
|
|
|
|
|
for (auto it = widgets.begin(); it != widgets.end(); ++it) {
|
|
|
|
ChatWidget *widget = *it;
|
|
|
|
|
2017-01-30 19:14:25 +01:00
|
|
|
if (channel == NULL || 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-04-12 17:46:44 +02:00
|
|
|
void MainWindow::repaintGifEmotes()
|
2017-02-07 00:03:15 +01:00
|
|
|
{
|
2017-04-12 17:46:44 +02:00
|
|
|
auto *page = _notebook.getSelectedPage();
|
2017-02-07 00:03:15 +01:00
|
|
|
|
|
|
|
if (page == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const std::vector<ChatWidget *> &widgets = page->getChatWidgets();
|
|
|
|
|
|
|
|
for (auto it = widgets.begin(); it != widgets.end(); ++it) {
|
|
|
|
ChatWidget *widget = *it;
|
|
|
|
|
2017-04-12 17:46:44 +02:00
|
|
|
widget->updateGifEmotes();
|
2017-02-07 00:03:15 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-12 17:46:44 +02:00
|
|
|
void MainWindow::load(const boost::property_tree::ptree &tree)
|
2017-01-28 22:35:23 +01:00
|
|
|
{
|
2017-04-12 17:46:44 +02:00
|
|
|
this->_notebook.load(tree);
|
2017-01-28 22:35:23 +01:00
|
|
|
|
2017-04-12 17:46:44 +02:00
|
|
|
_loaded = true;
|
2017-01-18 21:30:23 +01:00
|
|
|
}
|
2017-01-28 22:35:23 +01:00
|
|
|
|
2017-04-12 17:46:44 +02:00
|
|
|
boost::property_tree::ptree MainWindow::save()
|
2017-01-28 22:35:23 +01:00
|
|
|
{
|
|
|
|
boost::property_tree::ptree child;
|
|
|
|
|
|
|
|
child.put("type", "main");
|
|
|
|
|
2017-04-12 17:46:44 +02:00
|
|
|
_notebook.save(child);
|
2017-01-28 22:35:23 +01:00
|
|
|
|
|
|
|
return child;
|
2017-01-18 21:30:23 +01:00
|
|
|
}
|
2017-01-28 22:35:23 +01:00
|
|
|
|
2017-04-12 17:46:44 +02:00
|
|
|
void MainWindow::loadDefaults()
|
2017-01-28 22:35:23 +01:00
|
|
|
{
|
2017-04-12 17:46:44 +02:00
|
|
|
_notebook.loadDefaults();
|
2017-01-28 22:35:23 +01:00
|
|
|
|
2017-04-12 17:46:44 +02:00
|
|
|
_loaded = true;
|
2017-01-28 22:35:23 +01:00
|
|
|
}
|
|
|
|
|
2017-04-12 17:46:44 +02:00
|
|
|
bool MainWindow::isLoaded() const
|
|
|
|
{
|
|
|
|
return _loaded;
|
|
|
|
}
|
|
|
|
|
|
|
|
Notebook &MainWindow::getNotebook()
|
|
|
|
{
|
|
|
|
return _notebook;
|
|
|
|
}
|
2017-04-14 17:52:22 +02:00
|
|
|
} // namespace widgets
|
|
|
|
} // namespace chatterino
|