From 85356cdd6bea823403bf0e33a13e42fcac3ebbaa Mon Sep 17 00:00:00 2001 From: Rasmus Karlsson Date: Sat, 10 Jun 2017 23:53:39 +0200 Subject: [PATCH] clean up chat widget structure. how and where hotkeys are handled --- src/widgets/chatwidget.cpp | 42 ++++++++++++++++++++++++++++++++ src/widgets/chatwidget.h | 12 +++++++++ src/widgets/chatwidgetheader.cpp | 28 +++++++++------------ src/widgets/chatwidgetheader.h | 5 +--- src/widgets/notebook.cpp | 14 ----------- 5 files changed, 67 insertions(+), 34 deletions(-) diff --git a/src/widgets/chatwidget.cpp b/src/widgets/chatwidget.cpp index c55200696..e82cecbe3 100644 --- a/src/widgets/chatwidget.cpp +++ b/src/widgets/chatwidget.cpp @@ -1,6 +1,7 @@ #include "widgets/chatwidget.h" #include "channelmanager.h" #include "colorscheme.h" +#include "notebookpage.h" #include "settingsmanager.h" #include "widgets/textinputdialog.h" @@ -8,6 +9,7 @@ #include #include #include +#include #include #include @@ -32,6 +34,28 @@ ChatWidget::ChatWidget(QWidget *parent) this->_vbox.addWidget(&_header); this->_vbox.addWidget(&_view, 1); this->_vbox.addWidget(&_input); + + // Initialize widget-wide hotkeys + // CTRL+T: Create new split (Add page) + { + auto s = new QShortcut(QKeySequence("CTRL+T"), this); + s->setContext(Qt::WidgetWithChildrenShortcut); + connect(s, &QShortcut::activated, this, &ChatWidget::doAddSplit); + } + + // CTRL+W: Close Split + { + auto s = new QShortcut(QKeySequence("CTRL+W"), this); + s->setContext(Qt::WidgetWithChildrenShortcut); + connect(s, &QShortcut::activated, this, &ChatWidget::doCloseSplit); + } + + // CTRL+R: Change Channel + { + auto s = new QShortcut(QKeySequence("CTRL+R"), this); + s->setContext(Qt::WidgetWithChildrenShortcut); + connect(s, &QShortcut::activated, this, &ChatWidget::doChangeChannel); + } } ChatWidget::~ChatWidget() @@ -193,5 +217,23 @@ boost::property_tree::ptree ChatWidget::save() return tree; } +/// Slots +// +void ChatWidget::doAddSplit() +{ + NotebookPage *page = static_cast(this->parentWidget()); + page->addChat(); +} + +void ChatWidget::doCloseSplit() +{ + qDebug() << "Close split for" << this->getChannelName(); +} + +void ChatWidget::doChangeChannel() +{ + this->showChangeChannelPopup(); +} + } // namespace widgets } // namespace chatterino diff --git a/src/widgets/chatwidget.h b/src/widgets/chatwidget.h index 9904d7239..955077675 100644 --- a/src/widgets/chatwidget.h +++ b/src/widgets/chatwidget.h @@ -10,6 +10,7 @@ #include "widgets/chatwidgetview.h" #include +#include #include #include #include @@ -70,6 +71,17 @@ private: public: void load(const boost::property_tree::ptree &tree); boost::property_tree::ptree save(); + +public slots: + // Add new split to the notebook page that this chat widget is in + // Maybe we should use this chat widget as a hint to where the new split should be created + void doAddSplit(); + + // Close current split (chat widget) + void doCloseSplit(); + + // Show a dialog for changing the current splits/chat widgets channel + void doChangeChannel(); }; } // namespace widgets diff --git a/src/widgets/chatwidgetheader.cpp b/src/widgets/chatwidgetheader.cpp index ad7c6d371..4ad1c3599 100644 --- a/src/widgets/chatwidgetheader.cpp +++ b/src/widgets/chatwidgetheader.cpp @@ -40,12 +40,14 @@ ChatWidgetHeader::ChatWidgetHeader(ChatWidget *_chatWidget) QObject::connect(&_leftLabel, &ChatWidgetHeaderButton::clicked, this, &ChatWidgetHeader::leftButtonClicked); - _leftMenu.addAction("Add new split", this, SLOT(menuAddSplit()), QKeySequence(tr("Ctrl+T"))); - _leftMenu.addAction("Close split", this, SLOT(menuCloseSplit()), QKeySequence(tr("Ctrl+W"))); + _leftMenu.addAction("Add new split", this->chatWidget, &ChatWidget::doAddSplit, + QKeySequence(tr("Ctrl+T"))); + _leftMenu.addAction("Close split", this->chatWidget, &ChatWidget::doCloseSplit, + QKeySequence(tr("Ctrl+W"))); _leftMenu.addAction("Move split", this, SLOT(menuMoveSplit())); _leftMenu.addAction("Popup", this, SLOT(menuPopup())); _leftMenu.addSeparator(); - _leftMenu.addAction("Change channel", this, SLOT(menuChangeChannel()), + _leftMenu.addAction("Change channel", this->chatWidget, &ChatWidget::doChangeChannel, QKeySequence(tr("Ctrl+R"))); _leftMenu.addAction("Clear chat", this, SLOT(menuClearChat())); _leftMenu.addAction("Open channel", this, SLOT(menuOpenChannel())); @@ -154,43 +156,37 @@ void ChatWidgetHeader::rightButtonClicked() { } -void ChatWidgetHeader::menuAddSplit() -{ - auto page = static_cast(this->chatWidget->parentWidget()); - page->addChat(); -} -void ChatWidgetHeader::menuCloseSplit() -{ - printf("Close split\n"); -} void ChatWidgetHeader::menuMoveSplit() { } + void ChatWidgetHeader::menuPopup() { auto widget = new ChatWidget(); widget->setChannelName(this->chatWidget->getChannelName()); widget->show(); } -void ChatWidgetHeader::menuChangeChannel() -{ - this->chatWidget->showChangeChannelPopup(); -} + void ChatWidgetHeader::menuClearChat() { } + void ChatWidgetHeader::menuOpenChannel() { } + void ChatWidgetHeader::menuPopupPlayer() { } + void ChatWidgetHeader::menuReloadChannelEmotes() { } + void ChatWidgetHeader::menuManualReconnect() { } + void ChatWidgetHeader::menuShowChangelog() { } diff --git a/src/widgets/chatwidgetheader.h b/src/widgets/chatwidgetheader.h index 52396d24d..758bf3ba0 100644 --- a/src/widgets/chatwidgetheader.h +++ b/src/widgets/chatwidgetheader.h @@ -53,12 +53,9 @@ private: void leftButtonClicked(); void rightButtonClicked(); -private slots: - void menuAddSplit(); - void menuCloseSplit(); +public slots: void menuMoveSplit(); void menuPopup(); - void menuChangeChannel(); void menuClearChat(); void menuOpenChannel(); void menuPopupPlayer(); diff --git a/src/widgets/notebook.cpp b/src/widgets/notebook.cpp index 493c192a7..460042a0c 100644 --- a/src/widgets/notebook.cpp +++ b/src/widgets/notebook.cpp @@ -42,20 +42,6 @@ Notebook::Notebook(QWidget *parent) [this](const bool &) { performLayout(); }); SettingsManager::getInstance().hideUserButton.valueChanged.connect( [this](const bool &) { performLayout(); }); - - // Initialize notebook hotkeys - { - // CTRL+T: Create new split (Add page) - auto shortcut = new QShortcut(QKeySequence("CTRL+T"), this); - connect(shortcut, &QShortcut::activated, [this]() { - printf("ctrL+t pressed\n"); // - if (this->_selectedPage == nullptr) { - return; - } - - this->_selectedPage->addChat(); - }); - } } NotebookPage *Notebook::addPage(bool select)