00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef INPUTENGINE_H
00023 #define INPUTENGINE_H
00024
00025
00026 #include <QKeyEvent>
00027 #include <QWheelEvent>
00028 #include <QString>
00029 #include <QObject>
00030 #include <QTimer>
00031 #include <QHash>
00032 #include <QStringList>
00033
00034
00035 class ContextItem;
00036 class Command;
00037 class CommandPlugin;
00038
00039 static const int FKEY = 0;
00040 static const int FKEY2 = 1;
00041 static const int HOLDKEY = 2;
00042 static const int HKEY2 = 3;
00043 static const int D_FKEY = 4;
00044 static const int D_FKEY2 = 5;
00045 static const int FHKEY = 6;
00046 static const int FHKEY2 = 7;
00047 static const int S_FKEY_FKEY = 8;
00048 static const int S_FKEY_FKEY2 = 9;
00049 static const int S_FKEY2_FKEY = 10;
00050 static const int S_FKEY2_FKEY2 = 11;
00051 static const int S_FKEY_HKEY = 12;
00052 static const int S_FKEY_HKEY2 = 13;
00053 static const int S_FKEY2_HKEY = 14;
00054 static const int S_FKEY2_HKEY2 = 15;
00055
00056
00057 class EventCatcher : public QObject
00058 {
00059 Q_OBJECT
00060 public:
00061 EventCatcher();
00062
00063 QTimer holdTimer;
00064 QTimer clearOutputTimer;
00065 QTimer secondChanceTimer;
00066
00067 public slots:
00068 void assume_hold();
00069 void quit_second_chance();
00070 void clear_output();
00071 };
00072
00073
00074
00075 struct IEAction
00076 {
00077 void render_key_sequence(const QString& key1, const QString& key2);
00078 ~IEAction();
00079 struct Data {
00080 QStringList modes;
00081 QVariantList arguments;
00082 QList<int > modifierkeys;
00083 QString slotsignature;
00084 QString pluginname;
00085 QString commandname;
00086 QString submenu;
00087 bool useX;
00088 bool useY;
00089 int sortorder;
00090 };
00091
00092 QHash<QString, Data*> objects;
00093 QHash<QString, Data*> objectUsingModifierKeys;
00094
00095 int type;
00096 int fact1_key1;
00097 int fact1_key2;
00098 int fact2_key1;
00099 int fact2_key2;
00100 bool isInstantaneous;
00101 QByteArray keySequence;
00102 };
00103
00104
00105 struct MenuData {
00106 static bool smaller(const MenuData left, const MenuData right )
00107 {
00108 return left.sortorder < right.sortorder;
00109 }
00110 static bool greater(const MenuData* left, const MenuData* right )
00111 {
00112 return left->sortorder > right->sortorder;
00113 }
00114 QString keysequence;
00115 QString iedata;
00116 QString description;
00117 QString submenu;
00118 int sortorder;
00119 QList<int > modifierkeys;
00120 };
00121
00122 class InputEngine : public QObject
00123 {
00124 Q_OBJECT
00125 public:
00126
00127 void catch_key_press(QKeyEvent *);
00128 void catch_key_release(QKeyEvent *);
00129 void catch_mousebutton_press( QMouseEvent * e );
00130 void catch_mousebutton_release( QMouseEvent * e );
00131 void catch_mousebutton_doubleclick( QMouseEvent * e );
00132 void catch_scroll(QWheelEvent * e );
00133
00134 int collected_number();
00135
00136 bool is_jogging();
00137 bool is_holding();
00138
00139 QList<MenuData > create_menudata_for(QObject* item);
00140 Command* get_holding_command() const;
00141 void create_menudata_for_metaobject(const QMetaObject* mo, QList<MenuData >& list) const;
00142
00143 int broadcast_action_from_contextmenu(const QString& name);
00144
00145 void jog();
00146 void bypass_jog_until_mouse_movements_exceeded_manhattenlength(int length=35);
00147
00148 void activate();
00149 void suspend();
00150 void clear_modifier_keys();
00151
00152 Command* succes();
00153 Command* failure();
00154 Command* did_not_implement();
00155
00156
00157 int init_map(const QString& mapFilename);
00158
00159 void set_clear_time(int time);
00160 void set_hold_sensitiveness(int factor);
00161 void set_double_fact_interval(int time);
00162
00163
00164 private:
00165 InputEngine();
00166 InputEngine(const InputEngine&) : QObject() {}
00167 ~InputEngine();
00168
00169 static const int STACK_SIZE = 4;
00170 static const int MAX_ACTIONS = 300;
00171 static const int PRESS_EVENT = 1;
00172 static const int RELEASE_EVENT = 2;
00173
00174 enum BroadcastResult {
00175 SUCCES=1,
00176 FAILURE=2,
00177 DIDNOTIMPLEMENT=3
00178 };
00179
00180
00181 QList<IEAction* > m_ieActions;
00182 QList<int> m_modifierKeys;
00183 QList<int> m_activeModifierKeys;
00184 QHash<QString, CommandPlugin*> m_commandplugins;
00185 QHash<QString, int> m_modes;
00186 EventCatcher catcher;
00187 Command* holdingCommand;
00188 QString sCollectedNumber;
00189 QPoint m_jogBypassPos;
00190
00191
00192 bool active;
00193 bool isHolding;
00194 bool isPressEventLocked;
00195 bool isHoldingOutput;
00196 bool isFirstFact;
00197 bool isDoubleKey;
00198 bool isJogging;
00199 bool m_cancelHold;
00200 bool m_bypassJog;
00201
00202 int fact1_k1;
00203 int fact1_k2;
00204 int fact2_k1;
00205 int fact2_k2;
00206 int fact1Type;
00207 int wholeMapIndex;
00208 int wholeActionType;
00209 int collectedNumber;
00210 int stackIndex;
00211 int eventType[STACK_SIZE];
00212 int eventStack[STACK_SIZE];
00213 int pressEventCounter;
00214 int pairOf2;
00215 int pairOf3;
00216 int clearTime;
00217 int assumeHoldTime;
00218 int doubleFactWaitTime;
00219 long eventTime[STACK_SIZE];
00220 int m_broadcastResult;
00221 int m_unbypassJogDistance;
00222
00223 bool is_fake( int keyval);
00224 int identify_first_fact();
00225 int identify_first_and_second_facts_together();
00226 void push_event(int pType, int pKey);
00227 void press_checker();
00228 void release_checker();
00229 void push_fact( int k1 , int k2);
00230 void give_a_chance_for_second_fact();
00231 void dispatch_action(int mapIndex);
00232 void dispatch_hold();
00233 void finish_hold();
00234 void conclusion();
00235 void hold_output();
00236 void stop_collecting();
00237 bool check_number_collection(int eventcode);
00238
00240 int broadcast_action(IEAction* action, bool autorepeat=false, bool fromContextMenu=false);
00241
00242 void set_jogging(bool jog);
00243 void reset();
00244 void process_press_event(int eventcode, bool isAutoRepeat=false);
00245 void process_release_event(int eventcode);
00246 int find_index_for_instant_fkey( int key );
00247 int find_index_for_instant_fkey2( int key1, int key2 );
00248 int find_index_for_single_fact(int type, int key1, int key2);
00249 bool is_modifier_keyfact(int eventcode);
00250
00251 int holdEventCode;
00252
00253 friend class EventCatcher;
00254
00255
00256 friend InputEngine& ie();
00257 };
00258
00259
00260 InputEngine& ie();
00261
00262
00263 #endif
00264
00265