• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdeui
 

tdeui

Classes | Functions
TDEAccelGen Namespace Reference

Classes

class  Deref
 
class  Deref_Key
 

Functions

bool isLegalAccelerator (const TQString &str, uint index)
 
template<class Iter , class Deref >
void loadPredefined (Iter begin, Iter end, TQMap< TQChar, bool > &keys)
 
template<class Iter , class Iter_Deref >
void generate (Iter begin, Iter end, TQStringList &target)
 
template<class Iter >
void generateFromKeys (Iter begin, Iter end, TQStringList &target)
 
void generate (const TQStringList &source, TQStringList &target)
 
template<class Key >
void generateFromValues (const TQMap< Key, TQString > &source, TQStringList &target)
 
template<class Data >
void generateFromKeys (const TQMap< TQString, Data > &source, TQStringList &target)
 

Detailed Description

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" TQStringList 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):

  1. If the string already contains an '&' character, skip this string, because we consider such strings to be "user-specified" accelerators.
  2. No accelerator may clash with a previously defined accelerator, including any legal (alphanumeric) user-specified accelerator anywhere in the collection
  3. Prefer alphanumerics at the start of the string.
  4. Otherwise, prefer alphanumerics at the start of a word.
  5. 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.

TODO:

  • Add sugar functions for more collections.
  • Add more Deref classes so that we can access a wider variety of collections.

Function Documentation

◆ generate() [1/2]

void TDEAccelGen::generate ( const TQStringList &  source,
TQStringList &  target 
)
inline

Convenience function; generates accelerators for all the items in a TQStringList.

Parameters
sourceStrings for which to generate accelerators
targetOutput for accelerator-added strings

Definition at line 245 of file tdeaccelgen.h.

◆ generate() [2/2]

template<class Iter , class Iter_Deref >
void TDEAccelGen::generate ( Iter  begin,
Iter  end,
TQStringList &  target 
)

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.

Parameters
begin(you know)
end(you know)
targetcollection to store generated strings

Definition at line 167 of file tdeaccelgen.h.

◆ generateFromKeys() [1/2]

template<class Data >
void TDEAccelGen::generateFromKeys ( const TQMap< TQString, Data > &  source,
TQStringList &  target 
)
inline

Convenience function; generates an accelerator mapping from all the keys in a TQMap<TQString,T>

Parameters
sourceMap with input strings as KEYS.
targetOutput for accelerator-added strings

Definition at line 271 of file tdeaccelgen.h.

◆ generateFromKeys() [2/2]

template<class Iter >
void TDEAccelGen::generateFromKeys ( Iter  begin,
Iter  end,
TQStringList &  target 
)
inline

Another convenience function; looks up the key instead of dereferencing directly for the given iterator.

Parameters
begin
end
target

Definition at line 232 of file tdeaccelgen.h.

◆ generateFromValues()

template<class Key >
void TDEAccelGen::generateFromValues ( const TQMap< Key, TQString > &  source,
TQStringList &  target 
)
inline

Convenience function; generates accelerators for all the values in a TQMap<T,TQString>.

Parameters
sourceMap with input strings as VALUES.
targetOutput for accelerator-added strings

Definition at line 258 of file tdeaccelgen.h.

◆ isLegalAccelerator()

bool TDEAccelGen::isLegalAccelerator ( const TQString &  str,
uint  index 
)
inline

Helper to determine if the given offset in the string could be a legal alphanumeric accelerator.

Parameters
strbase string
indexoffset to check

Definition at line 114 of file tdeaccelgen.h.

◆ loadPredefined()

template<class Iter , class Deref >
void TDEAccelGen::loadPredefined ( Iter  begin,
Iter  end,
TQMap< TQChar, bool > &  keys 
)
inline

Loads all legal predefined accelerators in the (implicitly specified) collection into the given TQMap.

Parameters
beginstart iterator
end(last+1) iterator
keysmap to store output

Definition at line 130 of file tdeaccelgen.h.

tdeui

Skip menu "tdeui"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

tdeui

Skip menu "tdeui"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdeui by doxygen 1.9.4
This website is maintained by Timothy Pearson.