mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-21 22:24:07 +01:00
clean up chat widget structure. how and where hotkeys are handled
This commit is contained in:
parent
1472471ddb
commit
85356cdd6b
5 changed files with 67 additions and 34 deletions
|
@ -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 <QFont>
|
||||
#include <QFontDatabase>
|
||||
#include <QPainter>
|
||||
#include <QShortcut>
|
||||
#include <QVBoxLayout>
|
||||
#include <boost/signals2.hpp>
|
||||
|
||||
|
@ -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<NotebookPage *>(this->parentWidget());
|
||||
page->addChat();
|
||||
}
|
||||
|
||||
void ChatWidget::doCloseSplit()
|
||||
{
|
||||
qDebug() << "Close split for" << this->getChannelName();
|
||||
}
|
||||
|
||||
void ChatWidget::doChangeChannel()
|
||||
{
|
||||
this->showChangeChannelPopup();
|
||||
}
|
||||
|
||||
} // namespace widgets
|
||||
} // namespace chatterino
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#include "widgets/chatwidgetview.h"
|
||||
|
||||
#include <QFont>
|
||||
#include <QShortcut>
|
||||
#include <QVBoxLayout>
|
||||
#include <QWidget>
|
||||
#include <boost/property_tree/ptree.hpp>
|
||||
|
@ -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
|
||||
|
|
|
@ -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<NotebookPage *>(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()
|
||||
{
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue