.TH "KAccelGen" kde3 "11 Jun 2005" "Version Version 3.4.1" "kdeui Library" \" -*- nroff -*-
.ad l
.nh
.SH NAME
KAccelGen \- Provides functions that, given a collection of QStrings, will automatically and intelligently assign menu accelerators to the QStrings in the collection.  

.PP
.SH SYNOPSIS
.br
.PP
.SS "Classes"

.in +1c
.ti -1c
.RI "class \fBDeref\fP"
.br
.RI "\fIStatic dereference class, for use as a template parameter. \fP"
.ti -1c
.RI "class \fBDeref_Key\fP"
.br
.RI "\fIStatic dereference class that calls the key() method on its target; for use as a template parameter. \fP"
.in -1c
.SS "Functions"

.in +1c
.ti -1c
.RI "bool \fBisLegalAccelerator\fP (const \fBQString\fP &str, uint index)"
.br
.ti -1c
.RI "template<class Iter, class Deref> void \fBloadPredefined\fP (Iter begin, Iter end, \fBQMap\fP< \fBQChar\fP, bool > &keys)"
.br
.ti -1c
.RI "template<class Iter, class Iter_Deref> void \fBgenerate\fP (Iter begin, Iter end, \fBQStringList\fP &target)"
.br
.ti -1c
.RI "template<class Iter> void \fBgenerateFromKeys\fP (Iter begin, Iter end, \fBQStringList\fP &target)"
.br
.ti -1c
.RI "void \fBgenerate\fP (const \fBQStringList\fP &source, \fBQStringList\fP &target)"
.br
.ti -1c
.RI "template<class Key> void \fBgenerateFromValues\fP (const \fBQMap\fP< Key, \fBQString\fP > &source, \fBQStringList\fP &target)"
.br
.ti -1c
.RI "template<class Data> void \fBgenerateFromKeys\fP (const \fBQMap\fP< \fBQString\fP, Data > &source, \fBQStringList\fP &target)"
.br
.in -1c
.SH "Detailed Description"
.PP 
Provides functions that, given a collection of QStrings, will automatically and intelligently assign menu accelerators to the QStrings in the collection. 

NOTE: When this file speaks of 'accelerators', we really mean accelerators as defined by the \fBKDE\fP User Interface Guidelines. We do NOT mean 'shortcuts', which are what's handled by most other \fBKDE\fP libraries with 'accel' in the name.
.PP
In the \fBQt\fP library, the mechanism for adding a keyboard accelerator to a menu item is to insert an '&' before the letter. Since we usually don't want to disturb the original collection, the idiom in these functions is to populate a 'target' \fBQStringList\fP parameter with the input collectin's QStrings, plus possibly some added '&' characters.
.PP
That is the mechanism. Here is the policy, in order of decreasing importance (it may seem like these are implementation details, but IMHO the policy is an important part of the interface):
.PP
1. If the string already contains an '&' character, skip this string, because we consider such strings to be 'user-specified' accelerators.
.PP
2. No accelerator may clash with a previously defined accelerator, including any legal (alphanumeric) user-specified accelerator anywhere in the collection
.PP
3. Prefer alphanumerics at the start of the string.
.PP
4. Otherwise, prefer alphanumerics at the start of a word.
.PP
5. Otherwise, choose any alphanumeric character not already taken. If no such character is available, give up & skip this string.
.PP
A typical use of these functions would be to automatically assign accelerators to a dynamically populated popup menu. For example, the core code was written to automatically set accelerators for the 'Load View Profile' popup menu for Konqueror. We quickly realized that it would be useful to make this facility more generally available, so I abstracted it out into a set of templates.
.PP
TODO:
.PP
+ Add sugar functions for more collections.
.PP
+ Add more \fBDeref\fP classes so that we can access a wider variety of collections. 
.PP
.SH "Function Documentation"
.PP 
.SS "bool isLegalAccelerator (const \fBQString\fP & str, uint index)\fC [inline]\fP"
.PP
Helper to determine if the given offset in the string could be a legal alphanumeric accelerator. 
.PP
\fBParameters:\fP
.RS 4
\fIstr\fP base string 
.br
\fIindex\fP offset to check 
.RE
.PP

