# class KAction | Class to encapsulate user-driven action or event. More...
Definition | `#include <kaction.h>`
Inherits | QObject (qt) [public ]
Inherited by | KActionMenu, KActionSeparator, KFontAction, KFontSizeAction, KListAction, KRadioAction, KRecentFilesAction, KSelectAction, KToggleAction, KToolBarPopupAction
List of all Methods
Annotated List
Files
Globals
Hierarchy
Index

#### Public Methods

- KAction ( const QString& text, int accel = 0, QObject* parent = 0, const char* name = 0 )
- KAction ( const QString& text, int accel, const QObject* receiver, const char* slot, QObject* parent, const char* name = 0 )
- KAction ( const QString& text, const QIconSet& pix, int accel = 0, QObject* parent = 0, const char* name = 0 )
- KAction ( const QString& text, const QString& pix, int accel = 0, QObject* parent = 0, const char* name = 0 )
- KAction ( const QString& text, const QIconSet& pix, int accel, const QObject* receiver, const char* slot, QObject* parent, const char* name = 0 )
- KAction ( const QString& text, const QString& pix, int accel, const QObject* receiver, const char* slot, QObject* parent, const char* name = 0 )
- KAction ( QObject* parent = 0, const char* name = 0 )
- virtual ~KAction ()
- virtual int plug ( QWidget *w, int index = -1 )
- virtual void plugAccel (KAccel *accel, bool configurable = true)
- virtual void unplug ( QWidget *w )
- virtual void unplugAccel ()
- virtual bool isPlugged () const
- virtual bool isPlugged ( const QWidget *container, int id ) const
- virtual bool isPlugged ( const QWidget *container, const QWidget *_representative ) const
- QWidget* container ( int index ) const
- int itemId ( int index ) const
- QWidget* representative ( int index ) const
- int containerCount () const
- virtual QPixmap pixmap () const
- virtual bool hasIconSet () const
- virtual QString plainText () const
- virtual QString text () const
- virtual int accel () const
- virtual bool isEnabled () const
- virtual QString group () const
- virtual QString whatsThis () const
- virtual QString toolTip () const
- virtual QString statusText () const
- virtual QIconSet iconSet () const
- virtual QString icon () const
- KActionCollection * parentCollection () const
- void unplugAll ()

#### Public Slots

- virtual void setText (const QString &text)
- virtual void setAccel (int a)
- virtual void setGroup ( const QString& )
- virtual void setWhatsThis ( const QString& text )
- virtual void setToolTip ( const QString& )
- virtual void setIconSet ( const QIconSet &iconSet )
- virtual void setIcon ( const QString& icon )
- virtual void setStatusText ( const QString &text )
- virtual void setEnabled (bool enable)
- virtual void activate ()

#### Signals

- void activated ()
- void enabled ( bool )

#### Public Static Methods

- static int getToolButtonID ()

#### Protected Methods

- KToolBar* toolBar ( int index ) const
- QPopupMenu* popupMenu ( int index ) const
- void removeContainer ( int index )
- int findContainer ( const QWidget* widget ) const
- void addContainer ( QWidget* parent, int id )
- void addContainer ( QWidget* parent, QWidget* representative )
- virtual void setAccel ( int id, int accel )
- virtual void setGroup ( int id, const QString& grp )
- virtual void setText (int i, const QString &text)
- virtual void setEnabled (int i, bool enable)
- virtual void setIconSet (int i, const QIconSet &iconSet)
- virtual void setIcon ( int i, const QString& icon )
- virtual void setToolTip ( int id, const QString& tt )
- virtual void setStatusText ( int id, const QString &text )
- virtual void setWhatsThis ( int id, const QString& text )
- int menuId ( int i )

#### Protected Slots

- virtual void slotDestroyed ()
- virtual void slotKeycodeChanged ()
- virtual void slotActivated ()

#### Protected Members

- KActionCollection *m_parentCollection

## Detailed Description

The KAction class (and derived and super classes) provides a way to easily encapsulate a "real" user-selected action or event in your program.

For instance, a user may want to `paste` the contents of the clipboard or `scroll` `down` a document or @ quit the application. These are all `actions` -- events that the user causes to happen. The KAction class allows the developer to deal with these actions in an easy and intuitive manner.

Specifically, the KAction class encapsulated the various attributes to an event/action. For instance, an action might have an icon that goes along with it (a clipboard for a "paste" action or scissors for a "cut" action). The action might have some text to describe the action. It will certainly have a method or function that actually `executes` the action! All these attributes are contained within the KAction object.

