Commit f7de7131 authored by Simon Huerlimann's avatar Simon Huerlimann
Browse files

Some UI consistency work

 * Add main Toolbar

Some coding convention work
 * Add 'Navigation' menu für keyboard navigation actions. Mainly usefull to look up shortcuts... And it saves a call to 'addAction(action)' for those actions, as their shortcut aren't registered otherwise.
 * Add 'Navigation' toolbar for keyboard navigation actions.
 * Add tooltips to keyboard navigation actions.
 * Rename initKAction() method to setupActions(); towards best practice for all of KDE Games...
 * use 'actionCollection()->add<QAction>(name, this, SLOT(slotName()))' style action creation. This seems to be the preferred way now.
 * Added some comments

Some 'use available technologies' work
 * Use XMLGui Action states for enabling/disabling 'undo'
 * Move icon, shortcut, whatsThis and text declarations for actions into <ActionProperties> in the xxxui.rc file. Seperates Usablility and UI consistency concerns from coding. Not sure if the i18n work nice, though. 

Please report if I've broken something;-)


svn path=/trunk/KDE/kdegames/klines/; revision=667127
parent 67f4ec59
/***************************************************************************
begin : Fri May 19 2000
copyright : (C) 2000 by Roman Merzlyakov
email : roman@sbrf.barrt.ru
copyright : (C) 2000 by Roman Razilov
email : Roman.Razilov@gmx.de
copyright : (C) 2006 by Dmitry Suzdalev
email : dimsuz@gmail.com
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
/*
Copyright 2000 Roman Merzlyakov <roman@sbrf.barrt.ru>
Copyright 2000 Roman Razilov <roman@sbrf.barrt.ru>
Copyright 2006 Dimitry Suzdalev <dimsuz@gmail.com>
Copyright 2007 Simon Hürlimann <simon.huerlimann@huerlisi.ch>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "klines.h"
#include "prefs.h"
#include "mwidget.h"
......@@ -35,78 +38,53 @@
#include <kstandardaction.h>
#include <kstandardgameaction.h>
// Mainwindow Constructor
KLinesMainWindow::KLinesMainWindow()
{
mwidget = new MainWidget(this);
setCentralWidget( mwidget );
connect(mwidget->scene(), SIGNAL(scoreChanged(int)), SLOT(updateScore(int)));
connect(mwidget->scene(), SIGNAL(stateChanged(const QString &)), SLOT(slotStateChanged(const QString &)));
connect(mwidget->scene(), SIGNAL(gameOver(int)), SLOT(gameOver(int)));
statusBar()->insertItem(i18n("Score:"), 0);
updateScore(0);
initKAction();
setupActions();
stateChanged("init");
}
// Mainwindow Destructor
KLinesMainWindow::~KLinesMainWindow()
{
}
void KLinesMainWindow::initKAction()
void KLinesMainWindow::setupActions()
{
QAction *action;
// Game
KStandardGameAction::gameNew(this, SLOT(startGame()), actionCollection());
KStandardGameAction::highscores(this, SLOT(viewHighScore()), actionCollection());
KStandardGameAction::quit(this, SLOT(close()), actionCollection());
KStandardGameAction::endTurn(mwidget->scene(), SLOT(endTurn()), actionCollection());
// Move
action = KStandardGameAction::undo(mwidget->scene(), SLOT(undo()), actionCollection());
action->setEnabled(false);
connect( mwidget->scene(), SIGNAL(enableUndo(bool)), action, SLOT(setEnabled(bool)) );
KStandardGameAction::undo(mwidget->scene(), SLOT(undo()), actionCollection());
KStandardGameAction::endTurn(mwidget->scene(), SLOT(endTurn()), actionCollection());
// Preferences
KToggleAction *showNext = actionCollection()->add<KToggleAction>("show_next");
showNext->setText(i18n("&Show Next"));
showNext->setShortcut(KShortcut(Qt::CTRL+Qt::Key_P));
connect(showNext, SIGNAL(triggered(bool) ), SLOT(showNextToggled(bool)));
addAction(showNext);
showNext->setChecked(Prefs::showNext());
mwidget->setShowNextColors(Prefs::showNext());
action = actionCollection()->addAction("left");
action->setText(i18n("Move Left"));
connect(action, SIGNAL(triggered(bool) ), mwidget->scene(), SLOT(moveFocusLeft()));
action->setShortcut(Qt::Key_Left);
addAction(action);
action = actionCollection()->addAction("right");
action->setText(i18n("Move Right"));
connect(action, SIGNAL(triggered(bool) ), mwidget->scene(), SLOT(moveFocusRight()));
action->setShortcut(Qt::Key_Right);
addAction(action);
action = actionCollection()->addAction("up");
action->setText(i18n("Move Up"));
connect(action, SIGNAL(triggered(bool) ), mwidget->scene(), SLOT(moveFocusUp()));
action->setShortcut(Qt::Key_Up);
addAction(action);
action = actionCollection()->addAction("down");
action->setText(i18n("Move Down"));
connect(action, SIGNAL(triggered(bool) ), mwidget->scene(), SLOT(moveFocusDown()));
action->setShortcut(Qt::Key_Down);
addAction(action);
action = actionCollection()->addAction("select_cell");
action->setText(i18n("Move Ball"));
connect(action, SIGNAL(triggered(bool) ), mwidget->scene(), SLOT(cellSelected()));
action->setShortcut(Qt::Key_Space);
addAction(action);
// Navigation
actionCollection()->add<QAction>("navi_left", mwidget->scene(), SLOT(moveFocusLeft()));
actionCollection()->add<QAction>("navi_right", mwidget->scene(), SLOT(moveFocusRight()));
actionCollection()->add<QAction>("navi_up", mwidget->scene(), SLOT(moveFocusUp()));
actionCollection()->add<QAction>("navi_down", mwidget->scene(), SLOT(moveFocusDown()));
actionCollection()->add<QAction>("navi_select", mwidget->scene(), SLOT(cellSelected()));
setupGUI();
}
......
......@@ -32,7 +32,7 @@ public:
~KLinesMainWindow();
protected:
void initKAction();
void setupActions();
public Q_SLOTS:
void startGame();
......
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE kpartgui SYSTEM "kpartgui.dtd">
<gui name="klines" version="6">
<gui name="klines" version="7">
<MenuBar>
<Menu name="settings"><text>&amp;Settings</text>
<Menu name="settings">
<Action name="show_next" />
</Menu>
<Menu name="navigation">
<text>Navigation</text>
<Action name="navi_left" />
<Action name="navi_right" />
<Action name="navi_up" />
<Action name="navi_down" />
<Action name="navi_select" />
</Menu>
</MenuBar>
<ToolBar name="mainToolBar">
......@@ -14,4 +22,42 @@
<Action name="move_undo" />
<Action name="move_end_turn" />
</ToolBar>
<ToolBar name="navigationToolBar" hidden="true" iconText="icontextbottom">
<text>Navigation</text>
<Action name="navi_left" />
<Action name="navi_right" />
<Action name="navi_up" />
<Action name="navi_down" />
<Separator />
<Action name="navi_select" />
</ToolBar>
<State name="init">
<disable>
<Action name="move_undo" />
</disable>
</State>
<State name="not_undoable">
<disable>
<Action name="move_undo" />
</disable>
</State>
<State name="undoable">
<enable>
<Action name="move_undo" />
</enable>
</State>
<ActionProperties>
<Action name="navi_left" text="Left" toolTip="Move cursor to left" icon="arrow-left" shortcut="Left"/>
<Action name="navi_right" text="Right" toolTip="Move cursor to right" icon="arrow-right" shortcut="Right"/>
<Action name="navi_up" text="Up" toolTip="Move cursor up" icon="arrow-up" shortcut="Up"/>
<Action name="navi_down" text="Down" toolTip="Move cursor down" icon="arrow-down" shortcut="Down"/>
<Action name="navi_select" text="Select" toolTip="Select field under the cursor" icon="arrow-here" shortcut="Space"/>
<Action name="show_next" text="&amp;Show Next" shortcut="CTRL+P"/>
</ActionProperties>
</gui>
......@@ -102,7 +102,7 @@ void KLinesScene::startNewGame()
m_nextColors.append(c);
}
emit enableUndo(false);
emit stateChanged("not_undoable");
nextThreeBalls();
}
......@@ -289,7 +289,8 @@ void KLinesScene::removeAnimFinished()
{
if( m_itemsToDelete.isEmpty() && m_numFreeCells == 0 )
{
emit enableUndo(false);
emit stateChanged("not_undoable");
//emit enableUndo(false);
emit gameOver(m_score);
return;
}
......@@ -566,7 +567,7 @@ void KLinesScene::saveUndoInfo()
m_undoInfo.score = m_score;
m_undoInfo.nextColors = m_nextColors;
emit enableUndo(true);
emit stateChanged("undoable");
}
// Brings m_field and some other vars to the state it was before last turn
......@@ -615,7 +616,8 @@ void KLinesScene::undo()
m_previewItem->setPreviewColors( m_nextColors );
emit scoreChanged(m_score);
emit enableUndo(false);
emit stateChanged("not_undoable");
}
void KLinesScene::drawBackground(QPainter *p, const QRectF&)
......
......@@ -129,7 +129,7 @@ public slots:
void cellSelected();
signals:
void scoreChanged(int);
void enableUndo(bool);
void stateChanged(const QString &);
void gameOver(int);
private slots:
void moveAnimFinished();
......
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