2
Copyright (C) 1999-2001 Lubos Lunak <l.lunak@kde.org>
3
Copyright (C) 2008 Michael Jansen <kde@michael-jansen.biz>
5
This library is free software; you can redistribute it and/or
6
modify it under the terms of the GNU Library General Public
7
License version 2 as published by the Free Software Foundation.
9
This library is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
Library General Public License for more details.
14
You should have received a copy of the GNU Library General Public License
15
along with this library; see the file COPYING.LIB. If not, write to
16
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17
Boston, MA 02110-1301, USA.
23
#include <QtCore/QList>
24
#include <QtCore/QMap>
25
#include <QtCore/QUuid>
27
#include <KDE/KShortcut>
29
#include <kdemacros.h>
30
#include "khotkeysglobal.h"
31
#include "voicesignature.h"
34
#include "windows_handler.h"
35
#include "triggers/gestures.h"
48
virtual ~TriggerVisitor();
52
class KDE_EXPORT Trigger
54
Q_DISABLE_COPY( Trigger )
60
GestureTriggerType = 0x01, //!< @see GestureTrigger
61
ShortcutTriggerType = 0x02, //!< @see ShortcutTrigger
62
WindowTriggerType = 0x04, //!< @see WindowTrigger
63
TriggerListType = 0x08, //!< @see Trigger_list
64
AllTypes = 0xFF //!< All types. For convenience.
67
Q_DECLARE_FLAGS(TriggerTypes, TriggerType)
69
Trigger( ActionData* data_P );
71
virtual void cfg_write( KConfigGroup& cfg_P ) const = 0;
72
virtual Trigger* copy( ActionData* data_P ) const = 0;
73
virtual const QString description() const = 0;
74
virtual void activate( bool activate_P ) = 0;
76
//! Disable the trigger
77
virtual void disable();
79
//! Enable the trigger
80
virtual void enable();
83
* The trigger will be erased permanently
85
virtual void aboutToBeErased();
88
* The actual type for this trigger
90
virtual TriggerType type() const = 0;
93
* Acyclic visitor pattern
95
virtual void accept(TriggerVisitor&) = 0;
98
ActionData* const data;
101
Q_DECLARE_OPERATORS_FOR_FLAGS(Trigger::TriggerTypes)
104
class KDE_EXPORT Trigger_list
105
: public QList< Trigger* >
107
Q_DISABLE_COPY( Trigger_list )
110
Trigger_list( const QString& comment = QString() );
111
virtual ~Trigger_list();
113
void activate( bool activate_P );
114
void cfg_write( KConfigGroup& cfg_P ) const;
115
//! Some convenience typedef
116
typedef QList< Trigger* >::Iterator Iterator;
117
typedef QList< Trigger* >::ConstIterator ConstIterator;
118
const QString comment() const;
119
void set_comment(const QString &);
120
Trigger_list* copy( ActionData* data_P ) const;
122
//! Disable the trigger
123
virtual void disable();
125
//! Enable the trigger
126
virtual void enable();
131
void aboutToBeErased();
138
class ShortcutTrigger;
139
class ShortcutTriggerVisitor
142
virtual ~ShortcutTriggerVisitor();
143
virtual void visit(ShortcutTrigger&) = 0;
147
class KDE_EXPORT ShortcutTrigger
148
: public QObject, public Trigger
152
typedef Trigger base;
156
const KShortcut& shortcut = KShortcut(),
157
const QUuid &uuid = QUuid::createUuid() );
159
virtual ~ShortcutTrigger();
160
virtual void cfg_write( KConfigGroup& cfg_P ) const;
161
virtual ShortcutTrigger* copy( ActionData* data_P ) const;
162
virtual const QString description() const;
163
KShortcut shortcut() const;
164
virtual void activate( bool activate_P );
166
void set_key_sequence( const QKeySequence &seq );
168
virtual TriggerType type() const { return ShortcutTriggerType; }
173
void aboutToBeErased();
175
//! Disable the trigger
176
virtual void disable();
178
//! Enable the trigger
179
virtual void enable();
182
* Acyclic visitor pattern
184
virtual void accept(TriggerVisitor&);
188
//! Emitted when the global shortcut is changed from somewhere else
189
// (Global Shortcuts KCM)
190
void globalShortcutChanged(const QKeySequence&);
198
//! A persistent identifier for this shortcut
201
//! Are the conditions met?
205
* The Key Sequence associated with this Trigger. This is needed
206
* because a inactive trigger doesn't register it's shortcut with
207
* kde's global shortcuts registry so we have to remember the shortcut
208
* ourselves. Beware of synchronizing saved state, global shortcuts
209
* registry state and state of this var :-) .
219
class WindowTriggerVisitor
222
virtual ~WindowTriggerVisitor();
223
virtual void visit(WindowTrigger&) = 0;
227
class KDE_EXPORT WindowTrigger : public QObject, public Trigger
231
Q_FLAGS(WindowEvents)
233
typedef Trigger base;
240
WINDOW_APPEARS = ( 1 << 0 ), //!< The window is opened
241
WINDOW_DISAPPEARS = ( 1 << 1 ), //!< The window is closed
242
WINDOW_ACTIVATES = ( 1 << 2 ), //!< The window gets the focus
243
WINDOW_DEACTIVATES = ( 1 << 3 ) //!< The window loses the focus
246
Q_DECLARE_FLAGS(WindowEvents, window_action_t)
250
Windowdef_list* windowslist = NULL,
251
WindowEvents window_actions = 0 );
253
void setOnWindowEvents(WindowEvents events);
255
virtual ~WindowTrigger();
256
virtual void cfg_write( KConfigGroup& cfg_P ) const;
257
virtual WindowTrigger* copy( ActionData* data_P ) const;
258
virtual const QString description() const;
259
const Windowdef_list* windows() const;
260
void set_window_rules(Windowdef_list *list);
261
Windowdef_list* windows();
262
bool triggers_on( window_action_t w_action_P ) const;
263
virtual void activate( bool activate_P );
265
virtual TriggerType type() const { return WindowTriggerType; }
270
* Acyclic visitor pattern
272
virtual void accept(TriggerVisitor&);
275
void window_added( WId window_P );
276
void window_removed( WId window_P );
277
void active_window_changed( WId window_P );
278
void window_changed( WId window_P, unsigned int dirty_P );
282
//! Useful code for all constructors
285
Windowdef_list* _windows;
287
WindowEvents window_actions;
289
typedef QMap< WId, bool > Windows_map;
291
//! Internal cache. Remembers if a window is a match or not,
292
Windows_map existing_windows;
294
//! The last active window
295
WId last_active_window;
297
//! Is the trigger active?
301
Q_DECLARE_OPERATORS_FOR_FLAGS(WindowTrigger::WindowEvents)
304
* This class handles the storage of gesture data; it also matches gestures
305
* and links the gesture to an action.
306
* One object equals one configured gesture.
308
class GestureTrigger;
309
class GestureTriggerVisitor
312
virtual ~GestureTriggerVisitor();
313
virtual void visit(GestureTrigger&) = 0;
316
class KDE_EXPORT GestureTrigger
317
: public QObject, public Trigger
320
typedef Trigger base;
322
GestureTrigger( ActionData* data, const StrokePoints& pointdata_P = StrokePoints() );
324
virtual ~GestureTrigger();
325
virtual void cfg_write( KConfigGroup& cfg_P ) const;
326
virtual Trigger* copy( ActionData* data_P ) const;
327
virtual const QString description() const;
328
const StrokePoints& pointData() const;
330
//! Set the point data of the gesture
331
void setPointData(const StrokePoints &data);
332
void setPointData(const QStringList &strings);
333
void setKDE3Gesture(const QString &gestureCode);
335
virtual void activate( bool activate_P );
337
virtual TriggerType type() const { return GestureTriggerType; }
340
* Acyclic visitor pattern
342
virtual void accept(TriggerVisitor&);
345
void handle_gesture( const StrokePoints& gesture_P );
347
void gotScore( ActionData* const data, const qreal score );
350
qreal comparePointData(const StrokePoints &a, const StrokePoints &b) const;
351
inline qreal angleSquareDifference(qreal alpha, qreal beta) const;
353
StrokePoints _pointdata;
359
class KDE_EXPORT Voice_trigger
360
: public QObject, public Trigger
363
typedef Trigger base;
365
Voice_trigger( ActionData* data_P, const QString& Voice_P, const VoiceSignature & signature1_P, const VoiceSignature & signature2_P );
366
Voice_trigger( KConfigGroup& cfg_P, ActionData* data_P );
367
virtual ~Voice_trigger();
368
virtual void cfg_write( KConfigGroup& cfg_P ) const;
369
virtual Trigger* copy( ActionData* data_P ) const;
370
virtual const QString description() const;
371
const QString& voicecode() const;
372
virtual void activate( bool activate_P );
373
VoiceSignature voicesignature( int ech ) const;
375
virtual TriggerType type() const { return SoundTrigger; }
377
void handle_Voice( );
380
VoiceSignature _voicesignature[2];
388
const QString& Voice_trigger::voicecode() const
394
VoiceSignature Voice_trigger::voicesignature(int ech) const
396
return _voicesignature[ech-1];
399
} // namespace KHotKeys