The advantage of dealing with Actions is that you can manipulate the Action without regard to the GUI representation of it. For instance, in the "normal" way of dealing with actions like "cut", you would manually insert a item for Cut into a menu and a button into a toolbar. If you want to disable the cut action for a moment (maybe nothing is selected), you woud have to hunt down the pointer to the menu item and the toolbar button and disable both individually. Setting the menu item and toolbar item up uses very similar code.. but has to be done twice!

With the Action concept, you simply "plug" the Action into whatever GUI element you want. The KAction class will then take care of correctly defining the menu item (with icons, accelerators, text, etc) or toolbar button.. or whatever. From then on, if you manipulate the Action at all, the effect will propogate through all GUI representations of it. Back to the "cut" example: if you want to disable the Cut Action, you would simply do 'cutAction->setEnabled(false)' and the menuitem and button would instantly be disabled!

This is the biggest advantage to the Action concept -- there is a one-to-one relationship between the "real" action and `all` GUI representations of it.

### General Usage:

The steps to using actions are roughly as follows

- Decide which attributes you want to associate with a given action (icons, text, keyboard accelerator, etc)
- Create the action using KAction (or derived or super class).
- "Plug" the Action into whatever GUI element you want. Typically, this will be a menu or toolbar.

### Detailed Example:

Here is an example of enabling a "New [document]" action

     KAction *newAct = new KAction(i18n("&New"), "filenew",
                                   KStdAccel::key(KStdAccel::New), this,
                                   SLOT(fileNew()), this);

This line creates our action. It says that wherever this action is displayed, it will use "&New" as the text, the standard icon, and the standard accelerator. It further says that whenever this action is invoked, it will use the fileNew() slot to execute it.

     QPopupMenu *file = new QPopupMenu;
     newAct->plug(file);

That just inserted the action into the File menu. You can totally forget about that! In the future, all manipulation of the item is done through the newAct object.

     newAct->plug(toolBar());

And this inserted the Action into the main toolbar as a button.

That's it!

If you want to disable that action sometime later, you can do so with

     newAct->setEnabled(false)

and both the menuitem in File and the toolbar button will instantly be disabled.

Note: if you are using a "standard" action like "new", "paste", "quit", or any other action described in the KDE UI Standards, please use the methods in the KStdAction class rather then defining your own.

### Usage Within the XML Framework:

If you are using KAction within the context of the XML menu and toolbar building framework, then there are a few tiny changes. The first is that you must insert your new action into an action collection. The action collection (a KActionCollection) is, logically enough, a central collection of all of the actions defined in your application. The XML UI framework code in KXMLGUI classes needs access to this collection in order to build up the GUI (it's how the builder code knows which actions are valid and which aren't).

Inserting your action into the collection is very simple. To use a previous example:

     KAction *newAct = new KAction(i18n("&New"), "filenew",
                                   KStdAccel::key(KStdAccel::New), this,
                                   SLOT(fileNew()), actionCollection());

The only change is to use 'actionCollection()' as the parent of the action. That's it!

Also, if you use the XML builder framework, then you do not ever have to plug your actions into containers manually. The framework does that for you.

See also: KStdAction

KAction ( const QString& text, int accel = 0, QObject* parent = 0, const char* name = 0 ) | ### KAction

Construct an action with text and potential keyboard accelerator but nothing else. Use this only if you really know what you are doing.

Parameters:

text | The text that will be displayed.
accel | The corresponding keyboard accelerator (shortcut).
parent | This action's parent.
name | An internal name for this action.

KAction ( const QString& text, int accel, const QObject* receiver, const char* slot, QObject* parent, const char* name = 0 ) | ### KAction

Construct an action with text, potential keyboard accelerator, and a SLOT to call when this action is invoked by the user.

If you do not want or have a keyboard accelerator, set the `accel` param to 0.

