2018-03-15 13:57:45 +05:30
|
|
|
#include "KonamiCode.h"
|
|
|
|
|
|
|
|
#include <array>
|
|
|
|
#include <QDebug>
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
const std::array<Qt::Key, 10> konamiCode =
|
|
|
|
{
|
2018-07-15 18:21:05 +05:30
|
|
|
{
|
|
|
|
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 13:57:45 +05:30
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
KonamiCode::KonamiCode(QObject* parent) : QObject(parent)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void KonamiCode::input(QEvent* event)
|
|
|
|
{
|
2018-07-15 18:21:05 +05:30
|
|
|
if( event->type() == QEvent::KeyPress )
|
|
|
|
{
|
|
|
|
QKeyEvent *keyEvent = static_cast<QKeyEvent*>( 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();
|
|
|
|
}
|
|
|
|
}
|
2018-03-15 13:57:45 +05:30
|
|
|
}
|