00001 #ifndef ZKB_H
00002 #define ZKB_H
00003
00004 #include <qstring.h>
00005 #include <qstringlist.h>
00006 #include <qmap.h>
00007 #include <qwindowsystem_qws.h>
00008 #include <qkeyboard_qws.h>
00009 #include <qtimer.h>
00010 #include <stdio.h>
00011
00012 class State;
00013
00014 class Action {
00015 protected:
00016 State* state;
00017 ushort keycode;
00018 ushort unicode;
00019 int flags;
00020
00021 enum {
00022 Shift_Mod = 1,
00023 Ctrl_Mod = 2,
00024 Alt_Mod = 4,
00025 Keypad_Mod = 8,
00026 Mod_Bits = 15,
00027 Press = 16,
00028 Autorepeat = 32,
00029 Event = 64,
00030 Defined = 128,
00031 };
00032
00033 void setDefined(bool);
00034
00035 public:
00036 Action();
00037 Action(State*, ushort, ushort, int);
00038 ~Action();
00039
00040 State* getState() const;
00041 void setState(State*);
00042
00043 bool hasEvent() const;
00044 void setEvent(bool);
00045
00046 bool isDefined() const;
00047
00048 int getKeycode() const;
00049 void setKeycode(int);
00050
00051 int getUnicode() const;
00052 void setUnicode(int);
00053
00054 int getModifiers() const;
00055 void setModifiers(int m);
00056
00057 bool isPressed() const;
00058 void setPressed(bool);
00059
00060 bool isAutorepeat() const;
00061 void setAutorepeat(bool);
00062 };
00063
00064 class State {
00065 protected:
00066 State* parent;
00067 Action* keys;
00068
00069 enum {
00070 Key_a=0,
00071 Key_b=1,
00072 Key_c=2,
00073 Key_d=3,
00074 Key_e=4,
00075 Key_f=5,
00076 Key_g=6,
00077 Key_h=7,
00078 Key_i=8,
00079 Key_j=9,
00080 Key_k=10,
00081 Key_l=11,
00082 Key_m=12,
00083 Key_n=13,
00084 Key_o=14,
00085 Key_p=15,
00086 Key_q=16,
00087 Key_r=17,
00088 Key_s=18,
00089 Key_t=19,
00090 Key_u=20,
00091 Key_v=21,
00092 Key_w=22,
00093 Key_x=23,
00094 Key_y=24,
00095 Key_z=25,
00096 Key_Comma=26,
00097 Key_Slash=27,
00098 Key_Quote=28,
00099 Key_Dot=29,
00100 Key_Backspace=30,
00101 Key_Space=31,
00102 Key_Enter=32,
00103 Key_LeftShift=33,
00104 Key_RightShift=34,
00105 Key_Fn=35,
00106 Key_Tab=36,
00107 Key_Calendar=37,
00108 Key_Addressbook=38,
00109 Key_Home=39,
00110 Key_Menu=40,
00111 Key_Mail=41,
00112 Key_Cancel=42,
00113 Key_OK=43,
00114 Key_Left=44,
00115 Key_Up=45,
00116 Key_Right=46,
00117 Key_Down=47,
00118 Key_Middle=48,
00119 Key_Off=49,
00120 Key_Light=50,
00121
00122 Key_Max=51
00123 };
00124
00125 static const short x1[];
00126 static const short x2[];
00127
00128 int translateKeycode(int keycode) const;
00129
00130 public:
00131 State(State* parent=0);
00132 State(const State&);
00133 ~State();
00134
00135 Action* get(int keycode, bool pressed, bool follow = false) const;
00136 bool set(int keycode, bool pressed, Action& action);
00137
00138 State* getParent() const;
00139 void setParent(State*);
00140 };
00141
00142 class Keymap : public QObject, public QWSServer::KeyboardFilter {
00143 Q_OBJECT
00144
00145 public:
00146 Keymap();
00147 virtual ~Keymap();
00148
00149 virtual bool filter(int unicode, int keycode, int modifiers,
00150 bool isPress, bool autoRepeat);
00151
00152 void enable();
00153 void disable();
00154
00155 QStringList listStates();
00156 State* getStateByName(const QString& name);
00157
00158 QStringList listLabels();
00159 State* getStateByLabel(const QString& label);
00160
00161 bool addState(const QString& name, State* state);
00162 bool removeState(const QString& name, bool force = false);
00163 bool setCurrentState(State*);
00164 State* getCurrentState() const;
00165 QString getCurrentLabel();
00166
00167 bool addLabel(const QString& label, const QString& state,
00168 int index=-1);
00169 bool removeLabel(const QString& label);
00170
00171 int getAutorepeatDelay() const;
00172 void setAutorepeatDelay(int);
00173
00174 int getAutorepeatPeriod() const;
00175 void setAutorepeatPeriod(int);
00176
00177 signals:
00178 void stateChanged(const QString& name);
00179
00180 protected slots:
00181 void autoRepeat();
00182
00183 protected:
00184 QMap<QString, State*> states;
00185 QMap<QString, QString> labels;
00186 QStringList labelList;
00187
00188 QMap<State*,QString> stateLabelMap;
00189 bool lsmapInSync;
00190
00191 bool enabled;
00192 State* currentState;
00193 QString currentStateName;
00194 QString currentLabel;
00195 Action* autoRepeatAction;
00196
00197 int repeatDelay;
00198 int repeatPeriod;
00199 QTimer repeater;
00200
00201 QList<Action> findStateUsage(State* s);
00202 void generateLabelStateMaps();
00203 };
00204
00205 #endif