.PP
Definition at line 114 of file kaccelgen.h.
.PP
Referenced by generate(), and loadPredefined().
.SS "template<class Iter, class Deref> void loadPredefined (Iter begin, Iter end, \fBQMap\fP< \fBQChar\fP, bool > & keys)\fC [inline]\fP"
.PP
\fBLoads\fP all legal predefined accelerators in the (implicitly specified) collection into the given \fBQMap\fP. 
.PP
\fBParameters:\fP
.RS 4
\fIbegin\fP start iterator 
.br
\fIend\fP (last+1) iterator 
.br
\fIkeys\fP map to store output 
.RE
.PP

.PP
Definition at line 130 of file kaccelgen.h.
.PP
References QString::find(), QString::insert(), and isLegalAccelerator().
.SS "template<class Iter, class Iter_Deref> void generate (Iter begin, Iter end, \fBQStringList\fP & target)"
.PP
Main, maximally flexible template function that assigns accelerators to the elements of a collection of QStrings. 
.PP
Clients will seldom use this directly, as it's usually easier to use one of the wrapper functions that simply takes a collection (see below).
.PP
The \fBDeref\fP template parameter is a class containing a static dereferencing function, modeled after the comparison class C in Stroustrup 13.4.
.PP
\fBParameters:\fP
.RS 4
\fIbegin\fP (you know) 
.br
\fIend\fP (you know) 
.br
\fItarget\fP collection to store generated strings 
.RE
.PP

.PP
Definition at line 167 of file kaccelgen.h.
.PP
References QString::append(), QMap::contains(), QString::find(), QString::insert(), QMap::insert(), isLegalAccelerator(), and QString::length().
.SS "template<class Iter> void generateFromKeys (Iter begin, Iter end, \fBQStringList\fP & target)\fC [inline]\fP"
.PP
Another convenience function; looks up the key instead of dereferencing directly for the given iterator. 
.PP
\fBParameters:\fP
.RS 4
\fIbegin\fP .br
\fIend\fP .br
\fItarget\fP .RE
.PP

.PP
Definition at line 232 of file kaccelgen.h.
.PP
Referenced by generateFromKeys().
.SS "void generate (const \fBQStringList\fP & source, \fBQStringList\fP & target)\fC [inline]\fP"
.PP
Convenience function; generates accelerators for all the items in a \fBQStringList\fP. 
.PP
\fBParameters:\fP
.RS 4
\fIsource\fP Strings for which to generate accelerators 
.br
\fItarget\fP Output for accelerator-added strings 
.RE
.PP

.PP
Definition at line 245 of file kaccelgen.h.
.SS "template<class Key> void generateFromValues (const \fBQMap\fP< Key, \fBQString\fP > & source, \fBQStringList\fP & target)\fC [inline]\fP"
.PP
Convenience function; generates accelerators for all the values in a QMap<T,QString>. 
.PP
\fBParameters:\fP
.RS 4
\fIsource\fP Map with input strings as VALUES. 
.br
\fItarget\fP Output for accelerator-added strings 
.RE
.PP

.PP
Definition at line 258 of file kaccelgen.h.
.SS "template<class Data> void generateFromKeys (const \fBQMap\fP< \fBQString\fP, Data > & source, \fBQStringList\fP & target)\fC [inline]\fP"
.PP
Convenience function; generates an accelerator mapping from all the keys in a QMap<QString,T>. 
.PP
\fBParameters:\fP
.RS 4
\fIsource\fP Map with input strings as KEYS. 
.br
\fItarget\fP Output for accelerator-added strings 
.RE
.PP

.PP
Definition at line 271 of file kaccelgen.h.
.PP
References generateFromKeys().
.SH "Author"
.PP 
Generated automatically by Doxygen for kdeui Library from the source code.
