Huge refactor

- Remove some underscore-prefixes
 - Start using this-> more
 - Remove a few of the singletons (We pass references to managers to
         things that need it now. Might not be much better, but for now
         it works. It also shows what places might be slightly wrong
         designed)
This commit is contained in:
Rasmus Karlsson
2017-06-13 21:13:58 +02:00
parent 55b04ee7eb
commit 59d383c161
37 changed files with 630 additions and 523 deletions
+6 -5
View File
@@ -30,9 +30,10 @@ inline void ezShortcut(ChatWidget *w, const char *key, T t)
} // namespace
ChatWidget::ChatWidget(QWidget *parent)
ChatWidget::ChatWidget(ChannelManager &_channelManager, QWidget *parent)
: QWidget(parent)
, channel(ChannelManager::getInstance().getEmpty())
, channelManager(_channelManager)
, channel(_channelManager.getEmpty())
, vbox(this)
, header(this)
, view(this)
@@ -90,7 +91,7 @@ void ChatWidget::setChannelName(const QString &_newChannelName)
// remove current channel
if (!this->channelName.isEmpty()) {
ChannelManager::getInstance().removeChannel(this->channelName);
this->channelManager.removeChannel(this->channelName);
this->detachChannel();
}
@@ -104,7 +105,7 @@ void ChatWidget::setChannelName(const QString &_newChannelName)
if (newChannelName.isEmpty()) {
this->channel = nullptr;
} else {
this->setChannel(ChannelManager::getInstance().addChannel(newChannelName));
this->setChannel(this->channelManager.addChannel(newChannelName));
}
// update header
@@ -240,7 +241,7 @@ void ChatWidget::doChangeChannel()
void ChatWidget::doPopup()
{
// TODO: Copy signals and stuff too
auto widget = new ChatWidget();
auto widget = new ChatWidget(this->channelManager);
widget->setChannelName(this->getChannelName());
widget->show();
}
+6 -1
View File
@@ -17,6 +17,9 @@
#include <boost/signals2/connection.hpp>
namespace chatterino {
class ChannelManager;
namespace widgets {
// Each ChatWidget consists of three sub-elements that handle their own part of the chat widget:
@@ -34,7 +37,7 @@ class ChatWidget : public QWidget
Q_OBJECT
public:
ChatWidget(QWidget *parent = nullptr);
ChatWidget(ChannelManager &_channelManager, QWidget *parent = nullptr);
~ChatWidget();
std::shared_ptr<Channel> getChannel() const;
@@ -53,6 +56,8 @@ protected:
void paintEvent(QPaintEvent *) override;
private:
ChannelManager &channelManager;
void setChannel(std::shared_ptr<Channel> newChannel);
void detachChannel();
+12 -10
View File
@@ -1,4 +1,5 @@
#include "widgets/mainwindow.hpp"
#include "channelmanager.hpp"
#include "colorscheme.hpp"
#include "settingsmanager.hpp"
#include "widgets/chatwidget.hpp"
@@ -18,9 +19,10 @@
namespace chatterino {
namespace widgets {
MainWindow::MainWindow(QWidget *parent)
MainWindow::MainWindow(ChannelManager &_channelManager, QWidget *parent)
: QWidget(parent)
, _notebook(this)
, channelManager(_channelManager)
, notebook(this->channelManager, this)
, _loaded(false)
, _titleBar()
{
@@ -31,7 +33,7 @@ MainWindow::MainWindow(QWidget *parent)
// layout->addWidget(&_titleBar);
// }
layout->addWidget(&_notebook);
layout->addWidget(&this->notebook);
setLayout(layout);
// set margin
@@ -63,7 +65,7 @@ MainWindow::~MainWindow()
void MainWindow::layoutVisibleChatWidgets(Channel *channel)
{
auto *page = _notebook.getSelectedPage();
auto *page = this->notebook.getSelectedPage();
if (page == nullptr) {
return;
@@ -82,7 +84,7 @@ void MainWindow::layoutVisibleChatWidgets(Channel *channel)
void MainWindow::repaintVisibleChatWidgets(Channel *channel)
{
auto *page = _notebook.getSelectedPage();
auto *page = this->notebook.getSelectedPage();
if (page == nullptr) {
return;
@@ -101,7 +103,7 @@ void MainWindow::repaintVisibleChatWidgets(Channel *channel)
void MainWindow::repaintGifEmotes()
{
auto *page = _notebook.getSelectedPage();
auto *page = this->notebook.getSelectedPage();
if (page == nullptr) {
return;
@@ -118,7 +120,7 @@ void MainWindow::repaintGifEmotes()
void MainWindow::load(const boost::property_tree::ptree &tree)
{
this->_notebook.load(tree);
this->notebook.load(tree);
_loaded = true;
}
@@ -129,14 +131,14 @@ boost::property_tree::ptree MainWindow::save()
child.put("type", "main");
_notebook.save(child);
this->notebook.save(child);
return child;
}
void MainWindow::loadDefaults()
{
_notebook.loadDefaults();
this->notebook.loadDefaults();
_loaded = true;
}
@@ -148,7 +150,7 @@ bool MainWindow::isLoaded() const
Notebook &MainWindow::getNotebook()
{
return _notebook;
return this->notebook;
}
} // namespace widgets
+7 -2
View File
@@ -11,6 +11,9 @@
#include <boost/property_tree/ptree.hpp>
namespace chatterino {
class ChannelManager;
namespace widgets {
class MainWindow : public QWidget
@@ -18,7 +21,7 @@ class MainWindow : public QWidget
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
explicit MainWindow(ChannelManager &_channelManager, QWidget *parent = nullptr);
~MainWindow();
void layoutVisibleChatWidgets(Channel *channel = nullptr);
@@ -34,7 +37,9 @@ public:
Notebook &getNotebook();
private:
Notebook _notebook;
ChannelManager &channelManager;
Notebook notebook;
bool _loaded;
TitleBar _titleBar;
};
+3 -2
View File
@@ -18,8 +18,9 @@
namespace chatterino {
namespace widgets {
Notebook::Notebook(QWidget *parent)
Notebook::Notebook(ChannelManager &_channelManager, QWidget *parent)
: QWidget(parent)
, channelManager(_channelManager)
, _addButton(this)
, _settingsButton(this)
, _userButton(this)
@@ -47,7 +48,7 @@ Notebook::Notebook(QWidget *parent)
NotebookPage *Notebook::addPage(bool select)
{
auto tab = new NotebookTab(this);
auto page = new NotebookPage(this, tab);
auto page = new NotebookPage(this->channelManager, this, tab);
tab->show();
+6 -1
View File
@@ -9,6 +9,9 @@
#include <boost/property_tree/ptree.hpp>
namespace chatterino {
class ChannelManager;
namespace widgets {
class Notebook : public QWidget
@@ -18,7 +21,7 @@ class Notebook : public QWidget
public:
enum HighlightType { none, highlighted, newMessage };
Notebook(QWidget *parent);
Notebook(ChannelManager &_channelManager, QWidget *parent);
NotebookPage *addPage(bool select = false);
@@ -46,6 +49,8 @@ public slots:
void addPageButtonClicked();
private:
ChannelManager &channelManager;
QList<NotebookPage *> _pages;
NotebookButton _addButton;
+7 -6
View File
@@ -19,9 +19,10 @@ bool NotebookPage::isDraggingSplit = false;
ChatWidget *NotebookPage::draggingSplit = nullptr;
std::pair<int, int> NotebookPage::dropPosition = std::pair<int, int>(-1, -1);
NotebookPage::NotebookPage(QWidget *parent, NotebookTab *tab)
NotebookPage::NotebookPage(ChannelManager &_channelManager, QWidget *parent, NotebookTab *_tab)
: QWidget(parent)
, _tab(tab)
, channelManager(_channelManager)
, tab(_tab)
, _parentbox(this)
, _chatWidgets()
, _preview(this)
@@ -46,12 +47,12 @@ const std::vector<ChatWidget *> &NotebookPage::getChatWidgets() const
NotebookTab *NotebookPage::getTab() const
{
return _tab;
return this->tab;
}
void NotebookPage::addChat(bool openChannelNameDialog)
{
ChatWidget *w = new ChatWidget();
ChatWidget *w = new ChatWidget(this->channelManager);
if (openChannelNameDialog) {
w->showChangeChannelPopup();
@@ -143,7 +144,7 @@ void NotebookPage::mouseReleaseEvent(QMouseEvent *event)
{
if (_hbox.count() == 0 && event->button() == Qt::LeftButton) {
// "Add Chat" was clicked
addToLayout(new ChatWidget(), std::pair<int, int>(-1, -1));
addToLayout(new ChatWidget(this->channelManager), std::pair<int, int>(-1, -1));
setCursor(QCursor(Qt::ArrowCursor));
}
@@ -275,7 +276,7 @@ void NotebookPage::load(const boost::property_tree::ptree &tree)
for (const auto &v : tree.get_child("columns.")) {
int row = 0;
for (const auto &innerV : v.second.get_child("")) {
auto widget = new ChatWidget();
auto widget = new ChatWidget(this->channelManager);
widget->load(innerV.second);
addToLayout(widget, std::pair<int, int>(column, row));
++row;
+7 -2
View File
@@ -15,6 +15,9 @@
#include <boost/signals2.hpp>
namespace chatterino {
class ChannelManager;
namespace widgets {
class NotebookPage : public QWidget
@@ -22,7 +25,7 @@ class NotebookPage : public QWidget
Q_OBJECT
public:
NotebookPage(QWidget *parent, NotebookTab *_tab);
NotebookPage(ChannelManager &_channelManager, QWidget *parent, NotebookTab *_tab);
std::pair<int, int> removeFromLayout(ChatWidget *widget);
void addToLayout(ChatWidget *widget, std::pair<int, int> position);
@@ -49,6 +52,8 @@ protected:
void dropEvent(QDropEvent *event) override;
private:
ChannelManager &channelManager;
struct DropRegion {
QRect rect;
std::pair<int, int> position;
@@ -60,7 +65,7 @@ private:
}
};
NotebookTab *_tab;
NotebookTab *tab;
QVBoxLayout _parentbox;
QHBoxLayout _hbox;
+3 -1
View File
@@ -153,7 +153,9 @@ void SettingsDialog::addTabs()
QObject::connect(slider, &QSlider::valueChanged, this, [&settings](int value) {
settings.themeHue.set(value / 1000.0);
WindowManager::getInstance().updateAll();
// TODO(pajlada): re-implement
// this->windowManager.updateAll();
});
group->setLayout(form);
+1
View File
@@ -17,6 +17,7 @@
#include <pajlada/settings/setting.hpp>
namespace chatterino {
namespace widgets {
class SettingsDialog : public QWidget