Difference between revisions of "Development/Tutorials/Games/KStandardGameAction"

Jump to: navigation, search
(Add Highscore Tutorial as next)
m (Text replace - "</code>" to "</syntaxhighlight>")
 
(7 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=[[Projects/Games/Highscores|High Scores Tutorial]]|
+
next=[[Development/Tutorials/Games/Highscores|High Scores Tutorial]]|
  
  
Line 24: Line 24:
 
the menu "game" instead of "file". This class provides the entries which
 
the menu "game" instead of "file". This class provides the entries which
 
differ from the usual KStandardAction entries.
 
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]]

Latest revision as of 20:51, 29 June 2011

KStandardGameAction
Tutorial Series   KDE Games
Previous   Introduction to KDE4 programming
What's Next   High Scores Tutorial
Further Reading   KStandardGameAction, KStandardAction

Abstract

This tutorial will explain the usage of KStandardGameActions in libkdegames.

KStandardGameAction

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.

Usage

Add some code like this to your action setup code.

 1 #include <KStandardGameAction>
 2 
 3 void setupActions()
 4 {
 5   // Game
 6   KStandardGameAction::gameNew(this, 
 7                        SLOT(newGame()), 
 8                        actionCollection());
 9   KStandardGameAction::highscores(this, 
10                        SLOT(showHighscores()), 
11                        actionCollection());
12   KStandardGameAction::quit(this, 
13                        SLOT(close()), 
14                        actionCollection());
15 
16   // Move
17   KStandardGameAction::undo(this, 
18                        SLOT(undoMove()), 
19                        actionCollection());
20   KStandardGameAction::redo(this, 
21                        SLOT(redoMove()), 
22                        actionCollection());
23 
24   // Settings
25   KStandardGameAction::configureHighscores(this, 
26                        SLOT(configureHighscores()), 
27                        actionCollection());
28   
29   setupGUI();
30 }

This page was last modified on 29 June 2011, at 20:51. Content is available under Creative Commons License SA 3.0 as well as the GNU Free Documentation License 1.2 unless otherwise noted.