mirror-chatterino2/src/widgets/helper/Shortcut.hpp
2018-06-26 13:24:55 +02:00

27 lines
702 B
C++

#pragma once
#include <QShortcut>
#include <QWidget>
namespace chatterino {
namespace widgets {
template <typename WidgetType, typename Func>
inline void CreateShortcut(WidgetType *w, const char *key, Func func)
{
auto s = new QShortcut(QKeySequence(key), w);
s->setContext(Qt::WidgetWithChildrenShortcut);
QObject::connect(s, &QShortcut::activated, w, func);
}
template <typename WidgetType, typename Func>
inline void CreateWindowShortcut(WidgetType *w, const char *key, Func func)
{
auto s = new QShortcut(QKeySequence(key), w);
s->setContext(Qt::WindowShortcut);
QObject::connect(s, &QShortcut::activated, w, func);
}
} // namespace widgets
} // namespace chatterino