From 20b9f2b42a3b58b6081af271774fbcc34025dccb Mon Sep 17 00:00:00 2001 From: Petr Mrázek Date: Sun, 25 Jul 2021 19:11:59 +0200 Subject: NOISSUE Flatten gui and logic libraries into MultiMC --- launcher/KonamiCode.cpp | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 launcher/KonamiCode.cpp (limited to 'launcher/KonamiCode.cpp') diff --git a/launcher/KonamiCode.cpp b/launcher/KonamiCode.cpp new file mode 100644 index 00000000..46a2a0b2 --- /dev/null +++ b/launcher/KonamiCode.cpp @@ -0,0 +1,44 @@ +#include "KonamiCode.h" + +#include +#include + +namespace { +const std::array konamiCode = +{ + { + Qt::Key_Up, Qt::Key_Up, + Qt::Key_Down, Qt::Key_Down, + Qt::Key_Left, Qt::Key_Right, + Qt::Key_Left, Qt::Key_Right, + Qt::Key_B, Qt::Key_A + } +}; +} + +KonamiCode::KonamiCode(QObject* parent) : QObject(parent) +{ +} + + +void KonamiCode::input(QEvent* event) +{ + if( event->type() == QEvent::KeyPress ) + { + QKeyEvent *keyEvent = static_cast( event ); + auto key = Qt::Key(keyEvent->key()); + if(key == konamiCode[m_progress]) + { + m_progress ++; + } + else + { + m_progress = 0; + } + if(m_progress == static_cast(konamiCode.size())) + { + m_progress = 0; + emit triggered(); + } + } +} -- cgit