class KAccel

Configurable shortcut support for widgets. More...

Definition#include <kaccel.h>
InheritsQAccel (qt) [public ]
List of all Methods
Annotated List
Files
Globals
Hierarchy
Index

Public Methods

Signals

Public Static Methods

Protected Methods


Detailed Description

Handle shortcuts.

Allow a user to configure shortcuts through application configuration files or through the KKeyChooser GUI.

A KAccel contains a list of accelerator actions.

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

A KAccel object handles key events sent to its parent widget and to all children of this parent widget. The most recently created KAccel object has precedence over any KAccel objects created before it. When a shortcut pressed, KAccel calls the slot to which it has been connected. If you want to set global accelerators, independent of the window which has the focus, use KGlobalAccel.

Reconfiguration of a given shortcut 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. A convenience method is 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* pAccel = new KAccel( this );

 // Insert an action "Scroll Up" which is associated with the "Up" key:
 pAccel->insert( "Scroll Up", i18n("Scroll up"),
                       i18n("Scroll up the current document by one line."),
                       Qt::Key_Up, this, SLOT(slotScrollUp()) );
 // Insert an standard acclerator action.
 pAccel->insert( KStdAccel::Print, this, SLOT(slotPrint()) );

 // Update the shortcuts by read any user-defined settings from the
 //  application's config file.
 pAccel->readSettings();

See also: KGlobalAccel, KAccelShortcutList, KKeyChooser, KKeyDialog

 KAccel ( QWidget* pParent, const char* psName = 0 )

KAccel

Creates a new KAccel that watches pParent, which is also the QObject's parent.

Parameters:
pParentthe parent and widget to watch for key strokes
psNamethe name of the QObject

 KAccel ( QWidget* watch, QObject* parent, const char* psName = 0 )

KAccel

Creates a new KAccel that watches watch.

Parameters:
watchthe widget to watch for key strokes
parentthe parent of the QObject
psNamethe name of the QObject

 ~KAccel ()

~KAccel

[virtual]

KAccelActions&  actions ()

actions

Returns the KAccel's KAccelActions, a list of KAccepAction.

Returns: the KAccelActions of the KAccel

const KAccelActions&  actions ()

actions

[const]

Returns the KAccel's KAccelActions, a list of KAccepAction.

Returns: the KAccelActions of the KAccel

bool  isEnabled ()

isEnabled

Checks whether the KAccel is active.

Returns: true if the QAccel enabled

Reimplemented from QAccel.

void  setEnabled ( bool bEnabled )

setEnabled

Enables or disables the KAccel.

Parameters:
bEnabledtrue to enable, false to disable

Reimplemented from QAccel.

bool  getAutoUpdate ()

getAutoUpdate

Checks whether auto-update of connections is enabled.

Returns: true if auto-update is enabled (the default)

See also: setAutoUpdate()

bool  setAutoUpdate ( bool bAuto )

setAutoUpdate

Enable auto-update of connections. This means that the signals are automatically disconnected when you disable an action, and re-enabled when you enable it. By default auto update is turned on. If you disable auto-update, you need to call updateConnections() after changing actions.

Parameters:
bAutotrue to enable, false to disable

Returns: the value of the flag before this call

KAccelAction*  insert ( const QString& sAction, const QString& sLabel, const QString& sWhatsThis, const KShortcut& cutDef, const QObject* pObjSlot, const char* psMethodSlot, bool bConfigurable = true, bool bEnabled = true )

insert

Create an accelerator action.

Usage:


 insert( "Do Something", i18n("Do Something"),
   i18n("This action allows you to do something really great with this program to "
        "the currently open document."),
   ALT+Key_D, this, SLOT(slotDoSomething()) );

Parameters:
sActionThe internal name of the action.
sLabelAn i18n'ized short description of the action displayed when using KKeyChooser to reconfigure the shortcuts.
sWhatsThisAn extended description of the action.
cutDefThe default shortcut.
pObjSlotPointer to the slot object.
psMethodSlotPointer to the slot method.
bConfigurableAllow the user to change this shortcut if set to 'true'.
bEnabledThe action will be activated by the shortcut if set to 'true'.

KAccelAction*  insert ( const QString& sAction, const QString& sLabel, const QString& sWhatsThis, const KShortcut& cutDef3, const KShortcut& cutDef4, const QObject* pObjSlot, const char* psMethodSlot, bool bConfigurable = true, bool bEnabled = true )

insert

Same as first insert(), but with separate shortcuts defined for 3- and 4- modifier defaults.

KAccelAction*  insert ( const char* psAction, const KShortcut& cutDef, const QObject* pObjSlot, const char* psMethodSlot, bool bConfigurable = true, bool bEnabled = true )

insert

This is an overloaded function provided for convenience. The advantage of this is when you want to use the same text for the name of the action as for the user-visible label.

Usage:


 insert( I18N_NOOP("Do Something"), ALT+Key_D, this, SLOT(slotDoSomething()) );

Parameters:
psActionThe name AND label of the action.
cutDefThe default shortcut for this action.

KAccelAction*  insert ( KStdAccel::StdAccel id, const QObject* pObjSlot, const char* psMethodSlot, bool bConfigurable = true, bool bEnabled = true )

insert

Similar to the first insert() method, but with the action name, short description, help text, and default shortcuts all set according to one of the standard accelerators.

See also: KStdAccel.

KAccelAction*  insert ( const QString& sName, const QString& sLabel )

insert

Use this to insert a label into the action list. This will be displayed when the user configures shortcuts.

Parameters:
sNamethe name of the action
sLabelthe label of the action

Returns: the created KAccelAction

bool  remove ( const QString& sAction )

remove

Removes the accelerator action identified by the name. Remember to also call updateConnections().

Parameters:
sActionthe name of the action to remove

Returns: true if successful, false otherwise

bool  updateConnections ()

updateConnections

Updates the connections of the accelerations after changing them. This is only neccessary if you have disabled auto updates which are on by default.

Returns: true if successful, false otherwise

See also: setAutoUpdate(), getAutoUpdate()

const KShortcut&  shortcut ( const QString& sAction )

shortcut

[const]

Return the shortcut associated with the action named by sAction.

Parameters:
sActionthe name of the action

Returns: the action's shortcut, or a null shortcut if not found

bool  setShortcut ( const QString& sAction, const KShortcut &shortcut )

setShortcut

Set the shortcut to be associated with the action named by sAction.

Parameters:
sActionthe name of the action
shortcutthe shortcut to set

Returns: true if successful, false otherwise

bool  setSlot ( const QString& sAction, const QObject* pObjSlot, const char* psMethodSlot )

setSlot

Set the slot to be called when the shortcut of the action named by sAction is pressed.

Parameters:
sActionthe name of the action
pObjSlotthe owner of the slot
psMethodSlotthe name of the slot

Returns: true if successful, false otherwise

bool  setEnabled ( const QString& sAction, bool bEnabled )

setEnabled

Enable or disable the action named by sAction.

Parameters:
sActionthe action to en-/disable
bEnabledtrue to enable, false to disable

Returns: true if successful, false otherwise

Reimplemented from QAccel.

const QString&  configGroup ()

configGroup

[const]

Returns the configuration group of the settings.

Returns: the configuration group

See also: KConfig

void  setConfigGroup ( const QString &name )

setConfigGroup

Returns the configuration group of the settings.

Parameters:
namethe new configuration group

See also: KConfig

bool  readSettings ( KConfigBase* pConfig = 0 )

readSettings

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

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

Parameters:
pConfigthe configuration file, or 0 for the application configuration file

Returns: true if successful, false otherwise

bool  writeSettings ( KConfigBase* pConfig = 0 )

writeSettings

[const]

Write the current shortcuts to pConfig, or (if pConfig is zero) to the application's configuration file.

Parameters:
pConfigthe configuration file, or 0 for the application configuration file

Returns: true if successful, false otherwise

void  emitKeycodeChanged ()

emitKeycodeChanged

Emits the keycodeChanged() signal.

void  keycodeChanged ()

keycodeChanged

[signal]

Emitted when one of the key codes has changed.

bool  insertItem ( const QString& sLabel, const QString& sAction, const char* psKey, int nIDMenu = 0, QPopupMenu* pMenu = 0, bool bConfigurable = true )

insertItem

Reimplemented from QAccel.

bool  insertItem ( const QString& sLabel, const QString& sAction, int key, int nIDMenu = 0, QPopupMenu* pMenu = 0, bool bConfigurable = true )

insertItem

Reimplemented from QAccel.

bool  insertStdItem ( KStdAccel::StdAccel id, const QString& descr = QString::null )

insertStdItem

bool  connectItem ( const QString& sAction, const QObject* pObjSlot, const char* psMethodSlot, bool bActivate = true )

connectItem

Reimplemented from QAccel.

bool  connectItem ( KStdAccel::StdAccel accel, const QObject* pObjSlot, const char* psMethodSlot )

connectItem

Reimplemented from QAccel.

bool  removeItem ( const QString& sAction )

removeItem

Reimplemented from QAccel.

bool  setItemEnabled ( const QString& sAction, bool bEnable )

setItemEnabled

Reimplemented from QAccel.

void  changeMenuAccel ( QPopupMenu *menu, int id, const QString& action )

changeMenuAccel

void  changeMenuAccel ( QPopupMenu *menu, int id, KStdAccel::StdAccel accel )

changeMenuAccel

int  stringToKey ( const QString& )

stringToKey

[static]

int  currentKey ( const QString& action )

currentKey

[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.

QString  findKey ( int key )

findKey

[const]

Return the name of the accelerator item with the keycode key, or QString::null if the item cannot be found.

Reimplemented from QAccel.

void  virtual_hook ( int id, void* data )

virtual_hook

[protected virtual]