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
|
'\" t
.TH TQAccel 3qt "2 February 2007" "Trolltech AS" \" -*- nroff -*-
.\" Copyright 1992-2007 Trolltech ASA. All rights reserved. See the
.\" license file included in the distribution for a complete license
.\" statement.
.\"
.ad l
.nh
.SH NAME
TQAccel \- Handles keyboard accelerator and shortcut keys
.SH SYNOPSIS
\fC#include <tqaccel.h>\fR
.PP
Inherits TQObject.
.PP
.SS "Public Members"
.in +1c
.ti -1c
.BI "\fBTQAccel\fR ( TQWidget * parent, const char * name = 0 )"
.br
.ti -1c
.BI "\fBTQAccel\fR ( TQWidget * watch, TQObject * parent, const char * name = 0 )"
.br
.ti -1c
.BI "\fB~TQAccel\fR ()"
.br
.ti -1c
.BI "bool \fBisEnabled\fR () const"
.br
.ti -1c
.BI "void \fBsetEnabled\fR ( bool enable )"
.br
.ti -1c
.BI "uint \fBcount\fR () const"
.br
.ti -1c
.BI "int \fBinsertItem\fR ( const TQKeySequence & key, int id = -1 )"
.br
.ti -1c
.BI "void \fBremoveItem\fR ( int id )"
.br
.ti -1c
.BI "void \fBclear\fR ()"
.br
.ti -1c
.BI "TQKeySequence \fBkey\fR ( int id )"
.br
.ti -1c
.BI "int \fBfindKey\fR ( const TQKeySequence & key ) const"
.br
.ti -1c
.BI "bool \fBisItemEnabled\fR ( int id ) const"
.br
.ti -1c
.BI "void \fBsetItemEnabled\fR ( int id, bool enable )"
.br
.ti -1c
.BI "bool \fBconnectItem\fR ( int id, const TQObject * receiver, const char * member )"
.br
.ti -1c
.BI "bool \fBdisconnectItem\fR ( int id, const TQObject * receiver, const char * member )"
.br
.ti -1c
.BI "void repairEventFilter () \fI(obsolete)\fR"
.br
.ti -1c
.BI "void \fBsetWhatsThis\fR ( int id, const TQString & text )"
.br
.ti -1c
.BI "TQString \fBwhatsThis\fR ( int id ) const"
.br
.in -1c
.SS "Signals"
.in +1c
.ti -1c
.BI "void \fBactivated\fR ( int id )"
.br
.ti -1c
.BI "void \fBactivatedAmbiguously\fR ( int id )"
.br
.in -1c
.SS "Static Public Members"
.in +1c
.ti -1c
.BI "TQKeySequence \fBshortcutKey\fR ( const TQString & str )"
.br
.ti -1c
.BI "TQString keyToString ( TQKeySequence k ) \fI(obsolete)\fR"
.br
.ti -1c
.BI "TQKeySequence stringToKey ( const TQString & s ) \fI(obsolete)\fR"
.br
.in -1c
.SS "Protected Members"
.in +1c
.ti -1c
.BI "virtual bool eventFilter ( TQObject *, TQEvent * ) \fI(obsolete)\fR"
.br
.in -1c
.SH DESCRIPTION
The TQAccel class handles keyboard accelerator and shortcut keys.
.PP
A keyboard accelerator triggers an action when a certain key combination is pressed. The accelerator handles all keyboard activity for all the children of one top-level widget, so it is not affected by the keyboard focus.
.PP
In most cases, you will not need to use this class directly. Use the TQAction class to create actions with accelerators that can be used in both menus and toolbars. If you're only interested in menus use TQMenuData::insertItem() or TQMenuData::setAccel() to make accelerators for operations that are also available on menus. Many widgets automatically generate accelerators, such as TQButton, TQGroupBox, TQLabel (with TQLabel::setBuddy()), TQMenuBar and TQTabBar. Example:
.PP
.nf
.br
TQPushButton p( "&Exit", parent ); // automatic shortcut ALT+Key_E
.br
TQPopupMenu *fileMenu = new fileMenu( parent );
.br
fileMenu->insertItem( "Undo", parent, TQ_SLOT(undo()), CTRL+Key_Z );
.br
.fi
.PP
A TQAccel contains a list of accelerator items that can be manipulated using insertItem(), removeItem(), clear(), key() and findKey().
.PP
Each accelerator item consists of an identifier and a TQKeySequence. A single key sequence consists of a keyboard code combined with modifiers (SHIFT, CTRL, ALT or UNICODE_ACCEL). For example, \fCCTRL + Key_P\fR could be a shortcut for printing a document. The key codes are listed in ntqnamespace.h. As an alternative, use UNICODE_ACCEL with the unicode code point of the character. For example, \fCUNICODE_ACCEL + 'A'\fR gives the same accelerator as Key_A.
.PP
When an accelerator key is pressed, the accelerator sends out the signal activated() with a number that identifies this particular accelerator item. Accelerator items can also be individually connected, so that two different keys will activate two different slots (see connectItem() and disconnectItem()).
.PP
The activated() signal is \fInot\fR emitted when two or more accelerators match the same key. Instead, the first matching accelerator sends out the activatedAmbiguously() signal. By pressing the key multiple times, users can navigate between all matching accelerators. Some standard controls like TQPushButton and TQCheckBox connect the activatedAmbiguously() signal to the harmless setFocus() slot, whereas activated() is connected to a slot invoking the button's action. Most controls, like TQLabel and TQTabBar, treat activated() and activatedAmbiguously() as equivalent.
.PP
Use setEnabled() to enable or disable all the items in an accelerator, or setItemEnabled() to enable or disable individual items. An item is active only when both the TQAccel and the item itself are enabled.
.PP
The function setWhatsThis() specifies a help text that appears when the user presses an accelerator key in What's This mode.
.PP
The accelerator will be deleted when \fIparent\fR is deleted, and will consume relevant key events until then.
.PP
Please note that the accelerator
.PP
.nf
.br
accelerator->insertItem( TQKeySequence("M") );
.br
.fi
can be triggered with both the 'M' key, and with Shift+M, unless a second accelerator is defined for the Shift+M combination.
.PP
Example:
.PP
.nf
.br
TQAccel *a = new TQAccel( myWindow ); // create accels for myWindow
.br
a->connectItem( a->insertItem(Key_P+CTRL), // adds Ctrl+P accelerator
.br
myWindow, // connected to myWindow's
.br
TQ_SLOT(printDoc()) ); // printDoc() slot
.br
.fi
.PP
See also TQKeyEvent, TQWidget::keyPressEvent(), TQMenuData::setAccel(), TQButton::accel, TQLabel::setBuddy(), TQKeySequence, GUI Design Handbook: Keyboard Shortcuts, and Miscellaneous Classes.
.SH MEMBER FUNCTION DOCUMENTATION
.SH "TQAccel::TQAccel ( TQWidget * parent, const char * name = 0 )"
Constructs a TQAccel object called \fIname\fR, with parent \fIparent\fR. The accelerator operates on \fIparent\fR.
.SH "TQAccel::TQAccel ( TQWidget * watch, TQObject * parent, const char * name = 0 )"
Constructs a TQAccel object called \fIname\fR, that operates on \fIwatch\fR, and is a child of \fIparent\fR.
.PP
This constructor is not needed for normal application programming.
.SH "TQAccel::~TQAccel ()"
Destroys the accelerator object and frees all allocated resources.
.SH "void TQAccel::activated ( int id )\fC [signal]\fR"
This signal is emitted when an accelerator key is pressed. \fIid\fR is a number that identifies this particular accelerator item.
.PP
See also activatedAmbiguously().
.SH "void TQAccel::activatedAmbiguously ( int id )\fC [signal]\fR"
This signal is emitted when an accelerator key is pressed. \fIid\fR is a number that identifies this particular accelerator item.
.PP
See also activated().
.SH "void TQAccel::clear ()"
Removes all accelerator items.
.SH "bool TQAccel::connectItem ( int id, const TQObject * receiver, const char * member )"
Connects the accelerator item \fIid\fR to the slot \fImember\fR of \fIreceiver\fR.
.PP
.nf
.br
a->connectItem( 201, mainView, TQ_SLOT(quit()) );
.br
.fi
.PP
Of course, you can also send a signal as \fImember\fR.
.PP
Normally accelerators are connected to slots which then receive the \fCactivated(int id)\fR signal with the id of the accelerator item that was activated. If you choose to connect a specific accelerator item using this function, the activated() signal is emitted if the associated key sequence is pressed but no \fCactivated(int id)\fR signal is emitted.
.PP
See also disconnectItem().
.PP
Example: t14/gamebrd.cpp.
.SH "uint TQAccel::count () const"
Returns the number of accelerator items in this accelerator.
.SH "bool TQAccel::disconnectItem ( int id, const TQObject * receiver, const char * member )"
Disconnects an accelerator item with id \fIid\fR from the function called \fImember\fR in the \fIreceiver\fR object.
.PP
See also connectItem().
.SH "bool TQAccel::eventFilter ( TQObject *, TQEvent * )\fC [virtual protected]\fR"
\fBThis function is obsolete.\fR It is provided to keep old source working. We strongly advise against using it in new code. serves no purpose anymore
.PP
Reimplemented from TQObject.
.SH "int TQAccel::findKey ( const TQKeySequence & key ) const"
Returns the identifier of the accelerator item with the key code \fIkey\fR, or -1 if the item cannot be found.
.SH "int TQAccel::insertItem ( const TQKeySequence & key, int id = -1 )"
Inserts an accelerator item and returns the item's identifier.
.PP
\fIkey\fR is a key code and an optional combination of SHIFT, CTRL and ALT. \fIid\fR is the accelerator item id.
.PP
If \fIid\fR is negative, then the item will be assigned a unique negative identifier less than -1.
.PP
.nf
.br
TQAccel *a = new TQAccel( myWindow ); // create accels for myWindow
.br
a->insertItem( CTRL + Key_P, 200 ); // Ctrl+P, e.g. to print document
.br
a->insertItem( ALT + Key_X, 201 ); // Alt+X, e.g. to quit
.br
a->insertItem( UNICODE_ACCEL + 'q', 202 ); // Unicode 'q', e.g. to quit
.br
a->insertItem( Key_D ); // gets a unique negative id < -1
.br
a->insertItem( CTRL + SHIFT + Key_P ); // gets a unique negative id < -1
.br
.fi
.PP
Example: t14/gamebrd.cpp.
.SH "bool TQAccel::isEnabled () const"
Returns TRUE if the accelerator is enabled; otherwise returns FALSE.
.PP
See also setEnabled() and isItemEnabled().
.SH "bool TQAccel::isItemEnabled ( int id ) const"
Returns TRUE if the accelerator item with the identifier \fIid\fR is enabled. Returns FALSE if the item is disabled or cannot be found.
.PP
See also setItemEnabled() and isEnabled().
.SH "TQKeySequence TQAccel::key ( int id )"
Returns the key sequence of the accelerator item with identifier \fIid\fR, or an invalid key sequence (0) if the id cannot be found.
.SH "TQString TQAccel::keyToString ( TQKeySequence k )\fC [static]\fR"
\fBThis function is obsolete.\fR It is provided to keep old source working. We strongly advise against using it in new code.
.PP
Creates an accelerator string for the key \fIk\fR. For instance CTRL+Key_O gives "Ctrl+O". The "Ctrl" etc. are translated (using TQObject::tr()) in the "TQAccel" context.
.PP
The function is superfluous. Cast the TQKeySequence \fIk\fR to a TQString for the same effect.
.SH "void TQAccel::removeItem ( int id )"
Removes the accelerator item with the identifier \fIid\fR.
.SH "void TQAccel::repairEventFilter ()"
\fBThis function is obsolete.\fR It is provided to keep old source working. We strongly advise against using it in new code. serves no purpose anymore
.SH "void TQAccel::setEnabled ( bool enable )"
Enables the accelerator if \fIenable\fR is TRUE, or disables it if \fIenable\fR is FALSE.
.PP
Individual keys can also be enabled or disabled using setItemEnabled(). To work, a key must be an enabled item in an enabled TQAccel.
.PP
See also isEnabled() and setItemEnabled().
.SH "void TQAccel::setItemEnabled ( int id, bool enable )"
Enables the accelerator item with the identifier \fIid\fR if \fIenable\fR is TRUE, and disables item \fIid\fR if \fIenable\fR is FALSE.
.PP
To work, an item must be enabled and be in an enabled TQAccel.
.PP
See also isItemEnabled() and isEnabled().
.SH "void TQAccel::setWhatsThis ( int id, const TQString & text )"
Sets a What's This help text for the accelerator item \fIid\fR to \fItext\fR.
.PP
The text will be shown when the application is in What's This mode and the user hits the accelerator key.
.PP
To set What's This help on a menu item (with or without an accelerator key), use TQMenuData::setWhatsThis().
.PP
See also whatsThis(), TQWhatsThis::inWhatsThisMode(), TQMenuData::setWhatsThis(), and TQAction::whatsThis.
.SH "TQKeySequence TQAccel::shortcutKey ( const TQString & str )\fC [static]\fR"
Returns the shortcut key sequence for \fIstr\fR, or an invalid key sequence (0) if \fIstr\fR has no shortcut sequence.
.PP
For example, shortcutKey("E&xit") returns ALT+Key_X, shortcutKey("&Quit") returns ALT+Key_Q and shortcutKey("Quit") returns 0. (In code that does not inherit the TQt namespace class, you must write e.g. TQt::ALT+TQt::Key_Q.)
.PP
We provide a list of common accelerators in English. At the time of writing, Microsoft and Open Group do not appear to have issued equivalent recommendations for other languages.
.SH "TQKeySequence TQAccel::stringToKey ( const TQString & s )\fC [static]\fR"
\fBThis function is obsolete.\fR It is provided to keep old source working. We strongly advise against using it in new code.
.PP
Returns an accelerator code for the string \fIs\fR. For example" Ctrl+O" gives CTRL+UNICODE_ACCEL+'O'. The strings "Ctrl"," Shift", "Alt" are recognized, as well as their translated equivalents in the "TQAccel" context (using TQObject::tr()). Returns 0 if \fIs\fR is not recognized.
.PP
This function is typically used with tr(), so that accelerator keys can be replaced in translations:
.PP
.nf
.br
TQPopupMenu *file = new TQPopupMenu( this );
.br
file->insertItem( p1, tr("&Open..."), this, TQ_SLOT(open()),
.br
TQAccel::stringToKey(tr("Ctrl+O", "File|Open")) );
.br
.fi
.PP
Notice the \fC"File|Open"\fR translator comment. It is by no means necessary, but it provides some context for the human translator.
.PP
The function is superfluous. Construct a TQKeySequence from the string \fIs\fR for the same effect.
.PP
See also TQObject::tr() and Internationalization with Qt.
.PP
Example: i18n/mywidget.cpp.
.SH "TQString TQAccel::whatsThis ( int id ) const"
Returns the What's This help text for the specified item \fIid\fR or TQString::null if no text has been specified.
.PP
See also setWhatsThis().
.SH "SEE ALSO"
.BR http://doc.trolltech.com/tqaccel.html
.BR http://www.trolltech.com/faq/tech.html
.SH COPYRIGHT
Copyright 1992-2007 Trolltech ASA, http://www.trolltech.com. See the
license file included in the distribution for a complete license
statement.
.SH AUTHOR
Generated automatically from the source code.
.SH BUGS
If you find a bug in Qt, please report it as described in
.BR http://doc.trolltech.com/bughowto.html .
Good bug reports help us to help you. Thank you.
.P
The definitive TQt documentation is provided in HTML format; it is
located at $TQTDIR/doc/html and can be read using TQt Assistant or with
a web browser. This man page is provided as a convenience for those
users who prefer man pages, although this format is not officially
supported by Trolltech.
.P
If you find errors in this manual page, please report them to
.BR qt-bugs@trolltech.com .
Please include the name of the manual page (tqaccel.3qt) and the Qt
version (3.3.8).
|