pollymc/application/KonamiCode.cpp
Jamie Mansfield 3a1abb555b
GH-3575 Fix build on Fedora 34
Presumably this is caused by the bump to GCC 11 in Fedora 34. See
the error that did occur below...

    ./MultiMC5/application/KonamiCode.cpp: In member function ‘void KonamiCode::input(QEvent*)’:
    ./MultiMC5/application/KonamiCode.cpp:38:23: error: comparison of integer expressions of different signedness: ‘int’ and ‘std::array<Qt::Key, 10>::size_type’ {aka ‘long unsigned int’} [-Werror=sign-compare]
       38 |         if(m_progress == konamiCode.size())
          |            ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~
2021-04-08 18:50:07 +01:00

45 lines
868 B
C++

#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 == static_cast<int>(konamiCode.size()))
{
m_progress = 0;
emit triggered();
}
}
}