KDECore
KAccelBase Class Reference
Configurable key binding support. More...
#include <kaccelbase.h>
Detailed Description
Configurable key binding support.
For internal use only.
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.
Definition at line 121 of file kaccelbase.h.
Member Typedef Documentation
typedef QMap<KKeyServer::Key, ActionInfo> KAccelBase::KKeyToActionMap [protected] |
Definition at line 264 of file kaccelbase.h.
Member Enumeration Documentation
enum KAccelBase::Init |
Initialization mode of the KAccelBase, used in constructor.
Definition at line 125 of file kaccelbase.h.
enum KAccelBase::Signal |
Constructor & Destructor Documentation
KAccelBase::KAccelBase | ( | int | fInitCode | ) |
Constructor.
fInitCode
should be a bitwise OR of values from the Init enum.
Definition at line 46 of file kaccelbase.cpp.
KAccelBase::~KAccelBase | ( | ) | [virtual] |
Definition at line 58 of file kaccelbase.cpp.
Member Function Documentation
uint KAccelBase::actionCount | ( | ) | const |
KAccelAction * KAccelBase::actionPtr | ( | const KKeyServer::Key & | key | ) |
Basically the same as above, except a KKeyServer::Key already has a key mapping defined (either NATIVE_KEYS or not).
Definition at line 78 of file kaccelbase.cpp.
KAccelAction * KAccelBase::actionPtr | ( | const KKey & | key | ) |
Returns a pointer to the KAccelAction associated with the key key
.
This function takes into account the key mapping defined in the constructor.
May return 0 if no (or more than one) action is associated with the key.
Definition at line 86 of file kaccelbase.cpp.
const KAccelAction * KAccelBase::actionPtr | ( | const QString & | sAction | ) | const |
KAccelAction * KAccelBase::actionPtr | ( | const QString & | sAction | ) |
KAccelActions & KAccelBase::actions | ( | ) |
const QString& KAccelBase::configGroup | ( | ) | const [inline] |
Returns the name of the configuration group these accelerators are stored in.
The default is "Shortcuts".
Definition at line 163 of file kaccelbase.h.
virtual bool KAccelBase::connectKey | ( | const KKeyServer::Key & | key | ) | [protected, pure virtual] |
Defines a key which activates the accelerator.
- Parameters:
-
key key which causes the action to be executed
Implemented in KAccelPrivate, KGlobalAccelPrivate, KGlobalAccelPrivate, and KGlobalAccelPrivate.
virtual bool KAccelBase::connectKey | ( | KAccelAction & | action, | |
const KKeyServer::Key & | key | |||
) | [protected, pure virtual] |
Defines a key which activates the accelerator and executes the action.
- Parameters:
-
action action to be executed when key is pressed key key which causes the action to be executed
Implemented in KAccelPrivate, KGlobalAccelPrivate, KGlobalAccelPrivate, and KGlobalAccelPrivate.
void KAccelBase::createKeyList | ( | QValueVector< struct X > & | rgKeys | ) | [protected] |
Constructs a list of keys to be connected, sorted highest priority first.
- Parameters:
-
rgKeys constructed list of keys
QPopupMenu * KAccelBase::createPopupMenu | ( | QWidget * | pParent, | |
const KKeySequence & | seq | |||
) |
Definition at line 579 of file kaccelbase.cpp.
virtual bool KAccelBase::disconnectKey | ( | const KKeyServer::Key & | ) | [protected, pure virtual] |
Removes the key from accelerator.
Implemented in KAccelPrivate, KGlobalAccelPrivate, KGlobalAccelPrivate, and KGlobalAccelPrivate.
virtual bool KAccelBase::disconnectKey | ( | KAccelAction & | , | |
const KKeyServer::Key & | ||||
) | [protected, pure virtual] |
Removes the key from accelerator so it no longer executes the action.
Implemented in KAccelPrivate, KGlobalAccelPrivate, KGlobalAccelPrivate, and KGlobalAccelPrivate.
Emits a signal.
- Parameters:
-
signal signal to be emitted
Implemented in KAccelPrivate, KGlobalAccelPrivate, KGlobalAccelPrivate, and KGlobalAccelPrivate.
bool KAccelBase::getAutoUpdate | ( | ) | [inline] |
Returns whether autoupdate is enabled for these accelerators.
Definition at line 175 of file kaccelbase.h.
KAccelAction * KAccelBase::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 | |||
) |
Definition at line 129 of file kaccelbase.cpp.
KAccelAction * KAccelBase::insert | ( | const QString & | sName, | |
const QString & | sDesc | |||
) |
Definition at line 148 of file kaccelbase.cpp.
bool KAccelBase::insertConnection | ( | KAccelAction * | pAction | ) | [protected] |
Definition at line 456 of file kaccelbase.cpp.
bool KAccelBase::isEnabled | ( | ) | const |
Returns whether this accelerator handler is enabled or not.
Definition at line 65 of file kaccelbase.cpp.
bool KAccelBase::isEnabledInternal | ( | ) | const [protected, virtual] |
Reimplemented in KGlobalAccelPrivate, and KGlobalAccelPrivate.
Definition at line 70 of file kaccelbase.cpp.
void KAccelBase::readSettings | ( | KConfigBase * | pConfig = 0 |
) |
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().
Definition at line 567 of file kaccelbase.cpp.
Definition at line 151 of file kaccelbase.cpp.
bool KAccelBase::removeConnection | ( | KAccelAction * | pAction | ) | [protected] |
Definition at line 519 of file kaccelbase.cpp.
Definition at line 99 of file kaccelbase.cpp.
bool KAccelBase::setActionSlot | ( | const QString & | sAction, | |
const QObject * | pObjSlot, | |||
const char * | psMethodSlot | |||
) |
Definition at line 161 of file kaccelbase.cpp.
Enables (or disables) autoupdate for these accelerators.
- Returns:
- the value of autoupdate before the call.
Definition at line 119 of file kaccelbase.cpp.
void KAccelBase::setConfigGlobal | ( | bool | global | ) |
Definition at line 96 of file kaccelbase.cpp.
void KAccelBase::setConfigGroup | ( | const QString & | group | ) |
Set the group (in the configuration file) for storing accelerators.
Definition at line 93 of file kaccelbase.cpp.
virtual void KAccelBase::setEnabled | ( | bool | bEnabled | ) | [pure virtual] |
Enables or disables the accelerator.
- Parameters:
-
bEnabled determines whether the accelerator should be enabled or disabled.
Implemented in KAccelPrivate, KGlobalAccelPrivate, KGlobalAccelPrivate, KGlobalAccelPrivate, and KGlobalAccelPrivate.
Definition at line 551 of file kaccelbase.cpp.
void KAccelBase::slotRemoveAction | ( | KAccelAction * | pAction | ) | [protected] |
Definition at line 156 of file kaccelbase.cpp.
bool KAccelBase::updateConnections | ( | ) |
Definition at line 315 of file kaccelbase.cpp.
void KAccelBase::writeSettings | ( | KConfigBase * | pConfig = 0 |
) | const |
Write the current configurable associations to config
, or (if config
is zero) to the application's configuration file.
Definition at line 574 of file kaccelbase.cpp.
Member Data Documentation
bool KAccelBase::m_bAutoUpdate [protected] |
Definition at line 273 of file kaccelbase.h.
bool KAccelBase::m_bConfigIsGlobal [protected] |
Definition at line 271 of file kaccelbase.h.
bool KAccelBase::m_bEnabled [protected] |
Definition at line 270 of file kaccelbase.h.
bool KAccelBase::m_bNativeKeys [protected] |
Definition at line 269 of file kaccelbase.h.
KKeyToActionMap KAccelBase::m_mapKeyToAction [protected] |
Definition at line 267 of file kaccelbase.h.
KAccelActions KAccelBase::m_rgActions [protected] |
Definition at line 266 of file kaccelbase.h.
QValueList<KAccelAction*> KAccelBase::m_rgActionsNonUnique [protected] |
Definition at line 268 of file kaccelbase.h.
QString KAccelBase::m_sConfigGroup [protected] |
Definition at line 272 of file kaccelbase.h.
KAccelAction* KAccelBase::mtemp_pActionRemoving [protected] |
Definition at line 274 of file kaccelbase.h.
The documentation for this class was generated from the following files: