Development/Tutorials/Games/KStandardGameAction

From KDE TechBase
Revision as of 20:51, 29 June 2011 by Neverendingo (talk | contribs) (Text replace - "</code>" to "</syntaxhighlight>")
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.
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.

#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();
}