|template<class Iter , class Iter_Deref > |
|void ||generate (Iter begin, Iter end, QStringList &target)|
|void ||generate (const QStringList &source, QStringList &target)|
|template<class Iter > |
|void ||generateFromKeys (Iter begin, Iter end, QStringList &target)|
|template<class Data > |
|void ||generateFromKeys (const QMap< QString, Data > &source, QStringList &target)|
|template<class Key > |
|void ||generateFromValues (const QMap< Key, QString > &source, QStringList &target)|
|bool ||isLegalAccelerator (const QString &str, int index)|
|template<class Iter , class Deref > |
|void ||loadPredefined (Iter begin, Iter end, QMap< QChar, bool > &keys)|
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 KDE User Interface Guidelines. We do NOT mean "shortcuts", which are what's handled by most other KDE libraries with "accel" in the name.
In the Qt 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" QStringList parameter with the input collectin's QStrings, plus possibly some added '&' characters.
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):
- If the string already contains an '&' character, skip this string, because we consider such strings to be "user-specified" accelerators.
- No accelerator may clash with a previously defined accelerator, including any legal (alphanumeric) user-specified accelerator anywhere in the collection
- Prefer alphanumerics at the start of the string.
- Otherwise, prefer alphanumerics at the start of a word.
- Otherwise, choose any alphanumeric character not already taken. If no such character is available, give up & skip this string.
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.
- Add sugar functions for more collections.
- Add more Deref classes so that we can access a wider variety of collections.
template<class Iter , class Iter_Deref >
Main, maximally flexible template function that assigns accelerators to the elements of a collection of QStrings.
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).
The Deref template parameter is a class containing a static dereferencing function, modeled after the comparison class C in Stroustrup 13.4.
|begin||(you know) |
|end||(you know) |
|target||collection to store generated strings |
Definition at line 171 of file kaccelgen.h.