KDEGames

kgamestandardaction.h
1/*
2 This file is part of the KDE games library
3 SPDX-FileCopyrightText: 2001 Andreas Beckermann <b_mann@gmx.de>
4 SPDX-FileCopyrightText: 2007 Simon Hürlimann <simon.huerlimann@huerlisi.ch>
5
6 SPDX-License-Identifier: LGPL-2.0-only
7
8 This class was shamelessly stolen from kdelibs/kdeui/kstdction.[cpp|h] and
9 after that just edited for our needs
10*/
11
12#ifndef KGAMESTANDARDACTION_H
13#define KGAMESTANDARDACTION_H
14
15// own
16#include "kdegames_export.h"
17// KF
18#include <KRecentFilesAction>
19#include <KToggleAction>
20// Qt
21#include <QAction>
22// std
23#include <type_traits>
24
25/**
26 * Extension for KStandardAction in KDE Games
27 *
28 * This class is an extension to the usual KStandardAction class which provides
29 * easy access to often used KDE actions.
30 *
31 * Using these actions helps maintaining consistency among the games.
32 *
33 * Games often use different menu entries than other programs, e.g. games use
34 * the menu "game" instead of "file". This class provides the entries which
35 * differ from the usual KStandardAction entries.
36 *
37 * @see <tt>KStandardAction</tt>
38 *
39 * @author Andreas Beckermann <b_mann@gmx.de>
40 */
42{
43/**
44 * The standard menubar and toolbar actions.
45 */
47 // Game menu
48 New = 1,
49 Load,
50 LoadRecent,
51 Save,
52 SaveAs,
53 End,
54 Pause,
55 Highscores,
56 Statistics,
57 Print,
58 Quit,
59 // Move menu
60 Repeat,
61 Undo,
62 Redo,
63 Roll,
64 EndTurn,
65 // Settings menu
66 Carddecks,
67 ConfigureHighscores,
68 ClearHighscores,
69 ClearStatistics,
70 Restart,
71 Hint,
72 Demo,
73 Solve,
74 ActionNone
75};
76
77/**
78 * Creates an action corresponding to the
79 * KStandardAction::StandardAction enum.
80 */
81KDEGAMES_EXPORT QAction *create(GameStandardAction id, const QObject *recvr, const char *slot, QObject *parent);
82
83/**
84 * @internal
85 */
86KDEGAMES_EXPORT QAction *_k_createInternal(GameStandardAction id, QObject *parent);
87
88/**
89 * This overloads create() to allow using the new connect syntax.
90 *
91 * @note If you use @c LoadRecent as @p id, you should manually connect to the urlSelected(const QUrl &)
92 * signal of the returned KRecentFilesAction instead or use KGameStandardAction::loadRecent(Receiver *, Func, QObject*).
93 *
94 * @see create(GameStandardAction, const QObject *, const char *, QObject *)
95 * @since 7.3
96 */
97#ifdef K_DOXYGEN
98inline QAction *create(GameStandardAction id, const QObject *recvr, Func slot, QObject *parent)
99#else
100template<class Receiver, class Func>
101inline typename std::enable_if<!std::is_convertible<Func, const char *>::value, QAction>::type *
102create(GameStandardAction id, const Receiver *recvr, Func slot, QObject *parent)
103#endif
104{
105 QAction *action = _k_createInternal(id, parent);
106 QObject::connect(action, &QAction::triggered, recvr, slot);
107 return action;
108}
109
110/**
111 * This will return the internal name of a given standard action.
112 */
113KDEGAMES_EXPORT QString name(GameStandardAction id);
114
115// we have to disable the templated function for const char* as Func, since it is ambiguous otherwise
116// TODO: KF6: unify const char* version and new style by removing std::enable_if
117#ifdef K_DOXYGEN
118#define KSTANDARDGAMEACTION_WITH_NEW_STYLE_CONNECT(name, enumValue) inline QAction *name(const QObject *recvr, Func slot, QObject *parent);
119#define KSTANDARDGAMETOGGLEACTION_WITH_NEW_STYLE_CONNECT(name, enumValue) inline KToggleAction *name(const QObject *recvr, Func slot, QObject *parent);
120#else
121#define KSTANDARDGAMEACTION_WITH_NEW_STYLE_CONNECT(name, enumValue) \
122 template<class Receiver, class Func> \
123 inline typename std::enable_if<!std::is_convertible<Func, const char *>::value, QAction>::type *name(const Receiver *recvr, Func slot, QObject *parent) \
124 { \
125 return create(enumValue, recvr, slot, parent); \
126 }
127#define KSTANDARDGAMETOGGLEACTION_WITH_NEW_STYLE_CONNECT(name, enumValue) \
128 template<class Receiver, class Func> \
129 inline typename std::enable_if<!std::is_convertible<Func, const char *>::value, KToggleAction>::type *name(const Receiver *recvr, \
130 Func slot, \
131 QObject *parent) \
132 { \
133 QAction *ret = create(enumValue, recvr, slot, parent); \
134 Q_ASSERT(qobject_cast<KToggleAction *>(ret)); \
135 return static_cast<KToggleAction *>(ret); \
136 }
137#endif
138
139/**
140 * Start a new game.
141 */
142KDEGAMES_EXPORT QAction *gameNew(const QObject *recvr, const char *slot, QObject *parent);
143/**
144 * Start a new game.
145 * @since 7.3
146 */
147KSTANDARDGAMEACTION_WITH_NEW_STYLE_CONNECT(gameNew, New)
148
149/**
150 * Load a previously saved game.
151 */
152KDEGAMES_EXPORT QAction *load(const QObject *recvr, const char *slot, QObject *parent);
153
154/**
155 * Load a previously saved game.
156 * @since 7.3
157 */
158KSTANDARDGAMEACTION_WITH_NEW_STYLE_CONNECT(load, Load)
159
160// FIXME why not to delete this and use just KStandardAction::openRecent???
161// loadRecent seems to mimic its behaviour
162/**
163 * Load a recently loaded game.
164 * The signature of slot is of the form slotURLSelected(const QUrl&)
165 */
166KDEGAMES_EXPORT KRecentFilesAction *loadRecent(const QObject *recvr, const char *slot, QObject *parent);
167/**
168 * Load a recently loaded game.
169 * @since 7.3
170 */
171#ifdef K_DOXYGEN
172inline KRecentFilesAction *loadRecent(const QObject *recvr, Func slot, QObject *parent)
173#else
174template<class Receiver, class Func>
175inline typename std::enable_if<!std::is_convertible<Func, const char *>::value, KRecentFilesAction>::type *
176loadRecent(const Receiver *recvr, Func slot, QObject *parent)
177#endif
178{
179 QAction *action = _k_createInternal(LoadRecent, parent);
180 KRecentFilesAction *recentAction = qobject_cast<KRecentFilesAction *>(action);
181 Q_ASSERT(recentAction);
182 QObject::connect(recentAction, &KRecentFilesAction::urlSelected, recvr, slot);
183 return recentAction;
184}
185
186/**
187 * Save the current game.
188 */
189KDEGAMES_EXPORT QAction *save(const QObject *recvr, const char *slot, QObject *parent);
190
191/**
192 * Save the current game.
193 * @since 7.3
194 */
195KSTANDARDGAMEACTION_WITH_NEW_STYLE_CONNECT(save, Save)
196
197/**
198 * Save the current game under a different filename.
199 */
200KDEGAMES_EXPORT QAction *saveAs(const QObject *recvr, const char *slot, QObject *parent);
201
202/**
203 * Save the current game under a different filename.
204 * @since 7.3
205 */
206KSTANDARDGAMEACTION_WITH_NEW_STYLE_CONNECT(saveAs, SaveAs)
207
208/**
209 * Pause the game.
210 */
211KDEGAMES_EXPORT KToggleAction *pause(const QObject *recvr, const char *slot, QObject *parent);
212
213/**
214 * Pause the game.
215 * @since 7.3
216 */
217KSTANDARDGAMETOGGLEACTION_WITH_NEW_STYLE_CONNECT(pause, Pause)
218
219/**
220 * Show the highscores.
221 */
222KDEGAMES_EXPORT QAction *highscores(const QObject *recvr, const char *slot, QObject *parent);
223
224/**
225 * Show the highscores.
226 * @since 7.3
227 */
228KSTANDARDGAMEACTION_WITH_NEW_STYLE_CONNECT(highscores, Highscores)
229
230/**
231 * Clear highscores.
232 */
233KDEGAMES_EXPORT QAction *clearHighscores(const QObject *recvr, const char *slot, QObject *parent);
234
235/**
236 * Clear highscores.
237 * @since 7.3
238 */
239KSTANDARDGAMEACTION_WITH_NEW_STYLE_CONNECT(clearHighscores, ClearHighscores)
240
241/**
242 * Show the statistics.
243 */
244KDEGAMES_EXPORT QAction *statistics(const QObject *recvr, const char *slot, QObject *parent);
245
246/**
247 * Show the statistics.
248 * @since 7.3
249 */
250KSTANDARDGAMEACTION_WITH_NEW_STYLE_CONNECT(statistics, Statistics)
251
252/**
253 * Clear statistics.
254 */
255KDEGAMES_EXPORT QAction *clearStatistics(const QObject *recvr, const char *slot, QObject *parent);
256
257/**
258 * Clear statistics.
259 * @since 7.3
260 */
261KSTANDARDGAMEACTION_WITH_NEW_STYLE_CONNECT(clearStatistics, ClearStatistics)
262
263/**
264 * End the current game, but do not quit the program.
265 * Think of a "close" entry.
266 */
267KDEGAMES_EXPORT QAction *end(const QObject *recvr, const char *slot, QObject *parent);
268
269/**
270 * End the current game, but do not quit the program.
271 * Think of a "close" entry.
272 * @since 7.3
273 */
274KSTANDARDGAMEACTION_WITH_NEW_STYLE_CONNECT(end, End)
275
276/**
277 * Print current game.
278 * Not useful in all games.
279 */
280KDEGAMES_EXPORT QAction *print(const QObject *recvr, const char *slot, QObject *parent);
281
282/**
283 * Print current game.
284 * Not useful in all games.
285 * @since 7.3
286 */
287KSTANDARDGAMEACTION_WITH_NEW_STYLE_CONNECT(print, Print)
288
289/**
290 * Quit the game.
291 */
292KDEGAMES_EXPORT QAction *quit(const QObject *recvr, const char *slot, QObject *parent);
293
294/**
295 * Quit the game.
296 * @since 7.3
297 */
298KSTANDARDGAMEACTION_WITH_NEW_STYLE_CONNECT(quit, Quit)
299
300/**
301 * Repeat the last move.
302 */
303KDEGAMES_EXPORT QAction *repeat(const QObject *recvr, const char *slot, QObject *parent);
304
305/**
306 * Repeat the last move.
307 * @since 7.3
308 */
309KSTANDARDGAMEACTION_WITH_NEW_STYLE_CONNECT(repeat, Repeat)
310
311/**
312 * Undo the last move.
313 */
314KDEGAMES_EXPORT QAction *undo(const QObject *recvr, const char *slot, QObject *parent);
315
316/**
317 * Undo the last move.
318 * @since 7.3
319 */
320KSTANDARDGAMEACTION_WITH_NEW_STYLE_CONNECT(undo, Undo)
321
322/**
323 * Redo the last move (which has been undone).
324 */
325KDEGAMES_EXPORT QAction *redo(const QObject *recvr, const char *slot, QObject *parent);
326
327/**
328 * Redo the last move (which has been undone).
329 * @since 7.3
330 */
331KSTANDARDGAMEACTION_WITH_NEW_STYLE_CONNECT(redo, Redo)
332
333/**
334 * Roll die or dice.
335 */
336KDEGAMES_EXPORT QAction *roll(const QObject *recvr, const char *slot, QObject *parent);
337
338/**
339 * Roll die or dice.
340 * @since 7.3
341 */
342KSTANDARDGAMEACTION_WITH_NEW_STYLE_CONNECT(roll, Roll)
343
344/**
345 * End the current turn (not the game).
346 * Usually to let the next player start.
347 */
348KDEGAMES_EXPORT QAction *endTurn(const QObject *recvr, const char *slot, QObject *parent);
349
350/**
351 * End the current turn (not the game).
352 * Usually to let the next player start.
353 * @since 7.3
354 */
355KSTANDARDGAMEACTION_WITH_NEW_STYLE_CONNECT(endTurn, EndTurn)
356
357/**
358 * Display configure carddecks dialog.
359 */
360KDEGAMES_EXPORT QAction *carddecks(const QObject *recvr, const char *slot, QObject *parent);
361
362/**
363 * Display configure carddecks dialog.
364 * @since 7.3
365 */
366KSTANDARDGAMEACTION_WITH_NEW_STYLE_CONNECT(carddecks, Carddecks)
367
368/**
369 * Display configure highscores dialog.
370 */
371KDEGAMES_EXPORT QAction *configureHighscores(const QObject *recvr, const char *slot, QObject *parent);
372
373/**
374 * Display configure highscores dialog.
375 * @since 7.3
376 */
377KSTANDARDGAMEACTION_WITH_NEW_STYLE_CONNECT(configureHighscores, ConfigureHighscores)
378
379/**
380 * Give an advice/hint.
381 */
382KDEGAMES_EXPORT QAction *hint(const QObject *recvr, const char *slot, QObject *parent);
383
384/**
385 * Give an advice/hint.
386 * @since 7.3
387 */
388KSTANDARDGAMEACTION_WITH_NEW_STYLE_CONNECT(hint, Hint)
389
390/**
391 * Show a demo.
392 */
393KDEGAMES_EXPORT KToggleAction *demo(const QObject *recvr, const char *slot, QObject *parent);
394
395/**
396 * Show a demo.
397 * @since 7.3
398 */
399KSTANDARDGAMETOGGLEACTION_WITH_NEW_STYLE_CONNECT(demo, Demo)
400
401/**
402 * Solve the game.
403 */
404KDEGAMES_EXPORT QAction *solve(const QObject *recvr, const char *slot, QObject *parent);
405
406/**
407 * Solve the game.
408 * @since 7.3
409 */
410KSTANDARDGAMEACTION_WITH_NEW_STYLE_CONNECT(solve, Solve)
411
412/**
413 * Restart the game.
414 */
415KDEGAMES_EXPORT QAction *restart(const QObject *recvr, const char *slot, QObject *parent);
416/**
417 * Restart the game.
418 * @since 7.3
419 */
420KSTANDARDGAMEACTION_WITH_NEW_STYLE_CONNECT(restart, Restart)
421}
422
423#endif
void urlSelected(const QUrl &url)
Q_SCRIPTABLE Q_NOREPLY void pause()
Extension for KStandardAction in KDE Games.
QAction * configureHighscores(const QObject *recvr, const char *slot, QObject *parent)
Display configure highscores dialog.
QAction * restart(const QObject *recvr, const char *slot, QObject *parent)
Restart the game.
GameStandardAction
The standard menubar and toolbar actions.
QAction * quit(const QObject *recvr, const char *slot, QObject *parent)
Quit the game.
QAction * highscores(const QObject *recvr, const char *slot, QObject *parent)
Show the highscores.
QAction * carddecks(const QObject *recvr, const char *slot, QObject *parent)
Display configure carddecks dialog.
QAction * _k_createInternal(GameStandardAction id, QObject *parent)
QAction * redo(const QObject *recvr, const char *slot, QObject *parent)
Redo the last move (which has been undone).
QAction * create(GameStandardAction id, const QObject *recvr, const char *slot, QObject *parent)
Creates an action corresponding to the KStandardAction::StandardAction enum.
QAction * hint(const QObject *recvr, const char *slot, QObject *parent)
Give an advice/hint.
QAction * clearHighscores(const QObject *recvr, const char *slot, QObject *parent)
Clear highscores.
QAction * gameNew(const QObject *recvr, const char *slot, QObject *parent)
Start a new game.
KToggleAction * demo(const QObject *recvr, const char *slot, QObject *parent)
Show a demo.
QAction * endTurn(const QObject *recvr, const char *slot, QObject *parent)
End the current turn (not the game).
QAction * repeat(const QObject *recvr, const char *slot, QObject *parent)
Repeat the last move.
KRecentFilesAction * loadRecent(const QObject *recvr, const char *slot, QObject *parent)
Load a recently loaded game.
QAction * solve(const QObject *recvr, const char *slot, QObject *parent)
Solve the game.
QAction * undo(const QObject *recvr, const char *slot, QObject *parent)
Undo the last move.
QString name(GameStandardAction id)
This will return the internal name of a given standard action.
QAction * statistics(const QObject *recvr, const char *slot, QObject *parent)
Show the statistics.
QAction * roll(const QObject *recvr, const char *slot, QObject *parent)
Roll die or dice.
QAction * print(const QObject *recvr, const char *slot, QObject *parent)
Print current game.
QAction * end(const QObject *recvr, const char *slot, QObject *parent)
End the current game, but do not quit the program.
QAction * save(const QObject *recvr, const char *slot, QObject *parent)
Save the current game.
QAction * clearStatistics(const QObject *recvr, const char *slot, QObject *parent)
Clear statistics.
QAction * saveAs(const QObject *recvr, const char *slot, QObject *parent)
Save the current game under a different filename.
QAction * load(const QObject *recvr, const char *slot, QObject *parent)
Load a previously saved game.
void triggered(bool checked)
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri May 3 2024 11:47:37 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.