mirror-chatterino2/src/widgets/mainwindow.cpp

158 lines
3.4 KiB
C++
Raw Normal View History

2017-06-11 09:31:45 +02:00
#include "widgets/mainwindow.hpp"
#include "channelmanager.hpp"
2017-06-11 09:31:45 +02:00
#include "colorscheme.hpp"
#include "settingsmanager.hpp"
#include "widgets/chatwidget.hpp"
#include "widgets/notebook.hpp"
#include "widgets/settingsdialog.hpp"
2016-12-29 17:31:07 +01:00
#include <QDebug>
2017-01-18 04:52:47 +01:00
#include <QPalette>
#include <QShortcut>
2017-04-12 17:46:44 +02:00
#include <QVBoxLayout>
#include <boost/foreach.hpp>
2017-01-18 04:52:47 +01:00
2017-04-12 17:46:44 +02:00
#ifdef USEWINSDK
2017-06-11 09:31:45 +02:00
#include "Windows.hpp"
2017-04-12 17:46:44 +02:00
#endif
2017-04-14 17:52:22 +02:00
namespace chatterino {
namespace widgets {
2017-01-18 21:30:23 +01:00
MainWindow::MainWindow(ChannelManager &_channelManager, QWidget *parent)
2017-04-12 17:46:44 +02:00
: QWidget(parent)
, channelManager(_channelManager)
, notebook(this->channelManager, this)
2017-04-12 17:46:44 +02:00
, _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(&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-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);
// 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-04-12 17:46:44 +02:00
void MainWindow::layoutVisibleChatWidgets(Channel *channel)
{
auto *page = this->notebook.getSelectedPage();
if (page == nullptr) {
return;
}
2017-01-18 04:33:30 +01:00
const std::vector<ChatWidget *> &widgets = page->getChatWidgets();
for (auto it = widgets.begin(); it != widgets.end(); ++it) {
ChatWidget *widget = *it;
if (channel == nullptr || channel == widget->getChannel().get()) {
2017-04-12 17:46:44 +02:00
widget->layoutMessages();
}
}
}
2017-04-12 17:46:44 +02:00
void MainWindow::repaintVisibleChatWidgets(Channel *channel)
{
auto *page = this->notebook.getSelectedPage();
if (page == nullptr) {
return;
}
2017-01-18 04:33:30 +01:00
const std::vector<ChatWidget *> &widgets = page->getChatWidgets();
for (auto it = widgets.begin(); it != widgets.end(); ++it) {
ChatWidget *widget = *it;
if (channel == nullptr || channel == widget->getChannel().get()) {
2017-04-12 17:46:44 +02:00
widget->layoutMessages();
}
}
}
2017-04-12 17:46:44 +02:00
void MainWindow::repaintGifEmotes()
2017-02-07 00:03:15 +01:00
{
auto *page = this->notebook.getSelectedPage();
2017-02-07 00:03:15 +01:00
if (page == nullptr) {
2017-02-07 00:03:15 +01:00
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)
{
this->notebook.load(tree);
2017-04-12 17:46:44 +02:00
_loaded = true;
2017-01-18 21:30:23 +01:00
}
2017-04-12 17:46:44 +02:00
boost::property_tree::ptree MainWindow::save()
{
boost::property_tree::ptree child;
child.put("type", "main");
this->notebook.save(child);
return child;
2017-01-18 21:30:23 +01:00
}
2017-04-12 17:46:44 +02:00
void MainWindow::loadDefaults()
{
this->notebook.loadDefaults();
2017-04-12 17:46:44 +02:00
_loaded = true;
}
2017-04-12 17:46:44 +02:00
bool MainWindow::isLoaded() const
{
return _loaded;
}
Notebook &MainWindow::getNotebook()
{
return this->notebook;
2017-04-12 17:46:44 +02:00
}
2017-04-14 17:52:22 +02:00
} // namespace widgets
} // namespace chatterino