[Kde-games-devel] Standard actions
Nicolas Hadacek
kde-games-devel@mail.kde.org
Tue, 24 Dec 2002 20:32:54 +0100
--------------Boundary-00=_UA2NN386EJ37W5FS010O
Content-Type: text/plain;
charset="us-ascii"
Content-Transfer-Encoding: 8bit
Hi,
I'd like to add more standard actions in KStdGameAction and to clean up the
files "kstdgameaction.h/cpp" so that they get similar to the kstdaction ones.
Here are the diffs. Comments ?
cu,
Nicolas
--------------Boundary-00=_UA2NN386EJ37W5FS010O
Content-Type: text/x-diff;
charset="us-ascii";
name="1.diff"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="1.diff"
Index: ui_standards.rc
===================================================================
RCS file: /home/kde/kdelibs/kdeui/ui_standards.rc,v
retrieving revision 1.25
diff -u -2 -d -p -b -r1.25 ui_standards.rc
--- ui_standards.rc 22 Jul 2002 16:02:25 -0000 1.25
+++ ui_standards.rc 24 Dec 2002 16:25:29 -0000
@@ -1,4 +1,4 @@
<!DOCTYPE kpartgui SYSTEM "kpartgui.dtd">
-<kpartgui name="standard_containers" version="4">
+<kpartgui name="standard_containers" version="5">
<MenuBar>
<Menu name="file"><text>&File</text>
@@ -34,4 +34,5 @@
<Action name="game_load"/>
<Action name="game_load_recent"/>
+ <Action name="game_restart"/>
<MergeLocal name="new_merge"/>
<Separator/>
@@ -82,4 +83,9 @@
<MergeLocal name="move_turn_merge"/>
<Separator/>
+ <Action name="move_hint"/>
+ <Action name="move_demo"/>
+ <Action name="move_solve"/>
+ <MergeLocal name="move_solve_merge"/>
+ <Separator/>
<MergeLocal/>
</Menu>
@@ -145,6 +151,10 @@
<Action name="options_configure_notifications"/>
<Action name="options_configure_carddecks"/>
+ <Action name="options_configure_highscores"/>
<Action name="options_configure"/>
<MergeLocal name="configure_merge"/>
+ <Separator/>
+ <Action name="options_choose_game_type"/>
+ <MergeLocal name="choose_merge"/>
<Separator/>
<MergeLocal/>
--------------Boundary-00=_UA2NN386EJ37W5FS010O
Content-Type: text/x-diff;
charset="us-ascii";
name="2.diff"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="2.diff"
Index: kstdgameaction.cpp
===================================================================
RCS file: /home/kde/kdegames/libkdegames/kstdgameaction.cpp,v
retrieving revision 1.27
diff -u -2 -d -p -b -r1.27 kstdgameaction.cpp
--- kstdgameaction.cpp 12 Oct 2002 18:55:41 -0000 1.27
+++ kstdgameaction.cpp 24 Dec 2002 16:25:46 -0000
@@ -18,233 +18,180 @@
*/
-#include <kstdgameaction.h>
+#include "kstdgameaction.h"
+
#include <klocale.h>
#include <kaction.h>
#include <kstdaccel.h>
+#include <kconfig.h>
+#include <kdebug.h>
+
KStdGameAction::KStdGameAction()
-{
-}
+{}
KStdGameAction::~KStdGameAction()
+{}
+
+struct KStdGameActionInfo
{
-}
+ KStdGameAction::StdGameAction id;
+ KStdAccel::StdAccel globalAccel; // if we reuse a global accel
+ int shortcut; // specific shortcut (NH: should be configurable)
+ const char* psName;
+ const char* psLabel;
+ const char* psWhatsThis;
+ const char* psIconName;
+};
-KAction *KStdGameAction::action(StdGameAction act_enum, const QObject *recvr,
- const char *slot, KActionCollection *parent, const char *name )
+const KStdGameActionInfo g_rgActionInfo[] = {
+// "game" menu
+ { KStdGameAction::New, KStdAccel::New, 0, "game_new", I18N_NOOP("&New"), 0, "filenew" },
+ { KStdGameAction::Load, KStdAccel::Open, 0, "game_load", I18N_NOOP("&Load..."), 0, "fileopen" },
+ { KStdGameAction::LoadRecent, KStdAccel::AccelNone, 0, "game_load_recent", I18N_NOOP("Load &Recent"), 0, 0 },
+ { KStdGameAction::Restart, KStdAccel::Reload, 0, "game_restart", I18N_NOOP("Restart &Game"), 0, "reload" },
+ { KStdGameAction::Save, KStdAccel::Save, 0, "game_save", I18N_NOOP("&Save"), 0, "filesave" },
+ { KStdGameAction::SaveAs, KStdAccel::AccelNone, 0, "game_save_as", I18N_NOOP("Save &As..."), 0, "filesaveas" },
+ { KStdGameAction::End, KStdAccel::End, 0, "game_end", I18N_NOOP("&End Game"), 0, "fileclose" },
+ { KStdGameAction::Pause, KStdAccel::AccelNone, Qt::Key_P, "game_pause", I18N_NOOP("Pa&use"), 0, "player_pause" },
+ { KStdGameAction::Highscores, KStdAccel::AccelNone, Qt::CTRL+Qt::Key_H, "game_highscores", I18N_NOOP("Show &Highscores"), 0, "highscore" },
+ { KStdGameAction::Print, KStdAccel::Print, 0, "game_print", I18N_NOOP("&Print..."), 0, "fileprint" },
+ { KStdGameAction::Quit, KStdAccel::Quit, 0, "game_quit", I18N_NOOP("&Quit"), 0, "exit" },
+// "move" menu
+ { KStdGameAction::Repeat, KStdAccel::AccelNone, 0, "move_repeat", I18N_NOOP("Repeat"), 0, 0 },
+ { KStdGameAction::Undo, KStdAccel::Undo, 0, "move_undo", I18N_NOOP("Und&o"), 0, "undo" },
+ { KStdGameAction::Redo, KStdAccel::Redo, 0, "move_redo", I18N_NOOP("Re&do"), 0, "redo" },
+ { KStdGameAction::Roll, KStdAccel::AccelNone, Qt::CTRL+Qt::Key_R, "move_roll", I18N_NOOP("&Roll Dice"), 0, "roll" },
+ { KStdGameAction::EndTurn, KStdAccel::AccelNone, 0, "move_end_turn", I18N_NOOP("End Turn"), 0, "endturn" },
+ { KStdGameAction::Hint, KStdAccel::AccelNone, Qt::Key_H, "move_hint", I18N_NOOP("&Hint"), 0, "wizard" },
+ { KStdGameAction::Demo, KStdAccel::AccelNone, Qt::Key_D, "move_demo", I18N_NOOP("&Demo"), 0, "1rightarrow" },
+ { KStdGameAction::Solve, KStdAccel::AccelNone, 0, "move_solve", I18N_NOOP("&Solve"), 0, "idea" },
+// "settings" menu
+ { KStdGameAction::ChooseGameType, KStdAccel::AccelNone, 0, "options_choose_game_type", I18N_NOOP("Choose Game &Type"), 0, 0 },
+ { KStdGameAction::Carddecks, KStdAccel::AccelNone, 0, "options_configure_carddecks", I18N_NOOP("Configure &Carddecks..."), 0, 0 },
+ { KStdGameAction::ConfigureHighscores, KStdAccel::AccelNone, 0, "options_configure_highscores", I18N_NOOP("Configure &Highscores..."), 0, 0 },
+
+ { KStdGameAction::ActionNone, KStdAccel::AccelNone, 0, 0, 0, 0, 0 }
+};
+
+static const KStdGameActionInfo* infoPtr( KStdGameAction::StdGameAction id )
{
- switch (act_enum)
- {
- case New:
- return gameNew(recvr, slot, parent, name);
- case Load:
- return load(recvr, slot, parent, name);
- case LoadRecent:
- return loadRecent(recvr, slot, parent, name);
- case Save:
- return save(recvr, slot, parent, name);
- case SaveAs:
- return saveAs(recvr, slot, parent, name);
- case End:
- return end(recvr, slot, parent, name);
- case Pause:
- return pause(recvr, slot, parent, name);
- case Highscores:
- return highscores(recvr, slot, parent, name);
- case Print:
- return print(recvr, slot, parent, name);
- case Quit:
- return quit(recvr, slot, parent, name);
- case Repeat:
- return repeat(recvr, slot, parent, name);
- case Undo:
- return undo(recvr, slot, parent, name);
- case Redo:
- return redo(recvr, slot, parent, name);
- case EndTurn:
- return endTurn(recvr, slot, parent, name);
- case Roll:
- return roll(recvr, slot, parent, name);
- case Carddecks:
- return carddecks(recvr, slot, parent, name);
- default:
- break;
+ for (uint i = 0; g_rgActionInfo[i].id!=KStdGameAction::ActionNone; i++) {
+ if( g_rgActionInfo[i].id == id )
+ return &g_rgActionInfo[i];
}
return 0;
}
-const char* KStdGameAction::stdName(StdGameAction act_enum)
+
+KAction* KStdGameAction::create(StdGameAction id, const char *name,
+ const QObject *recvr, const char *slot,
+ KActionCollection* parent )
{
- switch (act_enum)
- {
- case New:
- return "game_new";
- case Load:
- return "game_load";
+ KAction* pAction = 0;
+ const KStdGameActionInfo* pInfo = infoPtr( id );
+ kdDebug(125) << "KStdGameAction::create( " << id << "=" << (pInfo ? pInfo->psName : (const char*)0) << ", " << parent << ", " << name << " )" << endl;
+ if( pInfo ) {
+ QString sLabel = i18n(pInfo->psLabel);
+ KShortcut cut = (pInfo->globalAccel==KStdAccel::AccelNone
+ ? KShortcut(pInfo->shortcut)
+ : KStdAccel::shortcut(pInfo->globalAccel));
+ const char *n = name ? name : pInfo->psName;
+ switch( id ) {
case LoadRecent:
- return "game_load_recent";
- case Save:
- return "game_save";
- case SaveAs:
- return "game_save_as";
- case End:
- return "game_end";
+ pAction =
+ new KRecentFilesAction(sLabel, cut, recvr, slot, parent, n);
+ break;
case Pause:
- return "game_pause";
- case Highscores:
- return "game_highscores";
- case Print:
- return "game_print";
- case Quit:
- return "game_quit";
- case Repeat:
- return "move_repeat";
- case Undo:
- return "move_undo";
- case Redo:
- return "move_redo";
- case Roll:
- return "move_roll";
- case EndTurn:
- return "move_end_turn";
- case Carddecks:
- return "options_configure_carddecks";
+ case Demo:
+ pAction = new KToggleAction( sLabel, pInfo->psIconName, cut,
+ recvr, slot, parent, n);
+ break;
+ case ChooseGameType:
+ pAction = new KSelectAction( sLabel, pInfo->psIconName, cut,
+ recvr, slot, parent, n);
+ break;
default:
+ pAction = new KAction( sLabel, pInfo->psIconName, cut,
+ recvr, slot, parent, n);
break;
}
-
- return "";
+ }
+ return pAction;
}
-KAction *KStdGameAction::gameNew(const QObject *recvr, const char *slot,
- KActionCollection *parent, const char *name )
+const char* KStdGameAction::name( StdGameAction id )
{
- return new KAction(i18n("new game", "&New"), "filenew",
- KStdAccel::key(KStdAccel::New), recvr, slot, parent,
- name ? name : stdName(New));
+ const KStdGameActionInfo* pInfo = infoPtr( id );
+ return (pInfo) ? pInfo->psName : 0;
}
+KAction *KStdGameAction::gameNew(const QObject *recvr, const char *slot,
+ KActionCollection *parent, const char *name )
+{ return KStdGameAction::create(New, name, recvr, slot, parent); }
KAction *KStdGameAction::load(const QObject *recvr, const char *slot,
KActionCollection *parent, const char *name )
-{
- return new KAction(i18n("&Load..."), "fileopen",
- KStdAccel::key(KStdAccel::Open), recvr, slot, parent,
- name ? name : stdName(Load));
-}
-
+{ return KStdGameAction::create(Load, name, recvr, slot, parent); }
KRecentFilesAction *KStdGameAction::loadRecent(const QObject *recvr, const char *slot,
KActionCollection *parent, const char *name )
-{
- return new KRecentFilesAction(i18n("Load &Recent"), 0,
- KStdAccel::AccelNone, recvr, slot, parent,
- name ? name : stdName(LoadRecent));
-}
-
+{ return static_cast<KRecentFilesAction *>(KStdGameAction::create(LoadRecent, name, recvr, slot, parent)); }
KAction *KStdGameAction::save(const QObject *recvr, const char *slot,
KActionCollection *parent, const char *name )
-{
- return new KAction(i18n("&Save"), "filesave",
- KStdAccel::key(KStdAccel::Save), recvr, slot, parent,
- name ? name : stdName(Save));
-}
-
+{ return KStdGameAction::create(Save, name, recvr, slot, parent); }
KAction *KStdGameAction::saveAs(const QObject *recvr, const char *slot,
KActionCollection *parent, const char *name )
-{
- return new KAction(i18n("Save &As..."), 0, recvr, slot, parent,
- name ? name : stdName(SaveAs));
-}
-
+{ return KStdGameAction::create(SaveAs, name, recvr, slot, parent); }
+KAction *KStdGameAction::end(const QObject *recvr, const char *slot,
+ KActionCollection *parent, const char *name )
+{ return KStdGameAction::create(End, name, recvr, slot, parent); }
KToggleAction *KStdGameAction::pause(const QObject *recvr, const char *slot,
KActionCollection *parent, const char *name )
-{
- return new KToggleAction(i18n("Pa&use"), "player_pause", Qt::Key_P, recvr, slot, parent,
- name ? name : stdName(Pause));
-}
-
+{ return static_cast<KToggleAction *>(KStdGameAction::create(Pause, name, recvr, slot, parent)); }
KAction *KStdGameAction::highscores(const QObject *recvr, const char *slot,
KActionCollection *parent, const char *name )
-{
-//hmm perhaps we need a KStdGameAccel one day? currently this entry is hard
-//coded...
- return new KAction(i18n("Show &Highscores"), "highscore",
- Qt::CTRL+Qt::Key_H, recvr, slot, parent,
- name ? name : stdName(Highscores));
-}
-
+{ return KStdGameAction::create(Highscores, name, recvr, slot, parent); }
KAction *KStdGameAction::print(const QObject *recvr, const char *slot,
KActionCollection *parent, const char *name )
-{
- return new KAction(i18n("&Print..."), "fileprint",
- KStdAccel::key(KStdAccel::Print), recvr, slot, parent,
- name ? name : stdName(Print));
-}
-
-KAction *KStdGameAction::end(const QObject *recvr, const char *slot,
- KActionCollection *parent, const char *name )
-{
- return new KAction(i18n("&End Game"), "fileclose",
- KStdAccel::key(KStdAccel::End), recvr, slot, parent,
- name ? name : stdName(End));
-}
-
+{ return KStdGameAction::create(Print, name, recvr, slot, parent); }
KAction *KStdGameAction::quit(const QObject *recvr, const char *slot,
KActionCollection *parent, const char *name )
-{
- return new KAction(i18n("&Quit"), "exit",
- KStdAccel::key(KStdAccel::Quit), recvr, slot, parent,
- name ? name : stdName(Quit));
-}
+{ return KStdGameAction::create(Quit, name, recvr, slot, parent); }
KAction *KStdGameAction::repeat(const QObject *recvr, const char *slot,
KActionCollection *parent, const char *name )
-{
- return new KAction(i18n("Repeat"), /*0,*/// hm do we have a suitable icon for this?
-// KStdAccel::key(KStdAccel::Redo), recvr, slot, parent,
- 0, recvr, slot, parent, // what about an accel?
- name ? name : stdName(Repeat));
-}
-
+{ return KStdGameAction::create(Repeat, name, recvr, slot, parent); }
KAction *KStdGameAction::undo(const QObject *recvr, const char *slot,
KActionCollection *parent, const char *name )
-{
- return new KAction(i18n("Und&o"), "undo",
- KStdAccel::key(KStdAccel::Undo), recvr, slot, parent,
- name ? name : stdName(Undo));
-}
+{ return KStdGameAction::create(Undo, name, recvr, slot, parent); }
KAction *KStdGameAction::redo(const QObject *recvr, const char *slot,
KActionCollection *parent, const char *name )
-{
- return new KAction(i18n("Re&do"), "redo",
- KStdAccel::key(KStdAccel::Redo), recvr, slot, parent,
- name ? name : stdName(Redo));
-}
+{ return KStdGameAction::create(Redo, name, recvr, slot, parent); }
KAction *KStdGameAction::roll(const QObject *recvr, const char *slot,
KActionCollection *parent, const char *name )
-{
-//hmm perhaps we need a KStdGameAccel one day? currently this entry is hard
-//coded...
- return new KAction(i18n("&Roll Dice"), "roll",
- Qt::CTRL+Qt::Key_R, recvr, slot, parent,
- name ? name : stdName(Roll));
-}
-
+{ return KStdGameAction::create(Roll, name, recvr, slot, parent); }
KAction *KStdGameAction::endTurn(const QObject *recvr, const char *slot,
KActionCollection *parent, const char *name )
-{
- return new KAction(i18n("End Turn"), "endturn",
- 0, recvr, slot, parent,
- name ? name : stdName(EndTurn));
-}
+{ return KStdGameAction::create(EndTurn, name, recvr, slot, parent); }
KAction *KStdGameAction::carddecks(const QObject *recvr, const char *slot,
KActionCollection *parent, const char *name )
-{
-//AB: maybe we need an icon?
- return new KAction(i18n("Configure &Carddecks..."),
- 0, recvr, slot, parent,
- name ? name : stdName(Carddecks));
-}
-
+{ return KStdGameAction::create(Carddecks, name, recvr, slot, parent); }
+KAction *KStdGameAction::configureHighscores(const QObject*recvr, const char *slot,
+ KActionCollection *parent, const char *name)
+{ return KStdGameAction::create(ConfigureHighscores, name, recvr, slot, parent); }
+KAction *KStdGameAction::hint(const QObject*recvr, const char *slot,
+ KActionCollection *parent, const char *name)
+{ return KStdGameAction::create(Hint, name, recvr, slot, parent); }
+KToggleAction *KStdGameAction::demo(const QObject*recvr, const char *slot,
+ KActionCollection *parent, const char *name)
+{ return static_cast<KToggleAction *>(KStdGameAction::create(Demo, name, recvr, slot, parent)); }
+KAction *KStdGameAction::solve(const QObject*recvr, const char *slot,
+ KActionCollection *parent, const char *name)
+{ return KStdGameAction::create(Solve, name, recvr, slot, parent); }
+KSelectAction *KStdGameAction::chooseGameType(const QObject*recvr, const char *slot,
+ KActionCollection *parent, const char *name)
+{ return static_cast<KSelectAction *>(KStdGameAction::create(ChooseGameType, name, recvr, slot, parent)); }
+KAction *KStdGameAction::restart(const QObject*recvr, const char *slot,
+ KActionCollection *parent, const char *name)
+{ return KStdGameAction::create(Restart, name, recvr, slot, parent); }
Index: kstdgameaction.h
===================================================================
RCS file: /home/kde/kdegames/libkdegames/kstdgameaction.h,v
retrieving revision 1.9
diff -u -2 -d -p -b -r1.9 kstdgameaction.h
--- kstdgameaction.h 17 Feb 2002 15:35:30 -0000 1.9
+++ kstdgameaction.h 24 Dec 2002 16:25:46 -0000
@@ -27,5 +27,8 @@ class QObject;
class KActionCollection;
class KRecentFilesAction;
+class KSelectAction;
+
+//-----------------------------------------------------------------------------
/**
* @see KStdAction
@@ -40,4 +43,5 @@ class KRecentFilesAction;
* @author Andreas Beckermann <b_mann@gmx.de>
*/
+// #### KDE4: transform in namespace
class KStdGameAction
{
@@ -53,28 +57,57 @@ public:
Repeat, Undo, Redo, Roll, EndTurn,
// Settings menu
- Carddecks
+ Carddecks,
+ ChooseGameType, // @since 3.2
+ ConfigureHighscores, // @since 3.2
+
+ Restart, // @since 3.2
+ Hint, // @since 3.2
+ Demo, // @since 3.2
+ Solve, // @since 3.2
+ ActionNone // @since 3.2
};
- /**
- * Constructor.
- **/
KStdGameAction();
- /**
- * Destructor.
- **/
~KStdGameAction();
/**
+ * Creates an action corresponding to the
+ * @ref KStdAction::StdAction enum.
+ * @since 3.2
+ */
+ static KAction* create( StdGameAction id, const char *name,
+ const QObject *recvr, const char *slot,
+ KActionCollection* parent );
+
+ /**
+ * @since 3.2
+ */
+ static KAction* create( StdGameAction id,
+ const QObject *recvr, const char *slot,
+ KActionCollection* parent )
+ { return create( id, 0, recvr, slot, parent ); }
+
+
+ /**
* Retrieve the action corresponding to the
* @ref KStdGameAction::StdGameAction enum.
+ * @deprecated
*/
static KAction *action(StdGameAction act_enum, const QObject *recvr = 0,
const char *slot = 0, KActionCollection *parent = 0,
- const char *name = 0L );
+ const char *name = 0L )
+ { return create( act_enum, name, recvr, slot, parent ); }
/**
* This will return the internal name of a given standard action.
+ * @since 3.2
*/
- static const char* stdName(StdGameAction act_enum);
+ static const char* name( StdGameAction id );
+
+ /**
+ * This will return the internal name of a given standard action.
+ * @deprecated
+ */
+ static const char* stdName(StdGameAction act_enum) { return name(act_enum); }
/**
@@ -180,4 +213,46 @@ public:
static KAction *carddecks(const QObject *recvr = 0, const char *slot = 0,
KActionCollection *parent = 0, const char *name = 0L );
+
+ /**
+ * Display configure highscores dialog.
+ * @since 3.2
+ */
+ static KAction *configureHighscores(const QObject *recvr = 0, const char *slot = 0,
+ KActionCollection *parent = 0, const char *name = 0L );
+
+ /**
+ * Give an advice/hint.
+ * @since 3.2
+ */
+ static KAction *hint(const QObject *recvr = 0, const char *slot = 0,
+ KActionCollection *parent = 0, const char *name = 0L );
+
+ /**
+ * Show a demo.
+ * @since 3.2
+ */
+ static KToggleAction *demo(const QObject *recvr = 0, const char *slot = 0,
+ KActionCollection *parent = 0, const char *name = 0L );
+
+ /**
+ * Solve the game.
+ * @since 3.2
+ */
+ static KAction *solve(const QObject *recvr = 0, const char *slot = 0,
+ KActionCollection *parent = 0, const char *name = 0L );
+
+ /**
+ * Choose game type.
+ * @since 3.2
+ */
+ static KSelectAction *chooseGameType(const QObject *recvr = 0, const char *slot = 0,
+ KActionCollection *parent = 0, const char *name = 0L );
+
+ /**
+ * Restart game.
+ * @since 3.2
+ */
+ static KAction *restart(const QObject *recvr = 0, const char *slot = 0,
+ KActionCollection *parent = 0, const char *name = 0L );
};
--------------Boundary-00=_UA2NN386EJ37W5FS010O--