not quite so much needs to be delayed to the init() function
[personal-kdebase.git] / workspace / khotkeys / libkhotkeysprivate / triggers / gestures.h
blob24b6e42091ae6e5d11282ab5ef29633a5be899b6
1 /****************************************************************************
3 KHotKeys
5 Copyright (C) 1999-2002 Lubos Lunak <l.lunak@kde.org>
7 Distributed under the terms of the GNU General Public License version 2.
9 ****************************************************************************/
11 #ifndef _GESTURES_H_
12 #define _GESTURES_H_
14 #include <QWidget>
15 #include <QTimer>
16 #include <QMap>
17 #include <QtCore/QPointer>
20 #include <X11/Xlib.h>
21 #include <fixx11h.h>
23 #include "windows.h"
25 namespace KHotKeys
28 class Gesture;
29 KDE_EXPORT extern QPointer<Gesture> gesture_handler;
31 class KDE_EXPORT Stroke
33 public:
34 // maximum number of numbers in stroke
35 enum { MAX_SEQUENCE = 25 };
36 // largest number of points allowed to be sampled
37 enum { MAX_POINTS = 5000 };
38 // default percentage of sample points in a bin from all points to be valid
39 enum { MIN_BIN_POINTS_PERCENTAGE = 5 };
40 // default threshold of size of smaller axis needed for it to define its own bin size
41 enum { SCALE_RATIO = 4 };
42 // default number of sample points required to have a valid stroke
43 enum { MIN_POINTS = 10 };
44 Stroke();
45 ~Stroke();
46 bool record( int x, int y );
47 char* translate( int min_bin_points_percentage_P = MIN_BIN_POINTS_PERCENTAGE,
48 int scale_ratio_P = SCALE_RATIO, int min_points_P = MIN_POINTS ); // CHECKME returns ret_val ( see below )
49 void reset();
50 protected:
51 int bin( int x, int y );
52 // metrics for input stroke
53 int min_x, min_y;
54 int max_x, max_y;
55 int point_count;
56 int delta_x, delta_y;
57 int bound_x_1, bound_x_2;
58 int bound_y_1, bound_y_2;
59 struct point
61 int x;
62 int y;
64 point* points;
65 char ret_val[ MAX_SEQUENCE ];
68 class KDE_EXPORT Gesture
69 : public QWidget // not QObject because of x11EventFilter()
71 Q_OBJECT
72 public:
73 Gesture( bool enabled_P, QObject* parent_P );
74 virtual ~Gesture();
75 void enable( bool enable_P );
76 void set_mouse_button( unsigned int button_P );
77 void set_timeout( int time_P );
78 void set_exclude( Windowdef_list* windows_P );
79 void register_handler( QObject* receiver_P, const char* slot_P );
80 void unregister_handler( QObject* receiver_P, const char* slot_P );
81 protected:
82 virtual bool x11Event( XEvent* ev_P );
83 private Q_SLOTS:
84 void stroke_timeout();
85 void active_window_changed( WId window_P );
86 Q_SIGNALS:
87 void handle_gesture( const QString &gesture, WId window );
88 private:
89 void update_grab();
90 void grab_mouse( bool grab_P );
91 void mouse_replay( bool release_P );
92 bool _enabled;
93 Stroke stroke;
94 int start_x, start_y;
95 QTimer nostroke_timer;
96 bool recording;
97 unsigned int button;
98 int timeout;
99 WId gesture_window;
100 Windowdef_list* exclude;
101 QMap< QObject*, bool > handlers; // bool is just a dummy
104 // Gesture class must be QWidget derived because of x11Event()
105 // but it should be QObject owned -> use a QObject proxy that will delete it
106 class DeleteObject
107 : public QObject
109 Q_OBJECT
110 public:
111 DeleteObject( QWidget* widget_P, QObject* parent_P )
112 : QObject( parent_P ), widget( widget_P ) {}
113 virtual ~DeleteObject() { delete widget; }
114 private:
115 QWidget* widget;
119 //***************************************************************************
120 // Inline
121 //***************************************************************************
123 } // namespace KHotKeys
125 #endif