class KAccelBase

# class KAccelBase | Configurable key binding support. More...
Internal Use Only
Contains pure virtuals
Definition | `#include <kaccelbase.h>`
Inherited by | KAccelPrivate, KGlobalAccelPrivate
List of all Methods
Annotated List
Files
Globals
Hierarchy
Index

#### Public Types

- enum Init { QT_KEYS = 0x00, NATIVE_KEYS = 0x01 }
- enum Signal { KEYCODE_CHANGED }

#### Public Methods

- KAccelBase ( int fInitCode )
- virtual ~KAccelBase ()
- uint actionCount () const
- KAccelActions& actions ()
- bool isEnabled () const
- KAccelAction* actionPtr ( const QString& sAction )
- const KAccelAction* actionPtr ( const QString& sAction ) const
- KAccelAction* actionPtr ( const KKey& key )
- KAccelAction* actionPtr ( const KKeyServer::Key& key )
- const QString& configGroup () const
- void setConfigGroup ( const QString& group )
- void setConfigGlobal ( bool global )
- virtual void setEnabled ( bool bEnabled )
- bool getAutoUpdate ()
- bool setAutoUpdate ( bool bAuto )
- KAccelAction* insert ( const QString& sName, const QString& sDesc )
- KAccelAction* insert ( const QString& sAction, const QString& sDesc, const QString& sHelp, const KShortcut& rgCutDefaults3, const KShortcut& rgCutDefaults4, const QObject* pObjSlot, const char* psMethodSlot, bool bConfigurable = true, bool bEnabled = true )
- bool remove ( const QString& sAction )
- bool setActionSlot ( const QString& sAction, const QObject* pObjSlot, const char* psMethodSlot )
- bool updateConnections ()
- bool setShortcut ( const QString& sAction, const KShortcut& cut )
- bool setActionEnabled ( const QString& sAction, bool bEnable )
- void readSettings ( KConfigBase* pConfig = 0 )
- void writeSettings ( KConfigBase* pConfig = 0 ) const
- QPopupMenu* createPopupMenu ( QWidget* pParent, const KKeySequence& )

#### Protected Types

- struct ActionInfo
- typedef QMap KKeyToActionMap

#### Protected Methods

- void slotRemoveAction ( KAccelAction* )
- void createKeyList ( QValueVector& rgKeys )
- bool insertConnection ( KAccelAction* )
- bool removeConnection ( KAccelAction* )
- virtual bool emitSignal ( Signal )
- virtual bool connectKey ( KAccelAction&, const KKeyServer::Key& )
- virtual bool connectKey ( const KKeyServer::Key& )
- virtual bool disconnectKey ( KAccelAction&, const KKeyServer::Key& )
- virtual bool disconnectKey ( const KKeyServer::Key& )

#### Protected Members

- KAccelActions m_rgActions
- KKeyToActionMap m_mapKeyToAction
- QValueList m_rgActionsNonUnique
- bool m_bNativeKeys
- bool m_bEnabled
- bool m_bConfigIsGlobal
- QString m_sConfigGroup
- bool m_bAutoUpdate
- KAccelAction* mtemp_pActionRemoving

## Detailed Description

Handle keyboard accelerators.

Allow an user to configure key bindings through application configuration files or through the KKeyChooser GUI.

A KAccel contains a list of accelerator items. Each accelerator item consists of an action name and a keyboard code combined with modifiers (Shift, Ctrl and Alt.)

For example, "Ctrl+P" could be a shortcut for printing a document. The key codes are listed in ckey.h. "Print" could be the action name for printing. The action name identifies the key binding in configuration files and the KKeyChooser GUI.

When pressed, an accelerator key calls the slot to which it has been connected. Accelerator items can be connected so that a key will activate two different slots.

A KAccel object handles key events sent to its parent widget and to all children of this parent widget.

Key binding reconfiguration during run time can be prevented by specifying that an accelerator item is not configurable when it is inserted. A special group of non-configurable key bindings are known as the standard accelerators.

The standard accelerators appear repeatedly in applications for standard document actions such as printing and saving. Convenience methods are available to insert and connect these accelerators which are configurable on a desktop-wide basis.

It is possible for a user to choose to have no key associated with an action.

The translated first argument for insertItem() is used only in the configuration dialog.

     KAccel *a = new KAccel( myWindow );
     // Insert an action "Scroll Up" which is associated with the "Up" key:
     a->insertItem( i18n("Scroll up"), "Scroll Up", "Up" );
     // Insert an action "Scroll Down" which is not associated with any key:
     a->insertItem( i18n("Scroll down"), "Scroll Down", 0);
     a->connectItem( "Scroll up", myWindow, SLOT( scrollUp() ) );
     // a->insertStdItem( KStdAccel::Print ); //not necessary, since it
    	// is done automatially with the
    	// connect below!
     a->connectItem(KStdAccel::Print, myWindow, SLOT( printDoc() ) );

     a->readSettings();

If a shortcut has a menu entry as well, you could insert them like this. The example is again the KStdAccel::Print from above.

     int id;
     id = popup->insertItem("&Print",this, SLOT(printDoc()));
     a->changeMenuAccel(popup, id, KStdAccel::Print );

