[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    KDE/kdegames/kolf
From:       Albert Astals Cid <tsdgeos () terra ! es>
Date:       2005-09-02 9:25:47
Message-ID: 1125653147.320114.15373.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 456208 by aacid:

now it does not crash when starting a new game


 M  +2 -2      kolf.cpp  
 M  +23 -15    newgame.cpp  
 M  +7 -10     newgame.h  


--- trunk/KDE/kdegames/kolf/kolf.cpp #456207:456208
@@ -185,7 +185,7 @@
 	{
 		PlayerEditor *curEditor = 0;
 		int newId = 1;
-		for (curEditor = dialog->players()->first(); curEditor; curEditor = \
dialog->players()->next(), ++newId) +		for (curEditor = \
dialog->players()->at(newId-1); newId <= dialog->players()->count(); ++newId)  {
 			players.append(Player());
 			players.last().ball()->setColor(curEditor->color());
@@ -808,7 +808,7 @@
 
 void Kolf::setCurrentHole(int hole)
 {
-	if (!holeAction)
+	if (!holeAction || holeAction->items().count() < hole)
 		return;
 	// Golf is 1-based, KListAction is 0-based
 	holeAction->setCurrentItem(hole - 1);
--- trunk/KDE/kdegames/kolf/newgame.cpp #456207:456208
@@ -14,7 +14,6 @@
 
 #include <qcheckbox.h>
 #include <qevent.h>
-#include <q3frame.h>
 #include <qpen.h>
 #include <qlayout.h>
 #include <qlabel.h>
@@ -28,12 +27,9 @@
 #include <qpainter.h>
 #include <qpixmapcache.h>
 #include <qwidget.h>
-#include <q3scrollview.h>
-#include <q3valuelist.h>
-#include <q3ptrlist.h>
+#include <qscrollarea.h>
 #include <qstringlist.h>
 #include <qstring.h>
-#include <q3vbox.h>
 
 #include "newgame.h"
 #include "game.h"
@@ -43,7 +39,6 @@
 {
 	this->enableCourses = enableCourses;
 
-	editors.setAutoDelete(true);
 	KConfig *config = kapp->config();
 
 	// lots o' colors :)
@@ -57,16 +52,17 @@
 
 	connect(addButton, SIGNAL(clicked()), this, SLOT(addPlayer()));
 
-	scroller = new Q3ScrollView(playerPage);
+	scroller = new QScrollArea(playerPage);
 	bigLayout->addWidget(scroller);
-	layout = new Q3VBox(scroller->viewport());
+	playersWidget = new QWidget(playerPage);
+	scroller->setWidget(playersWidget);
+	new QVBoxLayout(playersWidget);
 	if (!QPixmapCache::find("grass", grass))
 	{
 		grass.load(locate("appdata", "pics/grass.png"));
 		QPixmapCache::insert("grass", grass);
 	}
-	scroller->viewport()->setBackgroundPixmap(grass);
-	scroller->addChild(layout);
+	scroller->setBackgroundPixmap(grass);
 
 	QMap<QString, QString> entries = config->entryMap("New Game Dialog");
 	int i = 0;
@@ -184,6 +180,11 @@
 	vlayout->addWidget(desc);
 }
 
+NewGameDialog::~NewGameDialog()
+{
+	qDeleteAll(editors);
+}
+
 void NewGameDialog::slotOk()
 {
 	KConfig *config = kapp->config();
@@ -201,7 +202,7 @@
 
 	PlayerEditor *curEditor = 0;
 	int i = 0;
-	for (curEditor = editors.first(); curEditor; curEditor = editors.next(), ++i)
+	for (curEditor = editors.at(i); i < editors.count(); ++i)
 		config->writeEntry(QString::number(i) + curEditor->name(), \
curEditor->color().name());  
 	config->sync();
@@ -290,11 +291,15 @@
 	if (editors.count() >= startColors.count())
 		return;
 
-	editors.append(new PlayerEditor(i18n("Player %1").arg(editors.count() + 1), \
                *startColors.at(editors.count()), layout));
-	editors.last()->show();
-	connect(editors.last(), SIGNAL(deleteEditor(PlayerEditor *)), this, \
SLOT(deleteEditor(PlayerEditor *))); +	
+	PlayerEditor *pe = new PlayerEditor(i18n("Player %1").arg(editors.count() + 1), \
startColors.at(editors.count()), playersWidget); +	editors.append(pe);
+	pe->show();
+	playersWidget->layout()->addWidget(pe);
+	connect(pe, SIGNAL(deleteEditor(PlayerEditor *)), this, \
SLOT(deleteEditor(PlayerEditor *)));  
 	enableButtons();
+	playersWidget->setMinimumSize(playersWidget->sizeHint());
 }
 
 void NewGameDialog::deleteEditor(PlayerEditor *editor)
@@ -302,9 +307,12 @@
 	if (editors.count() < 2)
 		return;
 
-	editors.removeRef(editor);
+	editors.remove(editor);
+	delete editor;
 
 	enableButtons();
+	playersWidget->setMinimumSize(playersWidget->sizeHint());
+	playersWidget->resize(playersWidget->sizeHint());
 }
 
 void NewGameDialog::enableButtons()
--- trunk/KDE/kdegames/kolf/newgame.h #456207:456208
@@ -7,28 +7,24 @@
 
 #include <qcheckbox.h>
 #include <qcolor.h>
-#include <q3ptrlist.h>
 #include <qstring.h>
 //Added by qt3to4:
 #include <QPixmap>
 #include <QEvent>
-#include <Q3Frame>
 #include <QLabel>
 #include <QVBoxLayout>
 #include <kpushbutton.h>
 #include <qstringlist.h>
-#include <q3valuelist.h>
 #include <qwidget.h>
 
 #include "game.h"
 
 class KLineEdit;
-class Q3Frame;
 class QVBoxLayout;
-class Q3VBox;
 class QPainter;
 class KListBox;
 class QEvent;
+class QScrollArea;
 
 class PlayerEditor : public QWidget
 {
@@ -59,7 +55,8 @@
 
 public:
 	NewGameDialog(bool enableCourses, QWidget *parent, const char *_name = 0);
-	Q3PtrList<PlayerEditor> *players() { return &editors; }
+	~NewGameDialog();
+	QList<PlayerEditor*> *players() { return &editors; }
 	bool competition() { return mode->isChecked(); }
 	QString course() { return currentCourse; }
 
@@ -78,14 +75,14 @@
 	void showHighscores();
 
 private:
-	Q3VBox *layout;
+	QWidget *playersWidget;
 	KPushButton *addButton;
 	QFrame *playerPage;
-	Q3ScrollView *scroller;
+	QScrollArea *scroller;
 	QFrame *coursePage;
 	QFrame *optionsPage;
-	Q3ValueList<QColor> startColors;
-	Q3PtrList<PlayerEditor> editors;
+	QList<QColor> startColors;
+	QList<PlayerEditor*> editors;
 	KPushButton *remove;
 	QCheckBox *mode;
 


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic