Diffstat (limited to 'noncore/applets/zkbapplet/keyzcfg/zkb.h') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/applets/zkbapplet/keyzcfg/zkb.h | 205 |
1 files changed, 205 insertions, 0 deletions
diff --git a/noncore/applets/zkbapplet/keyzcfg/zkb.h b/noncore/applets/zkbapplet/keyzcfg/zkb.h new file mode 100644 index 0000000..deff869 --- a/dev/null +++ b/noncore/applets/zkbapplet/keyzcfg/zkb.h | |||
@@ -0,0 +1,205 @@ | |||
1 | #ifndef ZKB_H | ||
2 | #define ZKB_H | ||
3 | |||
4 | #include <qstring.h> | ||
5 | #include <qstringlist.h> | ||
6 | #include <qmap.h> | ||
7 | #include <qwindowsystem_qws.h> | ||
8 | #include <qkeyboard_qws.h> | ||
9 | #include <qtimer.h> | ||
10 | #include <stdio.h> | ||
11 | |||
12 | class State; | ||
13 | |||
14 | class Action { | ||
15 | protected: | ||
16 | State* state; | ||
17 | ushort keycode; | ||
18 | ushort unicode; | ||
19 | int flags; | ||
20 | |||
21 | enum { | ||
22 | Shift_Mod = 1, | ||
23 | Ctrl_Mod = 2, | ||
24 | Alt_Mod = 4, | ||
25 | Keypad_Mod = 8, | ||
26 | Mod_Bits = 15, | ||
27 | Press = 16, | ||
28 | Autorepeat = 32, | ||
29 | Event = 64, | ||
30 | Defined = 128, | ||
31 | }; | ||
32 | |||
33 | void setDefined(bool); | ||
34 | |||
35 | public: | ||
36 | Action(); | ||
37 | Action(State*, ushort, ushort, int); | ||
38 | ~Action(); | ||
39 | |||
40 | State* getState() const; | ||
41 | void setState(State*); | ||
42 | |||
43 | bool hasEvent() const; | ||
44 | void setEvent(bool); | ||
45 | |||
46 | bool isDefined() const; | ||
47 | |||
48 | int getKeycode() const; | ||
49 | void setKeycode(int); | ||
50 | |||
51 | int getUnicode() const; | ||
52 | void setUnicode(int); | ||
53 | |||
54 | int getModifiers() const; | ||
55 | void setModifiers(int m); | ||
56 | |||
57 | bool isPressed() const; | ||
58 | void setPressed(bool); | ||
59 | |||
60 | bool isAutorepeat() const; | ||
61 | void setAutorepeat(bool); | ||
62 | }; | ||
63 | |||
64 | class State { | ||
65 | protected: | ||
66 | State* parent; | ||
67 | Action* keys; | ||
68 | |||
69 | enum { | ||
70 | Key_a=0, | ||
71 | Key_b=1, | ||
72 | Key_c=2, | ||
73 | Key_d=3, | ||
74 | Key_e=4, | ||
75 | Key_f=5, | ||
76 | Key_g=6, | ||
77 | Key_h=7, | ||
78 | Key_i=8, | ||
79 | Key_j=9, | ||
80 | Key_k=10, | ||
81 | Key_l=11, | ||
82 | Key_m=12, | ||
83 | Key_n=13, | ||
84 | Key_o=14, | ||
85 | Key_p=15, | ||
86 | Key_q=16, | ||
87 | Key_r=17, | ||
88 | Key_s=18, | ||
89 | Key_t=19, | ||
90 | Key_u=20, | ||
91 | Key_v=21, | ||
92 | Key_w=22, | ||
93 | Key_x=23, | ||
94 | Key_y=24, | ||
95 | Key_z=25, | ||
96 | Key_Comma=26, | ||
97 | Key_Slash=27, | ||
98 | Key_Quote=28, | ||
99 | Key_Dot=29, | ||
100 | Key_Backspace=30, | ||
101 | Key_Space=31, | ||
102 | Key_Enter=32, | ||
103 | Key_LeftShift=33, | ||
104 | Key_RightShift=34, | ||
105 | Key_Fn=35, | ||
106 | Key_Tab=36, | ||
107 | Key_Calendar=37, | ||
108 | Key_Addressbook=38, | ||
109 | Key_Home=39, | ||
110 | Key_Menu=40, | ||
111 | Key_Mail=41, | ||
112 | Key_Cancel=42, | ||
113 | Key_OK=43, | ||
114 | Key_Left=44, | ||
115 | Key_Up=45, | ||
116 | Key_Right=46, | ||
117 | Key_Down=47, | ||
118 | Key_Middle=48, | ||
119 | Key_Off=49, | ||
120 | Key_Light=50, | ||
121 | |||
122 | Key_Max=51 | ||
123 | }; | ||
124 | |||
125 | static const short x1[]; | ||
126 | static const short x2[]; | ||
127 | |||
128 | int translateKeycode(int keycode) const; | ||
129 | |||
130 | public: | ||
131 | State(State* parent=0); | ||
132 | State(const State&); | ||
133 | ~State(); | ||
134 | |||
135 | Action* get(int keycode, bool pressed, bool follow = false) const; | ||
136 | bool set(int keycode, bool pressed, Action& action); | ||
137 | |||
138 | State* getParent() const; | ||
139 | void setParent(State*); | ||
140 | }; | ||
141 | |||
142 | class Keymap : public QObject, public QWSServer::KeyboardFilter { | ||
143 | Q_OBJECT | ||
144 | |||
145 | public: | ||
146 | Keymap(); | ||
147 | virtual ~Keymap(); | ||
148 | |||
149 | virtual bool filter(int unicode, int keycode, int modifiers, | ||
150 | bool isPress, bool autoRepeat); | ||
151 | |||
152 | void enable(); | ||
153 | void disable(); | ||
154 | |||
155 | QStringList listStates(); | ||
156 | State* getStateByName(const QString& name); | ||
157 | |||
158 | QStringList listLabels(); | ||
159 | State* getStateByLabel(const QString& label); | ||
160 | |||
161 | bool addState(const QString& name, State* state); | ||
162 | bool removeState(const QString& name, bool force = false); | ||
163 | bool setCurrentState(State*); | ||
164 | State* getCurrentState() const; | ||
165 | QString getCurrentLabel(); | ||
166 | |||
167 | bool addLabel(const QString& label, const QString& state, | ||
168 | int index=-1); | ||
169 | bool removeLabel(const QString& label); | ||
170 | |||
171 | int getAutorepeatDelay() const; | ||
172 | void setAutorepeatDelay(int); | ||
173 | |||
174 | int getAutorepeatPeriod() const; | ||
175 | void setAutorepeatPeriod(int); | ||
176 | |||
177 | signals: | ||
178 | void stateChanged(const QString& name); | ||
179 | |||
180 | protected slots: | ||
181 | void autoRepeat(); | ||
182 | |||
183 | protected: | ||
184 | QMap<QString, State*> states; | ||
185 | QMap<QString, QString> labels; | ||
186 | QStringList labelList; | ||
187 | |||
188 | QMap<State*,QString> stateLabelMap; | ||
189 | bool lsmapInSync; | ||
190 | |||
191 | bool enabled; | ||
192 | State* currentState; | ||
193 | QString currentStateName; | ||
194 | QString currentLabel; | ||
195 | Action* autoRepeatAction; | ||
196 | |||
197 | int repeatDelay; | ||
198 | int repeatPeriod; | ||
199 | QTimer repeater; | ||
200 | |||
201 | QList<Action> findStateUsage(State* s); | ||
202 | void generateLabelStateMaps(); | ||
203 | }; | ||
204 | |||
205 | #endif | ||