clean up chat widget structure. how and where hotkeys are handled

This commit is contained in:
Rasmus Karlsson 2017-06-10 23:53:39 +02:00
parent 1472471ddb
commit 85356cdd6b
5 changed files with 67 additions and 34 deletions

View file

@ -1,6 +1,7 @@
#include "widgets/chatwidget.h" #include "widgets/chatwidget.h"
#include "channelmanager.h" #include "channelmanager.h"
#include "colorscheme.h" #include "colorscheme.h"
#include "notebookpage.h"
#include "settingsmanager.h" #include "settingsmanager.h"
#include "widgets/textinputdialog.h" #include "widgets/textinputdialog.h"
@ -8,6 +9,7 @@
#include <QFont> #include <QFont>
#include <QFontDatabase> #include <QFontDatabase>
#include <QPainter> #include <QPainter>
#include <QShortcut>
#include <QVBoxLayout> #include <QVBoxLayout>
#include <boost/signals2.hpp> #include <boost/signals2.hpp>
@ -32,6 +34,28 @@ ChatWidget::ChatWidget(QWidget *parent)
this->_vbox.addWidget(&_header); this->_vbox.addWidget(&_header);
this->_vbox.addWidget(&_view, 1); this->_vbox.addWidget(&_view, 1);
this->_vbox.addWidget(&_input); 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() ChatWidget::~ChatWidget()
@ -193,5 +217,23 @@ boost::property_tree::ptree ChatWidget::save()
return tree; return tree;
} }
/// Slots
//
void ChatWidget::doAddSplit()
{
NotebookPage *page = static_cast<NotebookPage *>(this->parentWidget());
page->addChat();
}
void ChatWidget::doCloseSplit()
{
qDebug() << "Close split for" << this->getChannelName();
}
void ChatWidget::doChangeChannel()
{
this->showChangeChannelPopup();
}
} // namespace widgets } // namespace widgets
} // namespace chatterino } // namespace chatterino

View file

@ -10,6 +10,7 @@
#include "widgets/chatwidgetview.h" #include "widgets/chatwidgetview.h"
#include <QFont> #include <QFont>
#include <QShortcut>
#include <QVBoxLayout> #include <QVBoxLayout>
#include <QWidget> #include <QWidget>
#include <boost/property_tree/ptree.hpp> #include <boost/property_tree/ptree.hpp>
@ -70,6 +71,17 @@ private:
public: public:
void load(const boost::property_tree::ptree &tree); void load(const boost::property_tree::ptree &tree);
boost::property_tree::ptree save(); 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 } // namespace widgets

View file

@ -40,12 +40,14 @@ ChatWidgetHeader::ChatWidgetHeader(ChatWidget *_chatWidget)
QObject::connect(&_leftLabel, &ChatWidgetHeaderButton::clicked, this, QObject::connect(&_leftLabel, &ChatWidgetHeaderButton::clicked, this,
&ChatWidgetHeader::leftButtonClicked); &ChatWidgetHeader::leftButtonClicked);
_leftMenu.addAction("Add new split", this, SLOT(menuAddSplit()), QKeySequence(tr("Ctrl+T"))); _leftMenu.addAction("Add new split", this->chatWidget, &ChatWidget::doAddSplit,
_leftMenu.addAction("Close split", this, SLOT(menuCloseSplit()), QKeySequence(tr("Ctrl+W"))); 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("Move split", this, SLOT(menuMoveSplit()));
_leftMenu.addAction("Popup", this, SLOT(menuPopup())); _leftMenu.addAction("Popup", this, SLOT(menuPopup()));
_leftMenu.addSeparator(); _leftMenu.addSeparator();
_leftMenu.addAction("Change channel", this, SLOT(menuChangeChannel()), _leftMenu.addAction("Change channel", this->chatWidget, &ChatWidget::doChangeChannel,
QKeySequence(tr("Ctrl+R"))); QKeySequence(tr("Ctrl+R")));
_leftMenu.addAction("Clear chat", this, SLOT(menuClearChat())); _leftMenu.addAction("Clear chat", this, SLOT(menuClearChat()));
_leftMenu.addAction("Open channel", this, SLOT(menuOpenChannel())); _leftMenu.addAction("Open channel", this, SLOT(menuOpenChannel()));
@ -154,43 +156,37 @@ void ChatWidgetHeader::rightButtonClicked()
{ {
} }
void ChatWidgetHeader::menuAddSplit()
{
auto page = static_cast<NotebookPage *>(this->chatWidget->parentWidget());
page->addChat();
}
void ChatWidgetHeader::menuCloseSplit()
{
printf("Close split\n");
}
void ChatWidgetHeader::menuMoveSplit() void ChatWidgetHeader::menuMoveSplit()
{ {
} }
void ChatWidgetHeader::menuPopup() void ChatWidgetHeader::menuPopup()
{ {
auto widget = new ChatWidget(); auto widget = new ChatWidget();
widget->setChannelName(this->chatWidget->getChannelName()); widget->setChannelName(this->chatWidget->getChannelName());
widget->show(); widget->show();
} }
void ChatWidgetHeader::menuChangeChannel()
{
this->chatWidget->showChangeChannelPopup();
}
void ChatWidgetHeader::menuClearChat() void ChatWidgetHeader::menuClearChat()
{ {
} }
void ChatWidgetHeader::menuOpenChannel() void ChatWidgetHeader::menuOpenChannel()
{ {
} }
void ChatWidgetHeader::menuPopupPlayer() void ChatWidgetHeader::menuPopupPlayer()
{ {
} }
void ChatWidgetHeader::menuReloadChannelEmotes() void ChatWidgetHeader::menuReloadChannelEmotes()
{ {
} }
void ChatWidgetHeader::menuManualReconnect() void ChatWidgetHeader::menuManualReconnect()
{ {
} }
void ChatWidgetHeader::menuShowChangelog() void ChatWidgetHeader::menuShowChangelog()
{ {
} }

View file

@ -53,12 +53,9 @@ private:
void leftButtonClicked(); void leftButtonClicked();
void rightButtonClicked(); void rightButtonClicked();
private slots: public slots:
void menuAddSplit();
void menuCloseSplit();
void menuMoveSplit(); void menuMoveSplit();
void menuPopup(); void menuPopup();
void menuChangeChannel();
void menuClearChat(); void menuClearChat();
void menuOpenChannel(); void menuOpenChannel();
void menuPopupPlayer(); void menuPopupPlayer();

View file

@ -42,20 +42,6 @@ Notebook::Notebook(QWidget *parent)
[this](const bool &) { performLayout(); }); [this](const bool &) { performLayout(); });
SettingsManager::getInstance().hideUserButton.valueChanged.connect( SettingsManager::getInstance().hideUserButton.valueChanged.connect(
[this](const bool &) { performLayout(); }); [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) NotebookPage *Notebook::addPage(bool select)