Add custom hotkeys. (#2340)

Co-authored-by: LosFarmosCTL <80157503+LosFarmosCTL@users.noreply.github.com>
Co-authored-by: Paweł <zneix@zneix.eu>
Co-authored-by: Felanbird <41973452+Felanbird@users.noreply.github.com>
Co-authored-by: Rasmus Karlsson <rasmus.karlsson@pajlada.com>
This commit is contained in:
Mm2PL
2021-11-21 17:46:21 +00:00
committed by GitHub
parent b94e21a600
commit 703f3717e2
54 changed files with 3613 additions and 617 deletions
+316 -46
View File
@@ -6,6 +6,9 @@
#include "common/NetworkRequest.hpp"
#include "common/QLogging.hpp"
#include "controllers/accounts/AccountController.hpp"
#include "controllers/commands/CommandController.hpp"
#include "controllers/hotkeys/HotkeyController.hpp"
#include "controllers/notifications/NotificationController.hpp"
#include "providers/twitch/EmoteValue.hpp"
#include "providers/twitch/TwitchChannel.hpp"
#include "providers/twitch/TwitchIrcServer.hpp"
@@ -17,9 +20,9 @@
#include "util/Clipboard.hpp"
#include "util/Helpers.hpp"
#include "util/NuulsUploader.hpp"
#include "util/Shortcut.hpp"
#include "util/StreamLink.hpp"
#include "widgets/Notebook.hpp"
#include "widgets/Scrollbar.hpp"
#include "widgets/TooltipWidget.hpp"
#include "widgets/Window.hpp"
#include "widgets/dialogs/QualityPopup.hpp"
@@ -97,51 +100,6 @@ Split::Split(QWidget *parent)
this->vbox_->addWidget(this->view_, 1);
this->vbox_->addWidget(this->input_);
// Initialize chat widget-wide hotkeys
// CTRL+W: Close Split
createShortcut(this, "CTRL+W", &Split::deleteFromContainer);
// CTRL+R: Change Channel
createShortcut(this, "CTRL+R", &Split::changeChannel);
// CTRL+F: Search
createShortcut(this, "CTRL+F", &Split::showSearch);
// F5: reload emotes
createShortcut(this, "F5", &Split::reloadChannelAndSubscriberEmotes);
// CTRL+F5: reconnect
createShortcut(this, "CTRL+F5", &Split::reconnect);
// Alt+X: create clip LUL
createShortcut(this, "Alt+X", [this] {
if (const auto type = this->getChannel()->getType();
type != Channel::Type::Twitch &&
type != Channel::Type::TwitchWatching)
{
return;
}
auto *twitchChannel =
dynamic_cast<TwitchChannel *>(this->getChannel().get());
twitchChannel->createClip();
});
// F10
createShortcut(this, "F10", [] {
auto *popup = new DebugPopup;
popup->setAttribute(Qt::WA_DeleteOnClose);
popup->setWindowTitle("Chatterino - Debug popup");
popup->show();
});
// xd
// CreateShortcut(this, "ALT+SHIFT+RIGHT", &Split::doIncFlexX);
// CreateShortcut(this, "ALT+SHIFT+LEFT", &Split::doDecFlexX);
// CreateShortcut(this, "ALT+SHIFT+UP", &Split::doIncFlexY);
// CreateShortcut(this, "ALT+SHIFT+DOWN", &Split::doDecFlexY);
this->input_->ui_.textEdit->installEventFilter(parent);
// update placeholder text on Twitch account change and channel change
@@ -293,6 +251,302 @@ Split::Split(QWidget *parent)
this->setAcceptDrops(val);
},
this->managedConnections_);
this->addShortcuts();
this->managedConnect(getApp()->hotkeys->onItemsUpdated, [this]() {
this->clearShortcuts();
this->addShortcuts();
});
}
void Split::addShortcuts()
{
HotkeyController::HotkeyMap actions{
{"delete",
[this](std::vector<QString>) -> QString {
this->deleteFromContainer();
return "";
}},
{"changeChannel",
[this](std::vector<QString>) -> QString {
this->changeChannel();
return "";
}},
{"showSearch",
[this](std::vector<QString>) -> QString {
this->showSearch();
return "";
}},
{"reconnect",
[this](std::vector<QString>) -> QString {
this->reconnect();
return "";
}},
{"debug",
[](std::vector<QString>) -> QString {
auto *popup = new DebugPopup;
popup->setAttribute(Qt::WA_DeleteOnClose);
popup->setWindowTitle("Chatterino - Debug popup");
popup->show();
return "";
}},
{"focus",
[this](std::vector<QString> arguments) -> QString {
if (arguments.size() == 0)
{
return "focus action requires only one argument: the "
"focus direction Use \"up\", \"above\", \"down\", "
"\"below\", \"left\" or \"right\".";
}
auto direction = arguments.at(0);
if (direction == "up" || direction == "above")
{
this->actionRequested.invoke(Action::SelectSplitAbove);
}
else if (direction == "down" || direction == "below")
{
this->actionRequested.invoke(Action::SelectSplitBelow);
}
else if (direction == "left")
{
this->actionRequested.invoke(Action::SelectSplitLeft);
}
else if (direction == "right")
{
this->actionRequested.invoke(Action::SelectSplitRight);
}
else
{
return "focus in unknown direction. Use \"up\", "
"\"above\", \"down\", \"below\", \"left\" or "
"\"right\".";
}
return "";
}},
{"scrollToBottom",
[this](std::vector<QString>) -> QString {
this->getChannelView().getScrollBar().scrollToBottom(
getSettings()->enableSmoothScrollingNewMessages.getValue());
return "";
}},
{"scrollPage",
[this](std::vector<QString> arguments) -> QString {
if (arguments.size() == 0)
{
qCWarning(chatterinoHotkeys)
<< "scrollPage hotkey called without arguments!";
return "scrollPage hotkey called without arguments!";
}
auto direction = arguments.at(0);
auto &scrollbar = this->getChannelView().getScrollBar();
if (direction == "up")
{
scrollbar.offset(-scrollbar.getLargeChange());
}
else if (direction == "down")
{
scrollbar.offset(scrollbar.getLargeChange());
}
else
{
qCWarning(chatterinoHotkeys) << "Unknown scroll direction";
}
return "";
}},
{"pickFilters",
[this](std::vector<QString>) -> QString {
this->setFiltersDialog();
return "";
}},
{"startWatching",
[this](std::vector<QString>) -> QString {
this->startWatching();
return "";
}},
{"openInBrowser",
[this](std::vector<QString>) -> QString {
if (this->getChannel()->getType() == Channel::Type::TwitchWhispers)
{
this->openWhispersInBrowser();
}
else
{
this->openInBrowser();
}
return "";
}},
{"openInStreamlink",
[this](std::vector<QString>) -> QString {
this->openInStreamlink();
return "";
}},
{"openInCustomPlayer",
[this](std::vector<QString>) -> QString {
this->openWithCustomScheme();
return "";
}},
{"openModView",
[this](std::vector<QString>) -> QString {
this->openModViewInBrowser();
return "";
}},
{"createClip",
[this](std::vector<QString>) -> QString {
// Alt+X: create clip LUL
if (const auto type = this->getChannel()->getType();
type != Channel::Type::Twitch &&
type != Channel::Type::TwitchWatching)
{
return "Cannot create clip it non-twitch channel.";
}
auto *twitchChannel =
dynamic_cast<TwitchChannel *>(this->getChannel().get());
twitchChannel->createClip();
return "";
}},
{"reloadEmotes",
[this](std::vector<QString> arguments) -> QString {
auto reloadChannel = true;
auto reloadSubscriber = true;
if (arguments.size() != 0)
{
auto arg = arguments.at(0);
if (arg == "channel")
{
reloadSubscriber = false;
}
else if (arg == "subscriber")
{
reloadChannel = false;
}
}
if (reloadChannel)
{
this->header_->reloadChannelEmotes();
}
if (reloadSubscriber)
{
this->header_->reloadSubscriberEmotes();
}
return "";
}},
{"setModerationMode",
[this](std::vector<QString> arguments) -> QString {
if (!this->getChannel()->isTwitchChannel())
{
return "Cannot set moderation mode in non-twitch channel.";
}
auto mode = 2;
// 0 is off
// 1 is on
// 2 is toggle
if (arguments.size() != 0)
{
auto arg = arguments.at(0);
if (arg == "off")
{
mode = 0;
}
else if (arg == "on")
{
mode = 1;
}
else
{
mode = 2;
}
}
if (mode == 0)
{
this->setModerationMode(false);
}
else if (mode == 1)
{
this->setModerationMode(true);
}
else
{
this->setModerationMode(!this->getModerationMode());
}
return "";
}},
{"openViewerList",
[this](std::vector<QString>) -> QString {
this->showViewerList();
return "";
}},
{"clearMessages",
[this](std::vector<QString>) -> QString {
this->clear();
return "";
}},
{"runCommand",
[this](std::vector<QString> arguments) -> QString {
if (arguments.size() == 0)
{
qCWarning(chatterinoHotkeys)
<< "runCommand hotkey called without arguments!";
return "runCommand hotkey called without arguments!";
}
QString command = getApp()->commands->execCommand(
arguments.at(0).replace('\n', ' '), this->getChannel(), false);
this->getChannel()->sendMessage(command);
return "";
}},
{"setChannelNotification",
[this](std::vector<QString> arguments) -> QString {
if (!this->getChannel()->isTwitchChannel())
{
return "Cannot set channel notifications for non-twitch "
"channel.";
}
auto mode = 2;
// 0 is off
// 1 is on
// 2 is toggle
if (arguments.size() != 0)
{
auto arg = arguments.at(0);
if (arg == "off")
{
mode = 0;
}
else if (arg == "on")
{
mode = 1;
}
else
{
mode = 2;
}
}
if (mode == 0)
{
getApp()->notifications->removeChannelNotification(
this->getChannel()->getName(), Platform::Twitch);
}
else if (mode == 1)
{
getApp()->notifications->addChannelNotification(
this->getChannel()->getName(), Platform::Twitch);
}
else
{
getApp()->notifications->updateChannelNotification(
this->getChannel()->getName(), Platform::Twitch);
}
return "";
}},
};
this->shortcuts_ = getApp()->hotkeys->shortcutsForCategory(
HotkeyCategory::Split, actions, this);
}
Split::~Split()
@@ -844,6 +1098,22 @@ void Split::copyToClipboard()
crossPlatformCopy(this->view_->getSelectedText());
}
void Split::startWatching()
{
#ifdef USEWEBENGINE
ChannelPtr _channel = this->getChannel();
TwitchChannel *tc = dynamic_cast<TwitchChannel *>(_channel.get());
if (tc != nullptr)
{
StreamView *view = new StreamView(
_channel,
"https://player.twitch.tv/?parent=twitch.tv&channel=" + tc->name);
view->setAttribute(Qt::WA_DeleteOnClose, true);
view->show();
}
#endif
}
void Split::setFiltersDialog()
{
SelectChannelFiltersDialog d(this->getFilters(), this);
+2
View File
@@ -114,6 +114,7 @@ private:
void channelNameUpdated(const QString &newChannelName);
void handleModifiers(Qt::KeyboardModifiers modifiers);
void updateInputPlaceholder();
void addShortcuts() override;
/**
* @brief Opens Twitch channel stream in a browser player (opens a formatted link)
@@ -168,6 +169,7 @@ public slots:
void openInStreamlink();
void openWithCustomScheme();
void copyToClipboard();
void startWatching();
void setFiltersDialog();
void showSearch();
void showViewerList();
+2 -14
View File
@@ -348,20 +348,8 @@ std::unique_ptr<QMenu> SplitHeader::createMainMenu()
menu->addAction("Set filters", this->split_, &Split::setFiltersDialog);
menu->addSeparator();
#ifdef USEWEBENGINE
this->dropdownMenu.addAction("Start watching", this, [this] {
ChannelPtr _channel = this->split->getChannel();
TwitchChannel *tc = dynamic_cast<TwitchChannel *>(_channel.get());
if (tc != nullptr)
{
StreamView *view = new StreamView(
_channel,
"https://player.twitch.tv/?parent=twitch.tv&channel=" +
tc->name);
view->setAttribute(Qt::WA_DeleteOnClose, true);
view->show();
}
});
this->dropdownMenu.addAction("Start watching", this->split_,
&Split::startWatching);
#endif
auto *twitchChannel =
+286 -228
View File
@@ -1,7 +1,9 @@
#include "widgets/splits/SplitInput.hpp"
#include "Application.hpp"
#include "common/QLogging.hpp"
#include "controllers/commands/CommandController.hpp"
#include "controllers/hotkeys/HotkeyController.hpp"
#include "messages/Link.hpp"
#include "providers/twitch/TwitchChannel.hpp"
#include "providers/twitch/TwitchIrcServer.hpp"
@@ -31,6 +33,7 @@ SplitInput::SplitInput(Split *_chatWidget)
: BaseWidget(_chatWidget)
, split_(_chatWidget)
{
this->installEventFilter(this);
this->initLayout();
auto completer =
@@ -45,10 +48,16 @@ SplitInput::SplitInput(Split *_chatWidget)
// misc
this->installKeyPressedEvent();
this->addShortcuts();
this->ui_.textEdit->focusLost.connect([this] {
this->hideCompletionPopup();
});
this->scaleChangedEvent(this->scale());
this->signalHolder_.managedConnect(getApp()->hotkeys->onItemsUpdated,
[this]() {
this->clearShortcuts();
this->addShortcuts();
});
}
void SplitInput::initLayout()
@@ -202,11 +211,280 @@ void SplitInput::openEmotePopup()
this->emotePopup_->activateWindow();
}
void SplitInput::addShortcuts()
{
HotkeyController::HotkeyMap actions{
{"cursorToStart",
[this](std::vector<QString> arguments) -> QString {
if (arguments.size() != 1)
{
qCWarning(chatterinoHotkeys)
<< "Invalid cursorToStart arguments. Argument 0: select "
"(\"withSelection\" or \"withoutSelection\")";
return "Invalid cursorToStart arguments. Argument 0: select "
"(\"withSelection\" or \"withoutSelection\")";
}
QTextCursor cursor = this->ui_.textEdit->textCursor();
auto place = QTextCursor::Start;
auto stringTakeSelection = arguments.at(0);
bool select;
if (stringTakeSelection == "withSelection")
{
select = true;
}
else if (stringTakeSelection == "withoutSelection")
{
select = false;
}
else
{
qCWarning(chatterinoHotkeys)
<< "Invalid cursorToStart select argument (0)!";
return "Invalid cursorToStart select argument (0)!";
}
cursor.movePosition(place,
select ? QTextCursor::MoveMode::KeepAnchor
: QTextCursor::MoveMode::MoveAnchor);
this->ui_.textEdit->setTextCursor(cursor);
return "";
}},
{"cursorToEnd",
[this](std::vector<QString> arguments) -> QString {
if (arguments.size() != 1)
{
qCWarning(chatterinoHotkeys)
<< "Invalid cursorToEnd arguments. Argument 0: select "
"(\"withSelection\" or \"withoutSelection\")";
return "Invalid cursorToEnd arguments. Argument 0: select "
"(\"withSelection\" or \"withoutSelection\")";
}
QTextCursor cursor = this->ui_.textEdit->textCursor();
auto place = QTextCursor::End;
auto stringTakeSelection = arguments.at(0);
bool select;
if (stringTakeSelection == "withSelection")
{
select = true;
}
else if (stringTakeSelection == "withoutSelection")
{
select = false;
}
else
{
qCWarning(chatterinoHotkeys)
<< "Invalid cursorToEnd select argument (0)!";
return "Invalid cursorToEnd select argument (0)!";
}
cursor.movePosition(place,
select ? QTextCursor::MoveMode::KeepAnchor
: QTextCursor::MoveMode::MoveAnchor);
this->ui_.textEdit->setTextCursor(cursor);
return "";
}},
{"openEmotesPopup",
[this](std::vector<QString>) -> QString {
this->openEmotePopup();
return "";
}},
{"sendMessage",
[this](std::vector<QString> arguments) -> QString {
auto c = this->split_->getChannel();
if (c == nullptr)
return "";
QString message = ui_.textEdit->toPlainText();
message = message.replace('\n', ' ');
QString sendMessage =
getApp()->commands->execCommand(message, c, false);
c->sendMessage(sendMessage);
// don't add duplicate messages and empty message to message history
if ((this->prevMsg_.isEmpty() ||
!this->prevMsg_.endsWith(message)) &&
!message.trimmed().isEmpty())
{
this->prevMsg_.append(message);
}
bool shouldClearInput = true;
if (arguments.size() != 0 && arguments.at(0) == "keepInput")
{
shouldClearInput = false;
}
if (shouldClearInput)
{
this->currMsg_ = QString();
this->ui_.textEdit->setPlainText(QString());
}
this->prevIndex_ = this->prevMsg_.size();
return "";
}},
{"previousMessage",
[this](std::vector<QString>) -> QString {
if (this->prevMsg_.size() && this->prevIndex_)
{
if (this->prevIndex_ == (this->prevMsg_.size()))
{
this->currMsg_ = ui_.textEdit->toPlainText();
}
this->prevIndex_--;
this->ui_.textEdit->setPlainText(
this->prevMsg_.at(this->prevIndex_));
QTextCursor cursor = this->ui_.textEdit->textCursor();
cursor.movePosition(QTextCursor::End);
this->ui_.textEdit->setTextCursor(cursor);
}
return "";
}},
{"nextMessage",
[this](std::vector<QString>) -> QString {
// If user did not write anything before then just do nothing.
if (this->prevMsg_.isEmpty())
{
return "";
}
bool cursorToEnd = true;
QString message = ui_.textEdit->toPlainText();
if (this->prevIndex_ != (this->prevMsg_.size() - 1) &&
this->prevIndex_ != this->prevMsg_.size())
{
this->prevIndex_++;
this->ui_.textEdit->setPlainText(
this->prevMsg_.at(this->prevIndex_));
}
else
{
this->prevIndex_ = this->prevMsg_.size();
if (message == this->prevMsg_.at(this->prevIndex_ - 1))
{
// If user has just come from a message history
// Then simply get currMsg_.
this->ui_.textEdit->setPlainText(this->currMsg_);
}
else if (message != this->currMsg_)
{
// If user are already in current message
// And type something new
// Then replace currMsg_ with new one.
this->currMsg_ = message;
}
// If user is already in current message
// Then don't touch cursos.
cursorToEnd =
(message == this->prevMsg_.at(this->prevIndex_ - 1));
}
if (cursorToEnd)
{
QTextCursor cursor = this->ui_.textEdit->textCursor();
cursor.movePosition(QTextCursor::End);
this->ui_.textEdit->setTextCursor(cursor);
}
return "";
}},
{"undo",
[this](std::vector<QString>) -> QString {
this->ui_.textEdit->undo();
return "";
}},
{"redo",
[this](std::vector<QString>) -> QString {
this->ui_.textEdit->redo();
return "";
}},
{"copy",
[this](std::vector<QString> arguments) -> QString {
// XXX: this action is unused at the moment, a qt standard shortcut is used instead
if (arguments.size() == 0)
{
return "copy action takes only one argument: the source "
"of the copy \"split\", \"input\" or "
"\"auto\". If the source is \"split\", only text "
"from the chat will be copied. If it is "
"\"splitInput\", text from the input box will be "
"copied. Automatic will pick whichever has a "
"selection";
}
bool copyFromSplit = false;
auto mode = arguments.at(0);
if (mode == "split")
{
copyFromSplit = true;
}
else if (mode == "splitInput")
{
copyFromSplit = false;
}
else if (mode == "auto")
{
const auto &cursor = this->ui_.textEdit->textCursor();
copyFromSplit = !cursor.hasSelection();
}
if (copyFromSplit)
{
this->split_->copyToClipboard();
}
else
{
this->ui_.textEdit->copy();
}
return "";
}},
{"paste",
[this](std::vector<QString>) -> QString {
this->ui_.textEdit->paste();
return "";
}},
{"clear",
[this](std::vector<QString>) -> QString {
this->ui_.textEdit->setText("");
this->ui_.textEdit->moveCursor(QTextCursor::Start);
return "";
}},
{"selectAll",
[this](std::vector<QString>) -> QString {
this->ui_.textEdit->selectAll();
return "";
}},
};
this->shortcuts_ = getApp()->hotkeys->shortcutsForCategory(
HotkeyCategory::SplitInput, actions, this);
}
bool SplitInput::eventFilter(QObject *obj, QEvent *event)
{
if (event->type() == QEvent::ShortcutOverride ||
event->type() == QEvent::Shortcut)
{
if (auto popup = this->inputCompletionPopup_.get())
{
if (popup->isVisible())
{
// Stop shortcut from triggering by saying we will handle it ourselves
event->accept();
// Return false means the underlying event isn't stopped, it will continue to propagate
return false;
}
}
}
return BaseWidget::eventFilter(obj, event);
}
void SplitInput::installKeyPressedEvent()
{
auto app = getApp();
this->ui_.textEdit->keyPressed.connect([this, app](QKeyEvent *event) {
this->ui_.textEdit->keyPressed.disconnectAll();
this->ui_.textEdit->keyPressed.connect([this](QKeyEvent *event) {
if (auto popup = this->inputCompletionPopup_.get())
{
if (popup->isVisible())
@@ -219,212 +497,11 @@ void SplitInput::installKeyPressedEvent()
}
}
if (event->key() == Qt::Key_Enter || event->key() == Qt::Key_Return)
{
auto c = this->split_->getChannel();
if (c == nullptr)
return;
QString message = ui_.textEdit->toPlainText();
message = message.replace('\n', ' ');
QString sendMessage = app->commands->execCommand(message, c, false);
c->sendMessage(sendMessage);
// don't add duplicate messages and empty message to message history
if ((this->prevMsg_.isEmpty() ||
!this->prevMsg_.endsWith(message)) &&
!message.trimmed().isEmpty())
{
this->prevMsg_.append(message);
}
event->accept();
if (!(event->modifiers() & Qt::ControlModifier))
{
this->currMsg_ = QString();
this->ui_.textEdit->setPlainText(QString());
}
this->prevIndex_ = this->prevMsg_.size();
}
else if (event->key() == Qt::Key_Up)
{
if ((event->modifiers() & Qt::ShiftModifier) != 0)
{
return;
}
if (event->modifiers() == Qt::AltModifier)
{
this->split_->actionRequested.invoke(
Split::Action::SelectSplitAbove);
}
else
{
if (this->prevMsg_.size() && this->prevIndex_)
{
if (this->prevIndex_ == (this->prevMsg_.size()))
{
this->currMsg_ = ui_.textEdit->toPlainText();
}
this->prevIndex_--;
this->ui_.textEdit->setPlainText(
this->prevMsg_.at(this->prevIndex_));
QTextCursor cursor = this->ui_.textEdit->textCursor();
cursor.movePosition(QTextCursor::End);
this->ui_.textEdit->setTextCursor(cursor);
// Don't let the keyboard event propagate further, we've
// handled it
event->accept();
}
}
}
else if (event->key() == Qt::Key_Home)
{
QTextCursor cursor = this->ui_.textEdit->textCursor();
cursor.movePosition(
QTextCursor::Start,
event->modifiers() & Qt::KeyboardModifier::ShiftModifier
? QTextCursor::MoveMode::KeepAnchor
: QTextCursor::MoveMode::MoveAnchor);
this->ui_.textEdit->setTextCursor(cursor);
event->accept();
}
else if (event->key() == Qt::Key_End)
{
if (event->modifiers() == Qt::ControlModifier)
{
this->split_->getChannelView().getScrollBar().scrollToBottom(
getSettings()->enableSmoothScrollingNewMessages.getValue());
}
else
{
QTextCursor cursor = this->ui_.textEdit->textCursor();
cursor.movePosition(
QTextCursor::End,
event->modifiers() & Qt::KeyboardModifier::ShiftModifier
? QTextCursor::MoveMode::KeepAnchor
: QTextCursor::MoveMode::MoveAnchor);
this->ui_.textEdit->setTextCursor(cursor);
}
event->accept();
}
else if (event->key() == Qt::Key_H &&
event->modifiers() == Qt::AltModifier)
{
// h: vim binding for left
this->split_->actionRequested.invoke(
Split::Action::SelectSplitLeft);
event->accept();
}
else if (event->key() == Qt::Key_J &&
event->modifiers() == Qt::AltModifier)
{
// j: vim binding for down
this->split_->actionRequested.invoke(
Split::Action::SelectSplitBelow);
event->accept();
}
else if (event->key() == Qt::Key_K &&
event->modifiers() == Qt::AltModifier)
{
// k: vim binding for up
this->split_->actionRequested.invoke(
Split::Action::SelectSplitAbove);
event->accept();
}
else if (event->key() == Qt::Key_L &&
event->modifiers() == Qt::AltModifier)
{
// l: vim binding for right
this->split_->actionRequested.invoke(
Split::Action::SelectSplitRight);
event->accept();
}
else if (event->key() == Qt::Key_Down)
{
if ((event->modifiers() & Qt::ShiftModifier) != 0)
{
return;
}
if (event->modifiers() == Qt::AltModifier)
{
this->split_->actionRequested.invoke(
Split::Action::SelectSplitBelow);
}
else
{
// If user did not write anything before then just do nothing.
if (this->prevMsg_.isEmpty())
{
return;
}
bool cursorToEnd = true;
QString message = ui_.textEdit->toPlainText();
if (this->prevIndex_ != (this->prevMsg_.size() - 1) &&
this->prevIndex_ != this->prevMsg_.size())
{
this->prevIndex_++;
this->ui_.textEdit->setPlainText(
this->prevMsg_.at(this->prevIndex_));
}
else
{
this->prevIndex_ = this->prevMsg_.size();
if (message == this->prevMsg_.at(this->prevIndex_ - 1))
{
// If user has just come from a message history
// Then simply get currMsg_.
this->ui_.textEdit->setPlainText(this->currMsg_);
}
else if (message != this->currMsg_)
{
// If user are already in current message
// And type something new
// Then replace currMsg_ with new one.
this->currMsg_ = message;
}
// If user is already in current message
// Then don't touch cursos.
cursorToEnd =
(message == this->prevMsg_.at(this->prevIndex_ - 1));
}
if (cursorToEnd)
{
QTextCursor cursor = this->ui_.textEdit->textCursor();
cursor.movePosition(QTextCursor::End);
this->ui_.textEdit->setTextCursor(cursor);
}
}
}
else if (event->key() == Qt::Key_Left)
{
if (event->modifiers() == Qt::AltModifier)
{
this->split_->actionRequested.invoke(
Split::Action::SelectSplitLeft);
}
}
else if (event->key() == Qt::Key_Right)
{
if (event->modifiers() == Qt::AltModifier)
{
this->split_->actionRequested.invoke(
Split::Action::SelectSplitRight);
}
}
else if ((event->key() == Qt::Key_C ||
event->key() == Qt::Key_Insert) &&
event->modifiers() == Qt::ControlModifier)
// One of the last remaining of it's kind, the copy shortcut.
// For some bizarre reason Qt doesn't want this key be rebound.
// TODO(Mm2PL): Revisit in Qt6, maybe something changed?
if ((event->key() == Qt::Key_C || event->key() == Qt::Key_Insert) &&
event->modifiers() == Qt::ControlModifier)
{
if (this->split_->view_->hasSelection())
{
@@ -432,25 +509,6 @@ void SplitInput::installKeyPressedEvent()
event->accept();
}
}
else if (event->key() == Qt::Key_E &&
event->modifiers() == Qt::ControlModifier)
{
this->openEmotePopup();
}
else if (event->key() == Qt::Key_PageUp)
{
auto &scrollbar = this->split_->getChannelView().getScrollBar();
scrollbar.offset(-scrollbar.getLargeChange());
event->accept();
}
else if (event->key() == Qt::Key_PageDown)
{
auto &scrollbar = this->split_->getChannelView().getScrollBar();
scrollbar.offset(scrollbar.getLargeChange());
event->accept();
}
});
}
+2
View File
@@ -44,7 +44,9 @@ protected:
virtual void mousePressEvent(QMouseEvent *event) override;
private:
void addShortcuts() override;
void initLayout();
bool eventFilter(QObject *obj, QEvent *event) override;
void installKeyPressedEvent();
void onCursorPositionChanged();
void onTextChanged();