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 45 46 47 48 49 50 51 52 53 54 55 56
| class PersistantKey : QObject
{
private:
QStringList list;
QTimer* timer;
int pos;
int key;
signals:
void valideKey(char c);
public:
PersistantKey()
{
charList << "ABC"
<< "DEF"
<< "GH"; // etc. je ne connais la liste des touches
timer = new QTimer(this);
connect(timer, SIGNAL(SIGNAL(timeout()), this, SLOT(finish()));
timer->setInterval (100);
pos = 1;
key = -1;
}
void newKeyEvent(int new_key)
{
timer->stop();
if(key != new_key)
{
emit valideKey(list[key][pos]);
pos = 1;
key = new_key;
timer->start();
}
else
{
pos++;
if(pos > list[key].size()) pos=1;
timer->start();
}
}
private slots:
void finish()
{
timer->stop();
emit valideKey(list[key][pos]);
pos = 1;
key = -1;
}
};
// creation
PersistantKey pk = new PersistantKey();
connect(pk, SIGNAL(valideKey(char)), this, SLOT(mon_slot(char)));
// quand on reçoit un event touche pressée
pk->newKeyEvent(msg); |
Partager