This is the most common KAction used when you do not have a corresponding icon (note that it won't appear in the current version of the "Edit ToolBar" dialog, because an action needs an icon to be plugged in a toolbar...).

Parameters:

text | The text that will be displayed.
accel | The corresponding keyboard accelerator (shortcut).
receiver | The SLOT's parent.
slot | The SLOT to invoke to execute this action.
parent | This action's parent.
name | An internal name for this action.

KAction ( const QString& text, const QIconSet& pix, int accel = 0, QObject* parent = 0, const char* name = 0 ) | ### KAction

Construct an action with text, icon, and a potential keyboard accelerator.

This Action cannot execute any command. Use this only if you really know what you are doing.

Parameters:

text | The text that will be displayed.
pix | The icons that go with this action.
accel | The corresponding keyboard accelerator (shortcut).
parent | This action's parent.
name | An internal name for this action.

KAction ( const QString& text, const QString& pix, int accel = 0, QObject* parent = 0, const char* name = 0 ) | ### KAction

Construct an action with text, automatically loaded icon, and a potential keyboard accelerator.

This Action cannot execute any command. Use this only if you really know what you are doing.

Parameters:

text | The text that will be displayed.
pix | The icons that go with this action.
accel | The corresponding keyboard accelerator (shortcut).
parent | This action's parent.
name | An internal name for this action.

KAction ( const QString& text, const QIconSet& pix, int accel, const QObject* receiver, const char* slot, QObject* parent, const char* name = 0 ) | ### KAction

Construct an action with text, icon, potential keyboard accelerator, and a SLOT to call when this action is invoked by the user.

If you do not want or have a keyboard accelerator, set the `accel` param to 0.

This is the other common KAction used. Use it when you `do` have a corresponding icon.

Parameters:

text | The text that will be displayed.
pix | The icon to display.
accel | The corresponding keyboard accelerator (shortcut).
receiver | The SLOT's parent.
slot | The SLOT to invoke to execute this action.
parent | This action's parent.
name | An internal name for this action.

KAction ( const QString& text, const QString& pix, int accel, const QObject* receiver, const char* slot, QObject* parent, const char* name = 0 ) | ### KAction

Construct an action with text, icon, potential keyboard accelerator, and a SLOT to call when this action is invoked by the user. The icon is loaded on demand later based on where it is plugged in.

If you do not want or have a keyboard accelerator, set the `accel` param to 0.

This is the other common KAction used. Use it when you `do` have a corresponding icon.

Parameters:

text | The text that will be displayed.
pix | The icon to display.
accel | The corresponding keyboard accelerator (shortcut).
receiver | The SLOT's parent.
slot | The SLOT to invoke to execute this action.
parent | This action's parent.
name | An internal name for this action.

KAction ( QObject* parent = 0, const char* name = 0 ) | ### KAction

Construct a null action. This is not recommended since all actions should have a text, for the "Edit ToolBar" dialog. So don't forget to call setText later :)

Parameters:

parent | This action's parent.
name | An internal name for this action.

~KAction () | ### ~KAction

[virtual]

Standard destructor

int plug ( QWidget *w, int index = -1 ) | ### plug

[virtual]

"Plug" or insert this action into a given widget.

This will typically be a menu or a toolbar. From this point on, you will never need to directly manipulate the item in the menu or toolbar. You do all enabling/disabling/manipulation directly with your KAction object.

Parameters:

w | The GUI element to display this action

void plugAccel (KAccel *accel, bool configurable = true) | ### plugAccel

[virtual]

"Plug" or insert this action into a given KAccel.

It is sometimes useful to use the action paradigm for actions that are not associated with some widget (ie actions that are only activated by keyboard).

Parameters:

accel | The KAccel which activates this action
configurable | If the accelerator is configurable via the KAccel configuration dialog (this is somehow deprecated since there is now a KAction key configuration dialog).

void unplug ( QWidget *w ) | ### unplug

[virtual]

"Unplug" or remove this action from a given widget.

This will typically be a menu or a toolbar. This is rarely used in "normal" application. Typically, it would be used if your application has several views or modes, each with a completely different menu structure. If you simply want to disable an action for a given period, use setEnabled() instead.

Parameters:

w | Remove the action from this GUI element.

void unplugAccel () | ### unplugAccel

[virtual]

Disconnect this action from the KAccel.

bool isPlugged () | ### isPlugged

[const virtual]

returns whether the action is plugged into any container widget or not.

bool isPlugged ( const QWidget *container, int id ) | ### isPlugged

[const virtual]

returns whether the action is plugged into the given container with the given, container specific, id (often menu or toolbar id ) .

bool isPlugged ( const QWidget *container, const QWidget *_representative ) | ### isPlugged

[const virtual]

returns whether the action is plugged into the given container with the given, container specific, representative container widget item.

QWidget* container ( int index ) | ### container

[const]

int itemId ( int index ) | ### itemId

[const]

QWidget* representative ( int index ) | ### representative

[const]

int containerCount () | ### containerCount

[const]

QPixmap pixmap () | ### pixmap

[const virtual]

bool hasIconSet () | ### hasIconSet

[const virtual]

QString plainText () | ### plainText

[const virtual]

QString text () | ### text

[const virtual]

Get the text associated with this action.

int accel () | ### accel

[const virtual]

Get the keyboard accelerator associated with this action.

bool isEnabled () | ### isEnabled

[const virtual]

QString group () | ### group

[const virtual]

QString whatsThis () | ### whatsThis

[const virtual]

Get the What's this text for the action.

QString toolTip () | ### toolTip

[const virtual]

Get the tooltip text for the action.

QString statusText () | ### statusText

[const virtual]

QIconSet iconSet () | ### iconSet

[const virtual]

Get the QIconSet from which the icons used to display this action will be chosen.

QString icon () | ### icon

[const virtual]

KActionCollection * parentCollection () | ### parentCollection

[const]

int getToolButtonID () | ### getToolButtonID

[static]

Generate a toolbar button id. Made public for reimplementations.

void unplugAll () | ### unplugAll

void setText (const QString &text) | ### setText

[virtual slot]

Set the text associated with this action. The text is used for menu and toolbar labels etc.

void setAccel (int a) | ### setAccel

[virtual slot]

Set the keyboard accelerator associated with this action.

void setGroup ( const QString& ) | ### setGroup

[virtual slot]

void setWhatsThis ( const QString& text ) | ### setWhatsThis

[virtual slot]

Set the What's this text for the action. This text will be displayed when a widget that has been created by plugging this action into a container is clicked on in What's this mode.

The What's this text can include QML markup as well as raw text.

void setToolTip ( const QString& ) | ### setToolTip

[virtual slot]

Set the tooltip text for the action. This will be used as a tooltip for a toolbar button, as a statusbar help-text for a menu item, and it also appears in the toolbar editor, to describe the action.

void setIconSet ( const QIconSet &iconSet ) | ### setIconSet

[virtual slot]

Set the QIconSet from which the icons used to display this action will be chosen.

void setIcon ( const QString& icon ) | ### setIcon

[virtual slot]

void setStatusText ( const QString &text ) | ### setStatusText

[virtual slot]

void setEnabled (bool enable) | ### setEnabled

[virtual slot]

Enables or disables this action. All uses of this action (eg. in menus or toolbars) will be updated to reflect the state of the action.

void activate () | ### activate

[virtual slot]

Emulate user's interaction programmatically, by activating the action. The implementation simply emits activated().

void slotDestroyed () | ### slotDestroyed

[protected slots virtual slot]

void slotKeycodeChanged () | ### slotKeycodeChanged

[protected slots virtual slot]

void slotActivated () | ### slotActivated

[protected slots virtual slot]

KToolBar* toolBar ( int index ) | ### toolBar

[protected const]

QPopupMenu* popupMenu ( int index ) | ### popupMenu

[protected const]

void removeContainer ( int index ) | ### removeContainer

[protected]

int findContainer ( const QWidget* widget ) | ### findContainer

[protected const]

void addContainer ( QWidget* parent, int id ) | ### addContainer

[protected]

void addContainer ( QWidget* parent, QWidget* representative ) | ### addContainer

[protected]

void setAccel ( int id, int accel ) | ### setAccel

[protected virtual]

void setGroup ( int id, const QString& grp ) | ### setGroup

[protected virtual]

void setText (int i, const QString &text) | ### setText

[protected virtual]

void setEnabled (int i, bool enable) | ### setEnabled

[protected virtual]

void setIconSet (int i, const QIconSet &iconSet) | ### setIconSet

[protected virtual]

void setIcon ( int i, const QString& icon ) | ### setIcon

[protected virtual]

void setToolTip ( int id, const QString& tt ) | ### setToolTip

[protected virtual]

void setStatusText ( int id, const QString &text ) | ### setStatusText

[protected virtual]

void setWhatsThis ( int id, const QString& text ) | ### setWhatsThis

[protected virtual]

int menuId ( int i ) | ### menuId

[protected]

for backwards compatibility. deprecated!

KActionCollection * m_parentCollection | ### m_parentCollection

[protected]

void activated () | ### activated

[signal]

void enabled ( bool ) | ### enabled

[signal]

Generated by: root@i386.ports.openbsd.org on Wed Apr 25 13:58:24 2001, using kdoc 2.0a53.