2018-03-15 08:27:45 +00:00
|
|
|
#include "KonamiCode.h"
|
|
|
|
|
|
|
|
#include <QDebug>
|
2023-08-02 17:35:35 +01:00
|
|
|
#include <array>
|
2018-03-15 08:27:45 +00:00
|
|
|
|
|
|
|
namespace {
|
2023-08-02 17:35:35 +01:00
|
|
|
const std::array<Qt::Key, 10> 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 } };
|
2018-03-15 08:27:45 +00:00
|
|
|
}
|
|
|
|
|
2023-08-02 17:35:35 +01:00
|
|
|
KonamiCode::KonamiCode(QObject* parent) : QObject(parent) {}
|
2018-03-15 08:27:45 +00:00
|
|
|
|
|
|
|
void KonamiCode::input(QEvent* event)
|
|
|
|
{
|
2023-08-02 17:35:35 +01:00
|
|
|
if (event->type() == QEvent::KeyPress) {
|
|
|
|
QKeyEvent* keyEvent = static_cast<QKeyEvent*>(event);
|
2018-07-15 13:51:05 +01:00
|
|
|
auto key = Qt::Key(keyEvent->key());
|
2023-08-02 17:35:35 +01:00
|
|
|
if (key == konamiCode[m_progress]) {
|
|
|
|
m_progress++;
|
|
|
|
} else {
|
2018-07-15 13:51:05 +01:00
|
|
|
m_progress = 0;
|
|
|
|
}
|
2023-08-02 17:35:35 +01:00
|
|
|
if (m_progress == static_cast<int>(konamiCode.size())) {
|
2018-07-15 13:51:05 +01:00
|
|
|
m_progress = 0;
|
|
|
|
emit triggered();
|
|
|
|
}
|
|
|
|
}
|
2018-03-15 08:27:45 +00:00
|
|
|
}
|