summaryrefslogtreecommitdiffstats
path: root/application/KonamiCode.cpp
blob: 4c5af837139da4c9779e36d2b9cfa3f53786d3c1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include "KonamiCode.h"

#include <array>
#include <QDebug>

namespace {
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
    }
};
}

KonamiCode::KonamiCode(QObject* parent) : QObject(parent)
{
}


void KonamiCode::input(QEvent* event)
{
    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();
        }
    }
}