2017-01-18 21:30:23 +01:00
|
|
|
#include "widgets/mainwindow.h"
|
2017-01-01 02:30:42 +01:00
|
|
|
#include "colorscheme.h"
|
2017-01-18 21:30:23 +01:00
|
|
|
#include "widgets/chatwidget.h"
|
|
|
|
#include "widgets/notebook.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-01-28 22:35:23 +01:00
|
|
|
#include <boost/foreach.hpp>
|
2017-01-18 04:52:47 +01:00
|
|
|
|
2017-01-18 21:30:23 +01:00
|
|
|
namespace chatterino {
|
|
|
|
namespace widgets {
|
|
|
|
|
2017-01-11 18:52:09 +01:00
|
|
|
MainWindow::MainWindow(QWidget *parent)
|
|
|
|
: QMainWindow(parent)
|
|
|
|
, notebook(this)
|
2016-12-29 17:31:07 +01:00
|
|
|
{
|
2016-12-30 12:20:26 +01:00
|
|
|
setCentralWidget(&this->notebook);
|
|
|
|
|
2017-01-01 02:30:42 +01:00
|
|
|
QPalette palette;
|
2017-01-11 18:52:09 +01:00
|
|
|
palette.setColor(QPalette::Background,
|
2017-01-24 20:15:12 +01:00
|
|
|
ColorScheme::getInstance().TabPanelBackground);
|
2017-01-01 02:30:42 +01:00
|
|
|
setPalette(palette);
|
|
|
|
|
|
|
|
resize(1280, 800);
|
2016-12-29 17:31:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
MainWindow::~MainWindow()
|
|
|
|
{
|
|
|
|
}
|
2017-01-16 03:15:07 +01:00
|
|
|
|
|
|
|
void
|
2017-01-16 15:06:12 +01:00
|
|
|
MainWindow::layoutVisibleChatWidgets(Channel *channel)
|
2017-01-16 03:15:07 +01:00
|
|
|
{
|
2017-01-18 04:33:30 +01: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-18 04:33:30 +01:00
|
|
|
if (channel == NULL || channel == widget->getChannel()) {
|
|
|
|
if (widget->getView().layoutMessages()) {
|
2017-01-26 07:10:46 +01:00
|
|
|
widget->update();
|
2017-01-16 15:06:12 +01:00
|
|
|
}
|
2017-01-16 03:15:07 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2017-01-16 15:06:12 +01:00
|
|
|
MainWindow::repaintVisibleChatWidgets(Channel *channel)
|
2017-01-16 03:15:07 +01:00
|
|
|
{
|
2017-01-18 04:33:30 +01: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-18 04:33:30 +01:00
|
|
|
if (channel == NULL || channel == widget->getChannel()) {
|
|
|
|
widget->getView().layoutMessages();
|
2017-01-26 07:10:46 +01:00
|
|
|
widget->update();
|
2017-01-16 15:06:12 +01:00
|
|
|
}
|
2017-01-16 03:15:07 +01:00
|
|
|
}
|
|
|
|
}
|
2017-01-28 22:35:23 +01:00
|
|
|
|
|
|
|
void
|
|
|
|
MainWindow::load(const boost::property_tree::ptree &tree)
|
|
|
|
{
|
|
|
|
this->notebook.load(tree);
|
|
|
|
|
|
|
|
this->loaded = true;
|
2017-01-18 21:30:23 +01:00
|
|
|
}
|
2017-01-28 22:35:23 +01: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-01-28 22:35:23 +01:00
|
|
|
|
|
|
|
void
|
|
|
|
MainWindow::loadDefaults()
|
|
|
|
{
|
|
|
|
this->notebook.loadDefaults();
|
|
|
|
|
|
|
|
this->loaded = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace widgets
|
|
|
|
} // namespace chatterino
|