From 303842a19e4893e4ac6784d60aca990b4276d0ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Thu, 15 Mar 2018 09:27:45 +0100 Subject: NOISSUE Add Konami Code Fun little thing for hiding extra debug options in the future. --- application/KonamiCode.cpp | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 application/KonamiCode.cpp (limited to 'application/KonamiCode.cpp') diff --git a/application/KonamiCode.cpp b/application/KonamiCode.cpp new file mode 100644 index 00000000..07c285bc --- /dev/null +++ b/application/KonamiCode.cpp @@ -0,0 +1,42 @@ +#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 == konamiCode.size()) + { + m_progress = 0; + emit triggered(); + } + } +} -- cgit v1.2.3