refactoring

This commit is contained in:
fourtf
2017-04-12 17:46:44 +02:00
parent 8ef492d7ae
commit 96db82e867
114 changed files with 5554 additions and 3703 deletions
+53 -31
View File
@@ -1,24 +1,46 @@
#include "widgets/mainwindow.h"
#include "colorscheme.h"
#include "settingsmanager.h"
#include "widgets/chatwidget.h"
#include "widgets/notebook.h"
#include <QDebug>
#include <QPalette>
#include <QVBoxLayout>
#include <boost/foreach.hpp>
#ifdef USEWINSDK
#include "Windows.h"
#endif
namespace chatterino {
namespace widgets {
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, notebook(this)
: QWidget(parent)
, _notebook(this)
, _loaded(false)
, _titleBar()
{
setCentralWidget(&this->notebook);
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);
// }
QPalette palette;
palette.setColor(QPalette::Background,
ColorScheme::getInstance().TabPanelBackground);
palette.setColor(QPalette::Background, ColorScheme::getInstance().TabPanelBackground);
setPalette(palette);
resize(1280, 800);
@@ -28,10 +50,9 @@ MainWindow::~MainWindow()
{
}
void
MainWindow::layoutVisibleChatWidgets(Channel *channel)
void MainWindow::layoutVisibleChatWidgets(Channel *channel)
{
auto *page = notebook.getSelectedPage();
auto *page = _notebook.getSelectedPage();
if (page == NULL) {
return;
@@ -43,17 +64,14 @@ MainWindow::layoutVisibleChatWidgets(Channel *channel)
ChatWidget *widget = *it;
if (channel == NULL || channel == widget->getChannel().get()) {
if (widget->getView().layoutMessages()) {
widget->getView().update();
}
widget->layoutMessages();
}
}
}
void
MainWindow::repaintVisibleChatWidgets(Channel *channel)
void MainWindow::repaintVisibleChatWidgets(Channel *channel)
{
auto *page = notebook.getSelectedPage();
auto *page = _notebook.getSelectedPage();
if (page == NULL) {
return;
@@ -65,16 +83,14 @@ MainWindow::repaintVisibleChatWidgets(Channel *channel)
ChatWidget *widget = *it;
if (channel == NULL || channel == widget->getChannel().get()) {
widget->getView().layoutMessages();
widget->getView().update();
widget->layoutMessages();
}
}
}
void
MainWindow::repaintGifEmotes()
void MainWindow::repaintGifEmotes()
{
auto *page = notebook.getSelectedPage();
auto *page = _notebook.getSelectedPage();
if (page == NULL) {
return;
@@ -85,37 +101,43 @@ MainWindow::repaintGifEmotes()
for (auto it = widgets.begin(); it != widgets.end(); ++it) {
ChatWidget *widget = *it;
widget->getView().updateGifEmotes();
widget->updateGifEmotes();
}
}
void
MainWindow::load(const boost::property_tree::ptree &tree)
void MainWindow::load(const boost::property_tree::ptree &tree)
{
this->notebook.load(tree);
this->_notebook.load(tree);
this->loaded = true;
_loaded = true;
}
boost::property_tree::ptree
MainWindow::save()
boost::property_tree::ptree MainWindow::save()
{
boost::property_tree::ptree child;
child.put("type", "main");
this->notebook.save(child);
_notebook.save(child);
return child;
}
void
MainWindow::loadDefaults()
void MainWindow::loadDefaults()
{
this->notebook.loadDefaults();
_notebook.loadDefaults();
this->loaded = true;
_loaded = true;
}
bool MainWindow::isLoaded() const
{
return _loaded;
}
Notebook &MainWindow::getNotebook()
{
return _notebook;
}
} // namespace widgets
} // namespace chatterino