Source Code (Use browser search to find items of interest.)
Class Index
kmines'MainWidget (./kdegames/kmines/main.h:11)
class MainWidget : public KTMainWindow
{
Q_OBJECT
public:
MainWidget();
private slots:
void easyLevel() { changeLevel(0); }
void normalLevel() { changeLevel(1); }
void expertLevel() { changeLevel(2); }
void customLevel() { changeLevel(3); }
void toggleMenubar();
void configureKeys();
void setKeyboardEnabled(bool);
void gameStateChanged(GameState);
protected:
bool eventFilter(QObject *, QEvent *);
private:
QArray<KRadioAction *> levelAction;
Status *status;
void readSettings();
void changeLevel(uint i);
};
kmines'MainWidget::MainWidget() (./kdegames/kmines/main.cpp:21)
MainWidget::MainWidget()
: levelAction(NbLevels)
{
installEventFilter(this);
status = new Status(this);
status->installEventFilter(this);
connect(status, SIGNAL(keyboardEnabled(bool)),
SLOT(setKeyboardEnabled(bool)));
connect(status, SIGNAL(gameStateChanged(GameState)),
SLOT(gameStateChanged(GameState)));
// File & Popup
KStdAction::openNew(status, SLOT(restartGame()),
actionCollection(), "game_new");
(void)new KAction(i18n("Pause"), Key_P, status, SLOT(pauseGame()),
actionCollection(), "game_pause");
(void)new KAction(i18n("High Scores..."), Key_H,
status, SLOT(showHighScores()),
actionCollection(), "game_highscores");
KStdAction::print(status, SLOT(print()), actionCollection(), "game_print");
KStdAction::quit(qApp, SLOT(quit()), actionCollection(), "game_quit");
// keyboard
QArray<KAction *> keyAction(7);
keyAction[0] = new KAction(i18n("Move up"), Key_Up,
status, SLOT(moveUp()),
actionCollection(), "keyboard_moveup");
keyAction[1] = new KAction(i18n("Move down"), Key_Down,
status, SLOT(moveDown()),
actionCollection(), "keyboard_movedown");
keyAction[2] = new KAction(i18n("Move left"), Key_Left,
status, SLOT(moveLeft()),
actionCollection(), "keyboard_moveleft");
keyAction[3] = new KAction(i18n("Move right"), Key_Right,
status, SLOT(moveRight()),
actionCollection(), "keyboard_moveright");
keyAction[4] = new KAction(i18n("Reveal mine"), Key_Shift,
status, SLOT(reveal()),
actionCollection(), "keyboard_revealmine");
keyAction[5] = new KAction(i18n("Mark mine"), Key_Space,
status, SLOT(mark()),
actionCollection(), "keyboard_markmine");
keyAction[6] = new KAction(i18n("Automatic reveal"), Key_Control,
status, SLOT(autoReveal()),
actionCollection(), "keyboard_autoreveal");
KAccel *kacc = new KAccel(this);
for (uint i=0; i<keyAction.size(); i++) {
keyAction[i]->setGroup("keyboard_group");
keyAction[i]->plugAccel(kacc);
}
// Settings
KStdAction::showMenubar(this, SLOT(toggleMenubar()), actionCollection());
KStdAction::preferences(status, SLOT(preferences()), actionCollection());
KStdAction::keyBindings(this, SLOT(configureKeys()), actionCollection());
// 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");
createGUI();
readSettings();
setView(status);
updateRects(); // #### should be in KTMainWindow::setView
}
kmines'MainWidget::readSettings() (./kdegames/kmines/main.cpp:107)
void MainWidget::readSettings()
{
GameType type = OptionDialog::readLevel();
levelAction[type]->setChecked(TRUE);
status->newGame(type);
bool visible = OptionDialog::readMenuVisible();
MENUBAR_ACTION->setChecked(visible);
toggleMenubar();
setKeyboardEnabled( OptionDialog::readKeyboard() );
}
kmines'MainWidget::changeLevel() (./kdegames/kmines/main.cpp:120)
void MainWidget::changeLevel(uint i)
{
if ( !levelAction[i]->isChecked() ) return;
GameType lev = (GameType)i;
if ( !status->newGame(lev) ) { // level unchanged
levelAction[lev]->setChecked(TRUE);
return;
}
OptionDialog::writeLevel(lev);
}
kmines'MainWidget::eventFilter() (./kdegames/kmines/main.cpp:132)
bool MainWidget::eventFilter(QObject *, QEvent *e)
{
QPopupMenu *popup;
switch (e->type()) {
case QEvent::MouseButtonPress :
if ( ((QMouseEvent *)e)->button()!=RightButton ) return FALSE;
popup = (QPopupMenu*)factory()->container("popup", this);
popup->popup(QCursor::pos());
return TRUE;
default : return FALSE;
}
}
kmines'MainWidget::toggleMenubar() (./kdegames/kmines/main.cpp:145)
void MainWidget::toggleMenubar()
{
bool b = MENUBAR_ACTION->isChecked();
if (b) menuBar()->show();
else {
menuBar()->hide();
// #### sort of hack : because KTMainWindow does not manage correctly
// main widget with a fixed layout
updateRects();
adjustSize();
}
OptionDialog::writeMenuVisible(b);
}
kmines'MainWidget::setKeyboardEnabled() (./kdegames/kmines/main.cpp:161)
void MainWidget::setKeyboardEnabled(bool enable)
{
QValueList<KAction *> list = actionCollection()->actions("keyboard_group");
QValueList<KAction *>::Iterator it;
for (it = list.begin(); it!=list.end(); ++it)
(*it)->setEnabled(enable);
}
kmines'MainWidget::configureKeys() (./kdegames/kmines/main.cpp:169)
void MainWidget::configureKeys()
{
KKeyDialog::configureKeys(actionCollection(), xmlFile());
}
kmines'MainWidget::gameStateChanged() (./kdegames/kmines/main.cpp:174)
void MainWidget::gameStateChanged(GameState s)
{
switch (s) {
case Stopped:
PAUSE_ACTION->setEnabled(FALSE);
break;
case Paused:
PAUSE_ACTION->setText(i18n("&Resume"));
break;
case Playing:
PAUSE_ACTION->setText(i18n("&Pause"));
PAUSE_ACTION->setEnabled(TRUE);
break;
case GameOver:
PAUSE_ACTION->setEnabled(FALSE);
break;
}
}
//----------------------------------------------------------------------------