Commit fab40398 authored by Nicolas Hadacek's avatar Nicolas Hadacek
Browse files

XML GUI conversion

svn path=/trunk/kdegames/kmines/; revision=42105
parent 7e914403
2.0.2
* XMLify the GUI
2.0.1
* KAction/KAccel integrated
* keyboard play
......
......@@ -3,12 +3,14 @@ INCLUDES = $(all_includes)
kmines_LDFLAGS = $(all_libraries) $(KDE_RPATH)
kmines_LDADD = $(LIB_KDEUI)
kmines_SOURCES = defines.cpp dialogs.cpp field.cpp status.cpp main.cpp
kmines_METASOURCES = USE_AUTOMOC
noinst_HEADERS = defines.h dialogs.h field.h status.h main.h
kmines_SOURCES = defines.cpp dialogs.cpp field.cpp status.cpp main.cpp
kmines_METASOURCES = USE_AUTOMOC
noinst_HEADERS = defines.h dialogs.h field.h status.h main.h
SUBDIRS = data bitmaps
rcdir = $(kde_datadir)/kmines
rc_DATA = ui_kmines.rc
messages:
$(XGETTEXT) $(kmines_SOURCES) -o $(podir)/kmines.pot
......@@ -18,108 +18,103 @@
#include "version.h"
#include "status.h"
MainWidget::MainWidget(const KAboutData *aboutData)
MainWidget::MainWidget()
: keyAction(7), levelAction(NbLevels)
{
installEventFilter(this);
status = new Status(this);
status->installEventFilter(this);
kacc = new KAccel(this);
// popup
popup = new KActionMenu(i18n("&File"), this);
menuBar()->insertItem(popup->text(), popup->popupMenu());
menuAction = new KAction(QString::null, 0,
this, SLOT(toggleMenu()), this);
// Popup
popup = new KActionMenu(i18n("Popup"), this);
KToggleAction *menuAction
= KStdAction::showMenubar(this, SLOT(toggleMenubar()),
actionCollection());
popup->insert(menuAction);
popup->insert( new KActionSeparator(this) );
KAction *action = KStdAction::openNew(status, SLOT(restartGame()), this);
action->setText(i18n("&New game"));
// File & Popup
KAction *action = KStdAction::openNew(status, SLOT(restartGame()),
actionCollection(), "game_new");
popup->insert(action);
action = new KAction(i18n("&Pause game"), Key_P,
status, SLOT(pauseGame()), this);
action->plugAccel(kacc, "pause");
action = new KAction(i18n("&Pause game"), Key_P, status, SLOT(pauseGame()),
actionCollection(), "game_pause");
action->plugAccel(kacc);
popup->insert(action);
popup->insert( new KActionSeparator(this) );
action = new KAction(i18n("&High scores..."), Key_H,
status, SLOT(showHighScores()), this);
action->plugAccel(kacc, "highscores");
status, SLOT(showHighScores()),
actionCollection(), "game_highscores");
action->plugAccel(kacc);
popup->insert(action);
action = KStdAction::print(status, SLOT(print()), this);
action = KStdAction::print(status, SLOT(print()),
actionCollection(), "game_print");
popup->insert(action);
popup->insert( new KActionSeparator(this) );
action = KStdAction::quit(qApp, SLOT(quit()), this);
action = KStdAction::quit(qApp, SLOT(quit()),
actionCollection(), "game_quit");
popup->insert(action);
// keyboard
keyAction[0] = new KAction(i18n("Move up"), Key_Up,
status, SLOT(moveUp()), this);
keyAction[0]->plugAccel(kacc, "moveup");
status, SLOT(moveUp()), this, "moveup");
keyAction[0]->plugAccel(kacc);
keyAction[1] = new KAction(i18n("Move down"), Key_Down,
status, SLOT(moveDown()), this);
keyAction[1]->plugAccel(kacc, "movedown");
status, SLOT(moveDown()), this, "movedown");
keyAction[1]->plugAccel(kacc);
keyAction[2] = new KAction(i18n("Move left"), Key_Left,
status, SLOT(moveLeft()), this);
keyAction[2]->plugAccel(kacc, "moveleft");
status, SLOT(moveLeft()), this, "moveleft");
keyAction[2]->plugAccel(kacc);
keyAction[3] = new KAction(i18n("Move right"), Key_Right,
status, SLOT(moveRight()), this);
keyAction[3]->plugAccel(kacc, "moveright");
status, SLOT(moveRight()), this, "moveright");
keyAction[3]->plugAccel(kacc);
keyAction[4] = new KAction(i18n("Reveal mine"), Key_Shift,
status, SLOT(reveal()), this);
keyAction[4]->plugAccel(kacc, "revealmine");
status, SLOT(reveal()), this, "revealmine");
keyAction[4]->plugAccel(kacc);
keyAction[5] = new KAction(i18n("Mark mine"), Key_Space,
status, SLOT(mark()), this);
keyAction[5]->plugAccel(kacc, "markmine");
status, SLOT(mark()), this, "markmine");
keyAction[5]->plugAccel(kacc);
keyAction[6] = new KAction(i18n("Automatic reveal"), Key_Control,
status, SLOT(autoReveal()), this);
keyAction[6]->plugAccel(kacc, "autoreveal");
// options
KActionMenu *options = new KActionMenu(i18n("&Settings"), this);
menuBar()->insertItem(options->text(), options->popupMenu());
KToggleAction *markAction = new KToggleAction(i18n("? &mark"), 0,
this, SLOT(toggleUMark()), this);
options->insert(markAction);
KToggleAction *keyboardAction = new KToggleAction(i18n("&keyboard play"),
0, this, SLOT(toggleKeyboard()), this);
options->insert(keyboardAction);
action = new KAction(i18n("&Other settings..."), 0,
status, SLOT(options()), this);
options->insert(action);
action = KStdAction::keyBindings(this, SLOT(configKeys()), this);
options->insert(action);
// levels
KActionMenu *levels = new KActionMenu(i18n("&Level"), this);
menuBar()->insertItem(levels->text(), levels->popupMenu());
levelAction[0] = new KRadioAction(i18n("&Easy"), 0,
this, SLOT(easyLevel()), this);
levelAction[1] = new KRadioAction(i18n("&Normal"), 0,
this, SLOT(normalLevel()), this);
levelAction[2] = new KRadioAction(i18n("&Expert"), 0,
this, SLOT(expertLevel()), this);
levelAction[3] = new KRadioAction(i18n("&Custom..."), 0,
this, SLOT(customLevel()), this);
for (uint i=0; i<levelAction.size(); i++) {
status, SLOT(autoReveal()), this, "autoreveal");
keyAction[6]->plugAccel(kacc);
// Settings
KStdAction::preferences(status, SLOT(options()), actionCollection());
KStdAction::keyBindings(this, SLOT(configKeys()), actionCollection());
KToggleAction *markAction
= new KToggleAction(i18n("? &mark"), 0, this, SLOT(toggleUMark()),
actionCollection(), "options_?_mark");
KToggleAction *keyboardAction
= new KToggleAction(i18n("&Enable keyboard"), 0,
this, SLOT(toggleKeyboard()),
actionCollection(), "options_enable_keyboard");
// Levels
levelAction[0]
= new KRadioAction(i18n("&Easy"), 0, this, SLOT(easyLevel()),
actionCollection(), "level_easy");
levelAction[1]
= new KRadioAction(i18n("&Normal"), 0, this, SLOT(normalLevel()),
actionCollection(), "level_normal");
levelAction[2]
= new KRadioAction(i18n("&Expert"), 0, this, SLOT(expertLevel()),
actionCollection(), "level_expert");
levelAction[3]
= new KRadioAction(i18n("&Custom..."), 0, this, SLOT(customLevel()),
actionCollection(), "level_custom");
for (uint i=0; i<levelAction.size(); i++)
levelAction[i]->setExclusiveGroup("level");
levels->insert(levelAction[i]);
if ( (GameType)i==Custom-1) levels->insert(new KActionSeparator(this));
}
// help
menuBar()->insertSeparator();
KHelpMenu *help = new KHelpMenu(this, aboutData);
menuBar()->insertItem(i18n("&Help"), help->menu());
// read key settings
kacc->readSettings();
enableToolBar(KToolBar::Hide);
createGUI("ui_kmines.rc");
// init
init = TRUE;
toggleMenu();
changeLevel(0);
menuAction->setChecked( toggleMenubar() );
markAction->setChecked( toggleUMark() );
keyboardAction->setChecked( toggleKeyboard() );
init = FALSE;
......@@ -168,11 +163,11 @@ bool MainWidget::toggle(const char *name)
return res;
}
void MainWidget::toggleMenu()
bool MainWidget::toggleMenubar()
{
bool show = toggle(OP_MENUBAR);
if (show) menuBar()->show(); else menuBar()->hide();
menuAction->setText((show ? i18n("Hide menu") : i18n("Show menu")));
return show;
}
bool MainWidget::toggleUMark()
......@@ -204,7 +199,7 @@ int main(int argc, char **argv)
KCmdLineArgs::init(argc, argv, &aboutData);
KApplication a;
MainWidget *mw = new MainWidget(&aboutData);
MainWidget *mw = new MainWidget;
a.setMainWidget(mw);
mw->show();
return a.exec();
......
......@@ -12,7 +12,7 @@ class MainWidget : public KTMainWindow
Q_OBJECT
public:
MainWidget(const KAboutData *);
MainWidget();
private slots:
void easyLevel() { changeLevel(0); }
......@@ -20,7 +20,7 @@ class MainWidget : public KTMainWindow
void expertLevel() { changeLevel(2); }
void customLevel() { changeLevel(3); }
void configKeys() { KKeyDialog::configureKeys(kacc); }
void toggleMenu();
bool toggleMenubar();
bool toggleUMark();
bool toggleKeyboard();
......@@ -33,7 +33,6 @@ class MainWidget : public KTMainWindow
KActionMenu *popup;
QArray<KAction *> keyAction;
QArray<KRadioAction *> levelAction;
KAction *menuAction;
Status *status;
bool toggle(const char *name);
......
<!DOCTYPE kpartgui>
<kpartgui name="kmines">
<MenuBar>
<Menu name="game"><text>&amp;Game</text>
<Action name="game_pause"/>
<Action name="game_print"/>
</Menu>
<Menu name="settings"><text>&amp;Settings</text>
<Action name="options_?_mark"/>
<Action name="options_enable_keyboard"/>
</Menu>
<Menu name="level"><text>&amp;Level</text>
<Action name="level_easy"/>
<Action name="level_normal"/>
<Action name="level_expert"/>
<Separator/>
<Action name="level_custom"/>
</Menu>
</MenuBar>
</kpartgui>
#define VERSION "2.0.1"
#define LONG_VERSION "2.0.1 (19 Fev 2000)"
#define VERSION "2.0.2"
#define LONG_VERSION "2.0.2 (29 Fev 2000)"
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment