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:
@@ -2,6 +2,8 @@
|
||||
|
||||
#include "BaseSettings.hpp"
|
||||
#include "BaseTheme.hpp"
|
||||
#include "common/QLogging.hpp"
|
||||
#include "controllers/hotkeys/HotkeyController.hpp"
|
||||
#include "widgets/BaseWindow.hpp"
|
||||
|
||||
#include <QChildEvent>
|
||||
@@ -25,6 +27,16 @@ BaseWidget::BaseWidget(QWidget *parent, Qt::WindowFlags f)
|
||||
this->update();
|
||||
});
|
||||
}
|
||||
void BaseWidget::clearShortcuts()
|
||||
{
|
||||
for (auto shortcut : this->shortcuts_)
|
||||
{
|
||||
shortcut->setKey(QKeySequence());
|
||||
shortcut->removeEventFilter(this);
|
||||
shortcut->deleteLater();
|
||||
}
|
||||
this->shortcuts_.clear();
|
||||
}
|
||||
|
||||
float BaseWidget::scale() const
|
||||
{
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <QShortcut>
|
||||
#include <QWidget>
|
||||
#include <boost/optional.hpp>
|
||||
#include <pajlada/signals/signal.hpp>
|
||||
@@ -40,11 +41,19 @@ protected:
|
||||
|
||||
virtual void scaleChangedEvent(float newScale);
|
||||
virtual void themeChangedEvent();
|
||||
[[deprecated("addShortcuts called without overriding it")]] virtual void
|
||||
addShortcuts()
|
||||
{
|
||||
}
|
||||
|
||||
void setScale(float value);
|
||||
|
||||
Theme *theme;
|
||||
|
||||
std::vector<QShortcut *> shortcuts_;
|
||||
void clearShortcuts();
|
||||
pajlada::Signals::SignalHolder signalHolder_;
|
||||
|
||||
private:
|
||||
float scale_{1.f};
|
||||
boost::optional<float> overrideScale_;
|
||||
@@ -52,8 +61,6 @@ private:
|
||||
|
||||
std::vector<BaseWidget *> widgets_;
|
||||
|
||||
pajlada::Signals::SignalHolder signalHolder_;
|
||||
|
||||
friend class BaseWindow;
|
||||
};
|
||||
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
#include "boost/algorithm/algorithm.hpp"
|
||||
#include "util/DebugCount.hpp"
|
||||
#include "util/PostToThread.hpp"
|
||||
#include "util/Shortcut.hpp"
|
||||
#include "util/WindowsHelper.hpp"
|
||||
#include "widgets/Label.hpp"
|
||||
#include "widgets/TooltipWidget.hpp"
|
||||
@@ -83,10 +82,6 @@ BaseWindow::BaseWindow(FlagsEnum<Flags> _flags, QWidget *parent)
|
||||
|
||||
this->updateScale();
|
||||
|
||||
createWindowShortcut(this, "CTRL+0", [] {
|
||||
getSettings()->uiScale.setValue(1);
|
||||
});
|
||||
|
||||
this->resize(300, 150);
|
||||
|
||||
#ifdef USEWINSDK
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
#include "singletons/Theme.hpp"
|
||||
#include "singletons/WindowManager.hpp"
|
||||
#include "util/InitUpdateButton.hpp"
|
||||
#include "util/Shortcut.hpp"
|
||||
#include "widgets/Window.hpp"
|
||||
#include "widgets/dialogs/SettingsDialog.hpp"
|
||||
#include "widgets/helper/NotebookButton.hpp"
|
||||
@@ -19,7 +18,6 @@
|
||||
#include <QFormLayout>
|
||||
#include <QLayout>
|
||||
#include <QList>
|
||||
#include <QShortcut>
|
||||
#include <QStandardPaths>
|
||||
#include <QUuid>
|
||||
#include <QWidget>
|
||||
|
||||
+367
-124
@@ -3,15 +3,16 @@
|
||||
#include "Application.hpp"
|
||||
#include "common/Credentials.hpp"
|
||||
#include "common/Modes.hpp"
|
||||
#include "common/QLogging.hpp"
|
||||
#include "common/Version.hpp"
|
||||
#include "controllers/accounts/AccountController.hpp"
|
||||
#include "controllers/hotkeys/HotkeyController.hpp"
|
||||
#include "providers/twitch/TwitchIrcServer.hpp"
|
||||
#include "singletons/Settings.hpp"
|
||||
#include "singletons/Theme.hpp"
|
||||
#include "singletons/Updates.hpp"
|
||||
#include "singletons/WindowManager.hpp"
|
||||
#include "util/InitUpdateButton.hpp"
|
||||
#include "util/Shortcut.hpp"
|
||||
#include "widgets/AccountSwitchPopup.hpp"
|
||||
#include "widgets/Notebook.hpp"
|
||||
#include "widgets/dialogs/SettingsDialog.hpp"
|
||||
@@ -37,7 +38,6 @@
|
||||
#include <QHeaderView>
|
||||
#include <QMenuBar>
|
||||
#include <QPalette>
|
||||
#include <QShortcut>
|
||||
#include <QStandardItemModel>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
@@ -49,7 +49,6 @@ Window::Window(WindowType type)
|
||||
, notebook_(new SplitNotebook(this))
|
||||
{
|
||||
this->addCustomTitlebarButtons();
|
||||
this->addDebugStuff();
|
||||
this->addShortcuts();
|
||||
this->addLayout();
|
||||
|
||||
@@ -72,6 +71,11 @@ Window::Window(WindowType type)
|
||||
this->resize(int(300 * this->scale()), int(500 * this->scale()));
|
||||
}
|
||||
|
||||
this->signalHolder_.managedConnect(getApp()->hotkeys->onItemsUpdated,
|
||||
[this]() {
|
||||
this->clearShortcuts();
|
||||
this->addShortcuts();
|
||||
});
|
||||
if (type == WindowType::Main || type == WindowType::Popup)
|
||||
{
|
||||
getSettings()->tabDirection.connect([this](int val) {
|
||||
@@ -180,7 +184,7 @@ void Window::addCustomTitlebarButtons()
|
||||
this->userLabel_->setMinimumWidth(20 * scale());
|
||||
}
|
||||
|
||||
void Window::addDebugStuff()
|
||||
void Window::addDebugStuff(HotkeyController::HotkeyMap &actions)
|
||||
{
|
||||
#ifndef NDEBUG
|
||||
std::vector<QString> cheerMessages, subMessages, miscMessages, linkMessages,
|
||||
@@ -242,30 +246,33 @@ void Window::addDebugStuff()
|
||||
emoteTestMessages.emplace_back(R"(@badge-info=subscriber/34;badges=moderator/1,subscriber/24;color=#FF0000;display-name=테스트계정420;emotes=41:6-13,15-22;flags=;id=a3196c7e-be4c-4b49-9c5a-8b8302b50c2a;mod=1;room-id=11148817;subscriber=1;tmi-sent-ts=1590922213730;turbo=0;user-id=117166826;user-type=mod :testaccount_420!testaccount_420@testaccount_420.tmi.twitch.tv PRIVMSG #pajlada :-tags Kreygasm,Kreygasm (no space))");
|
||||
// clang-format on
|
||||
|
||||
createWindowShortcut(this, "F6", [=] {
|
||||
actions.emplace("addMiscMessage", [=](std::vector<QString>) -> QString {
|
||||
const auto &messages = miscMessages;
|
||||
static int index = 0;
|
||||
auto app = getApp();
|
||||
const auto &msg = messages[index++ % messages.size()];
|
||||
app->twitch.server->addFakeMessage(msg);
|
||||
return "";
|
||||
});
|
||||
|
||||
createWindowShortcut(this, "F7", [=] {
|
||||
actions.emplace("addCheerMessage", [=](std::vector<QString>) -> QString {
|
||||
const auto &messages = cheerMessages;
|
||||
static int index = 0;
|
||||
const auto &msg = messages[index++ % messages.size()];
|
||||
getApp()->twitch.server->addFakeMessage(msg);
|
||||
return "";
|
||||
});
|
||||
|
||||
createWindowShortcut(this, "F8", [=] {
|
||||
actions.emplace("addLinkMessage", [=](std::vector<QString>) -> QString {
|
||||
const auto &messages = linkMessages;
|
||||
static int index = 0;
|
||||
auto app = getApp();
|
||||
const auto &msg = messages[index++ % messages.size()];
|
||||
app->twitch.server->addFakeMessage(msg);
|
||||
return "";
|
||||
});
|
||||
|
||||
createWindowShortcut(this, "F9", [=] {
|
||||
actions.emplace("addRewardMessage", [=](std::vector<QString>) -> QString {
|
||||
rapidjson::Document doc;
|
||||
auto app = getApp();
|
||||
static bool alt = true;
|
||||
@@ -284,139 +291,375 @@ void Window::addDebugStuff()
|
||||
doc["data"]["message"]["data"]["redemption"]);
|
||||
alt = !alt;
|
||||
}
|
||||
return "";
|
||||
});
|
||||
|
||||
createWindowShortcut(this, "F11", [=] {
|
||||
actions.emplace("addEmoteMessage", [=](std::vector<QString>) -> QString {
|
||||
const auto &messages = emoteTestMessages;
|
||||
static int index = 0;
|
||||
const auto &msg = messages[index++ % messages.size()];
|
||||
getApp()->twitch.server->addFakeMessage(msg);
|
||||
return "";
|
||||
});
|
||||
|
||||
#endif
|
||||
} // namespace chatterino
|
||||
}
|
||||
|
||||
void Window::addShortcuts()
|
||||
{
|
||||
/// Initialize program-wide hotkeys
|
||||
// Open settings
|
||||
createWindowShortcut(this, "CTRL+P", [this] {
|
||||
SettingsDialog::showDialog(this);
|
||||
});
|
||||
HotkeyController::HotkeyMap actions{
|
||||
{"openSettings", // Open settings
|
||||
[this](std::vector<QString>) -> QString {
|
||||
SettingsDialog::showDialog(this);
|
||||
return "";
|
||||
}},
|
||||
{"newSplit", // Create a new split
|
||||
[this](std::vector<QString>) -> QString {
|
||||
this->notebook_->getOrAddSelectedPage()->appendNewSplit(true);
|
||||
return "";
|
||||
}},
|
||||
{"openTab", // CTRL + 1-8 to open corresponding tab.
|
||||
[this](std::vector<QString> arguments) -> QString {
|
||||
if (arguments.size() == 0)
|
||||
{
|
||||
qCWarning(chatterinoHotkeys)
|
||||
<< "openTab shortcut called without arguments. "
|
||||
"Takes only "
|
||||
"one argument: tab specifier";
|
||||
return "openTab shortcut called without arguments. "
|
||||
"Takes only "
|
||||
"one argument: tab specifier";
|
||||
}
|
||||
auto target = arguments.at(0);
|
||||
if (target == "last")
|
||||
{
|
||||
this->notebook_->selectLastTab();
|
||||
}
|
||||
else if (target == "next")
|
||||
{
|
||||
this->notebook_->selectNextTab();
|
||||
}
|
||||
else if (target == "previous")
|
||||
{
|
||||
this->notebook_->selectPreviousTab();
|
||||
}
|
||||
else
|
||||
{
|
||||
bool ok;
|
||||
int result = target.toInt(&ok);
|
||||
if (ok)
|
||||
{
|
||||
this->notebook_->selectIndex(result);
|
||||
}
|
||||
else
|
||||
{
|
||||
qCWarning(chatterinoHotkeys)
|
||||
<< "Invalid argument for openTab shortcut";
|
||||
return QString("Invalid argument for openTab "
|
||||
"shortcut: \"%1\". Use \"last\", "
|
||||
"\"next\", \"previous\" or an integer.")
|
||||
.arg(target);
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}},
|
||||
{"popup",
|
||||
[this](std::vector<QString> arguments) -> QString {
|
||||
if (arguments.size() == 0)
|
||||
{
|
||||
return "popup action called without arguments. Takes only "
|
||||
"one: \"split\" or \"window\".";
|
||||
}
|
||||
if (arguments.at(0) == "split")
|
||||
{
|
||||
if (auto page = dynamic_cast<SplitContainer *>(
|
||||
this->notebook_->getSelectedPage()))
|
||||
{
|
||||
if (auto split = page->getSelectedSplit())
|
||||
{
|
||||
split->popup();
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (arguments.at(0) == "window")
|
||||
{
|
||||
if (auto page = dynamic_cast<SplitContainer *>(
|
||||
this->notebook_->getSelectedPage()))
|
||||
{
|
||||
page->popup();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return "Invalid popup target. Use \"split\" or \"window\".";
|
||||
}
|
||||
return "";
|
||||
}},
|
||||
{"zoom",
|
||||
[](std::vector<QString> arguments) -> QString {
|
||||
if (arguments.size() == 0)
|
||||
{
|
||||
qCWarning(chatterinoHotkeys)
|
||||
<< "zoom shortcut called without arguments. Takes "
|
||||
"only "
|
||||
"one argument: \"in\", \"out\", or \"reset\"";
|
||||
return "zoom shortcut called without arguments. Takes "
|
||||
"only "
|
||||
"one argument: \"in\", \"out\", or \"reset\"";
|
||||
}
|
||||
auto change = 0.0f;
|
||||
auto direction = arguments.at(0);
|
||||
if (direction == "reset")
|
||||
{
|
||||
getSettings()->uiScale.setValue(1);
|
||||
return "";
|
||||
}
|
||||
|
||||
// Switch tab
|
||||
createWindowShortcut(this, "CTRL+T", [this] {
|
||||
this->notebook_->getOrAddSelectedPage()->appendNewSplit(true);
|
||||
});
|
||||
if (direction == "in")
|
||||
{
|
||||
change = 0.1f;
|
||||
}
|
||||
else if (direction == "out")
|
||||
{
|
||||
change = -0.1f;
|
||||
}
|
||||
else
|
||||
{
|
||||
qCWarning(chatterinoHotkeys)
|
||||
<< "Invalid zoom direction, use \"in\", \"out\", or "
|
||||
"\"reset\"";
|
||||
return "Invalid zoom direction, use \"in\", \"out\", or "
|
||||
"\"reset\"";
|
||||
}
|
||||
getSettings()->setClampedUiScale(
|
||||
getSettings()->getClampedUiScale() + change);
|
||||
return "";
|
||||
}},
|
||||
{"newTab",
|
||||
[this](std::vector<QString>) -> QString {
|
||||
this->notebook_->addPage(true);
|
||||
return "";
|
||||
}},
|
||||
{"removeTab",
|
||||
[this](std::vector<QString>) -> QString {
|
||||
this->notebook_->removeCurrentPage();
|
||||
return "";
|
||||
}},
|
||||
{"reopenSplit",
|
||||
[this](std::vector<QString>) -> QString {
|
||||
if (ClosedSplits::empty())
|
||||
{
|
||||
return "";
|
||||
}
|
||||
ClosedSplits::SplitInfo si = ClosedSplits::pop();
|
||||
SplitContainer *splitContainer{nullptr};
|
||||
if (si.tab)
|
||||
{
|
||||
splitContainer = dynamic_cast<SplitContainer *>(si.tab->page);
|
||||
}
|
||||
if (!splitContainer)
|
||||
{
|
||||
splitContainer = this->notebook_->getOrAddSelectedPage();
|
||||
}
|
||||
this->notebook_->select(splitContainer);
|
||||
Split *split = new Split(splitContainer);
|
||||
split->setChannel(
|
||||
getApp()->twitch.server->getOrAddChannel(si.channelName));
|
||||
split->setFilters(si.filters);
|
||||
splitContainer->appendSplit(split);
|
||||
return "";
|
||||
}},
|
||||
{"toggleLocalR9K",
|
||||
[](std::vector<QString>) -> QString {
|
||||
getSettings()->hideSimilar.setValue(!getSettings()->hideSimilar);
|
||||
getApp()->windows->forceLayoutChannelViews();
|
||||
return "";
|
||||
}},
|
||||
{"openQuickSwitcher",
|
||||
[](std::vector<QString>) -> QString {
|
||||
auto quickSwitcher =
|
||||
new QuickSwitcherPopup(&getApp()->windows->getMainWindow());
|
||||
quickSwitcher->show();
|
||||
return "";
|
||||
}},
|
||||
{"quit",
|
||||
[](std::vector<QString>) -> QString {
|
||||
QApplication::exit();
|
||||
return "";
|
||||
}},
|
||||
{"moveTab",
|
||||
[this](std::vector<QString> arguments) -> QString {
|
||||
if (arguments.size() == 0)
|
||||
{
|
||||
qCWarning(chatterinoHotkeys)
|
||||
<< "moveTab shortcut called without arguments. "
|
||||
"Takes only one argument: new index (number, "
|
||||
"\"next\" "
|
||||
"or \"previous\")";
|
||||
return "moveTab shortcut called without arguments. "
|
||||
"Takes only one argument: new index (number, "
|
||||
"\"next\" "
|
||||
"or \"previous\")";
|
||||
}
|
||||
int newIndex = -1;
|
||||
bool indexIsGenerated =
|
||||
false; // indicates if `newIndex` was generated using target="next" or target="previous"
|
||||
|
||||
// CTRL + 1-8 to open corresponding tab.
|
||||
for (auto i = 0; i < 8; i++)
|
||||
{
|
||||
const auto openTab = [this, i] {
|
||||
this->notebook_->selectIndex(i);
|
||||
};
|
||||
createWindowShortcut(this, QString("CTRL+%1").arg(i + 1).toUtf8(),
|
||||
openTab);
|
||||
}
|
||||
auto target = arguments.at(0);
|
||||
qCDebug(chatterinoHotkeys) << target;
|
||||
if (target == "next")
|
||||
{
|
||||
newIndex = this->notebook_->getSelectedIndex() + 1;
|
||||
indexIsGenerated = true;
|
||||
}
|
||||
else if (target == "previous")
|
||||
{
|
||||
newIndex = this->notebook_->getSelectedIndex() - 1;
|
||||
indexIsGenerated = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
bool ok;
|
||||
int result = target.toInt(&ok);
|
||||
if (!ok)
|
||||
{
|
||||
qCWarning(chatterinoHotkeys)
|
||||
<< "Invalid argument for moveTab shortcut";
|
||||
return QString("Invalid argument for moveTab shortcut: "
|
||||
"%1. Use \"next\" or \"previous\" or an "
|
||||
"integer.")
|
||||
.arg(target);
|
||||
}
|
||||
newIndex = result;
|
||||
}
|
||||
if (newIndex >= this->notebook_->getPageCount() || 0 > newIndex)
|
||||
{
|
||||
if (indexIsGenerated)
|
||||
{
|
||||
return ""; // don't error out on generated indexes, ie move tab right
|
||||
}
|
||||
qCWarning(chatterinoHotkeys)
|
||||
<< "Invalid index for moveTab shortcut:" << newIndex;
|
||||
return QString("Invalid index for moveTab shortcut: %1.")
|
||||
.arg(newIndex);
|
||||
}
|
||||
this->notebook_->rearrangePage(this->notebook_->getSelectedPage(),
|
||||
newIndex);
|
||||
return "";
|
||||
}},
|
||||
{"setStreamerMode",
|
||||
[](std::vector<QString> arguments) -> QString {
|
||||
auto mode = 2;
|
||||
if (arguments.size() != 0)
|
||||
{
|
||||
auto arg = arguments.at(0);
|
||||
if (arg == "off")
|
||||
{
|
||||
mode = 0;
|
||||
}
|
||||
else if (arg == "on")
|
||||
{
|
||||
mode = 1;
|
||||
}
|
||||
else if (arg == "toggle")
|
||||
{
|
||||
mode = 2;
|
||||
}
|
||||
else if (arg == "auto")
|
||||
{
|
||||
mode = 3;
|
||||
}
|
||||
else
|
||||
{
|
||||
qCWarning(chatterinoHotkeys)
|
||||
<< "Invalid argument for setStreamerMode hotkey: "
|
||||
<< arg;
|
||||
return QString("Invalid argument for setStreamerMode "
|
||||
"hotkey: %1. Use \"on\", \"off\", "
|
||||
"\"toggle\" or \"auto\".")
|
||||
.arg(arg);
|
||||
}
|
||||
}
|
||||
|
||||
createWindowShortcut(this, "CTRL+9", [this] {
|
||||
this->notebook_->selectLastTab();
|
||||
});
|
||||
if (mode == 0)
|
||||
{
|
||||
getSettings()->enableStreamerMode.setValue(
|
||||
StreamerModeSetting::Disabled);
|
||||
}
|
||||
else if (mode == 1)
|
||||
{
|
||||
getSettings()->enableStreamerMode.setValue(
|
||||
StreamerModeSetting::Enabled);
|
||||
}
|
||||
else if (mode == 2)
|
||||
{
|
||||
if (isInStreamerMode())
|
||||
{
|
||||
getSettings()->enableStreamerMode.setValue(
|
||||
StreamerModeSetting::Disabled);
|
||||
}
|
||||
else
|
||||
{
|
||||
getSettings()->enableStreamerMode.setValue(
|
||||
StreamerModeSetting::Enabled);
|
||||
}
|
||||
}
|
||||
else if (mode == 3)
|
||||
{
|
||||
getSettings()->enableStreamerMode.setValue(
|
||||
StreamerModeSetting::DetectObs);
|
||||
}
|
||||
return "";
|
||||
}},
|
||||
{"setTabVisibility",
|
||||
[this](std::vector<QString> arguments) -> QString {
|
||||
auto mode = 2;
|
||||
if (arguments.size() != 0)
|
||||
{
|
||||
auto arg = arguments.at(0);
|
||||
if (arg == "off")
|
||||
{
|
||||
mode = 0;
|
||||
}
|
||||
else if (arg == "on")
|
||||
{
|
||||
mode = 1;
|
||||
}
|
||||
else if (arg == "toggle")
|
||||
{
|
||||
mode = 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
qCWarning(chatterinoHotkeys)
|
||||
<< "Invalid argument for setStreamerMode hotkey: "
|
||||
<< arg;
|
||||
return QString("Invalid argument for setTabVisibility "
|
||||
"hotkey: %1. Use \"on\", \"off\" or "
|
||||
"\"toggle\".")
|
||||
.arg(arg);
|
||||
}
|
||||
}
|
||||
|
||||
createWindowShortcut(this, "CTRL+TAB", [this] {
|
||||
this->notebook_->selectNextTab();
|
||||
});
|
||||
createWindowShortcut(this, "CTRL+SHIFT+TAB", [this] {
|
||||
this->notebook_->selectPreviousTab();
|
||||
});
|
||||
if (mode == 0)
|
||||
{
|
||||
this->notebook_->setShowTabs(false);
|
||||
}
|
||||
else if (mode == 1)
|
||||
{
|
||||
this->notebook_->setShowTabs(true);
|
||||
}
|
||||
else if (mode == 2)
|
||||
{
|
||||
this->notebook_->setShowTabs(!this->notebook_->getShowTabs());
|
||||
}
|
||||
return "";
|
||||
}},
|
||||
};
|
||||
|
||||
createWindowShortcut(this, "CTRL+N", [this] {
|
||||
if (auto page = dynamic_cast<SplitContainer *>(
|
||||
this->notebook_->getSelectedPage()))
|
||||
{
|
||||
if (auto split = page->getSelectedSplit())
|
||||
{
|
||||
split->popup();
|
||||
}
|
||||
}
|
||||
});
|
||||
this->addDebugStuff(actions);
|
||||
|
||||
createWindowShortcut(this, "CTRL+SHIFT+N", [this] {
|
||||
if (auto page = dynamic_cast<SplitContainer *>(
|
||||
this->notebook_->getSelectedPage()))
|
||||
{
|
||||
page->popup();
|
||||
}
|
||||
});
|
||||
|
||||
// Zoom in
|
||||
{
|
||||
auto s = new QShortcut(QKeySequence::ZoomIn, this);
|
||||
s->setContext(Qt::WindowShortcut);
|
||||
QObject::connect(s, &QShortcut::activated, this, [] {
|
||||
getSettings()->setClampedUiScale(
|
||||
getSettings()->getClampedUiScale() + 0.1f);
|
||||
});
|
||||
}
|
||||
|
||||
// Zoom out
|
||||
{
|
||||
auto s = new QShortcut(QKeySequence::ZoomOut, this);
|
||||
s->setContext(Qt::WindowShortcut);
|
||||
QObject::connect(s, &QShortcut::activated, this, [] {
|
||||
getSettings()->setClampedUiScale(
|
||||
getSettings()->getClampedUiScale() - 0.1f);
|
||||
});
|
||||
}
|
||||
|
||||
// New tab
|
||||
createWindowShortcut(this, "CTRL+SHIFT+T", [this] {
|
||||
this->notebook_->addPage(true);
|
||||
});
|
||||
|
||||
// Close tab
|
||||
createWindowShortcut(this, "CTRL+SHIFT+W", [this] {
|
||||
this->notebook_->removeCurrentPage();
|
||||
});
|
||||
|
||||
// Reopen last closed split
|
||||
createWindowShortcut(this, "CTRL+G", [this] {
|
||||
if (ClosedSplits::empty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
ClosedSplits::SplitInfo si = ClosedSplits::pop();
|
||||
SplitContainer *splitContainer{nullptr};
|
||||
if (si.tab)
|
||||
{
|
||||
splitContainer = dynamic_cast<SplitContainer *>(si.tab->page);
|
||||
}
|
||||
if (!splitContainer)
|
||||
{
|
||||
splitContainer = this->notebook_->getOrAddSelectedPage();
|
||||
}
|
||||
this->notebook_->select(splitContainer);
|
||||
Split *split = new Split(splitContainer);
|
||||
split->setChannel(
|
||||
getApp()->twitch.server->getOrAddChannel(si.channelName));
|
||||
split->setFilters(si.filters);
|
||||
splitContainer->appendSplit(split);
|
||||
});
|
||||
|
||||
createWindowShortcut(this, "CTRL+H", [] {
|
||||
getSettings()->hideSimilar.setValue(!getSettings()->hideSimilar);
|
||||
getApp()->windows->forceLayoutChannelViews();
|
||||
});
|
||||
|
||||
createWindowShortcut(this, "CTRL+K", [this] {
|
||||
auto quickSwitcher =
|
||||
new QuickSwitcherPopup(&getApp()->windows->getMainWindow());
|
||||
quickSwitcher->show();
|
||||
});
|
||||
|
||||
createWindowShortcut(this, "CTRL+U", [this] {
|
||||
this->notebook_->setShowTabs(!this->notebook_->getShowTabs());
|
||||
});
|
||||
this->shortcuts_ = getApp()->hotkeys->shortcutsForCategory(
|
||||
HotkeyCategory::Window, actions, this);
|
||||
}
|
||||
|
||||
void Window::addMenuBar()
|
||||
|
||||
@@ -33,8 +33,10 @@ protected:
|
||||
|
||||
private:
|
||||
void addCustomTitlebarButtons();
|
||||
void addDebugStuff();
|
||||
void addShortcuts();
|
||||
void addDebugStuff(
|
||||
std::map<QString, std::function<QString(std::vector<QString>)>>
|
||||
&actions);
|
||||
void addShortcuts() override;
|
||||
void addLayout();
|
||||
void onAccountSelected();
|
||||
void addMenuBar();
|
||||
|
||||
@@ -106,6 +106,10 @@ ColorPickerDialog::ColorPickerDialog(const QColor &initial, QWidget *parent)
|
||||
this->selectColor(initial, false);
|
||||
}
|
||||
|
||||
void ColorPickerDialog::addShortcuts()
|
||||
{
|
||||
}
|
||||
|
||||
ColorPickerDialog::~ColorPickerDialog()
|
||||
{
|
||||
if (this->htmlColorValidator_)
|
||||
|
||||
@@ -108,5 +108,7 @@ private:
|
||||
void initColorPicker(LayoutCreator<QWidget> &creator);
|
||||
void initSpinBoxes(LayoutCreator<QWidget> &creator);
|
||||
void initHtmlColor(LayoutCreator<QWidget> &creator);
|
||||
|
||||
void addShortcuts() override;
|
||||
};
|
||||
} // namespace chatterino
|
||||
|
||||
@@ -0,0 +1,312 @@
|
||||
#include "widgets/dialogs/EditHotkeyDialog.hpp"
|
||||
|
||||
#include "Application.hpp"
|
||||
#include "common/QLogging.hpp"
|
||||
#include "controllers/hotkeys/ActionNames.hpp"
|
||||
#include "controllers/hotkeys/HotkeyController.hpp"
|
||||
#include "controllers/hotkeys/HotkeyHelpers.hpp"
|
||||
#include "ui_EditHotkeyDialog.h"
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
EditHotkeyDialog::EditHotkeyDialog(const std::shared_ptr<Hotkey> hotkey,
|
||||
bool isAdd, QWidget *parent)
|
||||
: QDialog(parent, Qt::WindowStaysOnTopHint)
|
||||
, ui_(new Ui::EditHotkeyDialog)
|
||||
, data_(hotkey)
|
||||
{
|
||||
this->ui_->setupUi(this);
|
||||
// dynamically add category names to the category picker
|
||||
for (const auto &[_, hotkeyCategory] : getApp()->hotkeys->categories())
|
||||
{
|
||||
this->ui_->categoryPicker->addItem(hotkeyCategory.displayName,
|
||||
hotkeyCategory.name);
|
||||
}
|
||||
|
||||
this->ui_->warningLabel->hide();
|
||||
|
||||
if (hotkey)
|
||||
{
|
||||
if (!hotkey->validAction())
|
||||
{
|
||||
this->showEditError("Invalid action, make sure you select the "
|
||||
"correct action before saving.");
|
||||
}
|
||||
|
||||
// editing a hotkey
|
||||
|
||||
// update pickers/input boxes to values from Hotkey object
|
||||
this->ui_->categoryPicker->setCurrentIndex(size_t(hotkey->category()));
|
||||
this->ui_->keyComboEdit->setKeySequence(
|
||||
QKeySequence::fromString(hotkey->keySequence().toString()));
|
||||
this->ui_->nameEdit->setText(hotkey->name());
|
||||
// update arguments
|
||||
QString argsText;
|
||||
bool first = true;
|
||||
for (const auto &arg : hotkey->arguments())
|
||||
{
|
||||
if (!first)
|
||||
{
|
||||
argsText += '\n';
|
||||
}
|
||||
|
||||
argsText += arg;
|
||||
|
||||
first = false;
|
||||
}
|
||||
this->ui_->argumentsEdit->setPlainText(argsText);
|
||||
}
|
||||
else
|
||||
{
|
||||
// adding a new hotkey
|
||||
this->setWindowTitle("Add hotkey");
|
||||
this->ui_->categoryPicker->setCurrentIndex(
|
||||
size_t(HotkeyCategory::SplitInput));
|
||||
this->ui_->argumentsEdit->setPlainText("");
|
||||
}
|
||||
}
|
||||
|
||||
EditHotkeyDialog::~EditHotkeyDialog()
|
||||
{
|
||||
delete this->ui_;
|
||||
}
|
||||
|
||||
std::shared_ptr<Hotkey> EditHotkeyDialog::data()
|
||||
{
|
||||
return this->data_;
|
||||
}
|
||||
|
||||
void EditHotkeyDialog::afterEdit()
|
||||
{
|
||||
auto arguments =
|
||||
parseHotkeyArguments(this->ui_->argumentsEdit->toPlainText());
|
||||
|
||||
auto category = getApp()->hotkeys->hotkeyCategoryFromName(
|
||||
this->ui_->categoryPicker->currentData().toString());
|
||||
if (!category)
|
||||
{
|
||||
this->showEditError("Invalid Hotkey Category.");
|
||||
|
||||
return;
|
||||
}
|
||||
QString nameText = this->ui_->nameEdit->text();
|
||||
|
||||
// check if another hotkey with this name exists, accounts for editing a hotkey
|
||||
bool isEditing = bool(this->data_);
|
||||
if (getApp()->hotkeys->getHotkeyByName(nameText))
|
||||
{
|
||||
// A hotkey with this name already exists
|
||||
if (isEditing && this->data()->name() == nameText)
|
||||
{
|
||||
// The hotkey that already exists is the one we are editing
|
||||
}
|
||||
else
|
||||
{
|
||||
// The user is either creating a hotkey with a name that already exists, or
|
||||
// the user is editing an already-existing hotkey and changing its name to a hotkey that already exists
|
||||
this->showEditError("Hotkey with this name already exists.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (nameText.isEmpty())
|
||||
{
|
||||
this->showEditError("Hotkey name is missing");
|
||||
return;
|
||||
}
|
||||
if (this->ui_->keyComboEdit->keySequence().count() == 0)
|
||||
{
|
||||
this->showEditError("Key Sequence is missing");
|
||||
return;
|
||||
}
|
||||
if (this->ui_->actionPicker->currentText().isEmpty())
|
||||
{
|
||||
this->showEditError("Action name cannot be empty");
|
||||
return;
|
||||
}
|
||||
|
||||
auto firstKeyInt = this->ui_->keyComboEdit->keySequence()[0];
|
||||
bool hasModifier = ((firstKeyInt & Qt::CTRL) == Qt::CTRL) ||
|
||||
((firstKeyInt & Qt::ALT) == Qt::ALT) ||
|
||||
((firstKeyInt & Qt::META) == Qt::META);
|
||||
bool isKeyExcempt = ((firstKeyInt & Qt::Key_Escape) == Qt::Key_Escape) ||
|
||||
((firstKeyInt & Qt::Key_Enter) == Qt::Key_Enter) ||
|
||||
((firstKeyInt & Qt::Key_Return) == Qt::Key_Return);
|
||||
|
||||
if (!isKeyExcempt && !hasModifier && !this->shownSingleKeyWarning)
|
||||
{
|
||||
this->showEditError(
|
||||
"Warning: using keybindings without modifiers can lead to not "
|
||||
"being\nable to use the key for the normal purpose.\nPress the "
|
||||
"submit button again to do it anyway.");
|
||||
this->shownSingleKeyWarning = true;
|
||||
return;
|
||||
}
|
||||
|
||||
// use raw name from item data if possible, otherwise fallback to what the user has entered.
|
||||
auto actionTemp = this->ui_->actionPicker->currentData();
|
||||
QString action = this->ui_->actionPicker->currentText();
|
||||
if (actionTemp.isValid())
|
||||
{
|
||||
action = actionTemp.toString();
|
||||
}
|
||||
|
||||
auto hotkey = std::make_shared<Hotkey>(
|
||||
*category, this->ui_->keyComboEdit->keySequence(), action, arguments,
|
||||
nameText);
|
||||
auto keyComboWasEdited =
|
||||
this->data() &&
|
||||
this->ui_->keyComboEdit->keySequence() != this->data()->keySequence();
|
||||
auto nameWasEdited = this->data() && nameText != this->data()->name();
|
||||
|
||||
if (isEditing)
|
||||
{
|
||||
if (keyComboWasEdited || nameWasEdited)
|
||||
{
|
||||
if (getApp()->hotkeys->isDuplicate(hotkey, this->data()->name()))
|
||||
{
|
||||
this->showEditError(
|
||||
"Keybinding needs to be unique in the category.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (getApp()->hotkeys->isDuplicate(hotkey, QString()))
|
||||
{
|
||||
this->showEditError(
|
||||
"Keybinding needs to be unique in the category.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
this->data_ = hotkey;
|
||||
this->accept();
|
||||
}
|
||||
|
||||
void EditHotkeyDialog::updatePossibleActions()
|
||||
{
|
||||
const auto &hotkeys = getApp()->hotkeys;
|
||||
auto category = hotkeys->hotkeyCategoryFromName(
|
||||
this->ui_->categoryPicker->currentData().toString());
|
||||
if (!category)
|
||||
{
|
||||
this->showEditError("Invalid Hotkey Category.");
|
||||
|
||||
return;
|
||||
}
|
||||
auto currentText = this->ui_->actionPicker->currentData().toString();
|
||||
if (this->data_ &&
|
||||
(currentText.isEmpty() || this->data_->category() == category))
|
||||
{
|
||||
// is editing
|
||||
currentText = this->data_->action();
|
||||
}
|
||||
this->ui_->actionPicker->clear();
|
||||
qCDebug(chatterinoHotkeys)
|
||||
<< "update possible actions for" << (int)*category << currentText;
|
||||
auto actions = actionNames.find(*category);
|
||||
if (actions != actionNames.end())
|
||||
{
|
||||
int indexToSet = -1;
|
||||
for (const auto &action : actions->second)
|
||||
{
|
||||
this->ui_->actionPicker->addItem(action.second.displayName,
|
||||
action.first);
|
||||
if (action.first == currentText)
|
||||
{
|
||||
// update action raw name to display name
|
||||
indexToSet = this->ui_->actionPicker->model()->rowCount() - 1;
|
||||
}
|
||||
}
|
||||
if (indexToSet != -1)
|
||||
{
|
||||
this->ui_->actionPicker->setCurrentIndex(indexToSet);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
qCDebug(chatterinoHotkeys) << "key missing!!!!";
|
||||
}
|
||||
}
|
||||
|
||||
void EditHotkeyDialog::updateArgumentsInput()
|
||||
{
|
||||
auto currentText = this->ui_->actionPicker->currentData().toString();
|
||||
if (currentText.isEmpty())
|
||||
{
|
||||
this->ui_->argumentsEdit->setEnabled(true);
|
||||
return;
|
||||
}
|
||||
const auto &hotkeys = getApp()->hotkeys;
|
||||
auto category = hotkeys->hotkeyCategoryFromName(
|
||||
this->ui_->categoryPicker->currentData().toString());
|
||||
if (!category)
|
||||
{
|
||||
this->showEditError("Invalid Hotkey category.");
|
||||
|
||||
return;
|
||||
}
|
||||
auto allActions = actionNames.find(*category);
|
||||
if (allActions != actionNames.end())
|
||||
{
|
||||
const auto &actionsMap = allActions->second;
|
||||
auto definition = actionsMap.find(currentText);
|
||||
if (definition == actionsMap.end())
|
||||
{
|
||||
auto text = QString("Newline separated arguments for the action\n"
|
||||
" - Unable to find action named \"%1\"")
|
||||
.arg(currentText);
|
||||
this->ui_->argumentsEdit->setPlaceholderText(text);
|
||||
return;
|
||||
}
|
||||
const ActionDefinition &def = definition->second;
|
||||
|
||||
if (def.maxCountArguments != 0)
|
||||
{
|
||||
QString text =
|
||||
"Arguments wrapped in <> are required.\nArguments wrapped in "
|
||||
"[] "
|
||||
"are optional.\nArguments are separated by a newline.";
|
||||
if (!def.argumentDescription.isEmpty())
|
||||
{
|
||||
this->ui_->argumentsDescription->setVisible(true);
|
||||
this->ui_->argumentsDescription->setText(
|
||||
def.argumentDescription);
|
||||
}
|
||||
else
|
||||
{
|
||||
this->ui_->argumentsDescription->setVisible(false);
|
||||
}
|
||||
|
||||
text = QString("Arguments wrapped in <> are required.");
|
||||
if (def.maxCountArguments != def.minCountArguments)
|
||||
{
|
||||
text += QString("\nArguments wrapped in [] are optional.");
|
||||
}
|
||||
|
||||
text += "\nArguments are separated by a newline.";
|
||||
|
||||
this->ui_->argumentsEdit->setEnabled(true);
|
||||
this->ui_->argumentsEdit->setPlaceholderText(text);
|
||||
|
||||
this->ui_->argumentsLabel->setVisible(true);
|
||||
this->ui_->argumentsDescription->setVisible(true);
|
||||
this->ui_->argumentsEdit->setVisible(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
this->ui_->argumentsLabel->setVisible(false);
|
||||
this->ui_->argumentsDescription->setVisible(false);
|
||||
this->ui_->argumentsEdit->setVisible(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void EditHotkeyDialog::showEditError(QString errorText)
|
||||
{
|
||||
this->ui_->warningLabel->setText(errorText);
|
||||
this->ui_->warningLabel->show();
|
||||
}
|
||||
|
||||
} // namespace chatterino
|
||||
@@ -0,0 +1,59 @@
|
||||
#pragma once
|
||||
|
||||
#include "controllers/hotkeys/Hotkey.hpp"
|
||||
|
||||
#include <QDialog>
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace Ui {
|
||||
|
||||
class EditHotkeyDialog;
|
||||
|
||||
} // namespace Ui
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
class EditHotkeyDialog : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit EditHotkeyDialog(const std::shared_ptr<Hotkey> data,
|
||||
bool isAdd = false, QWidget *parent = nullptr);
|
||||
~EditHotkeyDialog() final;
|
||||
|
||||
std::shared_ptr<Hotkey> data();
|
||||
|
||||
protected slots:
|
||||
/**
|
||||
* @brief validates the hotkey
|
||||
*
|
||||
* fired by the ok button
|
||||
**/
|
||||
void afterEdit();
|
||||
|
||||
/**
|
||||
* @brief updates the list of actions based on the category
|
||||
*
|
||||
* fired by the category picker changing
|
||||
**/
|
||||
void updatePossibleActions();
|
||||
|
||||
/**
|
||||
* @brief updates the arguments description and input visibility
|
||||
*
|
||||
* fired by the action picker changing
|
||||
**/
|
||||
void updateArgumentsInput();
|
||||
|
||||
private:
|
||||
void showEditError(QString errorText);
|
||||
|
||||
Ui::EditHotkeyDialog *ui_;
|
||||
std::shared_ptr<Hotkey> data_;
|
||||
|
||||
bool shownSingleKeyWarning = false;
|
||||
};
|
||||
|
||||
} // namespace chatterino
|
||||
@@ -0,0 +1,235 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>EditHotkeyDialog</class>
|
||||
<widget class="QDialog" name="EditHotkeyDialog">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>400</width>
|
||||
<height>300</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Edit Hotkey</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QLabel" name="warningLabel">
|
||||
<property name="enabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Maximum">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="font">
|
||||
<font>
|
||||
<weight>75</weight>
|
||||
<bold>true</bold>
|
||||
<kerning>true</kerning>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Something went wrong, you should never
|
||||
see this message :)</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QFormLayout" name="formLayout">
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="nameLabel">
|
||||
<property name="text">
|
||||
<string>Name:</string>
|
||||
</property>
|
||||
<property name="buddy">
|
||||
<cstring>nameEdit</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QLineEdit" name="nameEdit">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="frame">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="readOnly">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="placeholderText">
|
||||
<string>A description of what the hotkey does.</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="categoryLabel">
|
||||
<property name="text">
|
||||
<string>Category:</string>
|
||||
</property>
|
||||
<property name="buddy">
|
||||
<cstring>categoryPicker</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="actionLabel">
|
||||
<property name="text">
|
||||
<string>Action:</string>
|
||||
</property>
|
||||
<property name="buddy">
|
||||
<cstring>actionPicker</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QComboBox" name="actionPicker">
|
||||
<property name="editable">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<widget class="QLabel" name="keyComboLabel">
|
||||
<property name="text">
|
||||
<string>Keybinding:</string>
|
||||
</property>
|
||||
<property name="buddy">
|
||||
<cstring>keyComboEdit</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="1">
|
||||
<widget class="QKeySequenceEdit" name="keyComboEdit"/>
|
||||
</item>
|
||||
<item row="4" column="0">
|
||||
<widget class="QLabel" name="argumentsLabel">
|
||||
<property name="text">
|
||||
<string>Arguments:</string>
|
||||
</property>
|
||||
<property name="buddy">
|
||||
<cstring>argumentsEdit</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="1">
|
||||
<widget class="QLabel" name="argumentsDescription">
|
||||
<property name="text">
|
||||
<string>You should never see this message :)</string>
|
||||
</property>
|
||||
<property name="buddy">
|
||||
<cstring>argumentsDescription</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="1">
|
||||
<widget class="QPlainTextEdit" name="argumentsEdit">
|
||||
<property name="plainText">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="placeholderText">
|
||||
<string>Newline separated arguments for the action</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QComboBox" name="categoryPicker"/>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QDialogButtonBox" name="buttons">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<tabstops>
|
||||
<tabstop>nameEdit</tabstop>
|
||||
<tabstop>categoryPicker</tabstop>
|
||||
<tabstop>actionPicker</tabstop>
|
||||
<tabstop>keyComboEdit</tabstop>
|
||||
<tabstop>argumentsEdit</tabstop>
|
||||
</tabstops>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>buttons</sender>
|
||||
<signal>accepted()</signal>
|
||||
<receiver>EditHotkeyDialog</receiver>
|
||||
<slot>afterEdit()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>257</x>
|
||||
<y>290</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>157</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>buttons</sender>
|
||||
<signal>rejected()</signal>
|
||||
<receiver>EditHotkeyDialog</receiver>
|
||||
<slot>reject()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>325</x>
|
||||
<y>290</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>286</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>categoryPicker</sender>
|
||||
<signal>currentIndexChanged(int)</signal>
|
||||
<receiver>EditHotkeyDialog</receiver>
|
||||
<slot>updatePossibleActions()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>246</x>
|
||||
<y>85</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>75</x>
|
||||
<y>218</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>actionPicker</sender>
|
||||
<signal>currentIndexChanged(int)</signal>
|
||||
<receiver>EditHotkeyDialog</receiver>
|
||||
<slot>updateArgumentsInput()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>148</x>
|
||||
<y>119</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>74</x>
|
||||
<y>201</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
<slots>
|
||||
<slot>afterEdit()</slot>
|
||||
<slot>updatePossibleActions()</slot>
|
||||
<slot>updateArgumentsInput()</slot>
|
||||
</slots>
|
||||
</ui>
|
||||
@@ -2,7 +2,9 @@
|
||||
|
||||
#include "Application.hpp"
|
||||
#include "common/CompletionModel.hpp"
|
||||
#include "common/QLogging.hpp"
|
||||
#include "controllers/accounts/AccountController.hpp"
|
||||
#include "controllers/hotkeys/HotkeyController.hpp"
|
||||
#include "debug/Benchmark.hpp"
|
||||
#include "messages/Message.hpp"
|
||||
#include "messages/MessageBuilder.hpp"
|
||||
@@ -10,13 +12,11 @@
|
||||
#include "providers/twitch/TwitchIrcServer.hpp"
|
||||
#include "singletons/Emotes.hpp"
|
||||
#include "singletons/WindowManager.hpp"
|
||||
#include "util/Shortcut.hpp"
|
||||
#include "widgets/Notebook.hpp"
|
||||
#include "widgets/Scrollbar.hpp"
|
||||
#include "widgets/helper/ChannelView.hpp"
|
||||
|
||||
#include <QHBoxLayout>
|
||||
#include <QShortcut>
|
||||
#include <QTabWidget>
|
||||
|
||||
namespace chatterino {
|
||||
@@ -137,8 +137,8 @@ EmotePopup::EmotePopup(QWidget *parent)
|
||||
auto layout = new QVBoxLayout(this);
|
||||
this->getLayoutContainer()->setLayout(layout);
|
||||
|
||||
auto notebook = new Notebook(this);
|
||||
layout->addWidget(notebook);
|
||||
this->notebook_ = new Notebook(this);
|
||||
layout->addWidget(this->notebook_);
|
||||
layout->setMargin(0);
|
||||
|
||||
auto clicked = [this](const Link &link) {
|
||||
@@ -152,7 +152,7 @@ EmotePopup::EmotePopup(QWidget *parent)
|
||||
MessageElementFlag::Default, MessageElementFlag::AlwaysShow,
|
||||
MessageElementFlag::EmoteImages});
|
||||
view->setEnableScrollingToBottom(false);
|
||||
notebook->addPage(view, tabTitle);
|
||||
this->notebook_->addPage(view, tabTitle);
|
||||
view->linkClicked.connect(clicked);
|
||||
|
||||
return view;
|
||||
@@ -164,43 +164,99 @@ EmotePopup::EmotePopup(QWidget *parent)
|
||||
this->viewEmojis_ = makeView("Emojis");
|
||||
|
||||
this->loadEmojis();
|
||||
this->addShortcuts();
|
||||
this->signalHolder_.managedConnect(getApp()->hotkeys->onItemsUpdated,
|
||||
[this]() {
|
||||
this->clearShortcuts();
|
||||
this->addShortcuts();
|
||||
});
|
||||
}
|
||||
void EmotePopup::addShortcuts()
|
||||
{
|
||||
HotkeyController::HotkeyMap actions{
|
||||
{"openTab", // CTRL + 1-8 to open corresponding tab.
|
||||
[this](std::vector<QString> arguments) -> QString {
|
||||
if (arguments.size() == 0)
|
||||
{
|
||||
qCWarning(chatterinoHotkeys)
|
||||
<< "openTab shortcut called without arguments. Takes "
|
||||
"only one argument: tab specifier";
|
||||
return "openTab shortcut called without arguments. "
|
||||
"Takes only one argument: tab specifier";
|
||||
}
|
||||
auto target = arguments.at(0);
|
||||
if (target == "last")
|
||||
{
|
||||
this->notebook_->selectLastTab();
|
||||
}
|
||||
else if (target == "next")
|
||||
{
|
||||
this->notebook_->selectNextTab();
|
||||
}
|
||||
else if (target == "previous")
|
||||
{
|
||||
this->notebook_->selectPreviousTab();
|
||||
}
|
||||
else
|
||||
{
|
||||
bool ok;
|
||||
int result = target.toInt(&ok);
|
||||
if (ok)
|
||||
{
|
||||
this->notebook_->selectIndex(result);
|
||||
}
|
||||
else
|
||||
{
|
||||
qCWarning(chatterinoHotkeys)
|
||||
<< "Invalid argument for openTab shortcut";
|
||||
return QString("Invalid argument for openTab "
|
||||
"shortcut: \"%1\". Use \"last\", "
|
||||
"\"next\", \"previous\" or an integer.")
|
||||
.arg(target);
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}},
|
||||
{"delete",
|
||||
[this](std::vector<QString>) -> QString {
|
||||
this->close();
|
||||
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 channelView = dynamic_cast<ChannelView *>(
|
||||
this->notebook_->getSelectedPage());
|
||||
|
||||
// CTRL + 1-8 to open corresponding tab
|
||||
for (auto i = 0; i < 8; i++)
|
||||
{
|
||||
const auto openTab = [this, i, notebook] {
|
||||
notebook->selectIndex(i);
|
||||
};
|
||||
createWindowShortcut(this, QString("CTRL+%1").arg(i + 1).toUtf8(),
|
||||
openTab);
|
||||
}
|
||||
auto &scrollbar = channelView->getScrollBar();
|
||||
if (direction == "up")
|
||||
{
|
||||
scrollbar.offset(-scrollbar.getLargeChange());
|
||||
}
|
||||
else if (direction == "down")
|
||||
{
|
||||
scrollbar.offset(scrollbar.getLargeChange());
|
||||
}
|
||||
else
|
||||
{
|
||||
qCWarning(chatterinoHotkeys) << "Unknown scroll direction";
|
||||
}
|
||||
return "";
|
||||
}},
|
||||
|
||||
// Open last tab (first one from right)
|
||||
createWindowShortcut(this, "CTRL+9", [=] {
|
||||
notebook->selectLastTab();
|
||||
});
|
||||
{"reject", nullptr},
|
||||
{"accept", nullptr},
|
||||
{"search", nullptr},
|
||||
};
|
||||
|
||||
// Cycle through tabs
|
||||
createWindowShortcut(this, "CTRL+Tab", [=] {
|
||||
notebook->selectNextTab();
|
||||
});
|
||||
createWindowShortcut(this, "CTRL+Shift+Tab", [=] {
|
||||
notebook->selectPreviousTab();
|
||||
});
|
||||
|
||||
// Scroll with Page Up / Page Down
|
||||
createWindowShortcut(this, "PgUp", [=] {
|
||||
auto &scrollbar =
|
||||
dynamic_cast<ChannelView *>(notebook->getSelectedPage())
|
||||
->getScrollBar();
|
||||
scrollbar.offset(-scrollbar.getLargeChange());
|
||||
});
|
||||
createWindowShortcut(this, "PgDown", [=] {
|
||||
auto &scrollbar =
|
||||
dynamic_cast<ChannelView *>(notebook->getSelectedPage())
|
||||
->getScrollBar();
|
||||
scrollbar.offset(scrollbar.getLargeChange());
|
||||
});
|
||||
this->shortcuts_ = getApp()->hotkeys->shortcutsForCategory(
|
||||
HotkeyCategory::PopupWindow, actions, this);
|
||||
}
|
||||
|
||||
void EmotePopup::loadChannel(ChannelPtr _channel)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "widgets/BasePopup.hpp"
|
||||
#include "widgets/Notebook.hpp"
|
||||
|
||||
#include <pajlada/signals/signal.hpp>
|
||||
|
||||
@@ -28,6 +29,9 @@ private:
|
||||
ChannelView *channelEmotesView_{};
|
||||
ChannelView *subEmotesView_{};
|
||||
ChannelView *viewEmojis_{};
|
||||
|
||||
Notebook *notebook_;
|
||||
void addShortcuts() override;
|
||||
};
|
||||
|
||||
} // namespace chatterino
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
#include "SelectChannelDialog.hpp"
|
||||
|
||||
#include "Application.hpp"
|
||||
#include "common/QLogging.hpp"
|
||||
#include "controllers/hotkeys/HotkeyController.hpp"
|
||||
#include "providers/twitch/TwitchIrcServer.hpp"
|
||||
#include "singletons/Theme.hpp"
|
||||
#include "util/LayoutCreator.hpp"
|
||||
#include "util/Shortcut.hpp"
|
||||
#include "widgets/Notebook.hpp"
|
||||
#include "widgets/dialogs/IrcConnectionEditor.hpp"
|
||||
#include "widgets/helper/NotebookTab.hpp"
|
||||
@@ -237,27 +238,15 @@ SelectChannelDialog::SelectChannelDialog(QWidget *parent)
|
||||
this->ui_.notebook->selectIndex(TAB_TWITCH);
|
||||
this->ui_.twitch.channel->setFocus();
|
||||
|
||||
// Shortcuts
|
||||
createWindowShortcut(this, "Return", [=] {
|
||||
this->ok();
|
||||
});
|
||||
createWindowShortcut(this, "Esc", [=] {
|
||||
this->close();
|
||||
});
|
||||
|
||||
// restore ui state
|
||||
// fourtf: enable when releasing irc
|
||||
if (getSettings()->enableExperimentalIrc)
|
||||
{
|
||||
this->ui_.notebook->selectIndex(getSettings()->lastSelectChannelTab);
|
||||
createWindowShortcut(this, "Ctrl+Tab", [=] {
|
||||
this->ui_.notebook->selectNextTab();
|
||||
});
|
||||
createWindowShortcut(this, "CTRL+Shift+Tab", [=] {
|
||||
this->ui_.notebook->selectPreviousTab();
|
||||
});
|
||||
}
|
||||
|
||||
this->addShortcuts();
|
||||
|
||||
this->ui_.irc.servers->getTableView()->selectRow(
|
||||
getSettings()->lastSelectIrcConn);
|
||||
}
|
||||
@@ -516,4 +505,80 @@ void SelectChannelDialog::themeChangedEvent()
|
||||
}
|
||||
}
|
||||
|
||||
void SelectChannelDialog::addShortcuts()
|
||||
{
|
||||
HotkeyController::HotkeyMap actions{
|
||||
{"accept",
|
||||
[this](std::vector<QString>) -> QString {
|
||||
this->ok();
|
||||
return "";
|
||||
}},
|
||||
{"reject",
|
||||
[this](std::vector<QString>) -> QString {
|
||||
this->close();
|
||||
return "";
|
||||
}},
|
||||
|
||||
// these make no sense, so they aren't implemented
|
||||
{"scrollPage", nullptr},
|
||||
{"search", nullptr},
|
||||
{"delete", nullptr},
|
||||
};
|
||||
|
||||
if (getSettings()->enableExperimentalIrc)
|
||||
{
|
||||
actions.insert(
|
||||
{"openTab", [this](std::vector<QString> arguments) -> QString {
|
||||
if (arguments.size() == 0)
|
||||
{
|
||||
qCWarning(chatterinoHotkeys)
|
||||
<< "openTab shortcut called without arguments. "
|
||||
"Takes only "
|
||||
"one argument: tab specifier";
|
||||
return "openTab shortcut called without arguments. "
|
||||
"Takes only one argument: tab specifier";
|
||||
}
|
||||
auto target = arguments.at(0);
|
||||
if (target == "last")
|
||||
{
|
||||
this->ui_.notebook->selectLastTab();
|
||||
}
|
||||
else if (target == "next")
|
||||
{
|
||||
this->ui_.notebook->selectNextTab();
|
||||
}
|
||||
else if (target == "previous")
|
||||
{
|
||||
this->ui_.notebook->selectPreviousTab();
|
||||
}
|
||||
else
|
||||
{
|
||||
bool ok;
|
||||
int result = target.toInt(&ok);
|
||||
if (ok)
|
||||
{
|
||||
this->ui_.notebook->selectIndex(result);
|
||||
}
|
||||
else
|
||||
{
|
||||
qCWarning(chatterinoHotkeys)
|
||||
<< "Invalid argument for openTab shortcut";
|
||||
return QString("Invalid argument for openTab "
|
||||
"shortcut: \"%1\". Use \"last\", "
|
||||
"\"next\", \"previous\" or an integer.")
|
||||
.arg(target);
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}});
|
||||
}
|
||||
else
|
||||
{
|
||||
actions.emplace("openTab", nullptr);
|
||||
}
|
||||
|
||||
this->shortcuts_ = getApp()->hotkeys->shortcutsForCategory(
|
||||
HotkeyCategory::PopupWindow, actions, this);
|
||||
}
|
||||
|
||||
} // namespace chatterino
|
||||
|
||||
@@ -64,6 +64,8 @@ private:
|
||||
|
||||
void ok();
|
||||
friend class EventFilter;
|
||||
|
||||
void addShortcuts() override;
|
||||
};
|
||||
|
||||
} // namespace chatterino
|
||||
|
||||
@@ -3,9 +3,9 @@
|
||||
#include "Application.hpp"
|
||||
#include "common/Args.hpp"
|
||||
#include "controllers/commands/CommandController.hpp"
|
||||
#include "controllers/hotkeys/HotkeyController.hpp"
|
||||
#include "singletons/Resources.hpp"
|
||||
#include "util/LayoutCreator.hpp"
|
||||
#include "util/Shortcut.hpp"
|
||||
#include "widgets/helper/Button.hpp"
|
||||
#include "widgets/settingspages/AboutPage.hpp"
|
||||
#include "widgets/settingspages/AccountsPage.hpp"
|
||||
@@ -30,6 +30,7 @@ SettingsDialog::SettingsDialog(QWidget *parent)
|
||||
{BaseWindow::Flags::DisableCustomScaling, BaseWindow::Flags::Dialog},
|
||||
parent)
|
||||
{
|
||||
this->setObjectName("SettingsDialog");
|
||||
this->setWindowTitle("Chatterino Settings");
|
||||
this->resize(915, 600);
|
||||
this->themeChangedEvent();
|
||||
@@ -40,14 +41,35 @@ SettingsDialog::SettingsDialog(QWidget *parent)
|
||||
this->overrideBackgroundColor_ = QColor("#111111");
|
||||
this->scaleChangedEvent(this->scale()); // execute twice to width of item
|
||||
|
||||
createWindowShortcut(this, "CTRL+F", [this] {
|
||||
this->ui_.search->setFocus();
|
||||
this->ui_.search->selectAll();
|
||||
});
|
||||
|
||||
// Disable the ? button in the titlebar until we decide to use it
|
||||
this->setWindowFlags(this->windowFlags() &
|
||||
~Qt::WindowContextHelpButtonHint);
|
||||
this->addShortcuts();
|
||||
this->signalHolder_.managedConnect(getApp()->hotkeys->onItemsUpdated,
|
||||
[this]() {
|
||||
this->clearShortcuts();
|
||||
this->addShortcuts();
|
||||
});
|
||||
}
|
||||
|
||||
void SettingsDialog::addShortcuts()
|
||||
{
|
||||
HotkeyController::HotkeyMap actions{
|
||||
{"search",
|
||||
[this](std::vector<QString>) -> QString {
|
||||
this->ui_.search->setFocus();
|
||||
this->ui_.search->selectAll();
|
||||
return "";
|
||||
}},
|
||||
{"delete", nullptr},
|
||||
{"accept", nullptr},
|
||||
{"reject", nullptr},
|
||||
{"scrollPage", nullptr},
|
||||
{"openTab", nullptr},
|
||||
};
|
||||
|
||||
this->shortcuts_ = getApp()->hotkeys->shortcutsForCategory(
|
||||
HotkeyCategory::PopupWindow, actions, this);
|
||||
}
|
||||
|
||||
void SettingsDialog::initUi()
|
||||
@@ -63,7 +85,7 @@ void SettingsDialog::initUi()
|
||||
.withoutMargin()
|
||||
.emplace<QLineEdit>()
|
||||
.assign(&this->ui_.search);
|
||||
edit->setPlaceholderText("Find in settings... (Ctrl+F)");
|
||||
edit->setPlaceholderText("Find in settings... (Ctrl+F by default)");
|
||||
|
||||
QObject::connect(edit.getElement(), &QLineEdit::textChanged, this,
|
||||
&SettingsDialog::filterElements);
|
||||
@@ -172,7 +194,7 @@ void SettingsDialog::addTabs()
|
||||
this->addTab([]{return new IgnoresPage;}, "Ignores", ":/settings/ignore.svg");
|
||||
this->addTab([]{return new FiltersPage;}, "Filters", ":/settings/filters.svg");
|
||||
this->ui_.tabContainer->addSpacing(16);
|
||||
this->addTab([]{return new KeyboardSettingsPage;}, "Keybindings", ":/settings/keybinds.svg");
|
||||
this->addTab([]{return new KeyboardSettingsPage;}, "Hotkeys", ":/settings/keybinds.svg");
|
||||
this->addTab([]{return new ModerationPage;}, "Moderation", ":/settings/moderation.svg", SettingsTabId::Moderation);
|
||||
this->addTab([]{return new NotificationPage;}, "Live Notifications", ":/settings/notification2.svg");
|
||||
this->addTab([]{return new ExternalToolsPage;}, "External tools", ":/settings/externaltools.svg");
|
||||
|
||||
@@ -60,6 +60,7 @@ private:
|
||||
|
||||
void onOkClicked();
|
||||
void onCancelClicked();
|
||||
void addShortcuts() override;
|
||||
|
||||
struct {
|
||||
QWidget *tabContainerContainer{};
|
||||
|
||||
@@ -3,8 +3,10 @@
|
||||
#include "Application.hpp"
|
||||
#include "common/Channel.hpp"
|
||||
#include "common/NetworkRequest.hpp"
|
||||
#include "common/QLogging.hpp"
|
||||
#include "controllers/accounts/AccountController.hpp"
|
||||
#include "controllers/highlights/HighlightBlacklistUser.hpp"
|
||||
#include "controllers/hotkeys/HotkeyController.hpp"
|
||||
#include "messages/Message.hpp"
|
||||
#include "messages/MessageBuilder.hpp"
|
||||
#include "providers/IvrApi.hpp"
|
||||
@@ -18,9 +20,9 @@
|
||||
#include "util/Helpers.hpp"
|
||||
#include "util/LayoutCreator.hpp"
|
||||
#include "util/PostToThread.hpp"
|
||||
#include "util/Shortcut.hpp"
|
||||
#include "util/StreamerMode.hpp"
|
||||
#include "widgets/Label.hpp"
|
||||
#include "widgets/Scrollbar.hpp"
|
||||
#include "widgets/helper/ChannelView.hpp"
|
||||
#include "widgets/helper/EffectLabel.hpp"
|
||||
#include "widgets/helper/Line.hpp"
|
||||
@@ -140,10 +142,47 @@ UserInfoPopup::UserInfoPopup(bool closeAutomatically, QWidget *parent)
|
||||
else
|
||||
this->setAttribute(Qt::WA_DeleteOnClose);
|
||||
|
||||
// Close the popup when Escape is pressed
|
||||
createWindowShortcut(this, "Escape", [this] {
|
||||
this->deleteLater();
|
||||
});
|
||||
HotkeyController::HotkeyMap actions{
|
||||
{"delete",
|
||||
[this](std::vector<QString>) -> QString {
|
||||
this->deleteLater();
|
||||
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->ui_.latestMessages->getScrollBar();
|
||||
if (direction == "up")
|
||||
{
|
||||
scrollbar.offset(-scrollbar.getLargeChange());
|
||||
}
|
||||
else if (direction == "down")
|
||||
{
|
||||
scrollbar.offset(scrollbar.getLargeChange());
|
||||
}
|
||||
else
|
||||
{
|
||||
qCWarning(chatterinoHotkeys) << "Unknown scroll direction";
|
||||
}
|
||||
return "";
|
||||
}},
|
||||
|
||||
// these actions make no sense in the context of a usercard, so they aren't implemented
|
||||
{"reject", nullptr},
|
||||
{"accept", nullptr},
|
||||
{"openTab", nullptr},
|
||||
{"search", nullptr},
|
||||
};
|
||||
|
||||
this->shortcuts_ = getApp()->hotkeys->shortcutsForCategory(
|
||||
HotkeyCategory::PopupWindow, actions, this);
|
||||
|
||||
auto layout = LayoutCreator<QWidget>(this->getLayoutContainer())
|
||||
.setLayoutType<QVBoxLayout>();
|
||||
|
||||
@@ -31,6 +31,8 @@ private:
|
||||
QHBoxLayout *buttons_{};
|
||||
|
||||
void moveRow(int dir);
|
||||
|
||||
public:
|
||||
void selectRow(int row);
|
||||
};
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@ ResizingTextEdit::ResizingTextEdit()
|
||||
});
|
||||
|
||||
this->setFocusPolicy(Qt::ClickFocus);
|
||||
this->installEventFilter(this);
|
||||
}
|
||||
|
||||
QSize ResizingTextEdit::sizeHint() const
|
||||
@@ -95,6 +96,22 @@ QString ResizingTextEdit::textUnderCursor(bool *hadSpace) const
|
||||
return lastWord;
|
||||
}
|
||||
|
||||
bool ResizingTextEdit::eventFilter(QObject *, QEvent *event)
|
||||
{
|
||||
// makes QShortcuts work in the ResizingTextEdit
|
||||
if (event->type() != QEvent::ShortcutOverride)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
auto ev = static_cast<QKeyEvent *>(event);
|
||||
ev->ignore();
|
||||
if ((ev->key() == Qt::Key_C || ev->key() == Qt::Key_Insert) &&
|
||||
ev->modifiers() == Qt::ControlModifier)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
void ResizingTextEdit::keyPressEvent(QKeyEvent *event)
|
||||
{
|
||||
event->ignore();
|
||||
|
||||
@@ -43,6 +43,7 @@ private:
|
||||
QCompleter *completer_ = nullptr;
|
||||
bool completionInProgress_ = false;
|
||||
|
||||
bool eventFilter(QObject *widget, QEvent *event) override;
|
||||
private slots:
|
||||
void insertCompletion(const QString &completion);
|
||||
};
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include <QVBoxLayout>
|
||||
|
||||
#include "common/Channel.hpp"
|
||||
#include "controllers/hotkeys/HotkeyController.hpp"
|
||||
#include "messages/Message.hpp"
|
||||
#include "messages/search/AuthorPredicate.hpp"
|
||||
#include "messages/search/ChannelPredicate.hpp"
|
||||
@@ -13,7 +14,6 @@
|
||||
#include "messages/search/MessageFlagsPredicate.hpp"
|
||||
#include "messages/search/RegexPredicate.hpp"
|
||||
#include "messages/search/SubstringPredicate.hpp"
|
||||
#include "util/Shortcut.hpp"
|
||||
#include "widgets/helper/ChannelView.hpp"
|
||||
|
||||
namespace chatterino {
|
||||
@@ -60,11 +60,32 @@ SearchPopup::SearchPopup(QWidget *parent)
|
||||
{
|
||||
this->initLayout();
|
||||
this->resize(400, 600);
|
||||
this->addShortcuts();
|
||||
}
|
||||
|
||||
createShortcut(this, "CTRL+F", [this] {
|
||||
this->searchInput_->setFocus();
|
||||
this->searchInput_->selectAll();
|
||||
});
|
||||
void SearchPopup::addShortcuts()
|
||||
{
|
||||
HotkeyController::HotkeyMap actions{
|
||||
{"search",
|
||||
[this](std::vector<QString>) -> QString {
|
||||
this->searchInput_->setFocus();
|
||||
this->searchInput_->selectAll();
|
||||
return "";
|
||||
}},
|
||||
{"delete",
|
||||
[this](std::vector<QString>) -> QString {
|
||||
this->close();
|
||||
return "";
|
||||
}},
|
||||
|
||||
{"reject", nullptr},
|
||||
{"accept", nullptr},
|
||||
{"openTab", nullptr},
|
||||
{"scrollPage", nullptr},
|
||||
};
|
||||
|
||||
this->shortcuts_ = getApp()->hotkeys->shortcutsForCategory(
|
||||
HotkeyCategory::PopupWindow, actions, this);
|
||||
}
|
||||
|
||||
void SearchPopup::setChannelFilters(FilterSetPtr filters)
|
||||
|
||||
@@ -26,6 +26,7 @@ protected:
|
||||
private:
|
||||
void initLayout();
|
||||
void search();
|
||||
void addShortcuts() override;
|
||||
|
||||
/**
|
||||
* @brief Only retains those message from a list of messages that satisfy a
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "GenericListView.hpp"
|
||||
#include "widgets/listview/GenericListView.hpp"
|
||||
|
||||
#include "singletons/Theme.hpp"
|
||||
#include "widgets/listview/GenericListModel.hpp"
|
||||
|
||||
@@ -18,7 +19,7 @@ GenericListView::GenericListView()
|
||||
auto *item = GenericListItem::fromVariant(index.data());
|
||||
item->action();
|
||||
|
||||
emit this->closeRequested();
|
||||
this->requestClose();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -42,64 +43,58 @@ void GenericListView::setInvokeActionOnTab(bool value)
|
||||
|
||||
bool GenericListView::eventFilter(QObject * /*watched*/, QEvent *event)
|
||||
{
|
||||
if (!this->model_)
|
||||
if (this->model_ == nullptr)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (event->type() == QEvent::KeyPress)
|
||||
{
|
||||
auto *keyEvent = static_cast<QKeyEvent *>(event);
|
||||
int key = keyEvent->key();
|
||||
|
||||
const QModelIndex &curIdx = this->currentIndex();
|
||||
const int curRow = curIdx.row();
|
||||
const int count = this->model_->rowCount(curIdx);
|
||||
|
||||
if (key == Qt::Key_Enter || key == Qt::Key_Return ||
|
||||
(key == Qt::Key_Tab && this->invokeActionOnTab_))
|
||||
if (key == Qt::Key_Enter || key == Qt::Key_Return)
|
||||
{
|
||||
// keep this before the other tab handler
|
||||
if (count <= 0)
|
||||
return true;
|
||||
|
||||
const auto index = this->currentIndex();
|
||||
auto *item = GenericListItem::fromVariant(index.data());
|
||||
|
||||
item->action();
|
||||
|
||||
emit this->closeRequested();
|
||||
this->acceptCompletion();
|
||||
return true;
|
||||
}
|
||||
else if (key == Qt::Key_Down || key == Qt::Key_Tab)
|
||||
|
||||
if (key == Qt::Key_Tab)
|
||||
{
|
||||
if (count <= 0)
|
||||
return true;
|
||||
if (this->invokeActionOnTab_)
|
||||
{
|
||||
this->acceptCompletion();
|
||||
}
|
||||
else
|
||||
{
|
||||
this->focusNextCompletion();
|
||||
}
|
||||
|
||||
const int newRow = (curRow + 1) % count;
|
||||
|
||||
this->setCurrentIndex(curIdx.siblingAtRow(newRow));
|
||||
return true;
|
||||
}
|
||||
else if (key == Qt::Key_Up ||
|
||||
(!this->invokeActionOnTab_ && key == Qt::Key_Backtab))
|
||||
|
||||
if (key == Qt::Key_Backtab && !this->invokeActionOnTab_)
|
||||
{
|
||||
if (count <= 0)
|
||||
return true;
|
||||
|
||||
int newRow = curRow - 1;
|
||||
if (newRow < 0)
|
||||
newRow += count;
|
||||
|
||||
this->setCurrentIndex(curIdx.siblingAtRow(newRow));
|
||||
this->focusPreviousCompletion();
|
||||
return true;
|
||||
}
|
||||
else if (key == Qt::Key_Escape)
|
||||
|
||||
if (key == Qt::Key_Down)
|
||||
{
|
||||
emit this->closeRequested();
|
||||
this->focusNextCompletion();
|
||||
return true;
|
||||
}
|
||||
else
|
||||
|
||||
if (key == Qt::Key_Up)
|
||||
{
|
||||
return false;
|
||||
this->focusPreviousCompletion();
|
||||
return true;
|
||||
}
|
||||
|
||||
if (key == Qt::Key_Escape)
|
||||
{
|
||||
this->requestClose();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -126,4 +121,63 @@ void GenericListView::refreshTheme(const Theme &theme)
|
||||
this->setStyleSheet(listStyle);
|
||||
}
|
||||
|
||||
bool GenericListView::acceptCompletion()
|
||||
{
|
||||
const QModelIndex &curIdx = this->currentIndex();
|
||||
const int curRow = curIdx.row();
|
||||
const int count = this->model_->rowCount(curIdx);
|
||||
if (count <= 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
const auto index = this->currentIndex();
|
||||
auto *item = GenericListItem::fromVariant(index.data());
|
||||
|
||||
item->action();
|
||||
|
||||
this->requestClose();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void GenericListView::focusNextCompletion()
|
||||
{
|
||||
const QModelIndex &curIdx = this->currentIndex();
|
||||
const int curRow = curIdx.row();
|
||||
const int count = this->model_->rowCount(curIdx);
|
||||
if (count <= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
const int newRow = (curRow + 1) % count;
|
||||
|
||||
this->setCurrentIndex(curIdx.siblingAtRow(newRow));
|
||||
}
|
||||
|
||||
void GenericListView::focusPreviousCompletion()
|
||||
{
|
||||
const QModelIndex &curIdx = this->currentIndex();
|
||||
const int curRow = curIdx.row();
|
||||
const int count = this->model_->rowCount(curIdx);
|
||||
if (count <= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int newRow = curRow - 1;
|
||||
if (newRow < 0)
|
||||
{
|
||||
newRow += count;
|
||||
}
|
||||
|
||||
this->setCurrentIndex(curIdx.siblingAtRow(newRow));
|
||||
}
|
||||
|
||||
void GenericListView::requestClose()
|
||||
{
|
||||
emit this->closeRequested();
|
||||
}
|
||||
|
||||
} // namespace chatterino
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
#include <QListView>
|
||||
#include "widgets/listview/GenericItemDelegate.hpp"
|
||||
#include "widgets/listview/GenericListItem.hpp"
|
||||
|
||||
#include <QListView>
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
class GenericListModel;
|
||||
@@ -31,6 +32,28 @@ signals:
|
||||
|
||||
private:
|
||||
bool invokeActionOnTab_{};
|
||||
|
||||
/**
|
||||
* @brief Gets the currently selected item (if any) and calls its action
|
||||
*
|
||||
* @return true if an action was called on an item, false if no item was selected and thus no action was called
|
||||
**/
|
||||
bool acceptCompletion();
|
||||
|
||||
/**
|
||||
* @brief Select the next item in the list. Wraps around if the bottom of the list has been reached.
|
||||
**/
|
||||
void focusNextCompletion();
|
||||
|
||||
/**
|
||||
* @brief Select the previous item in the list. Wraps around if the top of the list has been reached.
|
||||
**/
|
||||
void focusPreviousCompletion();
|
||||
|
||||
/**
|
||||
* @brief Request for the GUI powering this list view to be closed. Shorthand for emit this->closeRequested()
|
||||
**/
|
||||
void requestClose();
|
||||
};
|
||||
|
||||
} // namespace chatterino
|
||||
|
||||
@@ -1,81 +1,100 @@
|
||||
#include "KeyboardSettingsPage.hpp"
|
||||
|
||||
#include "Application.hpp"
|
||||
#include "common/QLogging.hpp"
|
||||
#include "controllers/hotkeys/HotkeyController.hpp"
|
||||
#include "controllers/hotkeys/HotkeyModel.hpp"
|
||||
#include "util/LayoutCreator.hpp"
|
||||
#include "widgets/dialogs/EditHotkeyDialog.hpp"
|
||||
|
||||
#include <QFormLayout>
|
||||
#include <QHeaderView>
|
||||
#include <QLabel>
|
||||
#include <QTableView>
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
KeyboardSettingsPage::KeyboardSettingsPage()
|
||||
{
|
||||
auto layout =
|
||||
LayoutCreator<KeyboardSettingsPage>(this).setLayoutType<QVBoxLayout>();
|
||||
LayoutCreator<KeyboardSettingsPage> layoutCreator(this);
|
||||
auto layout = layoutCreator.emplace<QVBoxLayout>();
|
||||
|
||||
auto scroll = layout.emplace<QScrollArea>();
|
||||
auto model = getApp()->hotkeys->createModel(nullptr);
|
||||
EditableModelView *view =
|
||||
layout.emplace<EditableModelView>(model).getElement();
|
||||
|
||||
this->setStyleSheet("QLabel, #container { background: #333 }");
|
||||
view->setTitles({"Hotkey name", "Keybinding"});
|
||||
view->getTableView()->horizontalHeader()->setVisible(true);
|
||||
view->getTableView()->horizontalHeader()->setStretchLastSection(false);
|
||||
view->getTableView()->horizontalHeader()->setSectionResizeMode(
|
||||
QHeaderView::ResizeToContents);
|
||||
view->getTableView()->horizontalHeader()->setSectionResizeMode(
|
||||
1, QHeaderView::Stretch);
|
||||
|
||||
auto form = new QFormLayout(this);
|
||||
scroll->setWidgetResizable(true);
|
||||
auto widget = new QWidget();
|
||||
widget->setLayout(form);
|
||||
widget->setObjectName("container");
|
||||
scroll->setWidget(widget);
|
||||
view->addButtonPressed.connect([view, model] {
|
||||
EditHotkeyDialog dialog(nullptr);
|
||||
bool wasAccepted = dialog.exec() == 1;
|
||||
|
||||
form->addRow(new QLabel("Hold Ctrl"), new QLabel("Show resize handles"));
|
||||
form->addRow(new QLabel("Hold Ctrl + Alt"),
|
||||
new QLabel("Show split overlay"));
|
||||
if (wasAccepted)
|
||||
{
|
||||
auto newHotkey = dialog.data();
|
||||
int vectorIndex = getApp()->hotkeys->hotkeys_.append(newHotkey);
|
||||
getApp()->hotkeys->save();
|
||||
|
||||
form->addItem(new QSpacerItem(16, 16));
|
||||
form->addRow(new QLabel("Ctrl + ScrollDown/-"), new QLabel("Zoom out"));
|
||||
form->addRow(new QLabel("Ctrl + ScrollUp/+"), new QLabel("Zoom in"));
|
||||
form->addRow(new QLabel("Ctrl + 0"), new QLabel("Reset zoom size"));
|
||||
// Select and scroll to newly added hotkey
|
||||
auto modelRow = model->getModelIndexFromVectorIndex(vectorIndex);
|
||||
auto modelIndex = model->index(modelRow, 0);
|
||||
view->selectRow(modelRow);
|
||||
view->getTableView()->scrollTo(modelIndex,
|
||||
QAbstractItemView::PositionAtCenter);
|
||||
}
|
||||
});
|
||||
|
||||
form->addItem(new QSpacerItem(16, 16));
|
||||
form->addRow(new QLabel("Ctrl + T"), new QLabel("Create new split"));
|
||||
form->addRow(new QLabel("Ctrl + W"), new QLabel("Close current split"));
|
||||
form->addRow(new QLabel("Ctrl + N"),
|
||||
new QLabel("Open current split as a popup"));
|
||||
form->addRow(new QLabel("Ctrl + K"), new QLabel("Jump to split"));
|
||||
form->addRow(new QLabel("Ctrl + G"),
|
||||
new QLabel("Reopen last closed split"));
|
||||
QObject::connect(view->getTableView(), &QTableView::doubleClicked,
|
||||
[this, view, model](const QModelIndex &clicked) {
|
||||
this->tableCellClicked(clicked, view, model);
|
||||
});
|
||||
|
||||
form->addRow(new QLabel("Ctrl + Shift + T"), new QLabel("Create new tab"));
|
||||
form->addRow(new QLabel("Ctrl + Shift + W"),
|
||||
new QLabel("Close current tab"));
|
||||
form->addRow(new QLabel("Ctrl + Shift + N"),
|
||||
new QLabel("Open current tab as a popup"));
|
||||
form->addRow(new QLabel("Ctrl + H"),
|
||||
new QLabel("Hide/Show similar messages (See General->R9K)"));
|
||||
QPushButton *resetEverything = new QPushButton("Reset to defaults");
|
||||
QObject::connect(resetEverything, &QPushButton::clicked, [this]() {
|
||||
auto reply = QMessageBox::question(
|
||||
this, "Reset hotkeys",
|
||||
"Are you sure you want to reset hotkeys to defaults?",
|
||||
QMessageBox::Yes | QMessageBox::Cancel);
|
||||
|
||||
form->addItem(new QSpacerItem(16, 16));
|
||||
form->addRow(new QLabel("Ctrl + 1/2/3/..."),
|
||||
new QLabel("Select tab 1/2/3/..."));
|
||||
form->addRow(new QLabel("Ctrl + 9"), new QLabel("Select last tab"));
|
||||
form->addRow(new QLabel("Ctrl + Tab"), new QLabel("Select next tab"));
|
||||
form->addRow(new QLabel("Ctrl + Shift + Tab"),
|
||||
new QLabel("Select previous tab"));
|
||||
if (reply == QMessageBox::Yes)
|
||||
{
|
||||
getApp()->hotkeys->resetToDefaults();
|
||||
}
|
||||
});
|
||||
view->addCustomButton(resetEverything);
|
||||
}
|
||||
|
||||
form->addRow(new QLabel("Alt + ←/↑/→/↓"),
|
||||
new QLabel("Select left/upper/right/bottom split"));
|
||||
form->addRow(new QLabel("Ctrl + U"),
|
||||
new QLabel("Toggle visibility of tabs"));
|
||||
void KeyboardSettingsPage::tableCellClicked(const QModelIndex &clicked,
|
||||
EditableModelView *view,
|
||||
HotkeyModel *model)
|
||||
{
|
||||
auto hotkey = getApp()->hotkeys->getHotkeyByName(
|
||||
clicked.siblingAtColumn(0).data(Qt::EditRole).toString());
|
||||
if (!hotkey)
|
||||
{
|
||||
return; // clicked on header or invalid hotkey
|
||||
}
|
||||
EditHotkeyDialog dialog(hotkey);
|
||||
bool wasAccepted = dialog.exec() == 1;
|
||||
|
||||
form->addItem(new QSpacerItem(16, 16));
|
||||
form->addRow(new QLabel("Ctrl + R"), new QLabel("Change channel"));
|
||||
form->addRow(new QLabel("Ctrl + F"),
|
||||
new QLabel("Search in current channel"));
|
||||
form->addRow(new QLabel("Ctrl + E"), new QLabel("Open Emote menu"));
|
||||
form->addRow(new QLabel("Ctrl + P"), new QLabel("Open Settings menu"));
|
||||
form->addRow(new QLabel("F5"),
|
||||
new QLabel("Reload subscriber and channel emotes"));
|
||||
form->addRow(new QLabel("Ctrl + F5"), new QLabel("Reconnect channels"));
|
||||
form->addRow(new QLabel("Alt + X"), new QLabel("Create a clip"));
|
||||
if (wasAccepted)
|
||||
{
|
||||
auto newHotkey = dialog.data();
|
||||
auto vectorIndex =
|
||||
getApp()->hotkeys->replaceHotkey(hotkey->name(), newHotkey);
|
||||
getApp()->hotkeys->save();
|
||||
|
||||
form->addItem(new QSpacerItem(16, 16));
|
||||
form->addRow(new QLabel("PageUp"), new QLabel("Scroll up"));
|
||||
form->addRow(new QLabel("PageDown"), new QLabel("Scroll down"));
|
||||
// Select the replaced hotkey
|
||||
auto modelRow = model->getModelIndexFromVectorIndex(vectorIndex);
|
||||
auto modelIndex = model->index(modelRow, 0);
|
||||
view->selectRow(modelRow);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace chatterino
|
||||
|
||||
@@ -1,13 +1,20 @@
|
||||
#pragma once
|
||||
|
||||
#include "widgets/helper/EditableModelView.hpp"
|
||||
#include "widgets/settingspages/SettingsPage.hpp"
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
class HotkeyModel;
|
||||
|
||||
class KeyboardSettingsPage : public SettingsPage
|
||||
{
|
||||
public:
|
||||
KeyboardSettingsPage();
|
||||
|
||||
private:
|
||||
void tableCellClicked(const QModelIndex &clicked, EditableModelView *view,
|
||||
HotkeyModel *model);
|
||||
};
|
||||
|
||||
} // namespace chatterino
|
||||
|
||||
+316
-46
@@ -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);
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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
@@ -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();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user