Commit a195039f authored by Andreas Beckermann's avatar Andreas Beckermann

- KAccel->KAction

  this is a quick port. a few things could be made better/nicer.

svn path=/trunk/kdegames/ktron/; revision=156030
parent ec7746a8
......@@ -24,7 +24,6 @@
#include "ktoptdlg.h"
#include <kglobal.h>
#include <kaccel.h>
#include <klocale.h>
#include <kiconloader.h>
#include <kkeydialog.h>
......@@ -61,27 +60,24 @@ KTron::KTron(const char *name)
statusbar->insertItem("abcdefghijklmnopqrst: 0 ",ID_STATUS_BASE+1);
statusbar->insertItem("abcdefghijklmnopqrst: 0 ",ID_STATUS_BASE+2);
accel=new KAccel(this,"Key Accel");
(void)new KAction(i18n("Player 1 Up"), Key_R, 0, 0, actionCollection(), "Pl1Up");
(void)new KAction(i18n("Player 1 Down"), Key_F, 0, 0, actionCollection(), "Pl1Down");
(void)new KAction(i18n("Player 1 Right"), Key_G, 0, 0, actionCollection(), "Pl1Right");
(void)new KAction(i18n("Player 1 Left"), Key_D, 0, 0, actionCollection(), "Pl1Left");
(void)new KAction(i18n("Player 1 Accelerator"), Key_A, 0, 0, actionCollection(), "Pl1Ac");
accel->insert("Pl1Up", i18n("Player 1 Up"), 0, Key_R, 0, 0);
accel->insert("Pl1Down", i18n("Player 1 Down"), 0, Key_F, 0, 0);
accel->insert("Pl1Right", i18n("Player 1 Right"), 0, Key_G, 0, 0);
accel->insert("Pl1Left", i18n("Player 1 Left"), 0, Key_D, 0, 0);
accel->insert("Pl1Ac", i18n("Player 1 Accelerator"), 0, Key_A, 0, 0);
accel->insert("Pl2Up", i18n("Player 2 Up"), 0, Key_Up, 0, 0);
accel->insert("Pl2Down", i18n("Player 2 Down"), 0, Key_Down, 0, 0);
accel->insert("Pl2Right", i18n("Player 2 Right"), 0, Key_Right, 0, 0);
accel->insert("Pl2Left", i18n("Player 2 Left"), 0, Key_Left, 0, 0);
accel->insert("Pl2Ac", i18n("Player 2 Accelerator"), 0, Key_Plus, 0, 0);
accel->readSettings();
(void)new KAction(i18n("Player 2 Up"), Key_Up, 0, 0, actionCollection(), "Pl2Up");
(void)new KAction(i18n("Player 2 Down"), Key_Down, 0, 0, actionCollection(), "Pl2Down");
(void)new KAction(i18n("Player 2 Right"), Key_Right, 0, 0, actionCollection(), "Pl2Right");
(void)new KAction(i18n("Player 2 Left"), Key_Left, 0, 0, actionCollection(), "Pl2Left");
(void)new KAction(i18n("Player 2 Accelerator"), Key_Plus, 0, 0, actionCollection(), "Pl2Ac");
tron->setAccel(accel);
tron->setActionCollection(actionCollection());
KAction* action;
action=new KAction(i18n("&Pause/Continue"), Key_P, tron, SLOT(togglePause()),
actionCollection(), "game_pause");
action->plugAccel(accel);
KStdGameAction::gameNew( tron, SLOT( newGame() ), actionCollection() );
KStdGameAction::quit(this, SLOT( quit() ), actionCollection());
......@@ -142,16 +138,12 @@ KTron::KTron(const char *name)
action=new KAction(i18n("Color Player &1..."), 0, this, SLOT(colorPl1()),
actionCollection(), "color_player1");
action->plugAccel(accel);
action=new KAction(i18n("Color Player &2..."), 0, this, SLOT(colorPl2()),
actionCollection(), "color_player2");
action->plugAccel(accel);
action=new KAction(i18n("&Background Color..."), 0, this, SLOT(colorBackground()),
actionCollection(), "color_background");
action->plugAccel(accel);
action=new KAction(i18n("B&ackground Image..."), 0, this, SLOT(chooseBgPix()),
actionCollection(), "background_image");
action->plugAccel(accel);
......@@ -518,7 +510,7 @@ void KTron::setVelocity(int index)
void KTron::configureKeys()
{
KKeyDialog::configureKeys(accel);
KKeyDialog::configure(actionCollection(), this);
}
void KTron::toggleStatusbar()
......
......@@ -22,11 +22,11 @@
#include <qtimer.h>
#include <kdebug.h>
#include <kapplication.h>
#include <kaccel.h>
//#include <kapplication.h>
#include <klocale.h>
#include <kconfig.h>
#include <kcolordialog.h>
#include <kaction.h>
#include "tron.h"
......@@ -385,9 +385,9 @@ void Tron::drawRect(QPainter & p, int x, int y)
** config functions **
** *************************************************************** */
void Tron::setAccel(KAccel *acc)
void Tron::setActionCollection(KActionCollection *a)
{
accel=acc;
actionCollection = a;
}
void Tron::setBackgroundPix(QPixmap pix)
......@@ -751,62 +751,60 @@ void Tron::resizeEvent(QResizeEvent *)
void Tron::keyPressEvent(QKeyEvent *e)
{
int key=e->key();
KKey key(e);
if(!players[1].computer)
{
if(key==accel->shortcut("Pl2Up"))
if(actionCollection->action("Pl2Up")->shortcut().contains(key))
{
switchDir(1,::Up);
players[1].keyPressed=true;
}
else if(key==accel->shortcut("Pl2Left"))
else if(actionCollection->action("Pl2Left")->shortcut().contains(key))
{
switchDir(1,::Left);
players[1].keyPressed=true;
}
else if(key==accel->shortcut("Pl2Right"))
else if(actionCollection->action("Pl2Right")->shortcut().contains(key))
{
switchDir(1,::Right);
players[1].keyPressed=true;
}
else if(key==accel->shortcut("Pl2Down"))
else if(actionCollection->action("Pl2Down")->shortcut().contains(key))
{
switchDir(1,::Down);
players[1].keyPressed=true;
}
else if(key==accel->shortcut("Pl2Ac"))
else if(actionCollection->action("Pl2Ac")->shortcut().contains(key))
{
if(!blockAccelerator)
players[1].accelerated=true;
}
}
}
if(!players[0].computer)
{
if(key==accel->shortcut("Pl1Left"))
if(actionCollection->action("Pl1Left")->shortcut().contains(key))
{
switchDir(0,::Left);
players[0].keyPressed=true;
}
else if(key==accel->shortcut("Pl1Right"))
else if(actionCollection->action("Pl1Right")->shortcut().contains(key))
{
switchDir(0,::Right);
players[0].keyPressed=true;
}
else if(key==accel->shortcut("Pl1Up"))
else if(actionCollection->action("Pl1Up")->shortcut().contains(key))
{
switchDir(0,::Up);
players[0].keyPressed=true;
}
else if(key==accel->shortcut("Pl1Down"))
else if(actionCollection->action("Pl1Down")->shortcut().contains(key))
{
switchDir(0,::Down);
players[0].keyPressed=true;
}
else if(key==accel->shortcut("Pl1Ac"))
else if(actionCollection->action("Pl1Ac")->shortcut().contains(key))
{
if(!blockAccelerator)
players[0].accelerated=true;
......@@ -838,61 +836,60 @@ void Tron::keyPressEvent(QKeyEvent *e)
void Tron::keyReleaseEvent(QKeyEvent * e)
{
int key=e->key();
KKey key(e);
if(!players[1].computer)
{
if(key==accel->shortcut("Pl2Ac"))
{
players[1].accelerated=false;
return;
if(actionCollection->action("Pl2Ac")->shortcut().contains(key))
{
players[1].accelerated=false;
return;
}
else if(key==accel->shortcut("Pl2Left"))
else if(actionCollection->action("Pl2Left")->shortcut().contains(key))
{
players[1].keyPressed=false;
return;
players[1].keyPressed=false;
return;
}
else if(key==accel->shortcut("Pl2Right"))
else if(actionCollection->action("Pl2Right")->shortcut().contains(key))
{
players[1].keyPressed=false;
return;
}
else if(key==accel->shortcut("Pl2Up"))
else if(actionCollection->action("Pl2Up")->shortcut().contains(key))
{
players[1].keyPressed=false;
return;
}
else if(key==accel->shortcut("Pl2Down"))
else if(actionCollection->action("Pl2Down")->shortcut().contains(key))
{
players[1].keyPressed=false;
return;
}
}
if(!players[0].computer)
if(!players[0].computer)
{
if(key==accel->shortcut("Pl1Left"))
{
if(actionCollection->action("Pl1Left")->shortcut().contains(key))
{
players[0].keyPressed=false;
return;
}
else if(key==accel->shortcut("Pl1Right"))
}
else if(actionCollection->action("Pl1Right")->shortcut().contains(key))
{
players[0].keyPressed=false;
return;
}
else if(key==accel->shortcut("Pl1Up"))
else if(actionCollection->action("Pl1Up")->shortcut().contains(key))
{
players[0].keyPressed=false;
return;
}
else if(key==accel->shortcut("Pl1Down"))
else if(actionCollection->action("Pl1Down")->shortcut().contains(key))
{
players[0].keyPressed=false;
return;
}
else if(key==accel->shortcut("Pl1Ac"))
else if(actionCollection->action("Pl1Ac")->shortcut().contains(key))
{
players[0].accelerated=false;
return;
......
......@@ -34,8 +34,8 @@
#include <math.h>
#include <krandomsequence.h>
class KAccel;
class KConfig;
class KActionCollection;
#include "player.h"
......@@ -56,7 +56,7 @@ class Tron : public QWidget
public:
Tron(QWidget *parent=0, const char *name=0);
~Tron();
void setAccel(KAccel *);
void setActionCollection(KActionCollection*);
void updatePixmap();
void setBackgroundPix(QPixmap);
bool changeColor(int player);
......@@ -109,7 +109,7 @@ protected:
private:
/** Stores key shortcuts */
KAccel* accel;
KActionCollection* actionCollection;
/** Drawing buffer */
QPixmap *pixmap;
/** The playingfield */
......
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