List Info

Thread: KDE4 and QGraphicsView port of KGoldrunner




KDE4 and QGraphicsView port of KGoldrunner
user name
2006-08-08 22:28:06
Hi. I contacted Ian Wadham and Dmitry Suzdalev last week via
email, and
started working on a port of kgoldrunner to use the new
QGraphicsView API,
dropping QtCanvas and all of the Q3 support classes as well.
I have some
experience with software development (around 8 years or so)
and I am using
Qt commercial for the past 3 or 4 years. I also released a
couple of tools
in sourceforge, but this is my first involvement with the
KDE project.

And btw, I got the Developing Open Source Games book in the
last GDC as
well 

Attached is the first patch that implements the migrations
described
above. I got a SVN account, so I can commit it if you guys
find it easier
to build/test a working copy from SVN. When commiting I can
try to split
it into smaller commits as well, but some changes in the
QCanvas classes
are extense, so it makes sense to commit all at once.

I am also attaching two additional classes and header files
that need to
be added. They implement (more or less in an abstract way)
the classes
required to emulate QCanvasSprite and QCanvas behavior in
the new
QGraphicsView API.

The good part is that gameplay is apparently unaltered. The
original code
had already separated the display structures from game
logic, so the only
changes in game related files are the ports required to
escape Q3 support
(Q3Frame, Q3PtrList, for example.)

The not-so-good part is that there is still some work to be
done. The
patch has //TODO itens that need to be investigated, and
there are also
layout issues to be corrected. But the basic work (maybe
80%) is done, and
after this is commited to SVN I can go ahead and start
tackling these one
by one. Some are probably kdelib or qt4-preview bugs, or
differences in
the current behavior that need to be adjusted.

I should also add that there are two major areas that are
still
non-operational due to the issues discussed above: keyboard
play (just a
matter of wiring up these correctly for the new
architecture, looks like a
KAction issue) and a problem with saving files.

I will wait a couple of days for a review (feel free to
email me directly
if you want as well), and will commit by the end of the week
to continue
this work if no one objects.

Best regards,
Mauricio PiacentiniIndex: src/kgrdialog.cpp
============================================================
=======
--- src/kgrdialog.cpp	(revision 571247)
+++ src/kgrdialog.cpp	(working copy)
 -1,5
+1,5 
 /**********************************************************
*****************
-    Copyright 2003 Marco Krüger
+    Copyright 2003 Marco Krger
     Copyright 2003 Ian Wadham <ianwnetspace.net.au>
  *                                                         
               *
  *   This program is free software; you can redistribute it
and/or modify  *
 -20,11
+20,9 
 
 #ifndef KGR_PORTABLE
 #include <kglobalsettings.h>
-//Added by qt3to4:
 #include <QTextStream>
 #include <QGridLayout>
-#include <Q3PtrList>
-#include <Q3Frame>
+#include <QFrame>
 #include <QLabel>
 #include <QVBoxLayout>
 #endif
 -35,13
+33,13 
 
 #ifdef KGR_PORTABLE
 KGrSLDialog::KGrSLDialog (int action, int requestedLevel,
int collnIndex,
-			Q3PtrList<KGrCollection> & gamesList, KGrGame
* theGame,
+			QList<KGrCollection *> & gamesList, KGrGame *
theGame,
 			QWidget * parent, const char * name)
 		: QDialog (parent, name, true,
 			Qt::WStyle_Customize | Qt::WStyle_NormalBorder |
Qt::WStyle_Title)
 #else
 KGrSLDialog::KGrSLDialog (int action, int requestedLevel,
int collnIndex,
-			Q3PtrList<KGrCollection> & gamesList, KGrGame
* theGame,
+			QList<KGrCollection *> & gamesList, KGrGame *
theGame,
 			QWidget * parent, const char * name)
 		: KDialog (parent)
 #endif
 -75,7
+73,7 
 
     collnL    = new QLabel (i18n("List of
games:"), dad);
     mainLayout->addWidget (collnL);
-    colln     = new Q3ListBox (dad);
+    colln     = new QListWidget (dad);
     mainLayout->addWidget (colln);
 
     QWidget * gameInfo = new QWidget(dad);
 -92,8
+90,8 
     collnD    = new QLabel ("", dad);		//
Description of collection.
     mainLayout->addWidget (collnD);
 
-    Q3Frame * separator = new Q3Frame (dad);
-    separator->setFrameStyle (Q3Frame::HLine +
Q3Frame::Sunken);
+    QFrame * separator = new QFrame (dad);
+    separator->setFrameStyle (QFrame::HLine +
QFrame::Sunken);
     mainLayout->addWidget (separator);
 
     if ((action == SL_START) || (action == SL_UPD_GAME)) {
 -228,12
+226,12 
     }
 
     // Paint a thumbnail sketch of the level.
-    thumbNail->setFrameStyle (Q3Frame::Box |
Q3Frame::Plain);
+    thumbNail->setFrameStyle (QFrame::Box |
QFrame::Plain);
     thumbNail->setLineWidth (1);
     slPaintLevel();
     thumbNail->show();
 
-    connect (colln,   SIGNAL (highlighted (int)), this,
SLOT (slColln (int)));
+    connect (colln,   SIGNAL (itemClicked (QListWidgetItem
*)), this, SLOT (slColln (QListWidgetItem *)));
     connect (collnA,  SIGNAL (clicked ()), this, SLOT
(slAboutColln ()));
 
     connect (display, SIGNAL (textChanged (const QString
&)),
 -251,7
+249,7 
 	levelNH->hide();
     }
 
-    connect (colln,   SIGNAL (highlighted (int)), this,
SLOT (slPaintLevel ()));
+    connect (colln,   SIGNAL (itemClicked (QListWidgetItem
*)), this, SLOT (slPaintLevel ()));
     connect (number,  SIGNAL (sliderReleased()), this, SLOT
(slPaintLevel()));
 #warning "kde4: this signal doesn't exist";
 #if 0    
 -287,7
+285,7 
     slCollnIndex = -1;
 
     for (i = 0; i < imax; i++) {
-	colln->insertItem (collections.at(i)->name, -1);
+	colln->addItem(collections.at(i)->name);
 	if (slCollnIndex < 0) {
 	    slCollnIndex = i;		// There is at least one
collection.
 	}
 -297,26
+295,28 
 	return;				// There are no collections (unlikely).
     }
     // Mark the currently selected collection (or default
0).
-    colln->setCurrentItem (cIndex);
-    colln->setSelected (cIndex, true);
+    colln->setCurrentRow(cIndex);
+    colln->setItemSelected ( colln->item (cIndex),
true );
 
     // Fetch and display information on the selected
collection.
-    slColln (cIndex);
+    slColln ( colln->item (cIndex) );
 }
 
 /**********************************************************
********************/
 /*****************    SLOTS USED BY LEVEL SELECTION DIALOG 
  *****************/
 /**********************************************************
********************/
 
