1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
|
/****************************************************************************
KHotKeys
Copyright (C) 1999-2001 Lubos Lunak <l.lunak@kde.org>
Distributed under the terms of the GNU General Public License version 2.
****************************************************************************/
#define _TRIGGERS_TAB_CPP_
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include "triggers_tab.h"
#include <assert.h>
#include <qpushbutton.h>
#include <qlineedit.h>
#include <qpopupmenu.h>
#include <qlayout.h>
#include <qlabel.h>
#include <qheader.h>
#include <kdebug.h>
#include <klocale.h>
#include <kapplication.h>
#include <kshortcut.h>
#include <kconfig.h>
#include <kshortcutlist.h>
#include <kkeybutton.h>
#include <kkeydialog.h>
#include "kcmkhotkeys.h"
#include "windowdef_list_widget.h"
#include "window_trigger_widget.h"
#include "gesturerecordpage.h"
#include "voicerecordpage.h"
namespace KHotKeys
{
// Triggers_tab
Triggers_tab::Triggers_tab( QWidget* parent_P, const char* name_P )
: Triggers_tab_ui( parent_P, name_P ), selected_item( NULL )
{
QPopupMenu* popup = new QPopupMenu; // CHECKME looks like setting parent doesn't work
popup->insertItem( i18n( "Shortcut Trigger..." ), TYPE_SHORTCUT_TRIGGER );
popup->insertItem( i18n( "Gesture Trigger..." ), TYPE_GESTURE_TRIGGER );
popup->insertItem( i18n( "Window Trigger..." ), TYPE_WINDOW_TRIGGER );
#ifdef HAVE_ARTS
if( haveArts())
popup->insertItem( i18n( "Voice Trigger..." ), TYPE_VOICE_TRIGGER );
#endif
connect( popup, SIGNAL( activated( int )), SLOT( new_selected( int )));
connect( triggers_listview, SIGNAL( doubleClicked ( QListViewItem *, const QPoint &, int ) ),
this, SLOT( modify_pressed() ) );
new_button->setPopup( popup );
copy_button->setEnabled( false );
modify_button->setEnabled( false );
delete_button->setEnabled( false );
triggers_listview->header()->hide();
triggers_listview->addColumn( "" );
triggers_listview->setSorting( -1 );
triggers_listview->setForceSelect( true );
clear_data();
// KHotKeys::Module::changed()
connect( new_button, SIGNAL( clicked()),
module, SLOT( changed()));
connect( copy_button, SIGNAL( clicked()),
module, SLOT( changed()));
connect( modify_button, SIGNAL( clicked()),
module, SLOT( changed()));
connect( delete_button, SIGNAL( clicked()),
module, SLOT( changed()));
connect( comment_lineedit, SIGNAL( textChanged( const QString& )),
module, SLOT( changed()));
}
Triggers_tab::~Triggers_tab()
{
delete new_button->popup(); // CHECKME
}
void Triggers_tab::clear_data()
{
comment_lineedit->clear();
triggers_listview->clear();
}
void Triggers_tab::set_data( const Trigger_list* data_P )
{
if( data_P == NULL )
{
clear_data();
return;
}
comment_lineedit->setText( data_P->comment());
Trigger_list_item* after = NULL;
triggers_listview->clear();
for( Trigger_list::Iterator it( *data_P );
*it;
++it )
after = create_listview_item( *it, triggers_listview, after, true );
}
Trigger_list* Triggers_tab::get_data( Action_data* data_P ) const
{
Trigger_list* list = new Trigger_list( comment_lineedit->text());
for( QListViewItem* pos = triggers_listview->firstChild();
pos != NULL;
pos = pos->nextSibling())
list->append( static_cast< Trigger_list_item* >( pos )->trigger()->copy( data_P ));
return list;
}
void Triggers_tab::new_selected( int type_P )
{
Trigger_dialog* dlg = NULL;
switch( type_P )
{
case TYPE_SHORTCUT_TRIGGER: // Shortcut_trigger
dlg = new Shortcut_trigger_dialog(
new Shortcut_trigger( NULL, KShortcut())); // CHECKME NULL ?
break;
case TYPE_GESTURE_TRIGGER: // Gesture trigger
dlg = new Gesture_trigger_dialog(
new Gesture_trigger( NULL, QString::null )); // CHECKME NULL ?
break;
case TYPE_WINDOW_TRIGGER: // Window trigger
dlg = new Window_trigger_dialog( new Window_trigger( NULL, new Windowdef_list( "" ),
0 )); // CHECKME NULL ?
break;
case TYPE_VOICE_TRIGGER: // Voice trigger
dlg = new Voice_trigger_dialog( new Voice_trigger(NULL,QString::null,VoiceSignature(),VoiceSignature())); // CHECKME NULL ?
break;
}
if( dlg != NULL )
{
Trigger* trg = dlg->edit_trigger();
if( trg != NULL )
triggers_listview->setSelected( create_listview_item( trg, triggers_listview,
selected_item, false ), true );
delete dlg;
}
}
void Triggers_tab::copy_pressed()
{
if ( selected_item )
{
triggers_listview->setSelected( create_listview_item( selected_item->trigger(),triggers_listview, selected_item, true ), true );
}
}
void Triggers_tab::delete_pressed()
{
delete selected_item; // CHECKME snad vyvola signaly pro enable()
selected_item = NULL;
}
void Triggers_tab::modify_pressed()
{
if ( selected_item )
edit_listview_item( selected_item );
}
void Triggers_tab::current_changed( QListViewItem* item_P )
{
// if( item_P == selected_item )
// return;
selected_item = static_cast< Trigger_list_item* >( item_P );
// triggers_listview->setSelected( item_P, true );
copy_button->setEnabled( item_P != NULL );
modify_button->setEnabled( item_P != NULL );
delete_button->setEnabled( item_P != NULL );
}
Trigger_list_item* Triggers_tab::create_listview_item( Trigger* trigger_P,
QListView* parent_P, QListViewItem* after_P, bool copy_P )
{
Trigger* new_trg = copy_P ? trigger_P->copy( NULL ) : trigger_P; // CHECKME NULL ?
// CHECKME uz by nemelo byt treba if( after_P == NULL )
// return new Trigger_list_item( parent_P, new_trg );
// else
return new Trigger_list_item( parent_P, after_P, new_trg );
}
void Triggers_tab::edit_listview_item( Trigger_list_item* item_P )
{
Trigger_dialog* dlg = NULL;
if( Shortcut_trigger* trg = dynamic_cast< Shortcut_trigger* >( item_P->trigger()))
dlg = new Shortcut_trigger_dialog( trg );
else if( Gesture_trigger* trg = dynamic_cast< Gesture_trigger* >( item_P->trigger()))
dlg = new Gesture_trigger_dialog( trg );
else if( Window_trigger* trg = dynamic_cast< Window_trigger* >( item_P->trigger()))
dlg = new Window_trigger_dialog( trg );
else if( Voice_trigger* trg = dynamic_cast< Voice_trigger* >( item_P->trigger()))
dlg = new Voice_trigger_dialog( trg );
// CHECKME TODO dalsi
else
assert( false );
Trigger* new_trigger = dlg->edit_trigger();
if( new_trigger != NULL )
item_P->set_trigger( new_trigger );
delete dlg;
}
// Trigger_list_item
QString Trigger_list_item::text( int column_P ) const
{
return column_P == 0 ? trigger()->description() : QString::null;
}
// Shortcut_trigger_widget
Shortcut_trigger_widget::Shortcut_trigger_widget( QWidget* parent_P, const char* )
: QWidget( parent_P )
{
QVBoxLayout* lay = new QVBoxLayout( this, 11, 6 );
QLabel* lbl = new QLabel( i18n( "Select keyboard shortcut:" ), this );
lay->addWidget( lbl );
lay->addSpacing( 10 );
bt = new KKeyButton( this );
lay->addWidget( bt, 0 , Qt::AlignHCenter );
lay->addStretch();
clear_data();
connect( bt, SIGNAL( capturedShortcut( const KShortcut& )),
this, SLOT( capturedShortcut( const KShortcut& )));
}
void Shortcut_trigger_widget::clear_data()
{
bt->setShortcut( KShortcut(), false );
}
void Shortcut_trigger_widget::capturedShortcut( const KShortcut& s_P )
{
if( KKeyChooser::checkGlobalShortcutsConflict( s_P, true, topLevelWidget())
|| KKeyChooser::checkStandardShortcutsConflict( s_P, true, topLevelWidget()))
return;
// KHotKeys::Module::changed()
module->changed();
bt->setShortcut( s_P, false );
}
void Shortcut_trigger_widget::set_data( const Shortcut_trigger* data_P )
{
if( data_P == NULL )
{
clear_data();
return;
}
bt->setShortcut( data_P->shortcut(), false );
}
Shortcut_trigger* Shortcut_trigger_widget::get_data( Action_data* data_P ) const
{
return !bt->shortcut().isNull()
? new Shortcut_trigger( data_P, bt->shortcut()) : NULL;
}
// Shortcut_trigger_dialog
Shortcut_trigger_dialog::Shortcut_trigger_dialog( Shortcut_trigger* trigger_P )
: KDialogBase( NULL, NULL, true, "", Ok | Cancel ), // CHECKME caption
trigger( NULL )
{
widget = new Shortcut_trigger_widget( this );
widget->set_data( trigger_P );
setMainWidget( widget );
}
Trigger* Shortcut_trigger_dialog::edit_trigger()
{
exec();
return trigger;
}
void Shortcut_trigger_dialog::accept()
{
KDialogBase::accept();
trigger = widget->get_data( NULL ); // CHECKME NULL ?
}
// Window_trigger_dialog
Window_trigger_dialog::Window_trigger_dialog( Window_trigger* trigger_P )
: KDialogBase( NULL, NULL, true, "", Ok | Cancel ), // CHECKME caption
trigger( NULL )
{
widget = new Window_trigger_widget( this );
widget->set_data( trigger_P );
setMainWidget( widget );
}
Trigger* Window_trigger_dialog::edit_trigger()
{
exec();
return trigger;
}
void Window_trigger_dialog::accept()
{
KDialogBase::accept();
trigger = widget->get_data( NULL ); // CHECKME NULL ?
}
// Gesture_trigger_dialog
Gesture_trigger_dialog::Gesture_trigger_dialog( Gesture_trigger* trigger_P )
: KDialogBase( NULL, NULL, true, "", Ok | Cancel ), // CHECKME caption
_trigger( trigger_P ), _page( NULL )
{
_page = new GestureRecordPage( _trigger->gesturecode(),
this, "GestureRecordPage");
connect(_page, SIGNAL(gestureRecorded(bool)),
this, SLOT(enableButtonOK(bool)));
setMainWidget( _page );
}
Trigger* Gesture_trigger_dialog::edit_trigger()
{
if( exec())
return new Gesture_trigger( NULL, _page->getGesture()); // CHECKME NULL?
else
return NULL;
}
// Voice_trigger_dialog
Voice_trigger_dialog::Voice_trigger_dialog( Voice_trigger* trigger_P )
: KDialogBase( NULL, NULL, true, "", Ok | Cancel ), // CHECKME caption
_trigger( trigger_P ), _page( NULL )
{
_page = new VoiceRecordPage( _trigger ? _trigger->voicecode() : QString::null , this, "VoiceRecordPage");
connect(_page, SIGNAL(voiceRecorded(bool)), this, SLOT(enableButtonOK(bool)));
setMainWidget( _page );
}
Trigger* Voice_trigger_dialog::edit_trigger()
{
if( exec())
return new Voice_trigger(NULL, _page->getVoiceId(),
(_page->isModifiedSignature(1) || !_trigger) ? _page->getVoiceSignature(1) : _trigger->voicesignature(1) ,
(_page->isModifiedSignature(2) || !_trigger) ? _page->getVoiceSignature(2) : _trigger->voicesignature(2) );
else
return NULL;
}
} // namespace KHotKeys
#include "triggers_tab.moc"
|