summaryrefslogtreecommitdiff
authorzecke <zecke>2003-01-22 14:52:17 (UTC)
committer zecke <zecke>2003-01-22 14:52:17 (UTC)
commit36fab41fa6b38b9f3aa5ecd74b750eaf739beb16 (patch) (unidiff)
tree44c886f9d6673b8d0ac1c446fa9cbcabad6d9bb3
parentaa611367a06617e9ad12bd6787ce255a5965f695 (diff)
downloadopie-36fab41fa6b38b9f3aa5ecd74b750eaf739beb16.zip
opie-36fab41fa6b38b9f3aa5ecd74b750eaf739beb16.tar.gz
opie-36fab41fa6b38b9f3aa5ecd74b750eaf739beb16.tar.bz2
make it build with Qt/X11
for running one need to copy the kpacman.conf from share/kpacman to ~/Settings
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/games/kpacman/kpacman.cpp4
-rw-r--r--noncore/games/kpacman/kpacmanwidget.cpp5
-rw-r--r--noncore/games/kpacman/portable.h5
-rw-r--r--noncore/games/kpacman/status.cpp1
4 files changed, 8 insertions, 7 deletions
diff --git a/noncore/games/kpacman/kpacman.cpp b/noncore/games/kpacman/kpacman.cpp
index d9d2d69..aee8eea 100644
--- a/noncore/games/kpacman/kpacman.cpp
+++ b/noncore/games/kpacman/kpacman.cpp
@@ -1,266 +1,266 @@
1 1
2#include "portable.h" 2#include "portable.h"
3 3
4#if defined( KDE2_PORT ) 4#if defined( KDE2_PORT )
5#include <kpacman.h> 5#include <kpacman.h>
6#include <kpacman.moc> 6#include <kpacman.moc>
7#include <kcolordlg.h> 7#include <kcolordlg.h>
8#elif defined( QPE_PORT ) 8#elif defined( QPE_PORT )
9#include <qmenubar.h> 9#include <qmenubar.h>
10#include "config.h" 10#include "config.h"
11#include <qapplication.h> 11#include <qapplication.h>
12#include "kpacman.h" 12#include "kpacman.h"
13#endif 13#endif
14 14
15#include <qkeycode.h> 15#include <qkeycode.h>
16#include <qcolor.h> 16#include <qcolor.h>
17#include <qstring.h> 17#include <qstring.h>
18#include <qpopmenu.h> 18#include <qpopmenu.h>
19#include <qmsgbox.h> 19#include <qmsgbox.h>
20 20
21Kpacman::Kpacman(QWidget *parent, const char *name) 21Kpacman::Kpacman(QWidget *parent, const char *name)
22 : KTMainWindow(parent, name) 22 : KTMainWindow(parent, name)
23{ 23{
24 schemesPopup = new QList<QPopupMenu>; 24 schemesPopup = new QList<QPopupMenu>;
25 schemesPopup->setAutoDelete(TRUE); 25 schemesPopup->setAutoDelete(TRUE);
26 26
27 menu(); 27 menu();
28 28
29 m_view = new QWidget( this, "m_view" ); 29 m_view = new QWidget( this, "m_view" );
30 m_view->setBackgroundColor( black ); 30 m_view->setBackgroundColor( black );
31 m_layout = new QGridLayout( m_view ); 31 m_layout = new QGridLayout( m_view );
32 m_layout->setMargin( 7 ); 32 m_layout->setMargin( 7 );
33 33
34 view = new KpacmanWidget( this, QString(name)+"widget"); 34 view = new KpacmanWidget( this, QString(name)+"widget");
35 m_layout->addWidget( view, 0, 0 ); 35 m_layout->addWidget( view, 0, 0 );
36 36
37 setCaption( "KPacman" ); 37 setCaption( "KPacman" );
38 38
39 view->referee->setFocus(); 39 view->referee->setFocus();
40 40
41 connect(view->referee, SIGNAL(setScore(int, int)), 41 connect(view->referee, SIGNAL(setScore(int, int)),
42 view->score, SLOT(setScore(int, int))); 42 view->score, SLOT(setScore(int, int)));
43 connect(view->referee, SIGNAL(setPoints(int)), 43 connect(view->referee, SIGNAL(setPoints(int)),
44 view->score, SLOT(set(int))); 44 view->score, SLOT(set(int)));
45 connect(view->referee, SIGNAL(setLifes(int)), 45 connect(view->referee, SIGNAL(setLifes(int)),
46 view->status, SLOT(setLifes(int))); 46 view->status, SLOT(setLifes(int)));
47 connect(view->referee, SIGNAL(setLevel(int)), 47 connect(view->referee, SIGNAL(setLevel(int)),
48 view->status, SLOT(setLevel(int))); 48 view->status, SLOT(setLevel(int)));
49 connect(view->referee, SIGNAL(forcedHallOfFame(bool)), 49 connect(view->referee, SIGNAL(forcedHallOfFame(bool)),
50 this, SLOT(forcedHallOfFame(bool))); 50 this, SLOT(forcedHallOfFame(bool)));
51 connect(view->referee, SIGNAL(togglePaused()), this, SLOT(togglePaused())); 51 connect(view->referee, SIGNAL(togglePaused()), this, SLOT(togglePaused()));
52 connect(view->referee, SIGNAL(toggleNew()), this, SLOT(toggleNew())); 52 connect(view->referee, SIGNAL(toggleNew()), this, SLOT(toggleNew()));
53 53
54 connect(view->score, SIGNAL(toggleNew()), this, SLOT(toggleNew())); 54 connect(view->score, SIGNAL(toggleNew()), this, SLOT(toggleNew()));
55 connect(view->score, SIGNAL(forcedHallOfFame(bool)), 55 connect(view->score, SIGNAL(forcedHallOfFame(bool)),
56 this, SLOT(forcedHallOfFame(bool))); 56 this, SLOT(forcedHallOfFame(bool)));
57 57
58 APP_CONFIG_BEGIN( cfg ); 58 APP_CONFIG_BEGIN( cfg );
59 focusOutPause = !cfg->readBoolEntry("FocusOutPause", TRUE); 59 focusOutPause = !cfg->readBoolEntry("FocusOutPause", TRUE);
60 focusInContinue = !cfg->readBoolEntry("FocusInContinue", TRUE); 60 focusInContinue = !cfg->readBoolEntry("FocusInContinue", TRUE);
61 hideMouseCursor = !cfg->readBoolEntry("HideMouseCursor", TRUE); 61 hideMouseCursor = !cfg->readBoolEntry("HideMouseCursor", TRUE);
62 APP_CONFIG_END( cfg ); 62 APP_CONFIG_END( cfg );
63 63
64 toggleFocusOutPause(); 64 toggleFocusOutPause();
65 toggleFocusInContinue(); 65 toggleFocusInContinue();
66 toggleHideMouseCursor(); 66 toggleHideMouseCursor();
67 67
68 setCentralWidget( m_view ); 68 setCentralWidget( m_view );
69} 69}
70 70
71Kpacman::~Kpacman() 71Kpacman::~Kpacman()
72{ 72{
73 APP_CONFIG_BEGIN( cfg ); 73 APP_CONFIG_BEGIN( cfg );
74 cfg->writeEntry("FocusOutPause", focusOutPause); 74 cfg->writeEntry("FocusOutPause", focusOutPause);
75 cfg->writeEntry("FocusInContinue", focusInContinue); 75 cfg->writeEntry("FocusInContinue", focusInContinue);
76 cfg->writeEntry("HideMouseCursor", hideMouseCursor); 76 cfg->writeEntry("HideMouseCursor", hideMouseCursor);
77 APP_CONFIG_END( cfg ); 77 APP_CONFIG_END( cfg );
78 delete _menuBar; 78 delete _menuBar;
79} 79}
80 80
81void Kpacman::menu() 81void Kpacman::menu()
82{ 82{
83 gamePopup = new QPopupMenu(); 83 gamePopup = new QPopupMenu();
84 CHECK_PTR( gamePopup ); 84 CHECK_PTR( gamePopup );
85 newID = gamePopup->insertItem(tr("&New"), this, SLOT(newKpacman()),Key_F2); 85 newID = gamePopup->insertItem(tr("&New"), this, SLOT(newKpacman()),Key_F2);
86 pauseID = gamePopup->insertItem(tr("&Pause"), 86 pauseID = gamePopup->insertItem(tr("&Pause"),
87 this, SLOT(pauseKpacman()), Key_F3); 87 this, SLOT(pauseKpacman()), Key_F3);
88 hofID = gamePopup->insertItem(tr("&Hall of fame"), 88 hofID = gamePopup->insertItem(tr("&Hall of fame"),
89 this, SLOT(toggleHallOfFame()), Key_F4); 89 this, SLOT(toggleHallOfFame()), Key_F4);
90 gamePopup->insertSeparator(); 90 gamePopup->insertSeparator();
91 gamePopup->insertItem(tr("&Quit"), this, SLOT(quitKpacman()), CTRL+Key_Q); 91 gamePopup->insertItem(tr("&Quit"), this, SLOT(quitKpacman()), CTRL+Key_Q);
92 gamePopup->setCheckable(TRUE); 92 gamePopup->setCheckable(TRUE);
93 93
94 optionsPopup = new QPopupMenu(); 94 optionsPopup = new QPopupMenu();
95 CHECK_PTR(optionsPopup); 95 CHECK_PTR(optionsPopup);
96 96
97 modesPopup = new QPopupMenu(); 97 modesPopup = new QPopupMenu();
98 CHECK_PTR(modesPopup); 98 CHECK_PTR(modesPopup);
99 99
100 hideMouseCursorID = optionsPopup->insertItem(tr("&Hide Mousecursor"), 100 hideMouseCursorID = optionsPopup->insertItem(tr("&Hide Mousecursor"),
101 this, SLOT(toggleHideMouseCursor()), 101 this, SLOT(toggleHideMouseCursor()),
102 CTRL+Key_H); 102 CTRL+Key_H);
103 optionsPopup->insertSeparator(); 103 optionsPopup->insertSeparator();
104 104
105 if (lookupSchemes() > 0) { 105 if (lookupSchemes() > 0) {
106 optionsPopup->insertItem(tr("&Select graphic scheme"), modesPopup); 106 optionsPopup->insertItem(tr("&Select graphic scheme"), modesPopup);
107 optionsPopup->insertSeparator(); 107 optionsPopup->insertSeparator();
108 } 108 }
109 109
110 focusOutPauseID = optionsPopup->insertItem(tr("&Pause in Background"), 110 focusOutPauseID = optionsPopup->insertItem(tr("&Pause in Background"),
111 this, SLOT(toggleFocusOutPause())); 111 this, SLOT(toggleFocusOutPause()));
112 focusInContinueID = optionsPopup->insertItem(tr("&Continue in Foreground"), 112 focusInContinueID = optionsPopup->insertItem(tr("&Continue in Foreground"),
113 this, SLOT(toggleFocusInContinue())); 113 this, SLOT(toggleFocusInContinue()));
114 optionsPopup->insertSeparator(); 114 optionsPopup->insertSeparator();
115 115
116 optionsPopup->insertItem(tr("Change &keys..."), this, SLOT(confKeys())); 116 optionsPopup->insertItem(tr("Change &keys..."), this, SLOT(confKeys()));
117 117
118#ifndef QWS 118#ifndef QPE_PORT
119 QString aboutText = tr("@PACKAGE@ - @VERSION@\n\n" 119 QString aboutText = tr("@PACKAGE@ - @VERSION@\n\n"
120 "Joerg Thoennissen (joe@dsite.de)\n\n" 120 "Joerg Thoennissen (joe@dsite.de)\n\n"
121 "A pacman game for the KDE Desktop\n\n" 121 "A pacman game for the KDE Desktop\n\n"
122 "The program based on the source of ksnake\n" 122 "The program based on the source of ksnake\n"
123 "by Michel Filippi (mfilippi@sade.rhein-main.de).\n" 123 "by Michel Filippi (mfilippi@sade.rhein-main.de).\n"
124 "The design was strongly influenced by the pacman\n" 124 "The design was strongly influenced by the pacman\n"
125 "(c) 1980 MIDWAY MFG.CO.\n\n" 125 "(c) 1980 MIDWAY MFG.CO.\n\n"
126 "I like to thank my girlfriend Elke Krueers for\n" 126 "I like to thank my girlfriend Elke Krueers for\n"
127 "the last 10 years of her friendship.\n"); 127 "the last 10 years of her friendship.\n");
128 aboutText.replace(QRegExp("@PACKAGE@"), PACKAGE); 128 aboutText.replace(QRegExp("@PACKAGE@"), PACKAGE);
129 aboutText.replace(QRegExp("@VERSION@"), VERSION); 129 aboutText.replace(QRegExp("@VERSION@"), VERSION);
130 QPopupMenu *helpPopup = helpMenu(aboutText, FALSE); 130 QPopupMenu *helpPopup = helpMenu(aboutText, FALSE);
131#endif 131#endif
132 132
133 //_menuBar = new KMenuBar(this); 133 //_menuBar = new KMenuBar(this);
134 //CHECK_PTR( _menuBar ); 134 //CHECK_PTR( _menuBar );
135 //_menuBar->insertItem(tr("&Game"), gamePopup); 135 //_menuBar->insertItem(tr("&Game"), gamePopup);
136 //_menuBar->insertItem(tr("&Options"), optionsPopup); 136 //_menuBar->insertItem(tr("&Options"), optionsPopup);
137 //_menuBar->insertSeparator(); 137 //_menuBar->insertSeparator();
138#ifndef QWS 138#ifndef QPE_PORT
139 _menuBar->insertItem(tr("&Help"), helpPopup); 139 _menuBar->insertItem(tr("&Help"), helpPopup);
140#endif 140#endif
141} 141}
142 142
143int Kpacman::lookupSchemes() 143int Kpacman::lookupSchemes()
144{ 144{
145 APP_CONFIG_BEGIN( cfg ); 145 APP_CONFIG_BEGIN( cfg );
146 int ModeCount = cfg->readNumEntry("ModeCount", -1); 146 int ModeCount = cfg->readNumEntry("ModeCount", -1);
147 int Mode = cfg->readNumEntry("Mode", -1); 147 int Mode = cfg->readNumEntry("Mode", -1);
148 int SchemeCount = cfg->readNumEntry("SchemeCount"); 148 int SchemeCount = cfg->readNumEntry("SchemeCount");
149 int Scheme = cfg->readNumEntry("Scheme", -1); 149 int Scheme = cfg->readNumEntry("Scheme", -1);
150 150
151 if (SchemeCount == 0 || Scheme == -1) { 151 if (SchemeCount == 0 || Scheme == -1) {
152 QMessageBox::warning(this, tr("Configuration Error"), 152 QMessageBox::warning(this, tr("Configuration Error"),
153 tr("There are no schemes defined,\n" 153 tr("There are no schemes defined,\n"
154 "or no scheme is selected.")); 154 "or no scheme is selected."));
155 APP_CONFIG_END( cfg ); 155 APP_CONFIG_END( cfg );
156 return 0; 156 return 0;
157 } 157 }
158 158
159 connect(modesPopup, SIGNAL(activated(int)), this, SLOT(schemeChecked(int))); 159 connect(modesPopup, SIGNAL(activated(int)), this, SLOT(schemeChecked(int)));
160 modeID.resize(ModeCount > 0 ? ModeCount : 0); 160 modeID.resize(ModeCount > 0 ? ModeCount : 0);
161 161
162 if (!schemesPopup->isEmpty()) 162 if (!schemesPopup->isEmpty())
163 schemesPopup->clear(); 163 schemesPopup->clear();
164 164
165 SAVE_CONFIG_GROUP( cfg, oldgroup ); 165 SAVE_CONFIG_GROUP( cfg, oldgroup );
166 166
167 QString ModeGroup; 167 QString ModeGroup;
168 QString ModeName; 168 QString ModeName;
169 169
170 for (int m = 0; m < ModeCount; m++) { 170 for (int m = 0; m < ModeCount; m++) {
171 ModeGroup.sprintf("Mode %d", m); 171 ModeGroup.sprintf("Mode %d", m);
172 cfg->setGroup(ModeGroup); 172 cfg->setGroup(ModeGroup);
173 173
174 ModeName = cfg->readEntry("Description", ModeGroup); 174 ModeName = cfg->readEntry("Description", ModeGroup);
175 175
176 QPopupMenu *p = new QPopupMenu; 176 QPopupMenu *p = new QPopupMenu;
177 p->setCheckable(TRUE); 177 p->setCheckable(TRUE);
178 connect(p, SIGNAL(activated(int)), this, SLOT(schemeChecked(int))); 178 connect(p, SIGNAL(activated(int)), this, SLOT(schemeChecked(int)));
179 schemesPopup->append(p); 179 schemesPopup->append(p);
180 180
181 modeID[m] = modesPopup->insertItem(ModeName, schemesPopup->at(m)); 181 modeID[m] = modesPopup->insertItem(ModeName, schemesPopup->at(m));
182 modesPopup->setItemEnabled(modeID[m], FALSE); 182 modesPopup->setItemEnabled(modeID[m], FALSE);
183 modesPopup->setItemChecked(modeID[m], m == Mode); 183 modesPopup->setItemChecked(modeID[m], m == Mode);
184 } 184 }
185 185
186 schemeID.resize(SchemeCount); 186 schemeID.resize(SchemeCount);
187 schemeMode.resize(SchemeCount); 187 schemeMode.resize(SchemeCount);
188 188
189 QString SchemeGroup; 189 QString SchemeGroup;
190 QString SchemeName; 190 QString SchemeName;
191 int SchemeMode; 191 int SchemeMode;
192 192
193 for (int i = 0; i < SchemeCount; i++) { 193 for (int i = 0; i < SchemeCount; i++) {
194 SchemeGroup.sprintf("Scheme %d", i); 194 SchemeGroup.sprintf("Scheme %d", i);
195 cfg->setGroup(SchemeGroup); 195 cfg->setGroup(SchemeGroup);
196 196
197 SchemeName = cfg->readEntry("Description", SchemeGroup); 197 SchemeName = cfg->readEntry("Description", SchemeGroup);
198 SchemeMode = cfg->readNumEntry("Mode", -1); 198 SchemeMode = cfg->readNumEntry("Mode", -1);
199 199
200 schemeMode[i] = SchemeMode; 200 schemeMode[i] = SchemeMode;
201 if (SchemeMode == -1) { 201 if (SchemeMode == -1) {
202 schemeID[i] = modesPopup->insertItem(SchemeName); 202 schemeID[i] = modesPopup->insertItem(SchemeName);
203 modesPopup->setItemChecked(schemeID[i], i == Scheme); 203 modesPopup->setItemChecked(schemeID[i], i == Scheme);
204 } else { 204 } else {
205 schemeID[i] = schemesPopup->at(SchemeMode)->insertItem(SchemeName); 205 schemeID[i] = schemesPopup->at(SchemeMode)->insertItem(SchemeName);
206 schemesPopup->at(SchemeMode)-> 206 schemesPopup->at(SchemeMode)->
207 setItemChecked(schemeID[i], i == Scheme); 207 setItemChecked(schemeID[i], i == Scheme);
208 modesPopup->setItemEnabled(modeID[SchemeMode], TRUE); 208 modesPopup->setItemEnabled(modeID[SchemeMode], TRUE);
209 } 209 }
210 } 210 }
211 211
212 RESTORE_CONFIG_GROUP( cfg, oldgroup ); 212 RESTORE_CONFIG_GROUP( cfg, oldgroup );
213 213
214 APP_CONFIG_END( cfg ); 214 APP_CONFIG_END( cfg );
215 return SchemeCount; 215 return SchemeCount;
216} 216}
217 217
218void Kpacman::quitKpacman() 218void Kpacman::quitKpacman()
219{ 219{
220 APP_QUIT(); 220 APP_QUIT();
221} 221}
222 222
223void Kpacman::newKpacman() 223void Kpacman::newKpacman()
224{ 224{
225 if (!gamePopup->isItemEnabled(hofID)) 225 if (!gamePopup->isItemEnabled(hofID))
226 gamePopup->setItemEnabled(hofID, TRUE); 226 gamePopup->setItemEnabled(hofID, TRUE);
227 227
228 if (gamePopup->isItemChecked(hofID)) 228 if (gamePopup->isItemChecked(hofID))
229 toggleHallOfFame(); 229 toggleHallOfFame();
230 230
231 if (gamePopup->isItemChecked(pauseID)) 231 if (gamePopup->isItemChecked(pauseID))
232 pauseKpacman(); 232 pauseKpacman();
233 233
234 view->referee->play(); 234 view->referee->play();
235} 235}
236 236
237void Kpacman::pauseKpacman() 237void Kpacman::pauseKpacman()
238{ 238{
239 view->referee->pause(); 239 view->referee->pause();
240 view->score->setPause(gamePopup->isItemChecked(pauseID)); 240 view->score->setPause(gamePopup->isItemChecked(pauseID));
241} 241}
242 242
243void Kpacman::toggleHallOfFame() 243void Kpacman::toggleHallOfFame()
244{ 244{
245 gamePopup->setItemChecked(hofID, !gamePopup->isItemChecked(hofID)); 245 gamePopup->setItemChecked(hofID, !gamePopup->isItemChecked(hofID));
246 view->referee->toggleHallOfFame(); 246 view->referee->toggleHallOfFame();
247 247
248 if (gamePopup->isItemChecked(hofID)) { 248 if (gamePopup->isItemChecked(hofID)) {
249 view->referee->lower(); 249 view->referee->lower();
250 view->status->lower(); 250 view->status->lower();
251 } else { 251 } else {
252 view->status->raise(); 252 view->status->raise();
253 view->referee->raise(); 253 view->referee->raise();
254 view->referee->setFocus(); 254 view->referee->setFocus();
255 } 255 }
256} 256}
257 257
258/* 258/*
259 * Disable or enable the "Hall of fame"-menuitem if the referee says so. 259 * Disable or enable the "Hall of fame"-menuitem if the referee says so.
260 * This is done, to disable turning off the "hall of fame"-display, in the automated 260 * This is done, to disable turning off the "hall of fame"-display, in the automated
261 * sequence of displaying the introduction, the demonstration (or playing) and the 261 * sequence of displaying the introduction, the demonstration (or playing) and the
262 * hall of fame. 262 * hall of fame.
263 * If on == TRUE then also lower the referee and the status widgets. 263 * If on == TRUE then also lower the referee and the status widgets.
264 */ 264 */
265void Kpacman::forcedHallOfFame(bool on) 265void Kpacman::forcedHallOfFame(bool on)
266{ 266{
diff --git a/noncore/games/kpacman/kpacmanwidget.cpp b/noncore/games/kpacman/kpacmanwidget.cpp
index feb782c..cf2aed9 100644
--- a/noncore/games/kpacman/kpacmanwidget.cpp
+++ b/noncore/games/kpacman/kpacmanwidget.cpp
@@ -1,153 +1,158 @@
1 1
2#include "portable.h" 2#include "portable.h"
3 3
4#if defined( KDE2_PORT ) 4#if defined( KDE2_PORT )
5#include <kapp.h> 5#include <kapp.h>
6#include <kconfig.h> 6#include <kconfig.h>
7#include <kstddirs.h> 7#include <kstddirs.h>
8#include <kpacmanwidget.h> 8#include <kpacmanwidget.h>
9#include <kpacmanwidget.moc> 9#include <kpacmanwidget.moc>
10#elif defined( QPE_PORT ) 10#elif defined( QPE_PORT )
11#include <qpe/qpeapplication.h> 11#include <qpe/qpeapplication.h>
12#include "config.h" 12#include "config.h"
13#include "kpacmanwidget.h" 13#include "kpacmanwidget.h"
14#endif 14#endif
15 15
16#include <qmessagebox.h> 16#include <qmessagebox.h>
17 17
18#include "bitfont.h" 18#include "bitfont.h"
19#include "score.h" 19#include "score.h"
20#include "referee.h" 20#include "referee.h"
21#include "status.h" 21#include "status.h"
22 22
23KpacmanWidget::KpacmanWidget( QWidget *parent, const char *name) 23KpacmanWidget::KpacmanWidget( QWidget *parent, const char *name)
24 : QWidget( parent, name ) 24 : QWidget( parent, name )
25{ 25{
26 score = 0l;
27 referee = 0l;
28 status = 0l;
26 bitfont = NULL; 29 bitfont = NULL;
27 fontName = ""; 30 fontName = "";
28 31
29 scheme = mode = -1; 32 scheme = mode = -1;
30 confScheme(); 33 confScheme();
31 34
32 score = new Score(this, name, scheme, mode, bitfont); 35 score = new Score(this, name, scheme, mode, bitfont);
33 referee = new Referee( this, name, scheme, mode, bitfont); 36 referee = new Referee( this, name, scheme, mode, bitfont);
34 status = new Status(this, name, scheme, mode); 37 status = new Status(this, name, scheme, mode);
35 38
36 setBackgroundColor( black ); 39 setBackgroundColor( black );
37} 40}
38 41
39KpacmanWidget::~KpacmanWidget() 42KpacmanWidget::~KpacmanWidget()
40{ 43{
41} 44}
42 45
43void KpacmanWidget::confMisc(bool defGroup) 46void KpacmanWidget::confMisc(bool defGroup)
44{ 47{
45 APP_CONFIG_BEGIN( cfg ); 48 APP_CONFIG_BEGIN( cfg );
46 //KStandardDirs *dirs = KGlobal::dirs(); 49 //KStandardDirs *dirs = KGlobal::dirs();
47 QString findPath; 50 QString findPath;
48 51
49 if (defGroup || cfg->hasKey("Font")) { 52 if (defGroup || cfg->hasKey("Font")) {
50 fontName = cfg->readEntry("Font"); 53 fontName = cfg->readEntry("Font");
51 54
52 if (fontName.left(1) != "/" && fontName.left(1) != "~") 55 if (fontName.left(1) != "/" && fontName.left(1) != "~")
53 fontName.insert(0, "fonts/"); 56 fontName.insert(0, "fonts/");
54 if (fontName.right(1) == "/") 57 if (fontName.right(1) == "/")
55 fontName.append("font.xbm"); 58 fontName.append("font.xbm");
56 59
57 //findPath = dirs->findResource("appdata", fontName); 60 //findPath = dirs->findResource("appdata", fontName);
58 findPath = FIND_APP_DATA( fontName ); 61 findPath = FIND_APP_DATA( fontName );
59 if (!findPath.isEmpty()) 62 if (!findPath.isEmpty())
60 fontName = findPath; 63 fontName = findPath;
61 64
62 bitfontFirstChar = cfg->readNumEntry("FontFirstChar", 0x0e); 65 bitfontFirstChar = cfg->readNumEntry("FontFirstChar", 0x0e);
63 bitfontLastChar = cfg->readNumEntry("FontLastChar", 0x5f); 66 bitfontLastChar = cfg->readNumEntry("FontLastChar", 0x5f);
64 } 67 }
65 APP_CONFIG_END( cfg ); 68 APP_CONFIG_END( cfg );
66} 69}
67 70
68void KpacmanWidget::confScheme() 71void KpacmanWidget::confScheme()
69{ 72{
70 APP_CONFIG_BEGIN( cfg ); 73 APP_CONFIG_BEGIN( cfg );
71 QString lastFontName = fontName; 74 QString lastFontName = fontName;
72 SAVE_CONFIG_GROUP( cfg, oldgroup ); 75 SAVE_CONFIG_GROUP( cfg, oldgroup );
73 QString newgroup; 76 QString newgroup;
74 77
75 // if not set, read mode and scheme from the configfile 78 // if not set, read mode and scheme from the configfile
76 if (mode == -1 && scheme == -1) { 79 if (mode == -1 && scheme == -1) {
77 scheme = cfg->readNumEntry("Scheme", -1); 80 scheme = cfg->readNumEntry("Scheme", -1);
78 mode = cfg->readNumEntry("Mode", -1); 81 mode = cfg->readNumEntry("Mode", -1);
79 82
80 // if mode is not set in the defGroup-group, lookup the scheme group 83 // if mode is not set in the defGroup-group, lookup the scheme group
81 if (scheme != -1 || mode == -1) { 84 if (scheme != -1 || mode == -1) {
82 newgroup.sprintf("Scheme %d", scheme); 85 newgroup.sprintf("Scheme %d", scheme);
83 cfg->setGroup(newgroup); 86 cfg->setGroup(newgroup);
84 87
85 mode = cfg->readNumEntry("Mode", -1); 88 mode = cfg->readNumEntry("Mode", -1);
86 RESTORE_CONFIG_GROUP( cfg, oldgroup ); 89 RESTORE_CONFIG_GROUP( cfg, oldgroup );
87 } 90 }
88 } 91 }
89 92
90 confMisc(); 93 confMisc();
91 94
92 if (mode != -1) { 95 if (mode != -1) {
93 newgroup.sprintf("Mode %d", mode); 96 newgroup.sprintf("Mode %d", mode);
94 cfg->setGroup(newgroup); 97 cfg->setGroup(newgroup);
95 98
96 confMisc(FALSE); 99 confMisc(FALSE);
97 } 100 }
98 101
99 if (scheme != -1) { 102 if (scheme != -1) {
100 newgroup.sprintf("Scheme %d", scheme); 103 newgroup.sprintf("Scheme %d", scheme);
101 cfg->setGroup(newgroup); 104 cfg->setGroup(newgroup);
102 105
103 confMisc(FALSE); 106 confMisc(FALSE);
104 } 107 }
105 108
106 if (lastFontName != fontName) { 109 if (lastFontName != fontName) {
107 110
108 if (bitfont != 0) 111 if (bitfont != 0)
109 delete bitfont; 112 delete bitfont;
110 113
111 bitfont = new Bitfont(fontName, bitfontFirstChar, bitfontLastChar); 114 bitfont = new Bitfont(fontName, bitfontFirstChar, bitfontLastChar);
112 if (bitfont->width() == 0 || bitfont->height() == 0) { 115 if (bitfont->width() == 0 || bitfont->height() == 0) {
113 QString msg = tr("The bitfont could not be contructed.\n\n" 116 QString msg = tr("The bitfont could not be contructed.\n\n"
114 "The file '@FONTNAME@' does not exist,\n" 117 "The file '@FONTNAME@' does not exist,\n"
115 "or is of an unknown format."); 118 "or is of an unknown format.");
116 msg.replace(QRegExp("@FONTNAME@"), fontName); 119 msg.replace(QRegExp("@FONTNAME@"), fontName);
117 // QMessageBox::critical(this, tr("Initialization Error"), msg); 120 // QMessageBox::critical(this, tr("Initialization Error"), msg);
118 printf("%s\n", msg.data()); 121 printf("%s\n", msg.data());
119 } 122 }
120 } 123 }
121 124
122 RESTORE_CONFIG_GROUP( cfg, oldgroup ); 125 RESTORE_CONFIG_GROUP( cfg, oldgroup );
123 APP_CONFIG_END( cfg ); 126 APP_CONFIG_END( cfg );
124} 127}
125 128
126void KpacmanWidget::setScheme(int Scheme, int Mode) 129void KpacmanWidget::setScheme(int Scheme, int Mode)
127{ 130{
128 mode = Mode; 131 mode = Mode;
129 scheme = Scheme; 132 scheme = Scheme;
130 133
131 confScheme(); 134 confScheme();
132 135
133 score->setScheme(Scheme, Mode, bitfont); 136 score->setScheme(Scheme, Mode, bitfont);
134 referee->setScheme(Scheme, Mode, bitfont); 137 referee->setScheme(Scheme, Mode, bitfont);
135 status->setScheme(Scheme, Mode); 138 status->setScheme(Scheme, Mode);
136 139
137 score->repaint(FALSE); 140 score->repaint(FALSE);
138 referee->repaint(FALSE); 141 referee->repaint(FALSE);
139 status->repaint(FALSE); 142 status->repaint(FALSE);
140} 143}
141 144
142void KpacmanWidget::resizeEvent( QResizeEvent * ) 145void KpacmanWidget::resizeEvent( QResizeEvent * )
143{ 146{
147 qWarning("Resize");
144 referee->setGeometry(0, bitfont->height()*3, referee->width(), referee->height()); 148 referee->setGeometry(0, bitfont->height()*3, referee->width(), referee->height());
145 referee->setBackgroundColor(BLACK); 149 referee->setBackgroundColor(BLACK);
146 150
151 if(!status ) return;
147 status->setGeometry(0, bitfont->height()*3+referee->height(), referee->width(), 152 status->setGeometry(0, bitfont->height()*3+referee->height(), referee->width(),
148 status->height()); 153 status->height());
149 status->setBackgroundColor(BLACK); 154 status->setBackgroundColor(BLACK);
150 155
151 score->setGeometry(0, 0, referee->width(), bitfont->height()*3+referee->height()+status->height()); 156 score->setGeometry(0, 0, referee->width(), bitfont->height()*3+referee->height()+status->height());
152 score->setBackgroundColor(BLACK); 157 score->setBackgroundColor(BLACK);
153} 158}
diff --git a/noncore/games/kpacman/portable.h b/noncore/games/kpacman/portable.h
index ff0912b..b087be5 100644
--- a/noncore/games/kpacman/portable.h
+++ b/noncore/games/kpacman/portable.h
@@ -1,63 +1,58 @@
1/*************************************************************************** 1/***************************************************************************
2 portable.h - various bits that ease porting kpacman to other platforms. 2 portable.h - various bits that ease porting kpacman to other platforms.
3 Currently KDE2 and Qtopia ports exist. 3 Currently KDE2 and Qtopia ports exist.
4 ------------------- 4 -------------------
5 begin : Mon Mar 18 12:35:24 EET 2002 5 begin : Mon Mar 18 12:35:24 EET 2002
6 copyright : (C) 2002 by Catalin Climov 6 copyright : (C) 2002 by Catalin Climov
7 email : catalin@climov.com 7 email : catalin@climov.com
8 ***************************************************************************/ 8 ***************************************************************************/
9 9
10/*************************************************************************** 10/***************************************************************************
11 * * 11 * *
12 * This program is free software; you can redistribute it and/or modify * 12 * This program is free software; you can redistribute it and/or modify *
13 * it under the terms of the GNU General Public License as published by * 13 * it under the terms of the GNU General Public License as published by *
14 * the Free Software Foundation; either version 2 of the License, or * 14 * the Free Software Foundation; either version 2 of the License, or *
15 * (at your option) any later version. * 15 * (at your option) any later version. *
16 * * 16 * *
17 ***************************************************************************/ 17 ***************************************************************************/
18 18
19#ifndef PORTABLE_H 19#ifndef PORTABLE_H
20#define PORTABLE_H 20#define PORTABLE_H
21 21
22#ifdef QWS
23#define QPE_PORT 22#define QPE_PORT
24#else
25#define KDE2_PORT
26#define KDE_PORT
27#endif
28 23
29#if defined( KDE2_PORT ) 24#if defined( KDE2_PORT )
30 25
31#define APP kapp 26#define APP kapp
32 27
33#define APP_CONFIG_BEGIN( cfgname ) KConfig cfgname = kapp->config() 28#define APP_CONFIG_BEGIN( cfgname ) KConfig cfgname = kapp->config()
34#define APP_CONFIG_END( cfgname ) cfgname->sync() 29#define APP_CONFIG_END( cfgname ) cfgname->sync()
35#define SAVE_CONFIG_GROUP( cfgname, groupname ) QString groupname = configname->group() 30#define SAVE_CONFIG_GROUP( cfgname, groupname ) QString groupname = configname->group()
36#define RESTORE_CONFIG_GROUP( cfgname, groupname ) configname->setGroup( groupname ) 31#define RESTORE_CONFIG_GROUP( cfgname, groupname ) configname->setGroup( groupname )
37 32
38#define FIND_APP_DATA( dataname ) KGlobal::dirs()->findResource( "appdata", dataname ) 33#define FIND_APP_DATA( dataname ) KGlobal::dirs()->findResource( "appdata", dataname )
39 34
40#elif defined( QPE_PORT ) 35#elif defined( QPE_PORT )
41 36
42#define i18n( x ) x 37#define i18n( x ) x
43#define KTMainWindow QMainWindow 38#define KTMainWindow QMainWindow
44#define KMenuBar QMenuBar 39#define KMenuBar QMenuBar
45#define KAccel QAccel 40#define KAccel QAccel
46#define APP qApp 41#define APP qApp
47 42
48#define APP_CONFIG_BEGIN( cfgname ) Config* cfgname = new Config("kpacman"); cfgname->setGroup("Default"); 43#define APP_CONFIG_BEGIN( cfgname ) Config* cfgname = new Config("kpacman"); cfgname->setGroup("Default");
49#define APP_CONFIG_END( cfgname ) delete cfgname 44#define APP_CONFIG_END( cfgname ) delete cfgname
50#define SAVE_CONFIG_GROUP( cfgname, groupname ) 45#define SAVE_CONFIG_GROUP( cfgname, groupname )
51#define RESTORE_CONFIG_GROUP( cfgname, groupname ) cfgname->setGroup("Default") 46#define RESTORE_CONFIG_GROUP( cfgname, groupname ) cfgname->setGroup("Default")
52 47
53#define FIND_APP_DATA( dataname ) (QPEApplication::qpeDir()+"share/kpacman/"+dataname) 48#define FIND_APP_DATA( dataname ) (QPEApplication::qpeDir()+"share/kpacman/"+dataname)
54 49
55#else 50#else
56 51
57#error "Err, I don't know what platform to compile for (KDE2 or Qtopia)" 52#error "Err, I don't know what platform to compile for (KDE2 or Qtopia)"
58 53
59#endif 54#endif
60 55
61#define APP_QUIT() APP->quit() 56#define APP_QUIT() APP->quit()
62 57
63#endif // PORTABLE_H 58#endif // PORTABLE_H
diff --git a/noncore/games/kpacman/status.cpp b/noncore/games/kpacman/status.cpp
index 3453d37..1ef910d 100644
--- a/noncore/games/kpacman/status.cpp
+++ b/noncore/games/kpacman/status.cpp
@@ -1,152 +1,153 @@
1 1
2#include "portable.h" 2#include "portable.h"
3 3
4#if defined( KDE2_PORT ) 4#if defined( KDE2_PORT )
5#include <kapp.h> 5#include <kapp.h>
6#include <klocale.h> 6#include <klocale.h>
7#include <kstddirs.h> 7#include <kstddirs.h>
8#include <status.h> 8#include <status.h>
9#include <status.moc> 9#include <status.moc>
10#elif defined( QPE_PORT ) 10#elif defined( QPE_PORT )
11#include <qpe/qpeapplication.h> 11#include <qpe/qpeapplication.h>
12#include "config.h" 12#include "config.h"
13#include "status.h" 13#include "status.h"
14#endif 14#endif
15 15
16#include <qpixmap.h> 16#include <qpixmap.h>
17#include <qbitmap.h> 17#include <qbitmap.h>
18#include <qstring.h> 18#include <qstring.h>
19#include <qmsgbox.h> 19#include <qmsgbox.h>
20#include <qfileinfo.h> 20#include <qfileinfo.h>
21 21
22Status::Status( QWidget *parent, const char *name, int Scheme, int Mode ) : 22Status::Status( QWidget *parent, const char *name, int Scheme, int Mode ) :
23 QWidget( parent, name ) 23 QWidget( parent, name )
24{ 24{
25 qWarning("Status::Status");
25 actualLifes = 0; 26 actualLifes = 0;
26 actualLevel = 0; 27 actualLevel = 0;
27 28
28 lifesPix = NULL; 29 lifesPix = NULL;
29 levelPix = NULL; 30 levelPix = NULL;
30 31
31 scheme = Scheme; 32 scheme = Scheme;
32 mode = Mode; 33 mode = Mode;
33 level = 0; 34 level = 0;
34 35
35 confScheme(); 36 confScheme();
36} 37}
37 38
38QList<QPixmap> *Status::loadPixmap(QWidget *parent, QString pixmapName, 39QList<QPixmap> *Status::loadPixmap(QWidget *parent, QString pixmapName,
39 QList<QPixmap> *pixmaps) 40 QList<QPixmap> *pixmaps)
40{ 41{
41 if (pixmaps == NULL) { 42 if (pixmaps == NULL) {
42 pixmaps = new QList<QPixmap>; 43 pixmaps = new QList<QPixmap>;
43 pixmaps->setAutoDelete(TRUE); 44 pixmaps->setAutoDelete(TRUE);
44 } 45 }
45 46
46 if (!pixmaps->isEmpty()) 47 if (!pixmaps->isEmpty())
47 pixmaps->clear(); 48 pixmaps->clear();
48 49
49 QPixmap PIXMAP(pixmapName); 50 QPixmap PIXMAP(pixmapName);
50 if (PIXMAP.isNull() || PIXMAP.mask() == NULL) { 51 if (PIXMAP.isNull() || PIXMAP.mask() == NULL) {
51 QString msg = tr("The pixmap could not be contructed.\n\n" 52 QString msg = tr("The pixmap could not be contructed.\n\n"
52 "The file '@PIXMAPNAME@' does not exist,\n" 53 "The file '@PIXMAPNAME@' does not exist,\n"
53 "or is of an unknown format."); 54 "or is of an unknown format.");
54 msg.replace(QRegExp("@PIXMAPNAME@"), pixmapName); 55 msg.replace(QRegExp("@PIXMAPNAME@"), pixmapName);
55 QMessageBox::information(parent, tr("Initialization Error"), 56 QMessageBox::information(parent, tr("Initialization Error"),
56 (const char *) msg); 57 (const char *) msg);
57 return 0; 58 return 0;
58 } 59 }
59 60
60 int height = PIXMAP.height(); 61 int height = PIXMAP.height();
61 int width = (height == 0) ? 0 : PIXMAP.width()/(PIXMAP.width()/height); 62 int width = (height == 0) ? 0 : PIXMAP.width()/(PIXMAP.width()/height);
62 63
63 QBitmap BITMAP; 64 QBitmap BITMAP;
64 QBitmap MASK; 65 QBitmap MASK;
65 66
66 BITMAP = *PIXMAP.mask(); 67 BITMAP = *PIXMAP.mask();
67 MASK.resize(width, height); 68 MASK.resize(width, height);
68 69
69 for (int x = 0; x < PIXMAP.width()/width; x++) { 70 for (int x = 0; x < PIXMAP.width()/width; x++) {
70 QPixmap *pixmap = new QPixmap(width, height); 71 QPixmap *pixmap = new QPixmap(width, height);
71 pixmaps->append(pixmap); 72 pixmaps->append(pixmap);
72 bitBlt(pixmap, 0, 0, &PIXMAP, x*width, 0, width, height, CopyROP, TRUE); 73 bitBlt(pixmap, 0, 0, &PIXMAP, x*width, 0, width, height, CopyROP, TRUE);
73 bitBlt(&MASK, 0, 0, &BITMAP, x*width, 0, width, height, CopyROP, TRUE); 74 bitBlt(&MASK, 0, 0, &BITMAP, x*width, 0, width, height, CopyROP, TRUE);
74 pixmap->setMask(MASK); 75 pixmap->setMask(MASK);
75 } 76 }
76 77
77 return pixmaps; 78 return pixmaps;
78} 79}
79 80
80void Status::paintEvent( QPaintEvent *) 81void Status::paintEvent( QPaintEvent *)
81{ 82{
82 for (int x = 0; x < actualLifes && !lifesPix->isEmpty(); x++) 83 for (int x = 0; x < actualLifes && !lifesPix->isEmpty(); x++)
83 bitBlt(this, lifesPix->at(0)->width()+(lifesPix->at(0)->width()*x), 84 bitBlt(this, lifesPix->at(0)->width()+(lifesPix->at(0)->width()*x),
84 (height()-lifesPix->at(0)->height())/2, 85 (height()-lifesPix->at(0)->height())/2,
85 lifesPix->at(0), 0, 0, 86 lifesPix->at(0), 0, 0,
86 lifesPix->at(0)->width(), lifesPix->at(0)->height()); 87 lifesPix->at(0)->width(), lifesPix->at(0)->height());
87 88
88 for (int x = 0; x < actualLevel && !levelPix->isEmpty(); x++) { 89 for (int x = 0; x < actualLevel && !levelPix->isEmpty(); x++) {
89 erase((width()-levelPix->at(x)->width()*2)-(levelPix->at(x)->width()*levelPos[x]), 90 erase((width()-levelPix->at(x)->width()*2)-(levelPix->at(x)->width()*levelPos[x]),
90 (height()-levelPix->at(x)->height())/2, 91 (height()-levelPix->at(x)->height())/2,
91 levelPix->at(x)->width(), levelPix->at(x)->height()); 92 levelPix->at(x)->width(), levelPix->at(x)->height());
92 bitBlt(this, (width()-levelPix->at(x)->width()*2)-(levelPix->at(x)->width()*levelPos[x]), 93 bitBlt(this, (width()-levelPix->at(x)->width()*2)-(levelPix->at(x)->width()*levelPos[x]),
93 (height()-levelPix->at(x)->height())/2, 94 (height()-levelPix->at(x)->height())/2,
94 levelPix->at(x), 0, 0, 95 levelPix->at(x), 0, 0,
95 levelPix->at(x)->width(), levelPix->at(x)->height()); 96 levelPix->at(x)->width(), levelPix->at(x)->height());
96 } 97 }
97} 98}
98 99
99void Status::initPixmaps() 100void Status::initPixmaps()
100{ 101{
101 if (lastLifesPixmapName != lifesPixmapName.at(level)) { 102 if (lastLifesPixmapName != lifesPixmapName.at(level)) {
102 lifesPix = loadPixmap(this, lifesPixmapName.at(level), lifesPix); 103 lifesPix = loadPixmap(this, lifesPixmapName.at(level), lifesPix);
103 lastLifesPixmapName = lifesPixmapName.at(level); 104 lastLifesPixmapName = lifesPixmapName.at(level);
104 } 105 }
105 if (lastLevelPixmapName != levelPixmapName.at(level)) { 106 if (lastLevelPixmapName != levelPixmapName.at(level)) {
106 levelPix = loadPixmap(this, levelPixmapName.at(level), levelPix); 107 levelPix = loadPixmap(this, levelPixmapName.at(level), levelPix);
107 lastLevelPixmapName = levelPixmapName.at(level); 108 lastLevelPixmapName = levelPixmapName.at(level);
108 } 109 }
109} 110}
110 111
111QString Status::decodeHexOctString(QString s) 112QString Status::decodeHexOctString(QString s)
112{ 113{
113 QString value; 114 QString value;
114 QString valids; 115 QString valids;
115 int pos, xpos = 0, opos = 0; 116 int pos, xpos = 0, opos = 0;
116 int v, len, leadin; 117 int v, len, leadin;
117 const char *ptr; 118 const char *ptr;
118 uchar c; 119 uchar c;
119 120
120 while (((xpos = s.find(QRegExp("\\\\x[0-9a-fA-F]+"), xpos)) != -1) || 121 while (((xpos = s.find(QRegExp("\\\\x[0-9a-fA-F]+"), xpos)) != -1) ||
121 ((opos = s.find(QRegExp("\\\\[0-7]+"), opos)) != -1)) { 122 ((opos = s.find(QRegExp("\\\\[0-7]+"), opos)) != -1)) {
122 if (xpos != -1) { 123 if (xpos != -1) {
123 valids = "0123456789abcdef"; 124 valids = "0123456789abcdef";
124 leadin = 2; 125 leadin = 2;
125 pos = xpos; 126 pos = xpos;
126 } else { 127 } else {
127 valids = "01234567"; 128 valids = "01234567";
128 leadin = 1; 129 leadin = 1;
129 pos = opos; 130 pos = opos;
130 } 131 }
131 132
132 c = '\0'; 133 c = '\0';
133 len = 0; 134 len = 0;
134 value = s.mid(pos+leadin, 3); 135 value = s.mid(pos+leadin, 3);
135 ptr = (const char *) value; 136 ptr = (const char *) value;
136 137
137 while (*ptr != '\0' && (v = valids.find(*ptr++, 0, FALSE)) != -1) { 138 while (*ptr != '\0' && (v = valids.find(*ptr++, 0, FALSE)) != -1) {
138 c = (c * valids.length()) + v; 139 c = (c * valids.length()) + v;
139 len++; 140 len++;
140 } 141 }
141 142
142 value.fill(c, 1); 143 value.fill(c, 1);
143 s.replace(pos, len+leadin, value); 144 s.replace(pos, len+leadin, value);
144 } 145 }
145 146
146 return s; 147 return s;
147} 148}
148 149
149void Status::fillArray(QArray<int> &array, QString values, int max) 150void Status::fillArray(QArray<int> &array, QString values, int max)
150{ 151{
151 array.resize(max); 152 array.resize(max);
152 int last = 0; 153 int last = 0;