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"
46 class KDE_EXPORT Trigger
48 Q_DISABLE_COPY( Trigger
)
54 GestureTriggerType
= 0x01, //!< @see GestureTrigger
55 ShortcutTriggerType
= 0x02, //!< @see ShortcutTrigger
56 WindowTriggerType
= 0x04, //!< @see WindowTrigger
57 TriggerListType
= 0x08, //!< @see Trigger_list
58 AllTypes
= 0xFF //!< All types. For convenience.
61 Q_DECLARE_FLAGS(TriggerTypes
, TriggerType
)
63 Trigger( ActionData
* data_P
);
64 Trigger( KConfigGroup
& cfg_P
, ActionData
* data_P
);
66 virtual void cfg_write( KConfigGroup
& cfg_P
) const = 0;
67 virtual Trigger
* copy( ActionData
* data_P
) const = 0;
68 virtual const QString
description() const = 0;
69 static Trigger
* create_cfg_read( KConfigGroup
& cfg_P
, ActionData
* data_P
);
70 virtual void activate( bool activate_P
) = 0;
73 * The trigger will be erased permanently
75 virtual void aboutToBeErased();
78 * The actual type for this trigger
80 virtual TriggerType
type() const = 0;
83 ActionData
* const data
;
86 Q_DECLARE_OPERATORS_FOR_FLAGS(Trigger::TriggerTypes
)
89 class KDE_EXPORT Trigger_list
90 : public QList
< Trigger
* >
92 Q_DISABLE_COPY( Trigger_list
)
95 Trigger_list( const QString
& comment_P
); // CHECKME nebo i data ?
96 Trigger_list( KConfigGroup
& cfg_P
, ActionData
* data_P
);
98 void activate( bool activate_P
);
99 void cfg_write( KConfigGroup
& cfg_P
) const;
100 //! Some convenience typedef
101 typedef QList
< Trigger
* >::Iterator Iterator
;
102 typedef QList
< Trigger
* >::ConstIterator ConstIterator
;
103 const QString
comment() const;
104 Trigger_list
* copy( ActionData
* data_P
) const;
109 void aboutToBeErased();
115 class KDE_EXPORT ShortcutTrigger
116 : public QObject
, public Trigger
120 typedef Trigger base
;
124 const KShortcut
& shortcut_P
,
125 const QUuid
&uuid
= QUuid::createUuid() );
129 ActionData
* data_P
);
131 virtual ~ShortcutTrigger();
132 virtual void cfg_write( KConfigGroup
& cfg_P
) const;
133 virtual ShortcutTrigger
* copy( ActionData
* data_P
) const;
134 virtual const QString
description() const;
135 KShortcut
shortcut() const;
136 virtual void activate( bool activate_P
);
138 void set_key_sequence( const QKeySequence
&seq
);
140 virtual TriggerType
type() const { return ShortcutTriggerType
; }
145 void aboutToBeErased();
149 //! Emitted when the global shortcut is changed from somewhere else
150 // (Global Shortcuts KCM)
151 void globalShortcutChanged(const QKeySequence
&);
159 //! A persistent identifier for this shortcut
163 class KDE_EXPORT WindowTrigger
164 : public QObject
, public Trigger
167 typedef Trigger base
;
171 WINDOW_APPEARS
= ( 1 << 0 ),
172 WINDOW_DISAPPEARS
= ( 1 << 1 ),
173 WINDOW_ACTIVATES
= ( 1 << 2 ),
174 WINDOW_DEACTIVATES
= ( 1 << 3 )
176 WindowTrigger( ActionData
* data_P
, Windowdef_list
* windows_P
, int window_actions_P
);
177 WindowTrigger( KConfigGroup
& cfg_P
, ActionData
* data_P
);
178 virtual ~WindowTrigger();
179 virtual void cfg_write( KConfigGroup
& cfg_P
) const;
180 virtual WindowTrigger
* copy( ActionData
* data_P
) const;
181 virtual const QString
description() const;
182 const Windowdef_list
* windows() const;
183 bool triggers_on( window_action_t w_action_P
) const;
184 virtual void activate( bool activate_P
);
186 virtual TriggerType
type() const { return WindowTriggerType
; }
187 protected: // CHECKME neco private ?
188 Windowdef_list
* _windows
;
191 typedef QMap
< WId
, bool > Windows_map
;
192 Windows_map existing_windows
;
193 WId last_active_window
;
195 void window_added( WId window_P
);
196 void window_removed( WId window_P
);
197 void active_window_changed( WId window_P
);
198 void window_changed( WId window_P
, unsigned int dirty_P
);
203 class KDE_EXPORT GestureTrigger
204 : public QObject
, public Trigger
207 typedef Trigger base
;
209 GestureTrigger( ActionData
* data_P
, const QString
& gesture_P
);
210 GestureTrigger( KConfigGroup
& cfg_P
, ActionData
* data_P
);
211 virtual ~GestureTrigger();
212 virtual void cfg_write( KConfigGroup
& cfg_P
) const;
213 virtual Trigger
* copy( ActionData
* data_P
) const;
214 virtual const QString
description() const;
215 const QString
& gesturecode() const;
216 virtual void activate( bool activate_P
);
218 virtual TriggerType
type() const { return GestureTriggerType
; }
220 void handle_gesture( const QString
& gesture_P
, WId window_P
);
222 QString _gesturecode
;
228 class KDE_EXPORT Voice_trigger
229 : public QObject
, public Trigger
232 typedef Trigger base
;
234 Voice_trigger( ActionData
* data_P
, const QString
& Voice_P
, const VoiceSignature
& signature1_P
, const VoiceSignature
& signature2_P
);
235 Voice_trigger( KConfigGroup
& cfg_P
, ActionData
* data_P
);
236 virtual ~Voice_trigger();
237 virtual void cfg_write( KConfigGroup
& cfg_P
) const;
238 virtual Trigger
* copy( ActionData
* data_P
) const;
239 virtual const QString
description() const;
240 const QString
& voicecode() const;
241 virtual void activate( bool activate_P
);
242 VoiceSignature
voicesignature( int ech
) const;
244 virtual TriggerType
type() const { return SoundTrigger
; }
246 void handle_Voice( );
249 VoiceSignature _voicesignature
[2];
257 const QString
& Voice_trigger::voicecode() const
263 VoiceSignature
Voice_trigger::voicesignature(int ech
) const
265 return _voicesignature
[ech
-1];
268 } // namespace KHotKeys