Created
September 18, 2013 14:37
-
-
Save ynonp/6610132 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "typer.h" | |
#include <QDebug> | |
Typer::Typer(QObject *parent) : | |
QObject(parent) | |
{ | |
m_text = "The quick brown fox jumps over the lazy dog"; | |
m_idx = 0; | |
} | |
void Typer::letterPressed(QString letter) | |
{ | |
if ( letter.isEmpty() ) return; | |
if ( m_idx >= m_text.size() ) return; | |
qDebug() << m_text; | |
QString rpl; | |
if ( m_text.at(m_idx) == letter ) | |
{ | |
rpl = QString("<font color=\"green\">%1</font>").arg(letter); | |
} | |
else | |
{ | |
rpl = QString("<font color=\"red\">%1</font>").arg(m_text.at(m_idx)); | |
} | |
m_text.replace(m_idx, 1, rpl); | |
qDebug() << m_text; | |
m_idx += rpl.size(); | |
} | |
QString Typer::getText() | |
{ | |
return m_text; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef TYPER_H | |
#define TYPER_H | |
#include <QObject> | |
#include <QString> | |
class Typer : public QObject | |
{ | |
Q_OBJECT | |
public: | |
explicit Typer(QObject *parent = 0); | |
Q_INVOKABLE QString getText(); | |
signals: | |
void gameEnd(); | |
public slots: | |
void letterPressed(QString letter); | |
private: | |
QString m_text; | |
int m_idx; | |
}; | |
#endif // TYPER_H |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment