Source Code (Use browser search to find items of interest.)
Class Index
kdelibs'KAccel (./kdelibs/kdecore/kaccel.h:140)
class KAccel : public QAccel
{
Q_OBJECT
public:
/**
* Create a KAccel object with a parent widget and a name.
*/
KAccel( QWidget * parent, const char *name = 0 );
/**
* Remove all accelerator items.
*/
void clear();
/**
* Connect an accelerator item to a slot/signal in another object.
*
* Arguments:
*
* @param action The accelerator item action name.
* @param receiver The object to receive a signal.
* @param member A slot or signal in the receiver.
* @param activate Indicates whether the accelerator item should be
* enabled immediately.
*/
void connectItem( const QString& action,
const QObject* receiver, const char *member,
bool activate = true );
/**
* Same as @ref connectItem() from above, but for standard
* accelerators.
*
* If the standard accelerator was not inserted so far, it
* will be inserted automatically.
*/
void connectItem( KStdAccel::StdAccel accel,
const QObject* receiver, const char *member,
bool activate = true );
/**
* Retrieve the number of accelerator items.
*/
uint count() const;
/**
* Retrieve the key code of the accelerator item with the action name
* action, or zero if either the action name cannot be
* found or the current key is set to no key.
*/
uint currentKey( const QString& action ) const;
/**
* Retrieve the description of the accelerator item with the
* action name @p action, or @ref QString::null if the action name cannot
* be found. Useful for menus.
*/
QString description( const QString& action ) const;
void setDescription(const QString &action, const QString &description);
/**
* Retrieve the default key code of the accelerator item with
* the action name
* @p action, or zero if the action name cannot be found.
*/
uint defaultKey( const QString& action) const;
/**
* Disconnect an accelerator item from a function in another object.
*/
void disconnectItem( const QString& action,
const QObject* receiver, const char *member );
/**
* Rerieve the identifier of the accelerator item with the keycode @p key,
* or @ref QString::null if the item cannot be found.
*/
QString findKey( int key ) const;
/**
* Insert an accelerator item.
*
* If an action already exists the old association and connections
* will be removed.
*
* @param descr The localized name of the action, useful in
* menus or the keybinding editor.
* @param action The internal accelerator item action name. It
* is supposed to be the same for all languages.
* @param defaultKeyCode A key code to be used as the default
* for the action. Set it to 0 for no default key (It still
* may be configured later.)
* @param configurable Indicates whether a user can configure
* the key binding using the @ref KKeyChooser GUI and whether the
* key will be written back to configuration files when
* @ref writeSettings() is called.
* @return @p true if successful.
*/
bool insertItem( const QString& descr, const QString& action,
uint defaultKeyCode, bool configurable = true );
/**
* Insert an accelerator item.
*
* If an action already exists the old association and connections
* will be removed.
*
* @param descr The localized name of the action, useful in
* menus or the keybinding editor.
* @param action The internal accelerator item action name. It
* is supposed to be the same for all languages.
* @param defaultKeyCode A key code to be used as the default
* for the action. Set it to 0 for no default key (It still
* may be configured later.)
* @param id Menu index of menu item associated with this action.
* @param qmenu Menu containing item associated with this action.
* @param configurable Indicates whether a user can configure
* the key binding using the @ref KKeyChooser GUI and whether the
* key will be written back to configuration files when
* @ref writeSettings() is called.
* @return @p true if successful.
*
*/
bool insertItem( const QString& descr, const QString& action,
uint defaultKeyCode, int id, QPopupMenu *qmenu,
bool configurable = true );
/**
* Insert an accelerator item.
*
* If an action already exists the old association and connections
* will be removed.
*
* @param descr The localized name of the action, useful in
* menus or the keybinding editor.
* @param action The internal accelerator item action name. It
* is supposed to be the same for all languages.
* @param defaultKeyCode A key plus a combination of Shift, Ctrl
* and Alt to be used as the default for the action.
* @param id Menu index of menu item associated with this action.
* @param qmenu Menu containing item associated with this action.
* @param configurable Indicates whether a user can configure
* the key binding using the @ref KKeyChooser GUI and whether the
* key will be written back to configuration files when
* @ref writeSettings() is called.
* @return @p true if successful.
*
*/
bool insertItem( const QString& descr, const QString& action,
const QString& defaultKeyCode,
bool configurable = true );
/**
* Insert an accelerator item.
*
* If an action already exists the old association and connections
* will be removed..
*
* @param descr The localized name of the action, useful in
* menus or the keybinding editor.
* @param action The internal accelerator item action name. It
* is supposed to be the same for all languages.
* @param defaultKeyCode A key plus a combination of Shift, Ctrl
* and Alt to be used as the default for the action.
* @param configurable Indicates whether a user can configure
* the key binding using the @ref KKeyChooser GUI and whether the
* key will be written back to configuration files when
* @ref writeSettings() is called.
* @return @p true if successful.
*
*/
bool insertItem( const QString& descr, const QString& action,
const QString& defaultKeyCode,
int id, QPopupMenu *qmenu, bool configurable = true );
/**
* Insert a standard accelerator item.
*
* If an action already exists the old association and connections
* will be removed.
* param id One of the following: Open,
* New, Close, Save, Print, Quit, Cut, Copy, Paste, Undo, Redo,
* Find, Replace, Insert, Home, End, Prior, Next, or Help.
* param descr You can optionally also assign a description to
* the standard item which may be used a in a popup menu.
*/
bool insertStdItem( KStdAccel::StdAccel id, const QString& descr = QString::null );
/**
* Convenience function form of @ref insertItem()
* without the need to specify a localized
* function name for the user.
*
* This is useful if the accelerator
* is only used internally, without appearing in a menu or a
* keybinding editor.
*/
bool insertItem( const QString& action, uint defaultKeyCode,
bool configurable = true );
/**
* Convenience function for of @ref insertItem() without the need
* to specify a localized
* function name for the user.
*
* This is useful if the accelerator
* is only used internally, without appearing in a menu or a
* keybinding editor.
*/
bool insertItem( const QString& action, uint defaultKeyCode,
int id, QPopupMenu *qmenu,
bool configurable = true );
/**
* Remove the accelerator item with the action name action.
*/
void removeItem( const QString& action );
/**
* Shortcuts should be visible in the menu
* structure of an application.
*
* Use this function for that
* purpose. Note that the action must have been inserted
* before!
*/
void changeMenuAccel ( QPopupMenu *menu, int id,
const QString& action );
/**
* Same as @ref changeMenuAccel() but for standard accelerators.
*/
void changeMenuAccel ( QPopupMenu *menu, int id,
KStdAccel::StdAccel accel );
/**
* Set the dictionary of accelerator action names and @ref KKeyEntry
* objects to @p nKeyDict.
*
* Note that only a shallow copy is made so
* that items will be lost when the @ref KKeyEntry objects are deleted.
*/
bool setKeyDict( QDict<KKeyEntry> nKeyDict );
/**
* Retrieve the dictionary of accelerator action names and
* @ref KKeyEntry
* objects. Note that only a shallow copy is returned so that
* items will be lost when the @ref KKeyEntry objects are deleted.
*/
QDict<KKeyEntry> keyDict();
/**
* Read all key associations from @p config, or (if @p config
* is zero) from the application's configuration file
* @ref KGlobal::config().
*
* The group in which the configuration is stored can be
* set with @ref setConfigGroup().
*/
void readSettings(KConfig* config = 0);
/**
* Write the current configurable associations to @p config,
* or (if @p config is zero) to the application's
* configuration file.
*/
void writeSettings(KConfig* config = 0);
/**
* Set the group in the configuration file in which the
* accelerator settings are stored.
*
* By default, this is "Keys".
*/
void setConfigGroup( const QString& group );
/**
* Retrieve the name of the group in which accelerator
* settings are stored.
**/
QString configGroup() const;
/**
* If @global is @true, KAccel writes to the global
* configurtion file, instead of the application configuration file.
**/
void setConfigGlobal( bool global );
/**
* Will KAccel write to the global configuration file (instead of
* the appliation configuration file)?
**/
bool configGlobal() const;
/**
* Enable all accelerators if activate is @p true, or disable it if
* activate is @p false.
*
* Individual keys can also be enabled or disabled.
*/
void setEnabled( bool activate );
/**
* Are accelerators enabled?
**/
bool isEnabled() const;
/**
* Enable or disable an accelerator item.
*
* @param action The accelerator item action name.
* @param activate Specifies whether the item should be enabled or
* disabled.
*/
void setItemEnabled( const QString& action, bool activate );
/**
* Check whether a specific accelerator, @p action, is enabled.
**/
bool isItemEnabled( const QString& action ) const;
/**
* Returns @p true if keyentry can be modified.
*/
bool configurable( const QString &action ) const;
/**
* Change the keycode for an accelerator.
*/
bool updateItem( const QString &action, uint keyCode);
/**
* Remove the keycode for an accelerator.
**/
void clearItem(const QString &action);
/**
* Clear any pointers to a menu.
**/
void removeDeletedMenu(QPopupMenu *menu);
/**
* Retrieve the key code corresponding to the string @p sKey or
* zero if the string
* is not recognized.
*
* The string must be something like "Shift+A",
* "F1+Ctrl+Alt" or "Backspace" for example. That is, the string
* must consist of a key name plus a combination of
* the modifiers Shift, Ctrl and Alt.
*
* N.B.: @p sKey must @bf not be @ref i18n()'d!
*/
static uint stringToKey( const QString& sKey );
/**
* Retrieve a string corresponding to the key code @p keyCode,
* which is empty if
* @p keyCode is not recognized or zero.
*/
static QString keyToString( uint keyCode, bool i18_n = false );
signals:
void keycodeChanged();
protected:
int aAvailableId;
QDict<KKeyEntry> aKeyDict;
bool bEnabled;
bool bGlobal;
QString aGroup;
private:
KAccelPrivate *d;
};
kdelibs'KAccel::KAccel() (./kdelibs/kdecore/kaccel.cpp:37)
KAccel::KAccel( QWidget * parent, const char *name )
: QAccel(parent, name), aKeyDict(100, false){
aAvailableId = 1;
bEnabled = true;
aGroup = "Keys";
bGlobal = false;
}
kdelibs'KAccel::clear() (./kdelibs/kdecore/kaccel.cpp:45)
void KAccel::clear()
{
QAccel::clear();
aKeyDict.clear();
}
kdelibs'KAccel::connectItem() (./kdelibs/kdecore/kaccel.cpp:51)
void KAccel::connectItem( const QString& action,
const QObject* receiver, const char *member,
bool activate )
{
if (action.isNull()) return;
KKeyEntry *pEntry = aKeyDict[ action ];
if ( !pEntry ) {
kdWarning(125) << "cannot connect action " << action
<< " which is not in the object dictionary" << endl;
return;
}
pEntry->receiver = receiver;
pEntry->member = member;
pEntry->aAccelId = aAvailableId;
aAvailableId++;
// Qt does strange things if a QAccel contains a accelerator
// with key code 0, so leave it out here.
if (pEntry->aCurrentKeyCode) {
QAccel::insertItem( pEntry->aCurrentKeyCode, pEntry->aAccelId );
QAccel::connectItem( pEntry->aAccelId, receiver, member );
}
if ( !activate ) setItemEnabled( action, false );
}
kdelibs'KAccel::connectItem() (./kdelibs/kdecore/kaccel.cpp:79)
void KAccel::connectItem( KStdAccel::StdAccel accel,
const QObject* receiver, const char *member,
bool activate )
{
QString action(KStdAccel::action(accel));
if (!action.isNull() && !aKeyDict[ action ]){
insertStdItem(accel);
}
connectItem(action, receiver, member, activate);
}
kdelibs'KAccel::count() (./kdelibs/kdecore/kaccel.cpp:90)
uint KAccel::count() const
{
return aKeyDict.count();
}
kdelibs'KAccel::currentKey() (./kdelibs/kdecore/kaccel.cpp:95)
uint KAccel::currentKey( const QString& action ) const
{
KKeyEntry *pEntry = aKeyDict[ action ];
if ( !pEntry )
return 0;
else
return pEntry->aCurrentKeyCode;
}
kdelibs'KAccel::setDescription() (./kdelibs/kdecore/kaccel.cpp:105)
void KAccel::setDescription(const QString &action,
const QString &description)
{
KKeyEntry *pEntry = aKeyDict[ action ];
if ( !pEntry )
kdWarning(125) << "cannot set description for absent action "
<< action << endl;
else pEntry->descr = description;
}
kdelibs'KAccel::description() (./kdelibs/kdecore/kaccel.cpp:116)
QString KAccel::description( const QString& action ) const
{
KKeyEntry *pEntry = aKeyDict[ action ];
if ( !pEntry )
return QString::null;
else
return pEntry->descr;
}
kdelibs'KAccel::defaultKey() (./kdelibs/kdecore/kaccel.cpp:126)
uint KAccel::defaultKey( const QString& action ) const
{
KKeyEntry *pEntry = aKeyDict[ action ];
if ( !pEntry )
return 0;
else
return pEntry->aDefaultKeyCode;
}
kdelibs'KAccel::disconnectItem() (./kdelibs/kdecore/kaccel.cpp:136)
void KAccel::disconnectItem( const QString& action,
const QObject* receiver, const char *member )
{
KKeyEntry *pEntry = aKeyDict[ action ];
if ( !pEntry )
return;
QAccel::disconnectItem( pEntry->aAccelId, receiver, member );
}
kdelibs'KAccel::findKey() (./kdelibs/kdecore/kaccel.cpp:146)
QString KAccel::findKey( int key ) const
{
QDictIterator<KKeyEntry> aKeyIt( aKeyDict );
aKeyIt.toFirst();
while ( aKeyIt.current() ) {
if ( (unsigned int)key == aKeyIt.current()->aCurrentKeyCode )
return aKeyIt.currentKey();
++aKeyIt;
}
return QString::null;
}
kdelibs'KAccel::insertItem() (./kdelibs/kdecore/kaccel.cpp:158)
bool KAccel::insertItem( const QString& descr, const QString& action, uint keyCode,
bool configurable )
{
return insertItem( descr, action, keyCode,
0, 0, configurable);
}
kdelibs'KAccel::insertItem() (./kdelibs/kdecore/kaccel.cpp:165)
bool KAccel::insertItem( const QString& descr, const QString& action, uint keyCode,
int id, QPopupMenu *qmenu, bool configurable)
{
KKeyEntry *pEntry = aKeyDict[ action ];
if ( pEntry )
removeItem( action );
pEntry = new KKeyEntry;
aKeyDict.insert( action, pEntry );
pEntry->aDefaultKeyCode = keyCode;
pEntry->aCurrentKeyCode = keyCode;
pEntry->aConfigKeyCode = keyCode;
pEntry->bConfigurable = configurable;
pEntry->aAccelId = 0;
pEntry->receiver = 0;
pEntry->member = 0;
pEntry->descr = descr;
pEntry->menuId = id;
pEntry->menu = qmenu;
return true;
}
kdelibs'KAccel::insertItem() (./kdelibs/kdecore/kaccel.cpp:190)
bool KAccel::insertItem( const QString& descr, const QString& action,
const QString& keyCode, bool configurable )
{
uint iKeyCode = stringToKey( keyCode );
return insertItem( descr, action, iKeyCode, configurable );
}
kdelibs'KAccel::insertItem() (./kdelibs/kdecore/kaccel.cpp:197)
bool KAccel::insertItem( const QString& descr, const QString& action,
const QString& keyCode, int id,
QPopupMenu *qmenu, bool configurable)
{
uint iKeyCode = stringToKey( keyCode );
return insertItem( descr, action, iKeyCode, id, qmenu, configurable);
}
kdelibs'KAccel::insertItem() (./kdelibs/kdecore/kaccel.cpp:205)
bool KAccel::insertItem( const QString& action, uint keyCode,
bool configurable )
{
return insertItem(action, action, keyCode, configurable);
}
kdelibs'KAccel::insertItem() (./kdelibs/kdecore/kaccel.cpp:211)
bool KAccel::insertItem( const QString& action, uint keyCode,
int id, QPopupMenu *qmenu, bool configurable)
{
return insertItem(action, action, keyCode, id, qmenu, configurable);
}
kdelibs'KAccel::changeMenuAccel() (./kdelibs/kdecore/kaccel.cpp:217)
void KAccel::changeMenuAccel ( QPopupMenu *menu, int id,
const QString& action )
{
QString s = menu->text( id );
if ( s.isNull() ) return;
if (action.isNull()) return;
int i = s.find('\t');
QString k = keyToString( currentKey( action), true );
if( k.isNull() ) return;
if ( i >= 0 )
s.replace( i+1, s.length()-i, k );
else {
s += '\t';
s += k;
}
QPixmap *pp = menu->pixmap(id);
if(pp && !pp->isNull())
menu->changeItem( *pp, s, id );
else
menu->changeItem( s, id );
}
kdelibs'KAccel::changeMenuAccel() (./kdelibs/kdecore/kaccel.cpp:243)
void KAccel::changeMenuAccel( QPopupMenu *menu, int id,
KStdAccel::StdAccel accel )
{
changeMenuAccel(menu, id, KStdAccel::action(accel));
}
kdelibs'KAccel::insertStdItem() (./kdelibs/kdecore/kaccel.cpp:249)
bool KAccel::insertStdItem( KStdAccel::StdAccel id, const QString& descr )
{
return insertItem(descr.isNull() ? KStdAccel::description(id) : descr,
KStdAccel::action(id), KStdAccel::key(id), false );
}
kdelibs'KAccel::isEnabled() (./kdelibs/kdecore/kaccel.cpp:255)
bool KAccel::isEnabled() const
{
return bEnabled;
}
kdelibs'KAccel::isItemEnabled() (./kdelibs/kdecore/kaccel.cpp:260)
bool KAccel::isItemEnabled( const QString& action ) const
{
KKeyEntry *pEntry = aKeyDict[ action ];
if ( !pEntry )
return false;
else
return pEntry->bEnabled;
}
kdelibs'KAccel::keyDict() (./kdelibs/kdecore/kaccel.cpp:270)
QDict<KKeyEntry> KAccel::keyDict()
{
return aKeyDict;
}
kdelibs'KAccel::readSettings() (./kdelibs/kdecore/kaccel.cpp:275)
void KAccel::readSettings(KConfig* config)
{
QString s;
KConfig *pConfig = config ? config : KGlobal::config();
pConfig->setGroup( aGroup );
QDictIterator<KKeyEntry> aKeyIt( aKeyDict );
aKeyIt.toFirst();
kdelibs'KAccel::removeItem() (./kdelibs/kdecore/kaccel.cpp:312)
void KAccel::removeItem( const QString& action )
{
KKeyEntry *pEntry = aKeyDict[ action ];
if ( !pEntry )
return;
if ( pEntry->aAccelId ) {
QAccel::disconnectItem( pEntry->aAccelId, pEntry->receiver,
pEntry->member);
QAccel::removeItem( pEntry->aAccelId );
}
aKeyDict.remove( action );
}
kdelibs'KAccel::setEnabled() (./kdelibs/kdecore/kaccel.cpp:328)
void KAccel::setEnabled( bool activate )
{
QDictIterator<KKeyEntry> aKeyIt( aKeyDict );
aKeyIt.toFirst();
kdelibs'KAccel::setItemEnabled() (./kdelibs/kdecore/kaccel.cpp:341)
void KAccel::setItemEnabled( const QString& action, bool activate )
{
KKeyEntry *pEntry = aKeyDict[ action ];
if ( !pEntry ) {
kdWarning(125) << "cannot enable action " << action
<< " which is not in the object dictionary" << endl;
return;
}
QAccel::setItemEnabled( pEntry->aAccelId, activate );
}
kdelibs'KAccel::setKeyDict() (./kdelibs/kdecore/kaccel.cpp:353)
bool KAccel::setKeyDict( QDict<KKeyEntry> nKeyDict )
{
kdDebug(125) << "Disconnect and remove" << endl;
// Disconnect and remove all items in pAccel
QDictIterator<KKeyEntry> *aKeyIt = new QDictIterator<KKeyEntry>( aKeyDict );
aKeyIt->toFirst();
kdelibs'KAccel::setConfigGroup() (./kdelibs/kdecore/kaccel.cpp:419)
void KAccel::setConfigGroup( const QString& group )
{
aGroup = group;
}
kdelibs'KAccel::setConfigGlobal() (./kdelibs/kdecore/kaccel.cpp:424)
void KAccel::setConfigGlobal( bool global )
{
bGlobal = global;
}
kdelibs'KAccel::configGroup() (./kdelibs/kdecore/kaccel.cpp:429)
QString KAccel::configGroup() const
{
return aGroup;
}
kdelibs'KAccel::configGlobal() (./kdelibs/kdecore/kaccel.cpp:434)
bool KAccel::configGlobal() const
{
return bGlobal;
}
kdelibs'KAccel::writeSettings() (./kdelibs/kdecore/kaccel.cpp:439)
void KAccel::writeSettings(KConfig* config)
{
KConfig *pConfig = config?config:KGlobal::config();
pConfig->setGroup( aGroup );
QDictIterator<KKeyEntry> aKeyIt( aKeyDict );
aKeyIt.toFirst();
while ( aKeyIt.current() ) {
if ( aKeyIt.current()->bConfigurable ) {
if ( bGlobal )
pConfig->writeEntry( aKeyIt.currentKey(),
keyToString( aKeyIt.current()->aCurrentKeyCode),
true, true );
else
pConfig->writeEntry( aKeyIt.currentKey(),
keyToString( aKeyIt.current()->aCurrentKeyCode ));
}
++aKeyIt;
}
pConfig->sync();
}
kdelibs'KAccel::configurable() (./kdelibs/kdecore/kaccel.cpp:462)
bool KAccel::configurable( const QString &action ) const
{
KKeyEntry *pEntry = aKeyDict[ action ];
if ( !pEntry )
return false;
else
return pEntry->bConfigurable;
}
kdelibs'KAccel::clearItem() (./kdelibs/kdecore/kaccel.cpp:472)
void KAccel::clearItem(const QString &action)
{
KKeyEntry *pEntry = aKeyDict[ action ];
if (pEntry) {
if ( pEntry->aAccelId && pEntry->bConfigurable) {
QAccel::disconnectItem( pEntry->aAccelId, pEntry->receiver,
pEntry->member);
QAccel::removeItem( pEntry->aAccelId );
pEntry->aAccelId = 0;
pEntry->aCurrentKeyCode = 0;
if ( pEntry->menu ) {
changeMenuAccel(pEntry->menu, pEntry->menuId, action);
}
}
}
}
kdelibs'KAccel::updateItem() (./kdelibs/kdecore/kaccel.cpp:489)
bool KAccel::updateItem( const QString &action, uint keyCode)
{
KKeyEntry *pEntry = aKeyDict[ action ];
if ( pEntry->aCurrentKeyCode==keyCode ) return true;
if (pEntry) {
if ( pEntry->aAccelId ) {
QAccel::disconnectItem( pEntry->aAccelId, pEntry->receiver,
pEntry->member);
QAccel::removeItem( pEntry->aAccelId );
} else {
pEntry->aAccelId = aAvailableId;
aAvailableId++;
}
pEntry->aCurrentKeyCode = keyCode;
if (pEntry->aCurrentKeyCode) {
QAccel::insertItem( pEntry->aCurrentKeyCode, pEntry->aAccelId );
QAccel::connectItem( pEntry->aAccelId, pEntry->receiver, pEntry->member );
}
emit keycodeChanged();
return true;
} else
return false;
}
kdelibs'KAccel::removeDeletedMenu() (./kdelibs/kdecore/kaccel.cpp:514)
void KAccel::removeDeletedMenu(QPopupMenu *menu)
{
QDictIterator<KKeyEntry> aKeyIt( aKeyDict );
aKeyIt.toFirst();
kdelibs'KAccel::keyToString() (./kdelibs/kdecore/kaccel.cpp:532)
QString KAccel::keyToString( uint keyCode, bool i18_n )
{
QString res = "";
if ( keyCode == 0 ) return res;
if ( keyCode & Qt::SHIFT ){
if (i18_n) res += i18n("Shift");
else res += "Shift";
res += "+";
}
if ( keyCode & Qt::CTRL ){
if (i18_n) res += i18n("Ctrl");
else res += "Ctrl";
res += "+";
}
if ( keyCode & Qt::ALT ){
if (i18_n) res += i18n("Alt");
else res += "Alt";
res += "+";
}
uint kCode = keyCode & ~(Qt::SHIFT | Qt::CTRL | Qt::ALT);
for (int i=0; i<NB_KEYS; i++) {
if ( kCode == (uint)KKEYS[i].code ) {
res += KKEYS[i].name;
return res;
}
}
return QString::null;
}
kdelibs'KAccel::stringToKey() (./kdelibs/kdecore/kaccel.cpp:565)
uint KAccel::stringToKey(const QString& key)
{
// Empty string is interpreted as code zero, which is
// consistent with the behaviour of other KAccel methods
if ( key.isNull() ) {
// kdWarning(125) << "stringToKey::Null key" << endl;
return 0;
} else if ( key.isEmpty() ) {
// kdWarning(125) << "stringToKey::Empty key" << endl;
return 0;
}
// break the string in tokens separated by "+"
uint k = 0;
QArray<int> tokens;
int plus = -1;
do {
tokens.resize(k+1);
tokens[k] = plus+1;
plus = key.find('+', plus+1);
k++;
} while ( plus!=-1 );
tokens.resize(k+1);
tokens[k] = key.length() + 1;
// we have k tokens.
// find a keycode (only one)
// the other tokens are accelerators (SHIFT, CTRL & ALT)
// the order is unimportant
bool codeFound = false;
QString str;
uint keyCode = 0;
for (uint i=0; i<k; i++) {
str = key.mid(tokens[i], tokens[i+1]-tokens[i]-1);
str.stripWhiteSpace();
if ( str.isEmpty() ) {
kdWarning(125) << "stringToKey::Empty token" << endl;
return 0;
}
if ( k!=1 ) { // for e.g. "Shift" can be a modifier or a key
if ( str.upper()=="SHIFT" ) { keyCode |= Qt::SHIFT; continue; }
if ( str.upper()=="CTRL" ) { keyCode |= Qt::CTRL; continue; }
if ( str.upper()=="ALT" ) { keyCode |= Qt::ALT; continue; }
}
if (codeFound) {
kdWarning(125) << "stringToKey::Duplicate keycode" << endl;
return 0;
}
// search for keycode
uint j;
for(j=0; j<NB_KEYS; j++) {
if ( str==KKEYS[j].name ) {
keyCode |= KKEYS[j].code;
break;
}
}
if ( j==NB_KEYS ) {
kdWarning(125) << "stringToKey::Unknown key name " << str << endl;
return 0;
}
}
return keyCode;
}