[Qt-interest] [SOLVED] Help to Implement Easter Egg after certain keypattern is entered
Mike Short
Mike.Short at fawkesengineering.com
Wed Feb 3 23:57:13 CET 2010
Thanks Daryl and Stephen for helping me to get going in the right direction.
I was instructed to go to this site:
http://doc.trolltech.com/qq/qq02-early-easter-eggs.html
this is exactly the type of content I needed to see in order to get and idea
of where to start, and how to implement
something of this nature.
Appreciate your help!
Thanks for taking the time to reply.
-Mike Short
Fawkes Engineering, LLC
_____
From: Darryl Hunter [mailto:darryl.hunter at codersoft.com.au]
Sent: Wednesday, February 03, 2010 2:49 PM
To: qt-interest at trolltech.com
Cc: 'Mike Short'
Subject: RE: [Qt-interest] Help to Implement Easter Egg after certain
keypattern is entered
Hi Mike,
I found this code when I wanted to do a similar thing - I think on this list
but don't remember (it was quite a while ago):
*** EasterEgg.h ***
#include <QObject>
#include <QByteArray>
class EasterEgg : public QObject
{
Q_OBJECT
public:
EasterEgg(const char *magicWord, QObject *target, const char *slot);
virtual bool eventFilter (QObject *obj, QEvent *event);
signals:
void found();
private:
QByteArray magic;
int j;
QObject *_aparent;
};
#endif // EASTEREGG_H
*** EasterEgg.cpp ***
#include "EasterEgg.h"
#include <QApplication>
#include <QKeyEvent>
EasterEgg::EasterEgg(const char *magicWord, QObject *target, const char
*slot)
: magic (magicWord), j (0)
{
qApp->installEventFilter (this);
connect (this, SIGNAL (found()), target, slot);
_aparent=target;
}
bool EasterEgg::eventFilter (QObject *obj, QEvent *event)
{
if (_aparent==obj)
{
if (event->type() == QEvent::KeyPress)
{
QKeyEvent *keyEvent = (QKeyEvent *)event;
int key=keyEvent->key();
if ((int)magic[j] == key)
{
j++;
if (j==magic.length())
{
emit (found());
j=0;
}
}
else
{
int right=j;
while (j > 0)
{
if ((int)magic[j-1] == key &&
magic.left (j-1) == magic.mid (right - j
+ 1, j - 1))
{
break;
}
j--;
}
}
}
}
return FALSE;
}
To use it, you just need to do something like:
EasterEgg *saveEgg=new EasterEgg ("SAVE", this, SLOT
(saveEasterEggTriggered()));
Enjoy!
Darryl
_____
From: qt-interest-bounces at trolltech.com
[mailto:qt-interest-bounces at trolltech.com] On Behalf Of Mike Short
Sent: Thursday, 4 February 2010 5:33 AM
To: qt-interest at trolltech.com
Subject: [Qt-interest] Help to Implement Easter Egg after certain keypattern
is entered
I have written a small app in Qt that consists of a QWiget that contains a
QGroupBox, and inside that there are 2 layouts, one that has 3 QPushButtons,
and the other has various QRadioButtons, and depending on what QRadioButton
is selected when a certain QPushButton is clicked, dictates how the utility
functions or what task it completes.
I would like to add in a special feature or Easter Egg that appears only
after the user has pushed certain keys on the keyboard in a certain order or
pattern.
Has anyone tried anything like this?
I would appreciate any ideas on how something like this can be done in an
efficient manner, or if anyone else has done this successfully,then what
approach did you take to achieve the desired results?
Thanks in advance..
-Mike Short
Fawkes Engineering, LLC
No virus found in this incoming message.
Checked by AVG - www.avg.com
Version: 9.0.733 / Virus Database: 271.1.1/2664 - Release Date: 02/03/10
06:35:00
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20100203/9134bd76/attachment.html
More information about the Qt-interest-old
mailing list