• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdegames API Reference
  • KDE Home
  • Contact Us
 

libkdegames

  • sources
  • kde-4.14
  • kdegames
  • libkdegames
kstandardgameaction.cpp
Go to the documentation of this file.
1 /*
2  This file is part of the KDE games library
3  Copyright (C) 2001 Andreas Beckermann <b_mann@gmx.de>
4  Copyright (C) 2007 Simon Hürlimann <simon.huerlimann@huerlisi.ch>
5 
6  This library is free software; you can redistribute it and/or
7  modify it under the terms of the GNU Library General Public
8  License version 2 as published by the Free Software Foundation.
9 
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Library General Public License for more details.
14 
15  You should have received a copy of the GNU Library General Public License
16  along with this library; see the file COPYING.LIB. If not, write to
17  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  Boston, MA 02110-1301, USA.
19 */
20 
21 #include "kstandardgameaction.h"
22 
23 #include <klocale.h>
24 #include <kaction.h>
25 #include <kactioncollection.h>
26 #include <kstandardshortcut.h>
27 #include <ktoggleaction.h>
28 #include <kconfig.h>
29 #include <kdebug.h>
30 #include <kicon.h>
31 #include <krecentfilesaction.h>
32 
33 #undef I18N_NOOP2
34 #define I18N_NOOP2(ctx,txt) ctx, txt
35 
36 struct KStandardGameActionInfo
37 {
38  KStandardGameAction::StandardGameAction id;
39  KStandardShortcut::StandardShortcut globalAccel; // if we reuse a global accel
40  int shortcut; // specific shortcut (NH: should be configurable)
41  const char* psName;
42  const char* psLabelContext;
43  const char* psLabel;
44  const char* psWhatsThis;
45  const char* psIconName;
46  const char* psToolTip;
47 };
48 
49 const KStandardGameActionInfo g_rgActionInfo[] = {
50 // "game" menu
51  { KStandardGameAction::New, KStandardShortcut::New, 0, "game_new", I18N_NOOP2("new game", "&New"), I18N_NOOP("Start a new game."), "document-new", I18N_NOOP("Start a new game") },
52  { KStandardGameAction::Load, KStandardShortcut::Open, 0, "game_load", 0, I18N_NOOP("&Load..."), 0, "document-open", I18N_NOOP("Open a saved game...") },
53  { KStandardGameAction::LoadRecent, KStandardShortcut::AccelNone, 0, "game_load_recent", 0, I18N_NOOP("Load &Recent"), 0, 0, I18N_NOOP("Open a recently saved game...") },
54  { KStandardGameAction::Restart, KStandardShortcut::Reload, 0, "game_restart", 0, I18N_NOOP("Restart &Game"), 0, "view-refresh", I18N_NOOP("Restart the game") },
55  { KStandardGameAction::Save, KStandardShortcut::Save, 0, "game_save", 0, I18N_NOOP("&Save"), 0, "document-save", I18N_NOOP("Save the current game") },
56  { KStandardGameAction::SaveAs, KStandardShortcut::AccelNone, 0, "game_save_as", 0, I18N_NOOP("Save &As..."), 0, "document-save-as", I18N_NOOP("Save the current game to another file") },
57  { KStandardGameAction::End, KStandardShortcut::End, 0, "game_end", 0, I18N_NOOP("&End Game"), 0, "window-close", I18N_NOOP("End the current game") },
58  { KStandardGameAction::Pause, KStandardShortcut::AccelNone, Qt::Key_P, "game_pause", 0, I18N_NOOP("Pa&use"), 0, "media-playback-pause", I18N_NOOP("Pause the game") },
59  { KStandardGameAction::Highscores, KStandardShortcut::AccelNone, Qt::CTRL+Qt::Key_H, "game_highscores", 0, I18N_NOOP("Show &High Scores"), 0, "games-highscores", I18N_NOOP("Show high scores") },
60  { KStandardGameAction::ClearHighscores, KStandardShortcut::AccelNone, 0, "game_clear_highscores", 0, I18N_NOOP("&Clear High Scores"), 0, "clear_highscore", I18N_NOOP("Clear high scores") },
61  { KStandardGameAction::Statistics, KStandardShortcut::AccelNone, 0, "game_statistics", 0, I18N_NOOP("Show Statistics"), 0, "highscore", I18N_NOOP("Show statistics") },
62  { KStandardGameAction::ClearStatistics, KStandardShortcut::AccelNone, 0, "game_clear_statistics", 0, I18N_NOOP("&Clear Statistics"), 0, "flag", I18N_NOOP("Delete all-time statistics.") },
63  { KStandardGameAction::Print, KStandardShortcut::Print, 0, "game_print", 0, I18N_NOOP("&Print..."), 0, "document-print", 0 },
64  { KStandardGameAction::Quit, KStandardShortcut::Quit, 0, "game_quit", 0, I18N_NOOP("&Quit"), 0, "application-exit", I18N_NOOP("Quit the program") },
65 // "move" menu
66  { KStandardGameAction::Repeat, KStandardShortcut::AccelNone, 0, "move_repeat", 0, I18N_NOOP("Repeat"), 0, 0, I18N_NOOP("Repeat the last move") },
67  { KStandardGameAction::Undo, KStandardShortcut::Undo, 0, "move_undo", 0, I18N_NOOP("Und&o"), 0, "edit-undo", I18N_NOOP("Undo the last move") },
68  { KStandardGameAction::Redo, KStandardShortcut::Redo, 0, "move_redo", 0, I18N_NOOP("Re&do"), 0, "edit-redo", I18N_NOOP("Redo the latest move") },
69  { KStandardGameAction::Roll, KStandardShortcut::AccelNone, Qt::CTRL+Qt::Key_R, "move_roll", 0, I18N_NOOP("&Roll Dice"), 0, "roll", I18N_NOOP("Roll the dice") },
70  { KStandardGameAction::EndTurn, KStandardShortcut::AccelNone, 0, "move_end_turn", 0, I18N_NOOP("End Turn"), 0, "games-endturn", 0 },
71  { KStandardGameAction::Hint, KStandardShortcut::AccelNone, Qt::Key_H, "move_hint", 0, I18N_NOOP("&Hint"), 0, "games-hint", I18N_NOOP("Give a hint") },
72  { KStandardGameAction::Demo, KStandardShortcut::AccelNone, Qt::Key_D, "move_demo", 0, I18N_NOOP("&Demo"), 0, "media-playback-start", I18N_NOOP("Play a demo") },
73  { KStandardGameAction::Solve, KStandardShortcut::AccelNone, 0, "move_solve", 0, I18N_NOOP("&Solve"), 0, "games-solve", I18N_NOOP("Solve the game") },
74 // "settings" menu
75  { KStandardGameAction::ChooseGameType, KStandardShortcut::AccelNone, 0, "options_choose_game_type", 0, I18N_NOOP("Choose Game &Type"), 0, 0, 0 },
76  { KStandardGameAction::Carddecks, KStandardShortcut::AccelNone, 0, "options_configure_carddecks", 0, I18N_NOOP("Configure &Carddecks..."), 0, 0, 0 },
77  { KStandardGameAction::ConfigureHighscores, KStandardShortcut::AccelNone, 0, "options_configure_highscores", 0, I18N_NOOP("Configure &High Scores..."), 0, 0, 0 },
78 
79  { KStandardGameAction::ActionNone, KStandardShortcut::AccelNone, 0, 0, 0, 0, 0, 0, 0 }
80 };
81 
82 static const KStandardGameActionInfo* infoPtr( KStandardGameAction::StandardGameAction id )
83 {
84  for (uint i = 0; g_rgActionInfo[i].id!=KStandardGameAction::ActionNone; i++) {
85  if( g_rgActionInfo[i].id == id )
86  return &g_rgActionInfo[i];
87  }
88  return 0;
89 }
90 
91 
92 KAction* KStandardGameAction::create(StandardGameAction id, const QObject *recvr, const char *slot,
93  QObject* parent )
94 {
95  KAction* pAction = 0;
96  const KStandardGameActionInfo* pInfo = infoPtr( id );
97  kDebug(125) << "KStandardGameAction::create( " << id << "=" << (pInfo ? pInfo->psName : (const char*)0) << "," << parent << " )";
98  if( pInfo ) {
99  QString sLabel = i18nc(pInfo->psLabelContext, pInfo->psLabel);
100  bool do_connect = (recvr && slot); //both not 0
101  switch( id ) {
102  case LoadRecent:
103  pAction = new KRecentFilesAction(sLabel, parent);
104  if(do_connect)
105  QObject::connect( pAction, SIGNAL(urlSelected(KUrl)), recvr, slot);
106  break;
107  case Pause:
108  case Demo:
109  pAction = new KToggleAction(KIcon(QLatin1String( pInfo->psIconName )), sLabel, parent);
110  if(do_connect)
111  QObject::connect(pAction, SIGNAL(triggered(bool)), recvr, slot);
112  break;
113  case ChooseGameType:
114  pAction = new KSelectAction( KIcon(QLatin1String( pInfo->psIconName )), sLabel, parent);
115  if(do_connect)
116  QObject::connect( pAction, SIGNAL(triggered(int)), recvr, slot );
117  break;
118  default:
119  pAction = new KAction(KIcon(QLatin1String( pInfo->psIconName )), sLabel, parent);
120  if(do_connect)
121  QObject::connect(pAction, SIGNAL(triggered(bool)), recvr, slot);
122  break;
123  }
124 
125  KShortcut cut = (pInfo->globalAccel==KStandardShortcut::AccelNone
126  ? KShortcut(pInfo->shortcut)
127  : KStandardShortcut::shortcut(pInfo->globalAccel));
128  pAction->setShortcut(cut);
129  if (pInfo->psToolTip)
130  pAction->setToolTip(i18n(pInfo->psToolTip));
131  if (pInfo->psWhatsThis)
132  pAction->setWhatsThis(i18n(pInfo->psWhatsThis));
133  else if (pInfo->psToolTip)
134  pAction->setWhatsThis(i18n(pInfo->psToolTip));
135 
136  pAction->setObjectName(QLatin1String( pInfo->psName ));
137  }
138 
139  KActionCollection *collection = qobject_cast<KActionCollection *>(parent);
140  if (collection && pAction)
141  collection->addAction(pAction->objectName(), pAction);
142 
143  return pAction;
144 }
145 
146 const char* KStandardGameAction::name( StandardGameAction id )
147 {
148  const KStandardGameActionInfo* pInfo = infoPtr( id );
149  return (pInfo) ? pInfo->psName : 0;
150 }
151 
152 KAction *KStandardGameAction::gameNew(const QObject *recvr, const char *slot,
153  QObject *parent)
154 { return KStandardGameAction::create(New, recvr, slot, parent); }
155 KAction *KStandardGameAction::load(const QObject *recvr, const char *slot,
156  QObject *parent)
157 { return KStandardGameAction::create(Load, recvr, slot, parent); }
158 KRecentFilesAction *KStandardGameAction::loadRecent(const QObject *recvr, const char *slot,
159  QObject *parent)
160 { return static_cast<KRecentFilesAction *>(KStandardGameAction::create(LoadRecent, recvr, slot, parent)); }
161 KAction *KStandardGameAction::save(const QObject *recvr, const char *slot,
162  QObject *parent)
163 { return KStandardGameAction::create(Save, recvr, slot, parent); }
164 KAction *KStandardGameAction::saveAs(const QObject *recvr, const char *slot,
165  QObject *parent)
166 { return KStandardGameAction::create(SaveAs, recvr, slot, parent); }
167 KAction *KStandardGameAction::end(const QObject *recvr, const char *slot,
168  QObject *parent)
169 { return KStandardGameAction::create(End, recvr, slot, parent); }
170 KToggleAction *KStandardGameAction::pause(const QObject *recvr, const char *slot,
171  QObject *parent)
172 { return static_cast<KToggleAction *>(KStandardGameAction::create(Pause, recvr, slot, parent)); }
173 KAction *KStandardGameAction::highscores(const QObject *recvr, const char *slot,
174  QObject *parent)
175 { return KStandardGameAction::create(Highscores, recvr, slot, parent); }
176 KAction *KStandardGameAction::statistics(const QObject *recvr, const char *slot,
177  QObject *parent)
178 { return KStandardGameAction::create(Highscores, recvr, slot, parent); }
179 KAction *KStandardGameAction::clearStatistics(const QObject *recvr, const char *slot,
180  QObject *parent)
181 { return KStandardGameAction::create(ClearStatistics, recvr, slot, parent); }
182 KAction *KStandardGameAction::print(const QObject *recvr, const char *slot,
183  QObject *parent)
184 { return KStandardGameAction::create(Print, recvr, slot, parent); }
185 KAction *KStandardGameAction::quit(const QObject *recvr, const char *slot,
186  QObject *parent)
187 { return KStandardGameAction::create(Quit, recvr, slot, parent); }
188 
189 KAction *KStandardGameAction::repeat(const QObject *recvr, const char *slot,
190  QObject *parent)
191 { return KStandardGameAction::create(Repeat, recvr, slot, parent); }
192 KAction *KStandardGameAction::undo(const QObject *recvr, const char *slot,
193  QObject *parent)
194 { return KStandardGameAction::create(Undo, recvr, slot, parent); }
195 
196 KAction *KStandardGameAction::redo(const QObject *recvr, const char *slot,
197  QObject *parent)
198 { return KStandardGameAction::create(Redo, recvr, slot, parent); }
199 
200 KAction *KStandardGameAction::roll(const QObject *recvr, const char *slot,
201  QObject *parent)
202 { return KStandardGameAction::create(Roll, recvr, slot, parent); }
203 KAction *KStandardGameAction::endTurn(const QObject *recvr, const char *slot,
204  QObject *parent)
205 { return KStandardGameAction::create(EndTurn, recvr, slot, parent); }
206 
207 KAction *KStandardGameAction::carddecks(const QObject *recvr, const char *slot,
208  QObject *parent)
209 { return KStandardGameAction::create(Carddecks, recvr, slot, parent); }
210 KAction *KStandardGameAction::configureHighscores(const QObject*recvr, const char *slot,
211  QObject *parent)
212 { return KStandardGameAction::create(ConfigureHighscores, recvr, slot, parent); }
213 KAction *KStandardGameAction::hint(const QObject*recvr, const char *slot,
214  QObject *parent)
215 { return KStandardGameAction::create(Hint, recvr, slot, parent); }
216 KToggleAction *KStandardGameAction::demo(const QObject*recvr, const char *slot,
217  QObject *parent)
218 { return static_cast<KToggleAction *>(KStandardGameAction::create(Demo, recvr, slot, parent)); }
219 KAction *KStandardGameAction::solve(const QObject*recvr, const char *slot,
220  QObject *parent)
221 { return KStandardGameAction::create(Solve, recvr, slot, parent); }
222 KSelectAction *KStandardGameAction::chooseGameType(const QObject*recvr, const char *slot,
223  QObject *parent)
224 { return static_cast<KSelectAction *>(KStandardGameAction::create(ChooseGameType, recvr, slot, parent)); }
225 KAction *KStandardGameAction::restart(const QObject*recvr, const char *slot,
226  QObject *parent)
227 { return KStandardGameAction::create(Restart, recvr, slot, parent); }
KStandardGameAction::restart
KDEGAMES_EXPORT KAction * restart(const QObject *recvr, const char *slot, QObject *parent)
Restart the game.
Definition: kstandardgameaction.cpp:225
KStandardGameAction::chooseGameType
KDEGAMES_EXPORT KSelectAction * chooseGameType(const QObject *recvr, const char *slot, QObject *parent)
Choose game type.
Definition: kstandardgameaction.cpp:222
KStandardGameAction::Roll
Definition: kstandardgameaction.h:59
KStandardGameAction::ClearHighscores
Definition: kstandardgameaction.h:64
KStandardGameAction::Restart
Definition: kstandardgameaction.h:66
KStandardGameAction::redo
KDEGAMES_EXPORT KAction * redo(const QObject *recvr, const char *slot, QObject *parent)
Redo the last move (which has been undone).
Definition: kstandardgameaction.cpp:196
KStandardGameAction::Redo
Definition: kstandardgameaction.h:59
KStandardGameAction::save
KDEGAMES_EXPORT KAction * save(const QObject *recvr, const char *slot, QObject *parent)
Save the current game.
Definition: kstandardgameaction.cpp:161
KStandardGameAction::End
Definition: kstandardgameaction.h:56
KStandardGameAction::Pause
Definition: kstandardgameaction.h:56
KStandardGameAction::Hint
Definition: kstandardgameaction.h:67
KStandardGameAction::carddecks
KDEGAMES_EXPORT KAction * carddecks(const QObject *recvr, const char *slot, QObject *parent)
Display configure carddecks dialog.
Definition: kstandardgameaction.cpp:207
KStandardGameAction::gameNew
KDEGAMES_EXPORT KAction * gameNew(const QObject *recvr, const char *slot, QObject *parent)
Start a new game.
Definition: kstandardgameaction.cpp:152
KStandardGameAction::Quit
Definition: kstandardgameaction.h:57
KStandardGameAction::pause
KDEGAMES_EXPORT KToggleAction * pause(const QObject *recvr, const char *slot, QObject *parent)
Pause the game.
Definition: kstandardgameaction.cpp:170
KStandardGameAction::Save
Definition: kstandardgameaction.h:56
I18N_NOOP2
#define I18N_NOOP2(ctx, txt)
Definition: kstandardgameaction.cpp:34
KStandardGameAction::SaveAs
Definition: kstandardgameaction.h:56
KStandardGameAction::Load
Definition: kstandardgameaction.h:56
KStandardGameAction::ChooseGameType
Definition: kstandardgameaction.h:62
KStandardGameAction::end
KDEGAMES_EXPORT KAction * end(const QObject *recvr, const char *slot, QObject *parent)
End the current game, but do not quit the program.
Definition: kstandardgameaction.cpp:167
KStandardGameAction::hint
KDEGAMES_EXPORT KAction * hint(const QObject *recvr, const char *slot, QObject *parent)
Give an advice/hint.
Definition: kstandardgameaction.cpp:213
QObject
KStandardGameAction::name
KDEGAMES_EXPORT const char * name(StandardGameAction id)
This will return the internal name of a given standard action.
Definition: kstandardgameaction.cpp:146
KStandardGameAction::ConfigureHighscores
Definition: kstandardgameaction.h:63
KStandardGameAction::Highscores
Definition: kstandardgameaction.h:56
KStandardGameAction::repeat
KDEGAMES_EXPORT KAction * repeat(const QObject *recvr, const char *slot, QObject *parent)
Repeat the last move.
Definition: kstandardgameaction.cpp:189
KStandardGameAction::ClearStatistics
Definition: kstandardgameaction.h:65
KStandardGameAction::StandardGameAction
StandardGameAction
The standard menubar and toolbar actions.
Definition: kstandardgameaction.h:54
KStandardGameAction::roll
KDEGAMES_EXPORT KAction * roll(const QObject *recvr, const char *slot, QObject *parent)
Roll die or dice.
Definition: kstandardgameaction.cpp:200
QString
KStandardGameAction::Undo
Definition: kstandardgameaction.h:59
KStandardGameAction::configureHighscores
KDEGAMES_EXPORT KAction * configureHighscores(const QObject *recvr, const char *slot, QObject *parent)
Display configure highscores dialog.
Definition: kstandardgameaction.cpp:210
infoPtr
static const KStandardGameActionInfo * infoPtr(KStandardGameAction::StandardGameAction id)
Definition: kstandardgameaction.cpp:82
KStandardGameAction::EndTurn
Definition: kstandardgameaction.h:59
KStandardGameAction::Repeat
Definition: kstandardgameaction.h:59
KStandardGameAction::Solve
Definition: kstandardgameaction.h:69
KStandardGameAction::demo
KDEGAMES_EXPORT KToggleAction * demo(const QObject *recvr, const char *slot, QObject *parent)
Show a demo.
Definition: kstandardgameaction.cpp:216
KStandardGameAction::Demo
Definition: kstandardgameaction.h:68
KStandardGameAction::loadRecent
KDEGAMES_EXPORT KRecentFilesAction * loadRecent(const QObject *recvr, const char *slot, QObject *parent)
Load a recently loaded game.
Definition: kstandardgameaction.cpp:158
KStandardGameAction::quit
KDEGAMES_EXPORT KAction * quit(const QObject *recvr, const char *slot, QObject *parent)
Quit the game.
Definition: kstandardgameaction.cpp:185
KStandardGameAction::highscores
KDEGAMES_EXPORT KAction * highscores(const QObject *recvr, const char *slot, QObject *parent)
Show the highscores.
Definition: kstandardgameaction.cpp:173
KStandardGameAction::statistics
KDEGAMES_EXPORT KAction * statistics(const QObject *recvr, const char *slot, QObject *parent)
Show the statistics.
Definition: kstandardgameaction.cpp:176
KStandardGameAction::Carddecks
Definition: kstandardgameaction.h:61
QLatin1String
KStandardGameAction::print
KDEGAMES_EXPORT KAction * print(const QObject *recvr, const char *slot, QObject *parent)
Print current game.
Definition: kstandardgameaction.cpp:182
KStandardGameAction::ActionNone
Definition: kstandardgameaction.h:70
KStandardGameAction::endTurn
KDEGAMES_EXPORT KAction * endTurn(const QObject *recvr, const char *slot, QObject *parent)
End the current turn (not the game).
Definition: kstandardgameaction.cpp:203
KStandardGameAction::Statistics
Definition: kstandardgameaction.h:56
KStandardGameAction::solve
KDEGAMES_EXPORT KAction * solve(const QObject *recvr, const char *slot, QObject *parent)
Solve the game.
Definition: kstandardgameaction.cpp:219
KStandardGameAction::LoadRecent
Definition: kstandardgameaction.h:56
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
KStandardGameAction::saveAs
KDEGAMES_EXPORT KAction * saveAs(const QObject *recvr, const char *slot, QObject *parent)
Save the current game under a different filename.
Definition: kstandardgameaction.cpp:164
KStandardGameAction::New
Definition: kstandardgameaction.h:56
g_rgActionInfo
const KStandardGameActionInfo g_rgActionInfo[]
Definition: kstandardgameaction.cpp:49
KStandardGameAction::load
KDEGAMES_EXPORT KAction * load(const QObject *recvr, const char *slot, QObject *parent)
Load a previousely saved game.
Definition: kstandardgameaction.cpp:155
KStandardGameAction::clearStatistics
KDEGAMES_EXPORT KAction * clearStatistics(const QObject *recvr, const char *slot, QObject *parent)
Clear statistics.
Definition: kstandardgameaction.cpp:179
KStandardGameAction::undo
KDEGAMES_EXPORT KAction * undo(const QObject *recvr, const char *slot, QObject *parent)
Undo the last move.
Definition: kstandardgameaction.cpp:192
kstandardgameaction.h
KStandardGameAction::Print
Definition: kstandardgameaction.h:57
KStandardGameAction::create
KDEGAMES_EXPORT KAction * create(StandardGameAction id, const QObject *recvr, const char *slot, QObject *parent)
Creates an action corresponding to the KStandardAction::StandardAction enum.
Definition: kstandardgameaction.cpp:92
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:18:42 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

libkdegames

Skip menu "libkdegames"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdegames API Reference

Skip menu "kdegames API Reference"
  • granatier
  • kapman
  • kblackbox
  • kgoldrunner
  • kigo
  • kmahjongg
  • KShisen
  • ksquares
  • libkdegames
  •   highscore
  •   libkdegamesprivate
  •     kgame
  • libkmahjongg
  • palapeli
  •   libpala

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal