kstdgameaction.cpp

00001 /*
00002     This file is part of the KDE games library
00003     Copyright (C) 2001 Andreas Beckermann (b_mann@gmx.de)
00004 
00005     This library is free software; you can redistribute it and/or
00006     modify it under the terms of the GNU Library General Public
00007     License version 2 as published by the Free Software Foundation.
00008 
00009     This library is distributed in the hope that it will be useful,
00010     but WITHOUT ANY WARRANTY; without even the implied warranty of
00011     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012     Library General Public License for more details.
00013 
00014     You should have received a copy of the GNU Library General Public License
00015     along with this library; see the file COPYING.LIB.  If not, write to
00016     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017     Boston, MA 02110-1301, USA.
00018 */
00019 
00020 #include "kstdgameaction.h"
00021 
00022 #include <klocale.h>
00023 #include <kaction.h>
00024 #include <kstdaccel.h>
00025 #include <kconfig.h>
00026 #include <kdebug.h>
00027 
00028 
00029 KStdGameAction::KStdGameAction()
00030 {}
00031 
00032 KStdGameAction::~KStdGameAction()
00033 {}
00034 
00035 KAction *KStdGameAction::action(StdGameAction act_enum, const QObject *recvr,
00036                                 const char *slot, KActionCollection *parent,
00037                                 const char *name)
00038 {
00039     return create( act_enum, name, recvr, slot, parent );
00040 }
00041 
00042 const char* KStdGameAction::stdName(StdGameAction act_enum)
00043 {
00044     return name(act_enum);
00045 }
00046 
00047 struct KStdGameActionInfo
00048 {
00049     KStdGameAction::StdGameAction id;
00050     KStdAccel::StdAccel globalAccel; // if we reuse a global accel
00051     int shortcut; // specific shortcut (NH: should be configurable)
00052     const char* psName;
00053     const char* psLabel;
00054     const char* psWhatsThis;
00055     const char* psIconName;
00056 };
00057 
00058 const KStdGameActionInfo g_rgActionInfo[] = {
00059 // "game" menu
00060     { KStdGameAction::New, KStdAccel::New, 0, "game_new", I18N_NOOP2("new game", "&New"), 0, "filenew" },
00061     { KStdGameAction::Load, KStdAccel::Open, 0, "game_load", I18N_NOOP("&Load..."), 0, "fileopen" },
00062     { KStdGameAction::LoadRecent, KStdAccel::AccelNone, 0, "game_load_recent", I18N_NOOP("Load &Recent"), 0, 0 },
00063     { KStdGameAction::Restart, KStdAccel::Reload, 0, "game_restart", I18N_NOOP("Restart &Game"), 0, "reload" },
00064     { KStdGameAction::Save, KStdAccel::Save, 0, "game_save", I18N_NOOP("&Save"), 0, "filesave" },
00065     { KStdGameAction::SaveAs, KStdAccel::AccelNone, 0, "game_save_as", I18N_NOOP("Save &As..."), 0, "filesaveas" },
00066     { KStdGameAction::End, KStdAccel::End, 0, "game_end", I18N_NOOP("&End Game"), 0, "fileclose" },
00067     { KStdGameAction::Pause, KStdAccel::AccelNone, Qt::Key_P, "game_pause", I18N_NOOP("Pa&use"), 0, "player_pause" },
00068     { KStdGameAction::Highscores, KStdAccel::AccelNone, Qt::CTRL+Qt::Key_H, "game_highscores", I18N_NOOP("Show &Highscores"), 0, "highscore" },
00069     { KStdGameAction::Print, KStdAccel::Print, 0, "game_print", I18N_NOOP("&Print..."), 0, "fileprint" },
00070     { KStdGameAction::Quit, KStdAccel::Quit, 0, "game_quit", I18N_NOOP("&Quit"), 0, "exit" },
00071 // "move" menu
00072     { KStdGameAction::Repeat, KStdAccel::AccelNone, 0, "move_repeat", I18N_NOOP("Repeat"), 0, 0 },
00073     { KStdGameAction::Undo, KStdAccel::Undo, 0, "move_undo", I18N_NOOP("Und&o"), 0, "undo" },
00074     { KStdGameAction::Redo, KStdAccel::Redo, 0, "move_redo", I18N_NOOP("Re&do"), 0, "redo" },
00075     { KStdGameAction::Roll, KStdAccel::AccelNone, Qt::CTRL+Qt::Key_R, "move_roll", I18N_NOOP("&Roll Dice"), 0, "roll" },
00076     { KStdGameAction::EndTurn, KStdAccel::AccelNone, 0, "move_end_turn", I18N_NOOP("End Turn"), 0, "endturn" },
00077     { KStdGameAction::Hint, KStdAccel::AccelNone, Qt::Key_H, "move_hint", I18N_NOOP("&Hint"), 0, "idea" },
00078     { KStdGameAction::Demo, KStdAccel::AccelNone, Qt::Key_D, "move_demo", I18N_NOOP("&Demo"), 0, "1rightarrow" },
00079     { KStdGameAction::Solve, KStdAccel::AccelNone, 0, "move_solve", I18N_NOOP("&Solve"), 0, "wizard" },
00080 // "settings" menu
00081     { KStdGameAction::ChooseGameType, KStdAccel::AccelNone, 0, "options_choose_game_type", I18N_NOOP("Choose Game &Type"), 0, 0 },
00082     { KStdGameAction::Carddecks, KStdAccel::AccelNone, 0, "options_configure_carddecks", I18N_NOOP("Configure &Carddecks..."), 0, 0 },
00083     { KStdGameAction::ConfigureHighscores, KStdAccel::AccelNone, 0, "options_configure_highscores", I18N_NOOP("Configure &Highscores..."), 0, 0 },
00084 
00085     { KStdGameAction::ActionNone, KStdAccel::AccelNone, 0, 0, 0, 0, 0 }
00086 };
00087 
00088 static const KStdGameActionInfo* infoPtr( KStdGameAction::StdGameAction id )
00089 {
00090     for (uint i = 0; g_rgActionInfo[i].id!=KStdGameAction::ActionNone; i++) {
00091         if( g_rgActionInfo[i].id == id )
00092             return &g_rgActionInfo[i];
00093     }
00094     return 0;
00095 }
00096 
00097 
00098 KAction* KStdGameAction::create(StdGameAction id, const char *name,
00099                                 const QObject *recvr, const char *slot,
00100                                 KActionCollection* parent )
00101 {
00102     KAction* pAction = 0;
00103     const KStdGameActionInfo* pInfo = infoPtr( id );
00104     kdDebug(125) << "KStdGameAction::create( " << id << "=" << (pInfo ? pInfo->psName : (const char*)0) << ", " << parent << ", " << name << " )" << endl;
00105     if( pInfo ) {
00106         QString sLabel = i18n(pInfo->psLabel);
00107         KShortcut cut = (pInfo->globalAccel==KStdAccel::AccelNone
00108                          ? KShortcut(pInfo->shortcut)
00109                          : KStdAccel::shortcut(pInfo->globalAccel));
00110         const char *n = name ? name : pInfo->psName;
00111         switch( id ) {
00112         case LoadRecent:
00113             pAction =
00114                 new KRecentFilesAction(sLabel, cut, recvr, slot, parent, n);
00115             break;
00116         case Pause:
00117         case Demo:
00118             pAction = new KToggleAction( sLabel, pInfo->psIconName, cut,
00119                                          recvr, slot, parent, n);
00120             break;
00121         case ChooseGameType:
00122             pAction = new KSelectAction( sLabel, pInfo->psIconName, cut,
00123                                          recvr, slot, parent, n);
00124             break;
00125          default:
00126             pAction = new KAction( sLabel, pInfo->psIconName, cut,
00127                                    recvr, slot, parent, n);
00128             break;
00129         }
00130     }
00131     return pAction;
00132 }
00133 
00134 const char* KStdGameAction::name( StdGameAction id )
00135 {
00136     const KStdGameActionInfo* pInfo = infoPtr( id );
00137     return (pInfo) ? pInfo->psName : 0;
00138 }
00139 
00140 KAction *KStdGameAction::gameNew(const QObject *recvr, const char *slot,
00141                              KActionCollection *parent, const char *name )
00142 { return KStdGameAction::create(New, name, recvr, slot, parent); }
00143 KAction *KStdGameAction::load(const QObject *recvr, const char *slot,
00144                               KActionCollection *parent, const char *name )
00145 { return KStdGameAction::create(Load, name, recvr, slot, parent); }
00146 KRecentFilesAction *KStdGameAction::loadRecent(const QObject *recvr, const char *slot,
00147                                                KActionCollection *parent, const char *name )
00148 { return static_cast<KRecentFilesAction *>(KStdGameAction::create(LoadRecent, name, recvr, slot, parent)); }
00149 KAction *KStdGameAction::save(const QObject *recvr, const char *slot,
00150                               KActionCollection *parent, const char *name )
00151 { return KStdGameAction::create(Save, name, recvr, slot, parent); }
00152 KAction *KStdGameAction::saveAs(const QObject *recvr, const char *slot,
00153                                 KActionCollection *parent, const char *name )
00154 { return KStdGameAction::create(SaveAs, name, recvr, slot, parent); }
00155 KAction *KStdGameAction::end(const QObject *recvr, const char *slot,
00156                              KActionCollection *parent, const char *name )
00157 { return KStdGameAction::create(End, name, recvr, slot, parent); }
00158 KToggleAction *KStdGameAction::pause(const QObject *recvr, const char *slot,
00159                                      KActionCollection *parent, const char *name )
00160 { return static_cast<KToggleAction *>(KStdGameAction::create(Pause, name, recvr, slot, parent)); }
00161 KAction *KStdGameAction::highscores(const QObject *recvr, const char *slot,
00162                                     KActionCollection *parent, const char *name )
00163 { return KStdGameAction::create(Highscores, name, recvr, slot, parent); }
00164 KAction *KStdGameAction::print(const QObject *recvr, const char *slot,
00165                                KActionCollection *parent, const char *name )
00166 { return KStdGameAction::create(Print, name, recvr, slot, parent); }
00167 KAction *KStdGameAction::quit(const QObject *recvr, const char *slot,
00168                               KActionCollection *parent, const char *name )
00169 { return KStdGameAction::create(Quit, name, recvr, slot, parent); }
00170 
00171 KAction *KStdGameAction::repeat(const QObject *recvr, const char *slot,
00172                                 KActionCollection *parent, const char *name )
00173 { return KStdGameAction::create(Repeat, name, recvr, slot, parent); }
00174 KAction *KStdGameAction::undo(const QObject *recvr, const char *slot,
00175                               KActionCollection *parent, const char *name )
00176 { return KStdGameAction::create(Undo, name, recvr, slot, parent); }
00177 
00178 KAction *KStdGameAction::redo(const QObject *recvr, const char *slot,
00179                               KActionCollection *parent, const char *name )
00180 { return KStdGameAction::create(Redo, name, recvr, slot, parent); }
00181 
00182 KAction *KStdGameAction::roll(const QObject *recvr, const char *slot,
00183                               KActionCollection *parent, const char *name )
00184 { return KStdGameAction::create(Roll, name, recvr, slot, parent); }
00185 KAction *KStdGameAction::endTurn(const QObject *recvr, const char *slot,
00186                                  KActionCollection *parent, const char *name )
00187 { return KStdGameAction::create(EndTurn, name, recvr, slot, parent); }
00188 
00189 KAction *KStdGameAction::carddecks(const QObject *recvr, const char *slot,
00190                                    KActionCollection *parent, const char *name )
00191 { return KStdGameAction::create(Carddecks, name, recvr, slot, parent); }
00192 KAction *KStdGameAction::configureHighscores(const QObject*recvr, const char *slot,
00193                                              KActionCollection *parent, const char *name)
00194 { return KStdGameAction::create(ConfigureHighscores, name, recvr, slot, parent); }
00195 KAction *KStdGameAction::hint(const QObject*recvr, const char *slot,
00196                               KActionCollection *parent, const char *name)
00197 { return KStdGameAction::create(Hint, name, recvr, slot, parent); }
00198 KToggleAction *KStdGameAction::demo(const QObject*recvr, const char *slot,
00199                                KActionCollection *parent, const char *name)
00200 { return static_cast<KToggleAction *>(KStdGameAction::create(Demo, name, recvr, slot, parent)); }
00201 KAction *KStdGameAction::solve(const QObject*recvr, const char *slot,
00202                                KActionCollection *parent, const char *name)
00203 { return KStdGameAction::create(Solve, name, recvr, slot, parent); }
00204 KSelectAction *KStdGameAction::chooseGameType(const QObject*recvr, const char *slot,
00205                                           KActionCollection *parent, const char *name)
00206 { return static_cast<KSelectAction *>(KStdGameAction::create(ChooseGameType, name, recvr, slot, parent)); }
00207 KAction *KStdGameAction::restart(const QObject*recvr, const char *slot,
00208                                  KActionCollection *parent, const char *name)
00209 { return KStdGameAction::create(Restart, name, recvr, slot, parent); }
KDE Home | KDE Accessibility Home | Description of Access Keys