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:
@@ -0,0 +1,93 @@
|
||||
#include "controllers/hotkeys/Hotkey.hpp"
|
||||
|
||||
#include "Application.hpp"
|
||||
#include "common/QLogging.hpp"
|
||||
#include "controllers/hotkeys/ActionNames.hpp"
|
||||
#include "controllers/hotkeys/HotkeyController.hpp"
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
Hotkey::Hotkey(HotkeyCategory category, QKeySequence keySequence,
|
||||
QString action, std::vector<QString> arguments, QString name)
|
||||
: category_(category)
|
||||
, keySequence_(keySequence)
|
||||
, action_(action)
|
||||
, arguments_(arguments)
|
||||
, name_(name)
|
||||
{
|
||||
}
|
||||
|
||||
const QKeySequence &Hotkey::keySequence() const
|
||||
{
|
||||
return this->keySequence_;
|
||||
}
|
||||
|
||||
QString Hotkey::name() const
|
||||
{
|
||||
return this->name_;
|
||||
}
|
||||
|
||||
HotkeyCategory Hotkey::category() const
|
||||
{
|
||||
return this->category_;
|
||||
}
|
||||
|
||||
QString Hotkey::action() const
|
||||
{
|
||||
return this->action_;
|
||||
}
|
||||
|
||||
bool Hotkey::validAction() const
|
||||
{
|
||||
auto categoryActionsIt = actionNames.find(this->category_);
|
||||
if (categoryActionsIt == actionNames.end())
|
||||
{
|
||||
// invalid category
|
||||
return false;
|
||||
}
|
||||
|
||||
auto actionDefinitionIt = categoryActionsIt->second.find(this->action());
|
||||
|
||||
return actionDefinitionIt != categoryActionsIt->second.end();
|
||||
}
|
||||
|
||||
std::vector<QString> Hotkey::arguments() const
|
||||
{
|
||||
return this->arguments_;
|
||||
}
|
||||
|
||||
QString Hotkey::getCategory() const
|
||||
{
|
||||
return getApp()->hotkeys->categoryDisplayName(this->category_);
|
||||
}
|
||||
|
||||
Qt::ShortcutContext Hotkey::getContext() const
|
||||
{
|
||||
switch (this->category_)
|
||||
{
|
||||
case HotkeyCategory::Window:
|
||||
return Qt::WindowShortcut;
|
||||
case HotkeyCategory::Split:
|
||||
return Qt::WidgetWithChildrenShortcut;
|
||||
case HotkeyCategory::SplitInput:
|
||||
return Qt::WidgetWithChildrenShortcut;
|
||||
case HotkeyCategory::PopupWindow:
|
||||
return Qt::WindowShortcut;
|
||||
}
|
||||
qCDebug(chatterinoHotkeys)
|
||||
<< "Using default shortcut context for" << this->getCategory()
|
||||
<< "and hopeing for the best.";
|
||||
return Qt::WidgetShortcut;
|
||||
}
|
||||
|
||||
QString Hotkey::toString() const
|
||||
{
|
||||
return this->keySequence().toString(QKeySequence::NativeText);
|
||||
}
|
||||
|
||||
QString Hotkey::toPortableString() const
|
||||
{
|
||||
return this->keySequence().toString(QKeySequence::PortableText);
|
||||
}
|
||||
|
||||
} // namespace chatterino
|
||||
Reference in New Issue
Block a user