m (Add more further reading) |
Neverendingo (Talk | contribs) m (Text replace - "</code>" to "</syntaxhighlight>") |
||
| (9 intermediate revisions by 3 users not shown) | |||
| Line 7: | Line 7: | ||
pre=[[Development/Tutorials/Programming_Tutorial_KDE_4|Introduction to KDE4 programming]]| | pre=[[Development/Tutorials/Programming_Tutorial_KDE_4|Introduction to KDE4 programming]]| | ||
| − | next=| | + | next=[[Development/Tutorials/Games/Highscores|High Scores Tutorial]]| |
| + | |||
reading={{class|KStandardGameAction}}, {{class|KStandardAction}} | reading={{class|KStandardGameAction}}, {{class|KStandardAction}} | ||
| Line 14: | Line 15: | ||
==Abstract== | ==Abstract== | ||
This tutorial will explain the usage of <tt>KStandardGameAction</tt>s in libkdegames. | This tutorial will explain the usage of <tt>KStandardGameAction</tt>s in libkdegames. | ||
| + | |||
| + | == KStandardGameAction == | ||
| + | This class is an extension to the usual <tt>KStandardAction</tt> class which provides easy access to often used KDE actions. | ||
| + | |||
| + | Using these actions helps maintaining consistency among the games. | ||
| + | |||
| + | Games often use different menu entries than other programs, e.g. games use | ||
| + | the menu "game" instead of "file". This class provides the entries which | ||
| + | differ from the usual KStandardAction entries. | ||
| + | |||
| + | == Usage == | ||
| + | Add some code like this to your action setup code. | ||
| + | <syntaxhighlight lang="cpp-qt" line> | ||
| + | #include <KStandardGameAction> | ||
| + | |||
| + | void setupActions() | ||
| + | { | ||
| + | // Game | ||
| + | KStandardGameAction::gameNew(this, | ||
| + | SLOT(newGame()), | ||
| + | actionCollection()); | ||
| + | KStandardGameAction::highscores(this, | ||
| + | SLOT(showHighscores()), | ||
| + | actionCollection()); | ||
| + | KStandardGameAction::quit(this, | ||
| + | SLOT(close()), | ||
| + | actionCollection()); | ||
| + | |||
| + | // Move | ||
| + | KStandardGameAction::undo(this, | ||
| + | SLOT(undoMove()), | ||
| + | actionCollection()); | ||
| + | KStandardGameAction::redo(this, | ||
| + | SLOT(redoMove()), | ||
| + | actionCollection()); | ||
| + | |||
| + | // Settings | ||
| + | KStandardGameAction::configureHighscores(this, | ||
| + | SLOT(configureHighscores()), | ||
| + | actionCollection()); | ||
| + | |||
| + | setupGUI(); | ||
| + | } | ||
| + | </syntaxhighlight> | ||
[[Category:C++]] | [[Category:C++]] | ||
| + | [[Category:KDEGames]] | ||
| Tutorial Series | KDE Games |
| Previous | Introduction to KDE4 programming |
| What's Next | High Scores Tutorial |
| Further Reading | KStandardGameAction, KStandardAction |
This tutorial will explain the usage of KStandardGameActions in libkdegames.
This class is an extension to the usual KStandardAction class which provides easy access to often used KDE actions.
Using these actions helps maintaining consistency among the games.
Games often use different menu entries than other programs, e.g. games use the menu "game" instead of "file". This class provides the entries which differ from the usual KStandardAction entries.
Add some code like this to your action setup code.
#include <KStandardGameAction>void setupActions()
{ // GameKStandardGameAction::gameNew(this,
SLOT(newGame()),
actionCollection());
KStandardGameAction::highscores(this,
SLOT(showHighscores()),
actionCollection());
KStandardGameAction::quit(this,
SLOT(close()),
actionCollection());
// MoveKStandardGameAction::undo(this,
SLOT(undoMove()),
actionCollection());
KStandardGameAction::redo(this,
SLOT(redoMove()),
actionCollection());
// SettingsKStandardGameAction::configureHighscores(this,
SLOT(configureHighscores()),
actionCollection());
setupGUI();
}