-void KGrSLDialog::slColln (int i)
+void KGrSLDialog::slColln (QListWidgetItem * item)
 {
+
     if (slCollnIndex < 0) {
 	// Ignore the "highlighted" signal caused by
inserting in an empty box.
 	return;
     }
-
+    int i = colln->row ( item );
     // User "highlighted" a new collection
(with one click) ...
-    colln->setSelected (i, true);			// One click =
selected.
+    colln->setItemSelected ( item, true );  // One click
= selected
+
     slCollnIndex = i;
     int n = slCollnIndex;				// Collection selected.
     int N = defaultGame;				// Current collection.
 -545,12
+545,8 
     mainLayout->addWidget (mleL);
 
    // Set up a widget to hold the wrapped text, using \n
for paragraph breaks.
-#ifdef QT3
-			mle = new Q3TextEdit (dad);
+			mle = new QTextEdit (dad);
     mle->		setTextFormat (Qt::PlainText);
-#else
-			mle = new Q3MultiLineEdit (dad);
-#endif
     mainLayout->addWidget (mle);
 
 #ifdef KGR_PORTABLE
 -574,10
+570,6 
 
     // Configure the text box.
     mle->		setAlignment (Qt::AlignLeft);
-#ifndef QT3
-    mle->		setWordWrap (Q3MultiLineEdit::WidgetWidth);
-    mle->		setFixedVisibleLines (9);
-#endif
 
     nhName->		setText (levelName);
     mle->		setText (levelHint);
 -601,13
+593,13 
 
 #ifdef KGR_PORTABLE
 KGrECDialog::KGrECDialog (int action, int collnIndex,
-			Q3PtrList<KGrCollection> & gamesList,
+			QList<KGrCollection *> & gamesList,
 			QWidget * parent, const char * name)
 		: QDialog (parent, name, true,
 			Qt::WStyle_Customize | Qt::WStyle_NormalBorder |
Qt::WStyle_Title)
 #else
 KGrECDialog::KGrECDialog (int action, int collnIndex,
-			Q3PtrList<KGrCollection> & gamesList,
+			QList<KGrCollection *> & gamesList,
 			QWidget * parent, const char * name)
 		: KDialog(parent)
 #endif
 -633,6
+625,7 
     mainLayout->setSpacing(spacing);
     mainLayout->setMargin(margin);
 
+    //TODO need to fix this layout
     QWidget * nameBox = new QWidget(dad);
     QHBoxLayout *hboxLayout5 = new QHBoxLayout(nameBox);
     nameBox->setLayout(hboxLayout5);
 -641,6
+634,7 
     nameL    = new QLabel (i18n("Name of
game:"), nameBox);
     ecName   = new QLineEdit (nameBox);
 
+    //TODO need to fix this layout
     QWidget * prefixBox = new QWidget(dad);
     QHBoxLayout *hboxLayout6 = new QHBoxLayout(prefixBox);
     prefixBox->setLayout(hboxLayout6);
 -649,11
+643,18 
     prefixL  = new QLabel (i18n("File name
prefix:"), prefixBox);
     ecPrefix = new QLineEdit (prefixBox);
 
-    ecGrp    = new Q3ButtonGroup (1, Qt::Horizontal, 0,
dad);
-    mainLayout->addWidget (ecGrp);
-    ecTradB  = new QRadioButton (i18n("Traditional
rules"), ecGrp);
-    ecKGrB   = new QRadioButton (i18n("KGoldrunner
rules"), ecGrp);
+    //In Qt4, QButtonGroup is no longer a widget...
+    ecGrp    = new QButtonGroup (dad);
+    ecTradB  = new QRadioButton (i18n("Traditional
rules"), dad); //last parameter was ecGrp
+    ecKGrB   = new QRadioButton (i18n("KGoldrunner
rules"), dad); //last parameter was ecGrp
+    ecGrp->addButton(ecTradB);
+    ecGrp->addButton(ecKGrB);
 
+    //..so we need to add the radio buttons directly to the
layout
+    mainLayout->addWidget (ecTradB);
+    mainLayout->addWidget (ecKGrB);
+
+
     nLevL    = new QLabel (i18n( "0 levels" ),
dad);
     mainLayout->addWidget (nLevL);
 
 -661,12
+662,8 
     mainLayout->addWidget (mleL);
 
    // Set up a widget to hold the wrapped text, using \n
for paragraph breaks.
-#ifdef QT3
-    mle	     = new Q3TextEdit (dad);
+    mle	     = new QTextEdit (dad);
     mle->    setTextFormat (Qt::PlainText);
-#else
-    mle      = new Q3MultiLineEdit (dad);
-#endif
     mainLayout->addWidget (mle);
 
 #ifdef KGR_PORTABLE
 -734,10
+731,6 
 
     // Configure the edit box.
     mle->		setAlignment (Qt::AlignLeft);
-#ifndef QT3
-    mle->		setWordWrap (Q3MultiLineEdit::WidgetWidth);
-    mle->		setFixedVisibleLines (8);
-#endif
 
     if ((action == SL_UPD_GAME) &&
 	(collections.at(defaultGame)->about.length() > 0)) {
 -788,13
+781,13 
 
 #ifdef KGR_PORTABLE
 KGrLGDialog::KGrLGDialog (QFile * savedGames,
-			Q3PtrList<KGrCollection> & collections,
+			QList<KGrCollection *> & collections,
 			QWidget * parent, const char * name)
 		: QDialog (parent, name, true,
 			Qt::WStyle_Customize | Qt::WStyle_NormalBorder |
Qt::WStyle_Title)
 #else
 KGrLGDialog::KGrLGDialog (QFile * savedGames,
-			Q3PtrList<KGrCollection> & collections,
+			QList<KGrCollection *> & collections,
 			QWidget * parent, const char * name)
 		: KDialog (parent)
 #endif
 -821,7
+814,7 
 			i18n("Game                       Level/Lives/Score
  "
 			"Day    Date     Time  "), dad);
 
-			lgList   = new Q3ListBox (dad);
+    lgList   = new QListWidget (dad);
 #ifdef KGR_PORTABLE
     QFont		f ("courier", 12);
 #else
 -878,25
+871,25 
 		break;
 	    }
 	}
-	lgList-> insertItem (s);
+	lgList-> addItem (s);
     }
     savedGames->close();
 
     // Mark row 0 (the most recently saved game) as the
default selection.
     lgList->	setCurrentItem (0);
-    lgList->	setSelected (0, true);
+    lgList->	setItemSelected  (lgList->currentItem(),
true);
 		lgHighlight = 0;
 
-    connect (lgList, SIGNAL (highlighted (int)), this, SLOT
(lgSelect (int)));
+    connect (lgList, SIGNAL ( itemClicked ( QListWidgetItem
* )), this, SLOT (lgSelect (QListWidgetItem *)));
 #ifdef KGR_PORTABLE
     connect (OK,     SIGNAL (clicked ()),        this, SLOT
(accept ()));
     connect (CANCEL, SIGNAL (clicked ()),        this, SLOT
(reject ()));
 #endif
 }
 
-void KGrLGDialog::lgSelect (int n)
+void KGrLGDialog::lgSelect (QListWidgetItem * item)
 {
-    lgHighlight = n;
+    lgHighlight = lgList->row(item);
 }
 
 /**********************************************************
*********************
 -967,20
+960,12 
 
     // Make text background grey not white (i.e. same as
widget background).
     QPalette		pl = mm->palette();
-#ifdef QT3
     pl.setColor (QPalette::Base,
mm->paletteBackgroundColor());
-#else
-    pl.setColor (QPalette::Base, mm->backgroundColor());
-#endif
     mm->		setPalette (pl);
 
    // Set up a widget to hold the wrapped text, using \n
for paragraph breaks.
-#ifdef QT3
-    Q3TextEdit *		mle = new Q3TextEdit (mm);
+    QTextEdit *		mle = new QTextEdit (mm);
     mle->		setTextFormat (Qt::PlainText);
-#else
-    Q3MultiLineEdit *	mle = new Q3MultiLineEdit (mm);
-#endif
     mainLayout->addWidget (mle);
 
     // Button is for Qt-only portability.  NOT COMPILED in
KDE environment.
 -996,19
+981,11 
     mle->		setMinimumSize ((FIELDWIDTH*c/2),
(FIELDHEIGHT/2)*c);
     OK->		setMaximumWidth (3*c);
 
-    mle->		setFrameStyle (Q3Frame::NoFrame);
+    mle->		setFrameStyle (QFrame::NoFrame);
     mle->		setAlignment (Qt::AlignLeft);
     mle->		setReadOnly (true);
     mle->		setText (contents);
 
-#ifndef QT3
-    mle->		setWordWrap (Q3MultiLineEdit::WidgetWidth);
-    mle->		setFixedVisibleLines (10);
-    if (mle->		numLines() < 10) {
-	mle->		setFixedVisibleLines (mle->numLines());
-    }
-#endif
-
     OK->		setAccel (Qt::Key_Return);
     connect (OK, SIGNAL (clicked ()), mm, SLOT (accept
()));
 
Index: src/kgrdialog.h
============================================================
=======
--- src/kgrdialog.h	(revision 571247)
+++ src/kgrdialog.h	(working copy)
 -27,22
+27,15 
 
 #include <QLayout>
 
-#include <q3listbox.h>
-#include <qscrollbar.h>
+#include <QListWidget>
+#include <QScrollBar>
 #include <QLineEdit>
-#include <q3hbox.h>
 #include <QPushButton>
-#include <q3buttongroup.h>
-#include <qradiobutton.h>
-#ifdef QT3
-#include <q3textedit.h>
-#else
-#include <q3multilineedit.h>
-#endif
-
-#include <q3ptrlist.h>
-//Added by qt3to4:
+#include <QButtonGroup>
+#include <QRadioButton>
+#include <QList>
 #include <QLabel>
+#include <QTextEdit>
 
 /**
 author Ian Wadham and Marco Krüger
 -62,7
+55,7 
 Q_OBJECT
 public:
     KGrSLDialog (int action, int requestedLevel, int
collnIndex,
-			Q3PtrList<KGrCollection> & gamesList, KGrGame
* theGame,
+			QList<KGrCollection *> & gamesList, KGrGame *
theGame,
 			QWidget * parent = 0, const char *name = 0);
     ~KGrSLDialog();
 
 -71,7
+64,8 
 
 private slots:
     void slSetCollections (int cIndex);
-    void slColln (int i);
+    //void slColln (int i);
+    void slColln (QListWidgetItem *);
     void slAboutColln ();
     void slShowLevel (int i);
     void slUpdate (const QString & text);
 -80,7
+74,7 
 
 private:
     int			slAction;
-    Q3PtrList<KGrCollection> collections;	// List of
games.
+    QList<KGrCollection *> collections;	// List of
games.
     int			defaultLevel;
     int			defaultGame;
     int			slCollnIndex;
 -89,7
+83,7 
     QWidget *		slParent;
 
     QLabel *		collnL;
-    Q3ListBox *		colln;
+    QListWidget *	colln;
     QLabel *		collnN;
     QLabel *		collnD;
     QPushButton *	collnA;
 -121,15
+115,11 
     ~KGrNHDialog();
 
     QString	getName()	{return (nhName->text());}
-    QString	getHint()	{return (mle->text());}
+    QString	getHint()	{return (mle->toPlainText ());}
 
 private:
     QLineEdit *	nhName;
-#ifdef QT3
-    Q3TextEdit *	mle;
-#else
-    Q3MultiLineEdit * mle;
-#endif
+    QTextEdit *	mle;
 };
 
 /**********************************************************
*********************
 -141,14
+131,14 
 Q_OBJECT
 public:
     KGrECDialog (int action, int collnIndex,
-			Q3PtrList<KGrCollection> & gamesList,
+			QList<KGrCollection *> & gamesList,
 			QWidget *parent = 0, const char *name = 0);
     ~KGrECDialog();
 
     QString	getName()	{return (ecName->text());}
     QString	getPrefix()	{return (ecPrefix->text());}
     bool	isTrad()	{return (ecTradB->isChecked());}
-    QString	getAboutText()	{return (mle->text());}
+    QString	getAboutText()	{return
(mle->toPlainText());}
 
 private slots:
     void ecSetRules (const char settings);
 -156,24
+146,20 
     void ecSetTrad();
 
 private:
-    Q3PtrList<KGrCollection> collections;	// List of
existing games.
+    QList<KGrCollection *> collections;	// List of
existing games.
     int			defaultGame;
 
     QLabel *		nameL;
     QLineEdit *		ecName;
     QLabel *		prefixL;
     QLineEdit *		ecPrefix;
-    Q3ButtonGroup *	ecGrp;
+    QButtonGroup *	ecGrp;
     QRadioButton *	ecKGrB;
     QRadioButton *	ecTradB;
     QLabel *		nLevL;
 
     QLabel *		mleL;
-#ifdef QT3
-    Q3TextEdit *		mle;
-#else
-    Q3MultiLineEdit *	mle;
-#endif
+    QTextEdit *		mle;
 
 #ifdef KGR_PORTABLE
     QPushButton *	OK;
 -192,15
+178,15 
 {
 Q_OBJECT
 public:
-    KGrLGDialog (QFile * savedGames,
Q3PtrList<KGrCollection> & collections,
+    KGrLGDialog (QFile * savedGames, QList<KGrCollection
*> & collections,
 			QWidget * parent, const char * name);
-    QString getCurrentText() {return
(lgList->currentText());}
+    QString getCurrentText() {return
(lgList->currentItem()->text());}
 
 private slots:
-    void lgSelect (int n);
+    void lgSelect (QListWidgetItem * item);
 
 private:
-    Q3ListBox * lgList;
+    QListWidget * lgList;
     int lgHighlight;
 };
 
Index: src/kgrobject.cpp
============================================================
=======
--- src/kgrobject.cpp	(revision 571247)
+++ src/kgrobject.cpp	(working copy)
 -2,7
+2,7 
                         kgrobject.cpp  -  description
                              -------------------
     begin                : Wed Jan 23 2002
-    Copyright 2002 Marco Krüger
+    Copyright 2002 Marco Krger
     Copyright 2002 Ian Wadham <ianwnetspace.net.au>
 
************************************************************
***************/
 
 -115,7
+115,7 
   hole_counter = HOLETIME;
   iamA = HOLE;
   objectView->paintCell (xpos, ypos, BRICK,
dig_counter);
-  objectView->updateCanvas();
+  //objectView->updateCanvas();
   timer->setSingleShot(true);
   timer->start ((DIGDELAY * NSPEED) / speed);
 }
 -161,7
+161,7 
 
     // Brick pix:- 0 normal, 1-4 crumbling, 5 hole
complete, 6-9 re-growing.
     objectView->paintCell (xpos, ypos, BRICK,
dig_counter);
-    objectView->updateCanvas();
+    //objectView->updateCanvas();
 }
 
 void KGrBrick::useHole() {
Index: src/kgrgame.cpp
============================================================
=======
--- src/kgrgame.cpp	(revision 571247)
+++ src/kgrgame.cpp	(working copy)
 -1,5
+1,5 
 /**********************************************************
*****************
-    Copyright 2003 Marco Krüger
+    Copyright 2003 Marco Krger
     Copyright 2003 Ian Wadham <ianwnetspace.net.au>
  *                                                         
               *
  *   This program is free software; you can redistribute it
and/or modify  *
 -31,10
+31,8 
 
 #ifndef KGR_PORTABLE
 #include <kglobalsettings.h>
-//Added by qt3to4:
 #include <QByteArray>
 #include <QTextStream>
-#include <Q3Frame>
 #include <QLabel>
 #include <QVBoxLayout>
 #include <QDate>
 -56,8
+54,6 
     editObj  = BRICK;
     shouldSave = false;
 
-    enemies.setAutoDelete(true);
-
     hero = new KGrHero (view, 0, 0);	// The hero is born
... Yay !!!
     hero->setPlayfield (&playfield);
 
 -88,6
+84,10 
 
 KGrGame::~KGrGame()
 {
+   //release collections
+   while (!collections.isEmpty())
+	        delete collections.takeFirst();
+
 }
 
 /**********************************************************
********************/
 -155,7
+155,10 
 	checkHighScore();	// Check if there is a high score for
this game.
 
 	enemyCount = 0;
-	enemies.clear();	// Stop the enemies catching the hero
again ...
+	//todo enemies.clear();	// Stop the enemies catching the
hero again ...
+	while (!enemies.isEmpty())
+	        delete enemies.takeFirst();
+
 	view->deleteEnemySprites();
 	unfreeze();		//    ... NOW we can unfreeze.
 	newLevel = true;
 -183,10
+186,10 
     for (j=1;j<29;j++)
       if (playfield[j][i]->whatIam()==HLADDER)
 	((KGrHladder *)playfield[j][i])->showLadder();
-  view->updateCanvas();
+  //view->updateCanvas();
   initSearchMatrix();
 }
-
+// 
 void KGrGame::goUpOneLevel()
 {
     lives++;			// Level completed: gain another life.
 -210,7
+213,10 
     }
 
     enemyCount = 0;
-    enemies.clear();
+    //enemies.clear();
+    while (!enemies.isEmpty())
+        delete enemies.takeFirst();
+
     view->deleteEnemySprites();
     newLevel = true;
     loadLevel (level);
 -353,7
+359,11 
     emit showLevel (level);
 
     enemyCount = 0;
-    enemies.clear();
+
+    //enemies.clear();
+    while (!enemies.isEmpty())
+        delete enemies.takeFirst();
+
     view->deleteEnemySprites();
 
     newLevel = true;;
 -469,8
+479,11 
 
   if (newLevel) {
       hero->setEnemyList (&enemies);
-      for (enemy=enemies.first();enemy != 0; enemy =
enemies.next())
-	enemy->setEnemyList(&enemies);
+	QListIterator<KGrEnemy *> i(enemies);
+        while (i.hasNext()){
+		KGrEnemy * enemy = i.next();
+		enemy->setEnemyList(&enemies);
+	}
   }
 
   hero->setbananas(bananas);
 -481,7
+494,7 
 
   // Re-draw the playfield frame, level title and figures.
   view->setTitle (getTitle());
-  view->updateCanvas();
+  //view->updateCanvas();
 
   // Check if this is a tutorial collection and we are not
on the "ENDE" screen.
   if ((collection->prefix.left(4) == "tute")
&& (levelNo != 0)) {
 -719,7
+732,7 
 	// Editing - check if we are in paint mode and have moved
the mouse.
 	if (paintEditObj && ((i != oldI) || (j != oldJ)))
{
 	    insertEditObj (i, j);
-	    view->updateCanvas();
+	    //view->updateCanvas();
 	    oldI = i;
 	    oldJ = j;
 	}
 -791,11
+804,7 
     QTime now =   QTime::currentTime();
     QString saved;
     QString day;
-#ifdef QT3
     day = today.shortDayName(today.dayOfWeek());
-#else
-    day = today.dayName(today.dayOfWeek());
-#endif
     saved = saved.sprintf
 		("%-6s %03d %03ld %7ld    %s %04d-%02d-%02d
%02d:%02d\n",
 		collection->prefix.myStr(), level, lives, startScore,
 -834,6
+843,7 
 
     file2.close();
 
+    //TODO This is not working, savegame.tmp is created but
the rename fails
     QDir dir;
     dir.rename (file2.fileName(), file1.fileName());
     KGrMessage::information (view, i18n("Save
Game"),
 -1048,11
+1058,7 
 
     QDate today = QDate::currentDate();
     QString hsDate;
-#ifdef QT3
     QString day = today.shortDayName(today.dayOfWeek());
-#else
-    QString day = today.dayName(today.dayOfWeek());
-#endif
     hsDate = hsDate.sprintf
 		("%s %04d-%02d-%02d",
 		day.myStr(),
 -1229,8
+1235,8 
 	n++;
     }
 
-    Q3Frame * separator = new Q3Frame (hs);
-    separator->setFrameStyle (Q3Frame::HLine +
Q3Frame::Sunken);
+    QFrame * separator = new QFrame (hs);
+    separator->setFrameStyle (QFrame::HLine +
QFrame::Sunken);
     mainLayout->addWidget (separator);
 
     OK->		setMaximumWidth (100);
 -1295,8
+1301,10 
 {
     if (KGrObject::frozen) {
 	hero->showState('p');
-	for (enemy=enemies.first();enemy != 0; enemy =
enemies.next()) {
-	    enemy->showState('p');
+	QListIterator<KGrEnemy *> i(enemies);
+        while (i.hasNext()){
+		KGrEnemy * enemy = i.next();
+		enemy->showState('p');
 	}
     }
 }
 -1311,8
+1319,10 
 void KGrGame::showEnemyState(int enemyId)
 {
     if (KGrObject::frozen) {
-	for (enemy=enemies.first();enemy != 0; enemy =
enemies.next()) {
-	    if (enemy->enemyId == enemyId)
enemy->showState('s');
+	QListIterator<KGrEnemy *> i(enemies);
+        while (i.hasNext()){
+		KGrEnemy * enemy = i.next();
+		if (enemy->enemyId == enemyId)
enemy->showState('s');
 	}
     }
 }
 -1411,7
+1421,7 
     // Re-enable player input.
     loading = false;
 
-    view->updateCanvas();				// Show the edit area.
+    //view->updateCanvas();				// Show the edit area.
     view->update();					// Show the level name.
 }
 
 -1511,7
+1521,7 
     levelFile.close ();
 
     view->setTitle (getTitle());		// Show the level
name.
-    view->updateCanvas();			// Show the edit area.
+    //view->updateCanvas();			// Show the edit area.
     showEditLevel();				// Reconnect signals.
 
     // Re-enable player input.
 -1649,7
+1659,7 
     level = selectedLevel;
     emit showLevel (level);
     view->setTitle (getTitle());		// Display new title.
-    view->updateCanvas();			// Show the edit area.
+    //view->updateCanvas();			// Show the edit area.
     return (true);
 }
 
 -1746,7
+1756,7 
     level = toL;
     collection = collections.at(toC);
     view->setTitle (getTitle());	// Re-write title.
-    view->updateCanvas();		// Re-display details of
level.
+    //view->updateCanvas();		// Re-display details of
level.
     emit showLevel (level);
 }
 
 -1815,7
+1825,10 
     }
     else if (level > 0) {
 	enemyCount = 0;				// Load level in play mode.
-	enemies.clear();
+	//enemies.clear();
+	while (!enemies.isEmpty())
+        	delete enemies.takeFirst();
+
 	view->deleteEnemySprites();
 	newLevel = true;;
 	loadLevel (level);
 -1984,7
+1997,10 
     oldJ = 0;
     heroCount = 0;
     enemyCount = 0;
-    enemies.clear();
+    //enemies.clear();
+    while (!enemies.isEmpty())
+        delete enemies.takeFirst();
+
     view->deleteEnemySprites();
     bananas = 0;
 
 -1996,7
+2012,7 
     setBlankLevel(false);	// Fill playfield with Editable
objects.
 
     view->setTitle (getTitle());// Show title of level.
-    view->updateCanvas();	// Show the edit area.
+    //view->updateCanvas();	// Show the edit area.
 
     shouldSave = false;		// Used to flag editing of name or
hint.
 }
 -2110,7
+2126,7 
     case Qt::RightButton:
         paintEditObj = true;
         insertEditObj (i, j);
-	view->updateCanvas();
+	//view->updateCanvas();
         oldI = i;
         oldJ = j;
         break;
 -2134,7
+2150,7 
         paintEditObj = false;
         if ((i != oldI) || (j != oldJ)) {
 	    insertEditObj (i, j);
-	    view->updateCanvas();
+	    //view->updateCanvas();
 	}
         break;
     default:
 -2225,14
+2241,15 
 bool KGrGame::ownerOK (Owner o)
 {
     // Check that this owner has at least one collection.
-    KGrCollection * c;
     bool OK = false;
 
-    for (c = collections.first(); c != 0; c =
collections.next()) {
+    QListIterator<KGrCollection *> i(collections);
+    while (i.hasNext()){
+	KGrCollection * c = i.next();
 	if (c->owner == o) {
 	    OK = true;
 	    break;
-	}
+	}		// Pit is blocked.  Find another way.
     }
 
     return (OK);
 -2243,7
+2260,7 
 /**********************************************************
********************/
 
 KGrThumbNail::KGrThumbNail (QWidget * parent, const char *
name)
-			: Q3Frame (parent, name)
+			: QFrame (parent, name)
 {
     // Let the parent do all the work.  We need a class
here so that
     // QFrame::drawContents (QPainter *) can be
re-implemented and
 -2261,21
+2278,31 
     lName = sln;				// path and level name field.
 }
 
-void KGrThumbNail::drawContents (QPainter * p)	// Activated
via "paintEvent".
+// This was previously a Q3Frame
+// void KGrThumbNail::drawContents (QPainter * p)
+//
+// In Qt4 there is no longer this method for QFrame,
suggested
+// workaround is to reimplement paintEvent
+//
+// TODO We need to respect the frame area, and draw inside
it
+//
+void KGrThumbNail::paintEvent (QPaintEvent * event)
 {
+
+    QPainter  p(this);
     QFile	openFile;
-    QPen	pen = p->pen();
+    QPen	pen = p.pen();
     char	obj = FREE;
     int		fw = 1;				// Set frame width.
     int		n = width() / FIELDWIDTH;	// Set thumbnail
cell-size.
 
     pen.setColor (backgroundColor);
-    p->setPen (pen);
+    p.setPen (pen);
 
     openFile.setFileName (filePath);
     if ((! openFile.exists()) || (! openFile.open
(QIODevice::ReadOnly))) {
 	// There is no file, so fill the thumbnail with
"FREE" cells.
-	p->drawRect (QRect(fw, fw, FIELDWIDTH*n,
FIELDHEIGHT*n));
+	p.drawRect (QRect(fw, fw, FIELDWIDTH*n, FIELDHEIGHT*n));
 	return;
     }
 
 -2289,29
+2316,29 
 	case BRICK:
 	case BETON:
 	case FBRICK:
-	    pen.setColor (brickColor); p->setPen (pen); break;
+	    pen.setColor (brickColor); p.setPen (pen); break;
 	case LADDER:
-	    pen.setColor (ladderColor); p->setPen (pen); break;
+	    pen.setColor (ladderColor); p.setPen (pen); break;
 	case POLE:
-	    pen.setColor (poleColor); p->setPen (pen); break;
+	    pen.setColor (poleColor); p.setPen (pen); break;
 	case HERO:
-	    pen.setColor (Qt::green); p->setPen (pen); break;
+	    pen.setColor (Qt::green); p.setPen (pen); break;
 	case ENEMY:
-	    pen.setColor (Qt::blue); p->setPen (pen); break;
+	    pen.setColor (Qt::blue); p.setPen (pen); break;
 	default:
 	    // Set the background for FREE, HLADDER and NUGGET.
-	    pen.setColor (backgroundColor); p->setPen (pen);
break;
+	    pen.setColor (backgroundColor); p.setPen (pen); break;
 	}
 
 	// Draw nxn pixels as n lines of length n.
-	p->drawLine (i*n+fw, j*n+fw, i*n+(n-1)+fw, j*n+fw);
+	p.drawLine (i*n+fw, j*n+fw, i*n+(n-1)+fw, j*n+fw);
 	if (obj == POLE) {
 	    // For a pole, only the top line is drawn in white.
 	    pen.setColor (backgroundColor);
-	    p->setPen (pen);
+	    p.setPen (pen);
 	}
 	for (int k = 1; k < n; k++) {
-	    p->drawLine (i*n+fw, j*n+k+fw, i*n+(n-1)+fw,
j*n+k+fw);
+	    p.drawLine (i*n+fw, j*n+k+fw, i*n+(n-1)+fw, j*n+k+fw);
 	}
 
 	// For a nugget, add just a vertical touch  of yellow (2-3
pixels).
 -2319,9
+2346,9 
 	    int k = (n/2)+fw;
 	    // pen.setColor (QColor("#ffff00"));
 	    pen.setColor (ladderColor);
-	    p->setPen (pen);
-	    p->drawLine (i*n+k, j*n+k, i*n+k, j*n+(n-1)+fw);
-	    p->drawLine (i*n+k+1, j*n+k, i*n+k+1,
j*n+(n-1)+fw);
+	    p.setPen (pen);
+	    p.drawLine (i*n+k, j*n+k, i*n+k, j*n+(n-1)+fw);
+	    p.drawLine (i*n+k+1, j*n+k, i*n+k+1, j*n+(n-1)+fw);
 	}
     }
 
 -2351,7
+2378,7 
 bool KGrGame::initCollections ()
 {
     // Initialise the list of collections of levels (i.e.
the list of games).
-    collections.setAutoDelete(true);
+    //collections.setAutoDelete(true);
     owner = SYSTEM;				// Use system levels initially.
     if (! loadCollections (SYSTEM))		// Load system
collections list.
 	return (false);				// If no collections, abort.
 -2377,7
+2404,10 
     QString		fileName2;
 
     // Find KGoldrunner level files, sorted by name (same
as numerical order).
-    for (colln = collections.first(); colln != 0; colln =
collections.next()) {
+    QListIterator<KGrCollection *> i(collections);
+    while (i.hasNext()){
+	colln = i.next();
+    //for (colln = collections.first(); colln != 0; colln =
collections.next()) {
 	d.setPath ((colln->owner == SYSTEM)	? systemDataDir +
"levels/"
 						: userDataDir + "levels/");
 	d_path = d.path();
 -2565,7
+2595,10 
     int			i, len;
     char		ch;
 
-    for (colln = collections.first(); colln != 0; colln =
collections.next()) {
+    QListIterator<KGrCollection *> it(collections);
+    while (it.hasNext()){
+	colln = it.next();
+    //for (colln = collections.first(); colln != 0; colln =
collections.next()) {
 	if (colln->owner == o) {
 	    line.sprintf ("%03d %c %s %s\n",
colln->nLevels, colln->settings,
 				colln->prefix.myStr(),
Index: src/kgrcanvas.cpp
============================================================
=======
--- src/kgrcanvas.cpp	(revision 571247)
+++ src/kgrcanvas.cpp	(working copy)
 -2,7
+2,7 
                           kgrcanvas.cpp  -  description
                              -------------------
     begin                : Wed Jan 23 2002
-    Copyright 2002 Marco Krüger
+    Copyright 2002 Marco Krger
     Copyright 2002 Ian Wadham <ianwnetspace.net.au>
 
************************************************************
***************/
 
 -31,17
+31,17 
 #include "enemy1.xpm"
 #include "enemy2.xpm"
 #include "kgraphics.h"
-//Added by qt3to4:
+
 #include <QPixmap>
-#include <Q3PtrList>
+#include <QList>
 #include <QLabel>
 #include <QList>
 #include <QMouseEvent>
-#include <Q3CanvasSprite>
+
 class KGoldrunner;
 
 KGrCanvas::KGrCanvas (QWidget * parent, const char *name)
-	: Q3CanvasView (0, parent, name)
+	: QGraphicsView (0, parent)
 {
     setBackgroundMode (Qt::NoBackground);
     m = new QCursor ();		// For handling the mouse.
 -91,6
+91,7 
 		}
 	    }
 
+	    borderT->setBrush (QBrush (borderColor));
 	    borderB->setBrush (QBrush (borderColor));
 	    borderL->setBrush (QBrush (borderColor));
 	    borderR->setBrush (QBrush (borderColor));
 -99,8
+100,6 
 	    makeTitle ();
 	    setTitle (t);
 
-	    // Repaint the playing area.
-	    updateCanvas();
 	    return;
 	}
     }
 -108,7
+107,6 
 
 bool KGrCanvas::changeSize (int d)
 {
-#ifdef QT3
     if ((d < 0) && (scaleStep <= STEP)) {
 	// Note: Smaller scales lose detail (e.g. the joints in
brickwork).
 	KGrMessage::information (this, i18n("Change
Size"),
 -123,7
+121,7 
 	return false;
     }
 
-    QMatrix wm = worldMatrix();
+    QMatrix wm = matrix();
     double   wmScale = 1.0;
 
     // Set the scale back to 1:1 and calculate the new
scale factor.
 -135,7
+133,7 
 	wmScale = (wmScale * scaleStep) / STEP;
 	wm.scale (wmScale, wmScale);
     }
-    setWorldMatrix (wm);
+    setMatrix (wm);
 
     // Force the title size and position to be
re-calculated.
     QString t = title->text();
 -148,19
+146,8 
 		  (FIELDHEIGHT + 4) * 4 * scaleStep + frame);
     return true;
 
-#else
-    KGrMessage::information (this, i18n( "Change
Size" ),
-    i18n( "Sorry, you cannot change the size of the
playing area. "
-    "That function requires Qt Library version 3 or
later." ));
-    return false;
-#endif
 }
 
-void KGrCanvas::updateCanvas()
-{
-    field->update();
-}
-
 void KGrCanvas::paintCell (int x, int y, char type, int
offset)
 {
     int tileNumber = 0;
 -224,12
+211,12 
     title->show();
 }
 
-void KGrCanvas::contentsMousePressEvent (QMouseEvent * m) {
-    emit mouseClick (m->button ());
+void KGrCanvas::contentsMouseClick (int i) {
+    emit mouseClick (i);
 }
 
-void KGrCanvas::contentsMouseReleaseEvent (QMouseEvent * m)
{
-    emit mouseLetGo (m->button ());
+void KGrCanvas::contentsMouseLetGo (int i) {
+    emit mouseLetGo (i);
 }
 
 QPoint KGrCanvas::getMousePos ()
 -260,8
+247,17 
 
 void KGrCanvas::makeHeroSprite (int i, int j, int
startFrame)
 {
-    heroSprite = new Q3CanvasSprite (heroArray, field);
+    heroSprite = new KGrSprite (0, field);
 
+    // Process the pixmap with the hero frames
+   
////////////////////////////////////////////////////////////
//////////////
+    // The pixmaps for hero and enemies are arranged in
strips of 20: walk  //
+    // right (4), walk left (4), climb right along bar (4),
climb left (4), //
+    // climb up ladder (2) and fall (2) --- total 20.      
                //
+   
////////////////////////////////////////////////////////////
//////////////
+    // Our KGrSprite class will extract the frames from the
strip (16x16 pix, 20 frames)
+    heroSprite->addFrames(QPixmap (hero_xpm), 16, 16, 20
);
+
     // In KGoldrunner, the top-left visible cell is [1,1]
--- in QCanvas [2,2].
     i++; j++;
     heroSprite->move (i * 4 * STEP, j * 4 * STEP,
startFrame);
 -276,8
+272,20 
 
 void KGrCanvas::makeEnemySprite (int i, int j, int
startFrame)
 {
-    Q3CanvasSprite * enemySprite = new Q3CanvasSprite
(enemyArray, field);
+    KGrSprite * enemySprite = new KGrSprite (0, field);
 
+   
////////////////////////////////////////////////////////////
//////////////
+    // The pixmaps for hero and enemies are arranged in
strips of 20: walk  //
+    // right (4), walk left (4), climb right along bar (4),
climb left (4), //
+    // climb up ladder (2) and fall (2) --- total 20.      
                //
+   
////////////////////////////////////////////////////////////
//////////////
+    // Our KGrSprite class will extract the frames from the
strip (16x16 pix, 20 frames)
+    // First convert the pixmap for enemies with no gold
...
+    enemySprite->addFrames(QPixmap (enemy1_xpm), 16, 16,
20 );
+
+    // Now adds the frames for enemies with no gold ...
+    enemySprite->addFrames(QPixmap (enemy2_xpm), 16, 16,
20 );
+
     enemySprites->append (enemySprite);
 
     // In KGoldrunner, the top-left visible cell is [1,1]
--- in QCanvas [2,2].
 -291,7
+299,6 
 {
     // In KGoldrunner, the top-left visible cell is [1,1]
--- in QCanvas [2,2].
     heroSprite->move (x + 4 * STEP, y + 4 * STEP,
frame);
-    updateCanvas();
 }
 
 void KGrCanvas::moveEnemy (int id, int x, int y, int frame,
int bananas)
 -302,12
+309,12 
 
     // In KGoldrunner, the top-left visible cell is [1,1]
--- in QCanvas [2,2].
     enemySprites->at(id)->move (x + 4 * STEP, y + 4 *
STEP, frame);
-    updateCanvas();
 }
 
 void KGrCanvas::deleteEnemySprites()
 {
-    enemySprites->clear();
+    while (!enemySprites->isEmpty())
+            delete enemySprites->takeFirst();
 }
 
 QPixmap KGrCanvas::getPixmap (char type)
 -372,99
+379,29 
 
     // Define the canvas as an array of tiles.  Default
tile is 0 (free space).
     int frame = frameWidth()*2;
-    field = new Q3Canvas ((FIELDWIDTH+border) * bgw,
(FIELDHEIGHT+border) * bgh);
+    field = new KGrScene();
+    field->setSceneRect(0,0,(FIELDWIDTH+border) * bgw,
(FIELDHEIGHT+border) * bgh);
+
+    //Set the KGrScene to this QGraphicsView
+    setScene(field);
+
+    //Now set our tileset in the scene
     field->setTiles (bgPix, (FIELDWIDTH+border),
(FIELDHEIGHT+border),
 			bgw, bgh);
 
-    // Embed the canvas in the view and make it occupy the
whole of the view.
-    setCanvas (field);
-    setVScrollBarMode (Q3ScrollView::AlwaysOff);
-    setHScrollBarMode (Q3ScrollView::AlwaysOff);
+    //TODO setVScrollBarMode (Q3ScrollView::AlwaysOff);
+    //TODO setHScrollBarMode (Q3ScrollView::AlwaysOff);
+    setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+    setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
     setFixedSize (field->width() + frame,
field->height() + frame);
 
-   
////////////////////////////////////////////////////////////
//////////////
-    // The pixmaps for hero and enemies are arranged in
strips of 20: walk  //
-    // right (4), walk left (4), climb right along bar (4),
climb left (4), //
-    // climb up ladder (2) and fall (2) --- total 20.      
                //
-   
////////////////////////////////////////////////////////////
//////////////
+    //Enable background caching at the view level
+    setCacheMode(QGraphicsView::CacheBackground);
 
-    // Convert the pixmap strip for hero animation into a
QCanvasPixmapArray.
-    pixmap = QPixmap (hero_xpm);
-    image = pixmap.toImage ();
+    //Relay mouse events received from QGraphicsScene and
send them upstream
+    connect( field, SIGNAL(mouseClick(int)), this,
SLOT(contentsMouseClick(int)) );
+    connect( field, SIGNAL(mouseLetGo(int)), this,
SLOT(contentsMouseLetGo(int)) );
 
-#ifdef QT3
-    QPixmap   pm;
-    QList<QPixmap> pmList;
-
-    for (int i = 0; i < 20; i++) {
-	pm = QPixmap::fromImage (image.copy (i * 16, 0, 16, 16));
-	pmList.append (pm);
-    }
-
-    heroArray = new Q3CanvasPixmapArray (pmList);	// Hot
spots all (0,0).
-#else
-    QPixmap * pm;
-    QPoint  * pt;
-    QList<QPixmap> pmList;
-    QList<QPoint>  ptList;
-
-    pt = new QPoint (0, 0);		// "Hot spot" not
used in KGoldrunner.
-
-    for (int i = 0; i < 20; i++) {
-	pm = new QPixmap ();
-	pm->convertFromImage (image.copy (i * 16, 0, 16, 16));
-	pmList.append (pm);
-	ptList.append (pt);
-    }
-
-    heroArray = new Q3CanvasPixmapArray (pmList, ptList);
-#endif
-
-    // Convert pixmap strips for enemy animations into a
QCanvasPixmapArray.
-    // First convert the pixmaps for enemies with no gold
...
-    pixmap = QPixmap (enemy1_xpm);
-    image = pixmap.toImage ();
-
-    pmList.clear();
-
-#ifdef QT3
-    for (int i = 0; i < 20; i++) {
-	pm = QPixmap::fromImage (image.copy (i * 16, 0, 16, 16));
-	pmList.append (pm);
-    }
-#else
-    ptList.clear();
-
-    for (int i = 0; i < 20; i++) {
-	pm = new QPixmap ();
-	pm->convertFromImage (image.copy (i * 16, 0, 16, 16));
-	pmList.append (pm);
-	ptList.append (pt);
-    }
-#endif
-
-    // ... then convert the gold-carrying enemies.
-    pixmap = QPixmap (enemy2_xpm);
-    image = pixmap.toImage ();
-
-#ifdef QT3
-    for (int i = 0; i < 20; i++) {
-	pm = QPixmap::fromImage (image.copy (i * 16, 0, 16, 16));
-	pmList.append (pm);
-    }
-
-    enemyArray = new Q3CanvasPixmapArray (pmList);	// Hot
spots all (0,0).
-#else
-    for (int i = 0; i < 20; i++) {
-	pm = new QPixmap ();
-	pm->convertFromImage (image.copy (i * 16, 0, 16, 16));
-	pmList.append (pm);
-	ptList.append (pt);
-    }
-
-    enemyArray = new Q3CanvasPixmapArray (pmList, ptList);
-#endif
-
     goldEnemy = 20;			// Offset of gold-carrying frames.
 
     // Draw the border around the playing area (z = 0).
 -475,12
+412,7 
     makeTitle();
 
     // Create an empty list of enemy sprites.
-#ifdef QT3
-    enemySprites = new Q3PtrList<Q3CanvasSprite> ();
-#else
-    enemySprites = new QList<Q3CanvasSprite> ();
-#endif
-    enemySprites->setAutoDelete(true);
+    enemySprites = new QList<KGrSprite *> ();
 }
 
 void KGrCanvas::makeTiles ()
 -509,8
+441,7 
     // Allow some overlap to prevent slits appearing when
using "changeSize".
     colour = borderColor;
 
-    // The first rectangle is actually a QLabel drawn by
"makeTitle()".
-    // borderT = drawRectangle (11, 0, 0, FIELDWIDTH*cw +
2*bw, mw);
+    borderT = drawRectangle (11, 0, 0, FIELDWIDTH*cw +
2*bw, mw);
     borderB = drawRectangle (11, 0, FIELDHEIGHT*cw + bw +
lw,
 						FIELDWIDTH*cw + 2*bw, mw);
     borderL = drawRectangle (12, 0, bw - lw - 1, mw,
FIELDHEIGHT*cw + 2*lw + 2);
 -525,13
+456,13 
     drawRectangle (10, FIELDWIDTH*cw + bw, bw, lw,
FIELDHEIGHT*cw);
 }
 
-Q3CanvasRectangle * KGrCanvas::drawRectangle (int z, int x,
int y, int w, int h)
+QGraphicsRectItem * KGrCanvas::drawRectangle (int z, int x,
int y, int w, int h)
 {
-    Q3CanvasRectangle * r = new Q3CanvasRectangle (x, y, w,
h, field);
+    QGraphicsRectItem * r = new QGraphicsRectItem (x, y, w,
h, 0, field);
 
     r->setBrush (QBrush (colour));
     r->setPen (QPen (Qt::NoPen));
-    r->setZ (z);
+    r->setZValue (z);
     r->show();
 
     return (r);
Index: src/kgrgame.h
============================================================
=======
--- src/kgrgame.h	(revision 571247)
+++ src/kgrgame.h	(working copy)
 -21,24
+21,16 
 #define endData		atEnd
 
 #include <QObject>
-
-#ifdef QT3
-#include <q3ptrlist.h>
-#else
-#include <qlist.h>
-#endif
+#include <QList>
 #include <QString>
-
 #include <QDir>
 #include <QFile>
-#include <qtextstream.h>
+#include <QTextStream>
 #include <QDataStream>
-
 #include <QColor>
-//Added by qt3to4:
 #include <QPixmap>
 #include <QLabel>
-#include <Q3Frame>
+#include <QFrame>
 
 /**
 Sets up games and levels in KGoldrunner and controls the
play.
 -158,11
+150,7 
     KGrHero *			hero;		// The HERO figure !!  Yay !!!
     int				startI, startJ;	// The hero's starting
position.
 
-#ifdef QT3
-    Q3PtrList<KGrEnemy>		enemies;	// The list of
enemies.
-#else
-    QList<KGrEnemy>		enemies;	// The list of enemies.
-#endif
+    QList<KGrEnemy *>		enemies;	// The list of
enemies.
     int				enemyCount;	// How many enemies.
     KGrEnemy *			enemy;		// One of the enemies.
 
 -250,11
+238,7 
 private:
 
 // Note that a collection of KGoldrunner levels is the same
thing as a "game".
-#ifdef QT3
-    Q3PtrList<KGrCollection>	collections;	// List of
ALL collections.
-#else
-    QList<KGrCollection>	collections;	// List of ALL
collections.
-#endif
+    QList<KGrCollection *>	collections;	// List of
ALL collections.
 
     KGrCollection *		collection;	// Collection currently in
use.
     Owner			owner;		// Collection owner.
 -275,7
+259,7 
 /**********************    CLASS TO DISPLAY THUMBNAIL  
***********************/
 /**********************************************************
********************/
 
-class KGrThumbNail : public Q3Frame
+class KGrThumbNail : public QFrame
 {
 public:
     KGrThumbNail (QWidget *parent = 0, const char *name =
0);
 -287,7
+271,8 
     static QColor poleColor;
 
 protected:
-    void drawContents (QPainter *);		// Draw a preview of a
level.
+    //void drawContents (QPainter *);		// Draw a preview of
a level.
+    void paintEvent ( QPaintEvent * event );
     QString filePath;
     QLabel * lName;
 };
Index: src/kgrcanvas.h
============================================================
=======
--- src/kgrcanvas.h	(revision 571247)
+++ src/kgrcanvas.h	(working copy)
 -2,7
+2,7 
                          kgrcanvas.h  -  description
                              -------------------
     begin                : Wed Jan 23 2002
-    Copyright 2002 Marco Krüger
+    Copyright 2002 Marco Krger
     Copyright 2002 Ian Wadham <ianwnetspace.net.au>
 
************************************************************
***************/
 
 -22,17
+22,20 
 #include <config.h>
 #endif
 
+#include "kgrscene.h"
+#include "kgrsprite.h"
+
 #include <qcursor.h>
-#include <q3canvas.h>
 #include <QLabel>
-#include <qimage.h>
-#include <qpainter.h>
-//Added by qt3to4:
+#include <QImage>
+#include <QPainter>
 #include <QPixmap>
 #include <QMouseEvent>
-#include <Q3PtrList>
+#include <QList>
+#include <QGraphicsView>
+#include <QGraphicsRectItem>
 
-class KGrCanvas : public Q3CanvasView
+class KGrCanvas : public QGraphicsView
 {
 	Q_OBJECT
 public:
 -47,7
+50,7 
 	bool changeSize (int);
 	void setBaseScale ();
 
-	void updateCanvas ();
+	//void updateCanvas ();
 	void paintCell (int, int, char, int offset = 0);
 	void setTitle (QString);
 
 -65,15
+68,15 
 	void mouseClick (int);
 	void mouseLetGo (int);
 
-protected:
-	void contentsMousePressEvent (QMouseEvent *);
-	void contentsMouseReleaseEvent (QMouseEvent *);
+public slots:
+	void contentsMouseClick (int);
+	void contentsMouseLetGo (int);
 
 private:
 	QCursor * m;
 
-	Q3Canvas * field;
-	Q3CanvasView * fieldView;
+	KGrScene * field;
+	//Q3CanvasView * fieldView;
 	int scaleStep;			// Current scale-factor of canvas.
 	int baseScale;			// Starting scale-factor of canvas.
 	int baseFontSize;
 -82,32
+85,27 
 	int cw, bw, lw, mw;		// Dimensions (in pixels) of the
border.
 	QColor borderColor, textColor;	// Border colours.
 	QLabel * title;			// Title and top part of border.
-	Q3CanvasRectangle * borderB;	// Bottom part of border.
-	Q3CanvasRectangle * borderL;	// Left-hand part of border.
-	Q3CanvasRectangle * borderR;	// Right-hand part of border.
+	QGraphicsRectItem * borderT;	// Bottom part of border.
+	QGraphicsRectItem * borderB;	// Bottom part of border.
+	QGraphicsRectItem * borderL;	// Left-hand part of border.
+	QGraphicsRectItem * borderR;	// Right-hand part of border.
 
 	int freebg, nuggetbg, polebg, ladderbg, hladderbg;
 	int edherobg, edenemybg, betonbg, brickbg, fbrickbg;
 	int bgw, bgh, bgd;
 	QPixmap bgPix;
 
-	Q3CanvasPixmapArray * heroArray;
-	Q3CanvasPixmapArray * enemyArray;
 	int goldEnemy;
 
-	Q3CanvasSprite * heroSprite;
-#ifdef QT3
-	Q3PtrList<Q3CanvasSprite> * enemySprites;
-#else
-	QList<Q3CanvasSprite> * enemySprites;
-#endif
+	KGrSprite * heroSprite;
+	QList<KGrSprite *> * enemySprites;
 
 	void initView();
 	void makeTiles();
 	void makeBorder();
 	void makeTitle();
 	QColor colour;
-	Q3CanvasRectangle * drawRectangle (int, int, int, int,
int);
+	QGraphicsRectItem * drawRectangle (int, int, int, int,
int);
 	void changeColours (const char * colours []);
 	void recolourObject (const char * object [], const char *
colours []);
 };
Index: src/kgrfigure.cpp
============================================================
=======
--- src/kgrfigure.cpp	(revision 571247)
+++ src/kgrfigure.cpp	(working copy)
 -1,7
+1,7 
 /**********************************************************
*****************
  *                      kgrfigure.cpp  -  description      
               *
  *                           -------------------           
               *
-    Copyright 2003 Marco Krüger
+    Copyright 2003 Marco Krger
     Copyright 2003 Ian Wadham <ianwnetspace.net.au>
  *                                                         
               *
  *   This program is free software; you can redistribute it
and/or modify  *
 -17,8
+17,7 
 #include "kgrfigure.h"
 
 #include <stdio.h>
-//Added by qt3to4:
-#include <Q3PtrList>
+#include <QList>
 
 KGrFigure :: KGrFigure (int px, int py)
 {
 -712,11
+711,7 
     ((KGrBrick*)(*playfield)[x+i][y+1])->dig();
 }
 
-#ifdef QT3
-void KGrHero::setEnemyList(Q3PtrList<KGrEnemy> *e)
-#else
-void KGrHero::setEnemyList(QList<KGrEnemy> *e)
-#endif
+void KGrHero::setEnemyList(QList<KGrEnemy *> * e)
 {
   enemies = e;
 }
 -1577,8
+1572,10 
 	}
     }
     if (rungs == 1) {
-	for (KGrEnemy
*enemy=enemies->first();enemy!=0;enemy=enemies->next()
) {
-	    if((x*16==enemy->getx()) &&
(y*16+16==enemy->gety()))
+	QListIterator<KGrEnemy *> i(*enemies);
+        while (i.hasNext()){
+		KGrEnemy * enemy = i.next();
+		if((x*16==enemy->getx()) &&
(y*16+16==enemy->gety()))
 		rungs = 0;		// Pit is blocked.  Find another way.
 	}
     }
 -1663,11
+1660,7 
     }
 }
 
-#ifdef QT3
-void KGrEnemy::setEnemyList(Q3PtrList<KGrEnemy> *e)
-#else
-void KGrEnemy::setEnemyList(QList<KGrEnemy> *e)
-#endif
+void KGrEnemy::setEnemyList(QList<KGrEnemy *> * e)
 {
   enemies = e;
 }
Index: src/kgoldrunner.cpp
============================================================
=======
--- src/kgoldrunner.cpp	(revision 571247)
+++ src/kgoldrunner.cpp	(working copy)
 -42,6
+42,8 
 #include "kgrgame.h"
 #include "kgoldrunner.h"
 
+#include <QtDebug>
+
 KGoldrunner::KGoldrunner()
     : KMainWindow (0, "KGoldrunner"),
       view (new KGrCanvas (this))
 -110,7
+112,7 
     // explicitly hide an edit toolbar - we need it in edit
mode only
     toolBar("editToolbar")->hide();
    
toolBar("editToolbar")->setAllowedAreas(Qt::T
opToolBarArea);
-#ifdef QT3
+
     // Base size of playing-area and widgets on the monitor
resolution.
     int dw = KApplication::desktop()->width();
     if (dw > 800) {				// More than 800x600.
 -121,10
+123,13 
 	view->changeSize (+1);		// Scale 1.75:1.
     }
     view->setBaseScale();		// Set scale for level-names.
-#endif
-    setFixedSize (view->size());
 
+    //TODO - Investigate more flexible resizing? 
+    // setFixedSize seems broken right now in KMainWindow,
not considering the status bar and menubar 
+    //
+    //setFixedSize (view->size());
 
+
     // Set mouse control of the hero as the default.
     game->setMouseMode (true);
 
 -140,7
+145,10 
 
 KGoldrunner::~KGoldrunner()
 {
-    delete editToolbar;
+	//Investigate:
+	//KGoldRunner crashes (KDE4) on quit when this is not
commented out
+	//Maybe a change in Qt or KDElibs since 3.x?
+	//    delete editToolbar;
 }
 
 void KGoldrunner::setupActions()
 -493,6
+501,13 
     digLeft->setShortcut( Qt::Key_Z );
     connect( digLeft, SIGNAL(triggered(bool)), this,
SLOT(digL()));
 
+    //TODO Investigate the reason for this message
(console) and why actions are not working
+    //
+    // kgoldrunner: WARNING: [void
KXMLGUIFactory::addClient(KXMLGUIClient*)] 
+    // The following actions are not plugged into the gui
(shortcuts will not work): 
+    // move_up move_right move_down move_left stop
dig_right dig_left
+    //
+
     setupEditToolbarActions();			// Uses pixmaps from
"view".
 
     // Alternate one-handed controls.  Set up in
"kgoldrunnerui.rc".
 -754,13
+769,23 
 void KGoldrunner::makeLarger()
 {
     if (view->changeSize (+1))
-	setFixedSize (view->size());
+	// TODO - Investigate resizing options
+	// setFixedSize seems broken in KMainWindow right now
+	//
+	//setFixedSize (view->size());
+	setGeometry(0,0,view->size().rwidth
(),view->size().rheight ());
 }
 
 void KGoldrunner::makeSmaller()
 {
     if (view->changeSize (-1))
-	setFixedSize (view->size());
+	// TODO - Investigate resizing options
+	// setFixedSize seems broken in KMainWindow right now
+	//
+	//setFixedSize (view->size());
+	setGeometry(0,0,view->size().rwidth
(),view->size().rheight ());
+	//TODO - Maybe we need a layout manager here? View is not
shrinking automatically
+
 }
 
 // Local slots for hero control keys.
 -892,11
+917,7 
 
     KStandardDirs * dirs = new KStandardDirs();
 
-#ifdef QT3
     QString myDir = "kgoldrunner";
-#else
-    QString myDir = "kgoldrun";
-#endif
 
     // Find the KGoldrunner Users' Guide, English version
(en).
     systemHTMLDir = dirs->findResourceDir
("html", "en/" + myDir +
"/");
Index: src/kgrfigure.h
============================================================
=======
--- src/kgrfigure.h	(revision 571247)
+++ src/kgrfigure.h	(working copy)
 -1,7
+1,7 
 /**********************************************************
*****************
  *                       kgrfigure.h  -  description       
               *
  *                           -------------------           
               *
-    Copyright 2003 Marco Krüger
+    Copyright 2003 Marco Krger
     Copyright 2003 Ian Wadham <ianwnetspace.net.au>
  *                                                         
               *
  *   This program is free software; you can redistribute it
and/or modify  *
 -16,14
+16,10 
 // Obsolete - #include <iostream.h>
 #include <iostream>
 
-#include <qimage.h>
-#ifdef QT3
-#include <q3ptrlist.h>
-#else
-#include <qlist.h>
-#endif
-#include <qpainter.h>
-#include <qpixmap.h>
+#include <QImage>
+#include <QList>
+#include <QPainter>
+#include <QPixmap>
 #include <QTimer>
 #include <QWidget>
 #include <stdlib.h> // für Zufallsfunktionen
 -109,11
+105,7 
   void digLeft();
   void digRight();
   void startWalk();
-#ifdef QT3
-  void setEnemyList(Q3PtrList<KGrEnemy> *);
-#else
-  void setEnemyList(QList<KGrEnemy> *);
-#endif
+  void setEnemyList(QList<KGrEnemy *> *);
   void init(int,int);
   void setKey(Direction);
   void setDirection(int, int);
 -126,11
+118,7 
   void showState (char);
 
 private:
-#ifdef QT3
-  Q3PtrList<KGrEnemy> *enemies;
-#else
-  QList<KGrEnemy> *enemies;
-#endif
+  QList<KGrEnemy *> *enemies;
   KGrCanvas * heroView;
   bool standOnEnemy();
   bool isInEnemy();
 -164,11
+152,7 
   virtual ~KGrEnemy();
   void showFigure();
   void startSearching();
-#ifdef QT3
-  void setEnemyList(Q3PtrList<KGrEnemy> *);
-#else
-  void setEnemyList(QList<KGrEnemy> *);
-#endif
+  void setEnemyList(QList<KGrEnemy *> *);
   virtual void init(int,int);
   static int WALKDELAY;
   static int FALLDELAY;
 -184,11
+168,7 
   int captiveCounter;
   QTimer *captiveTimer;
   bool canWalkUp();
-#ifdef QT3
-  Q3PtrList<KGrEnemy> *enemies;
-#else
-  QList<KGrEnemy> *enemies;
-#endif
+  QList<KGrEnemy *> *enemies;
   bool standOnEnemy();
   bool bumpingFriend();
 
Index: src/CMakeLists.txt
============================================================
=======
--- src/CMakeLists.txt	(revision 571247)
+++ src/CMakeLists.txt	(working copy)
 -1,10
+1,11 
 
 include_directories( $/libkdegames
$ )
 
-ADD_DEFINITIONS(-DQT3)
 ########### next target ###############
 
 set(kgoldrunner_SRCS 
+   kgrscene.cpp 
+   kgrsprite.cpp 
    kgoldrunner.cpp 
    kgrcanvas.cpp 
    kgrfigure.cpp
_______________________________________________
kde-games-devel mailing list
kde-games-develkde.org
https://mail.kde.org/mailman/listinfo/kde-games-devel
KDE4 and QGraphicsView port of KGoldrunner
user name
2006-08-08 23:22:42
On Wednesday 09 August 2006 02:28, mauriciotabuleiro.com wrote:
> Attached is the first patch that implements the
migrations described
> above. I got a SVN account, so I can commit it if you
guys find it easier
> to build/test a working copy from SVN. When commiting I
can try to split
> it into smaller commits as well, but some changes in
the QCanvas classes
> are extense, so it makes sense to commit all at once.
Great! (yes, I'm used to this word ;) )
Now I'm falling asleep (03.20 am here), so I'll look at
(and probably apply 
and test) your patch tomorrow .

Welcome abroad! 

Have fun!
Dmitry.
_______________________________________________
kde-games-devel mailing list
kde-games-develkde.org
https://mail.kde.org/mailman/listinfo/kde-games-devel
[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )