File: KeyController.h

package info (click to toggle)
clustalx 2.1%2Blgpl-5
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 2,868 kB
  • sloc: cpp: 40,050; sh: 163; xml: 102; makefile: 15
file content (50 lines) | stat: -rw-r--r-- 1,231 bytes parent folder | download | duplicates (5)
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
/**
 * Implements a singleton that maintains keyboard state. The single instance
 * is (re)instantiated on demand like:
 *     KeyController *kbd = KeyController::Instance();
 *
 * 25-04-07,Nigel Brown(EMBL): created.
 */

#ifndef KEYCONTROLLER_H
#define KEYCONTROLLER_H

#include <QObject>
#include <QKeyEvent>
#include <QEvent>

class KeyController : public QObject {
public:
    /* return the KeyController singleton */
    static KeyController *Instance();

    /* resetters */
    void clear()      { keyShift = keyCtrl = false; };
    void clearShift() { keyShift = false; };
    void clearCtrl()  { keyCtrl  = false; };

    /* setters */
    bool consumeKeyPress(int key);
    bool consumeKeyRelease(int key);

    /* testers */
    bool shiftPressed()  { return keyShift; }
    bool shiftReleased() { return !keyShift; }
    bool ctrlPressed()   { return keyCtrl; }
    bool ctrlReleased()  { return !keyCtrl; }

protected:
    /* hide the constructors */
    KeyController();
    KeyController(const KeyController&);
    KeyController& operator= (const KeyController&);

    //- bool eventFilter(QObject *o, QEvent *e);

private:
    /* keyboard state */
    bool keyShift;
    bool keyCtrl;
};

#endif //KEYCONTROLLER_H