If you want a somewhat "exotic" name for your standard print action, like id = popup->insertItem(i18n("Print &Document"),this, SLOT(printDoc())); it might be a good idea to insert the standard action before as a->insertStdItem( KStdAccel::Print, i18n("Print Document") ) as well, so that the user can easily find the corresponding function.

This technique works for other actions as well. Your "scroll up" function in a menu could be done with

        id = popup->insertItem(i18n"Scroll &up",this, SLOT(scrollUp()));
        a->changeMenuAccel(popup, id, "Scroll Up" );

Please keep the order right: First insert all functions in the acceleratior, then call a -> readSettings() and then build your menu structure.

enum Init { QT_KEYS = 0x00, NATIVE_KEYS = 0x01 } | ### Init

enum Signal { KEYCODE_CHANGED } | ### Signal

KAccelBase ( int fInitCode ) | ### KAccelBase

~KAccelBase () | ### ~KAccelBase

[virtual]

uint actionCount () | ### actionCount

[const]

KAccelActions& actions () | ### actions

bool isEnabled () | ### isEnabled

[const]

KAccelAction* actionPtr ( const QString& sAction ) | ### actionPtr

const KAccelAction* actionPtr ( const QString& sAction ) | ### actionPtr

[const]

KAccelAction* actionPtr ( const KKey& key ) | ### actionPtr

KAccelAction* actionPtr ( const KKeyServer::Key& key ) | ### actionPtr

const QString& configGroup () | ### configGroup

[const]

void setConfigGroup ( const QString& group ) | ### setConfigGroup

void setConfigGlobal ( bool global ) | ### setConfigGlobal

void setEnabled ( bool bEnabled ) | ### setEnabled

[pure virtual]

bool getAutoUpdate () | ### getAutoUpdate

bool setAutoUpdate ( bool bAuto ) | ### setAutoUpdate

KAccelAction* insert ( const QString& sName, const QString& sDesc ) | ### insert

KAccelAction* insert ( const QString& sAction, const QString& sDesc, const QString& sHelp, const KShortcut& rgCutDefaults3, const KShortcut& rgCutDefaults4, const QObject* pObjSlot, const char* psMethodSlot, bool bConfigurable = true, bool bEnabled = true ) | ### insert

bool remove ( const QString& sAction ) | ### remove

bool setActionSlot ( const QString& sAction, const QObject* pObjSlot, const char* psMethodSlot ) | ### setActionSlot

bool updateConnections () | ### updateConnections

bool setShortcut ( const QString& sAction, const KShortcut& cut ) | ### setShortcut

bool setActionEnabled ( const QString& sAction, bool bEnable ) | ### setActionEnabled

void readSettings ( KConfigBase* pConfig = 0 ) | ### readSettings

Read all key associations from `config`, or (if `config` is zero) from the application's configuration file KGlobal::config().

The group in which the configuration is stored can be set with setConfigGroup().

void writeSettings ( KConfigBase* pConfig = 0 ) | ### writeSettings

[const]

Write the current configurable associations to `config`, or (if `config` is zero) to the application's configuration file.

QPopupMenu* createPopupMenu ( QWidget* pParent, const KKeySequence& ) | ### createPopupMenu

void slotRemoveAction ( KAccelAction* ) | ### slotRemoveAction

[protected]

void createKeyList ( QValueVector& rgKeys ) | ### createKeyList

[protected]

bool insertConnection ( KAccelAction* ) | ### insertConnection

[protected]

bool removeConnection ( KAccelAction* ) | ### removeConnection

[protected]

bool emitSignal ( Signal ) | ### emitSignal

[protected pure virtual]

bool connectKey ( KAccelAction&, const KKeyServer::Key& ) | ### connectKey

[protected pure virtual]

bool connectKey ( const KKeyServer::Key& ) | ### connectKey

[protected pure virtual]

bool disconnectKey ( KAccelAction&, const KKeyServer::Key& ) | ### disconnectKey

[protected pure virtual]

bool disconnectKey ( const KKeyServer::Key& ) | ### disconnectKey

[protected pure virtual]

ActionInfo (struct) | ### ActionInfo

[protected]

typedef QMap<KKeyServer::Key, ActionInfo> KKeyToActionMap | ### KKeyToActionMap

[protected]

KAccelActions m_rgActions | ### m_rgActions

[protected]

KKeyToActionMap m_mapKeyToAction | ### m_mapKeyToAction

[protected]

QValueList<KAccelAction*> m_rgActionsNonUnique | ### m_rgActionsNonUnique

[protected]

bool m_bNativeKeys | ### m_bNativeKeys

[protected]

bool m_bEnabled | ### m_bEnabled

[protected]

bool m_bConfigIsGlobal | ### m_bConfigIsGlobal

[protected]

QString m_sConfigGroup | ### m_sConfigGroup

[protected]

bool m_bAutoUpdate | ### m_bAutoUpdate

[protected]

KAccelAction* mtemp_pActionRemoving | ### mtemp_pActionRemoving

[protected]

- Version: $Id: kaccelbase.h,v 1.22 2002/10/06 18:19:39 ellis Exp $
- Generated: root on macppc.ports.openbsd.org on Sat Sep 6 10:36:15 2003, using kdoc 2.0a54.