diff --git a/libs/ui/input/KisQtWidgetsTweaker.cpp b/libs/ui/input/KisQtWidgetsTweaker.cpp index a21b3a3..8c25cca 100644 --- a/libs/ui/input/KisQtWidgetsTweaker.cpp +++ b/libs/ui/input/KisQtWidgetsTweaker.cpp @@ -56,6 +56,48 @@ KisQtWidgetsTweaker::~KisQtWidgetsTweaker() } +QKeySequence toKeySequence(const QKeyEvent& event) +{ + return QKeySequence(event.key() | event.modifiers()); +} + +struct StandardSequence +{ + QVector widgetTypes; + QVector sequences; + + bool matches(QKeyEvent *event, QKeySequence::StandardKey key) { + return event->matches(key); + } +}; + +struct CustomSequence +{ + QVector widgetTypes; + QVector sequences; + + bool matches(QKeyEvent *event, QKeySequence key) { + return key.matches(toKeySequence(*event)) == QKeySequence::ExactMatch; + } +}; + +template +bool tryAcceptSequence(QObject *receiver, QEvent *event, const SequenceMap &sequenceMap) +{ + Q_FOREACH (const QLatin1String &type, sequenceMap.widgetTypes) { + if (receiver->inherits(type.data())) { + QKeyEvent* key = static_cast(event); + Q_FOREACH (QKeySequence seq, sequenceMap.sequences) { + if (sequenceMap.matches(key, seq)) { + event->accept(); + return true; + } + } + } + } + return false; +} + bool KisQtWidgetsTweaker::eventFilter(QObject *receiver, QEvent *event) {