author | zecke <zecke> | 2003-05-14 12:08:54 (UTC) |
---|---|---|
committer | zecke <zecke> | 2003-05-14 12:08:54 (UTC) |
commit | c480b91a5afe1f259287c3c4173ec02f2b4854cb (patch) (unidiff) | |
tree | ffe59a2fc544f6067fd96065d94a877188f1ef88 | |
parent | 415a300230e10e29660b2af26a23798fd0b12e03 (diff) | |
download | opie-c480b91a5afe1f259287c3c4173ec02f2b4854cb.zip opie-c480b91a5afe1f259287c3c4173ec02f2b4854cb.tar.gz opie-c480b91a5afe1f259287c3c4173ec02f2b4854cb.tar.bz2 |
patch by Scott Bronson
kill the duplicated config.cpp and config.h file
add proper default values so that kpacman actually works
out of the box
Config wanted to read kpacman.conf but this file did only exist
globally
-rw-r--r-- | noncore/games/kpacman/config.cpp | 394 | ||||
-rw-r--r-- | noncore/games/kpacman/config.h | 74 | ||||
-rw-r--r-- | noncore/games/kpacman/keys.cpp | 4 | ||||
-rw-r--r-- | noncore/games/kpacman/kpacman.cpp | 18 | ||||
-rw-r--r-- | noncore/games/kpacman/kpacman.pro | 2 | ||||
-rw-r--r-- | noncore/games/kpacman/kpacmanwidget.cpp | 2 | ||||
-rw-r--r-- | noncore/games/kpacman/painter.cpp | 2 | ||||
-rw-r--r-- | noncore/games/kpacman/referee.cpp | 2 | ||||
-rw-r--r-- | noncore/games/kpacman/status.cpp | 4 |
9 files changed, 19 insertions, 483 deletions
diff --git a/noncore/games/kpacman/config.cpp b/noncore/games/kpacman/config.cpp deleted file mode 100644 index b9e3607..0000000 --- a/noncore/games/kpacman/config.cpp +++ b/dev/null | |||
@@ -1,394 +0,0 @@ | |||
1 | /********************************************************************** | ||
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | ||
3 | ** | ||
4 | ** This file is part of Qt Palmtop Environment. | ||
5 | ** | ||
6 | ** This file may be distributed and/or modified under the terms of the | ||
7 | ** GNU General Public License version 2 as published by the Free Software | ||
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | ||
9 | ** packaging of this file. | ||
10 | ** | ||
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | ||
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | ||
13 | ** | ||
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | ||
15 | ** | ||
16 | ** Contact info@trolltech.com if any conditions of this licensing are | ||
17 | ** not clear to you. | ||
18 | ** | ||
19 | ** $Id$ | ||
20 | ** | ||
21 | **********************************************************************/ | ||
22 | |||
23 | #include "config.h" | ||
24 | |||
25 | #include <qfile.h> | ||
26 | #include <qdir.h> | ||
27 | #include <qfileinfo.h> | ||
28 | #include <qtextstream.h> | ||
29 | #if QT_VERSION <= 230 && defined(QT_NO_CODECS) | ||
30 | #include <qtextcodec.h> | ||
31 | #endif | ||
32 | #include <stdlib.h> | ||
33 | #include <sys/stat.h> | ||
34 | #include <sys/types.h> | ||
35 | #include <fcntl.h> | ||
36 | #include <unistd.h> | ||
37 | |||
38 | /*! | ||
39 | \internal | ||
40 | */ | ||
41 | QString Config::configFilename(const QString& name, Domain d) | ||
42 | { | ||
43 | switch (d) { | ||
44 | case File: | ||
45 | return name; | ||
46 | case User: { | ||
47 | QDir dir = (QString(getenv("HOME")) + "/Settings"); | ||
48 | if ( !dir.exists() ) | ||
49 | mkdir(dir.path().local8Bit(),0700); | ||
50 | return dir.path() + "/" + name + ".conf"; | ||
51 | } | ||
52 | } | ||
53 | return name; | ||
54 | } | ||
55 | |||
56 | /*! | ||
57 | \class Config config.h | ||
58 | \brief The Config class provides for saving application cofniguration state. | ||
59 | |||
60 | You should keep a Config in existence only while you do not want others | ||
61 | to be able to change the state. There is no locking currently, but there | ||
62 | may be in the future. | ||
63 | */ | ||
64 | |||
65 | /*! | ||
66 | \enum Config::ConfigGroup | ||
67 | \internal | ||
68 | */ | ||
69 | |||
70 | /*! | ||
71 | \enum Config::Domain | ||
72 | |||
73 | \value File | ||
74 | \value User | ||
75 | |||
76 | See Config for details. | ||
77 | */ | ||
78 | |||
79 | /*! | ||
80 | Constructs a config that will load or create a configuration with the | ||
81 | given \a name in the given \a domain. | ||
82 | |||
83 | You must call setGroup() before doing much else with the Config. | ||
84 | |||
85 | In the default Domain, \e User, | ||
86 | the configuration is user-specific. \a name should not contain "/" in | ||
87 | this case, and in general should be the name of the C++ class that is | ||
88 | primarily responsible for maintaining the configuration. | ||
89 | |||
90 | In the File Domain, \a name is an absolute filename. | ||
91 | */ | ||
92 | Config::Config( const QString &name, Domain domain ) | ||
93 | : filename( configFilename(name,domain) ) | ||
94 | { | ||
95 | git = groups.end(); | ||
96 | read(); | ||
97 | |||
98 | lang = getenv("LANG"); | ||
99 | int i = lang.find("."); | ||
100 | if ( i > 0 ) | ||
101 | lang = lang.left( i ); | ||
102 | i = lang.find( "_" ); | ||
103 | if ( i > 0 ) | ||
104 | glang = lang.left(i); | ||
105 | } | ||
106 | |||
107 | /*! | ||
108 | Writes any changes to disk and destroys the in-memory object. | ||
109 | */ | ||
110 | Config::~Config() | ||
111 | { | ||
112 | if ( changed ) | ||
113 | write(); | ||
114 | } | ||
115 | |||
116 | /*! | ||
117 | Returns whether the current group has an entry called \a key. | ||
118 | */ | ||
119 | bool Config::hasKey( const QString &key ) const | ||
120 | { | ||
121 | if ( groups.end() == git ) | ||
122 | return FALSE; | ||
123 | ConfigGroup::ConstIterator it = ( *git ).find( key ); | ||
124 | return it != ( *git ).end(); | ||
125 | } | ||
126 | |||
127 | /*! | ||
128 | Sets the current group for subsequent reading and writing of | ||
129 | entries to \a gname. Grouping allows the application to partition the namespace. | ||
130 | |||
131 | This function must be called prior to any reading or writing | ||
132 | of entries. | ||
133 | |||
134 | The \a gname must not be empty. | ||
135 | */ | ||
136 | void Config::setGroup( const QString &gname ) | ||
137 | { | ||
138 | QMap< QString, ConfigGroup>::Iterator it = groups.find( gname ); | ||
139 | if ( it == groups.end() ) { | ||
140 | ConfigGroup *grp = new ConfigGroup; | ||
141 | git = groups.insert( gname, *grp ); | ||
142 | changed = TRUE; | ||
143 | return; | ||
144 | } | ||
145 | git = it; | ||
146 | } | ||
147 | |||
148 | /*! | ||
149 | Writes a (\a key, \a value) entry to the current group. | ||
150 | |||
151 | \sa readEntry() | ||
152 | */ | ||
153 | void Config::writeEntry( const QString &key, const QString &value ) | ||
154 | { | ||
155 | if ( git == groups.end() ) { | ||
156 | qWarning( "no group set" ); | ||
157 | return; | ||
158 | } | ||
159 | if ( (*git)[key] != value ) { | ||
160 | ( *git ).insert( key, value ); | ||
161 | changed = TRUE; | ||
162 | } | ||
163 | } | ||
164 | |||
165 | /*! | ||
166 | Writes a (\a key, \a num) entry to the current group. | ||
167 | |||
168 | \sa readNumEntry() | ||
169 | */ | ||
170 | void Config::writeEntry( const QString &key, int num ) | ||
171 | { | ||
172 | QString s; | ||
173 | s.setNum( num ); | ||
174 | writeEntry( key, s ); | ||
175 | } | ||
176 | |||
177 | #ifdef Q_HAS_BOOL_TYPE | ||
178 | /*! | ||
179 | Writes a (\a key, \a b) entry to the current group. | ||
180 | |||
181 | \sa readBoolEntry() | ||
182 | */ | ||
183 | void Config::writeEntry( const QString &key, bool b ) | ||
184 | { | ||
185 | QString s; | ||
186 | s.setNum( ( int )b ); | ||
187 | writeEntry( key, s ); | ||
188 | } | ||
189 | #endif | ||
190 | |||
191 | /*! | ||
192 | Writes a (\a key, \a lst) entry to the current group. The list | ||
193 | is separated by \a sep, so the strings must not contain that character. | ||
194 | |||
195 | \sa readListEntry() | ||
196 | */ | ||
197 | void Config::writeEntry( const QString &key, const QStringList &lst, const QChar &sep ) | ||
198 | { | ||
199 | QString s; | ||
200 | QStringList::ConstIterator it = lst.begin(); | ||
201 | for ( ; it != lst.end(); ++it ) | ||
202 | s += *it + sep; | ||
203 | writeEntry( key, s ); | ||
204 | } | ||
205 | |||
206 | |||
207 | |||
208 | /*! | ||
209 | Reads a string entry stored with \a key, defaulting to \a deflt if there is no entry. | ||
210 | */ | ||
211 | QString Config::readEntry( const QString &key, const QString &deflt ) | ||
212 | { | ||
213 | QString res = readEntryDirect( key+"["+lang+"]" ); | ||
214 | if ( !res.isNull() ) | ||
215 | return res; | ||
216 | if ( !glang.isEmpty() ) { | ||
217 | res = readEntryDirect( key+"["+glang+"]" ); | ||
218 | if ( !res.isNull() ) | ||
219 | return res; | ||
220 | } | ||
221 | return readEntryDirect( key, deflt ); | ||
222 | } | ||
223 | |||
224 | /*! | ||
225 | \internal | ||
226 | */ | ||
227 | QString Config::readEntryDirect( const QString &key, const QString &deflt ) | ||
228 | { | ||
229 | if ( git == groups.end() ) { | ||
230 | //qWarning( "no group set" ); | ||
231 | return deflt; | ||
232 | } | ||
233 | ConfigGroup::Iterator it = ( *git ).find( key ); | ||
234 | if ( it != ( *git ).end() ) | ||
235 | return *it; | ||
236 | else | ||
237 | return deflt; | ||
238 | } | ||
239 | |||
240 | /*! | ||
241 | Reads a numeric entry stored with \a key, defaulting to \a deflt if there is no entry. | ||
242 | */ | ||
243 | int Config::readNumEntry( const QString &key, int deflt ) | ||
244 | { | ||
245 | QString s = readEntry( key ); | ||
246 | if ( s.isEmpty() ) | ||
247 | return deflt; | ||
248 | else | ||
249 | return s.toInt(); | ||
250 | } | ||
251 | |||
252 | /*! | ||
253 | Reads a bool entry stored with \a key, defaulting to \a deflt if there is no entry. | ||
254 | */ | ||
255 | bool Config::readBoolEntry( const QString &key, bool deflt ) | ||
256 | { | ||
257 | QString s = readEntry( key ); | ||
258 | if ( s.isEmpty() ) | ||
259 | return deflt; | ||
260 | else | ||
261 | return (bool)s.toInt(); | ||
262 | } | ||
263 | |||
264 | /*! | ||
265 | Reads a string list entry stored with \a key, and with \a sep as the separator. | ||
266 | */ | ||
267 | QStringList Config::readListEntry( const QString &key, const QChar &sep ) | ||
268 | { | ||
269 | QString s = readEntry( key ); | ||
270 | if ( s.isEmpty() ) | ||
271 | return QStringList(); | ||
272 | else | ||
273 | return QStringList::split( sep, s ); | ||
274 | } | ||
275 | |||
276 | /*! | ||
277 | Removes all entries from the current group. | ||
278 | */ | ||
279 | void Config::clearGroup() | ||
280 | { | ||
281 | if ( git == groups.end() ) { | ||
282 | qWarning( "no group set" ); | ||
283 | return; | ||
284 | } | ||
285 | if ( !(*git).isEmpty() ) { | ||
286 | ( *git ).clear(); | ||
287 | changed = TRUE; | ||
288 | } | ||
289 | } | ||
290 | |||
291 | /*! | ||
292 | \internal | ||
293 | */ | ||
294 | void Config::write( const QString &fn ) | ||
295 | { | ||
296 | if ( !fn.isEmpty() ) | ||
297 | filename = fn; | ||
298 | |||
299 | QFile f( filename ); | ||
300 | if ( !f.open( IO_WriteOnly ) ) { | ||
301 | qWarning( "could not open for writing `%s'", filename.latin1() ); | ||
302 | git = groups.end(); | ||
303 | return; | ||
304 | } | ||
305 | |||
306 | QTextStream s( &f ); | ||
307 | #if QT_VERSION <= 230 && defined(QT_NO_CODECS) | ||
308 | // The below should work, but doesn't in Qt 2.3.0 | ||
309 | s.setCodec( QTextCodec::codecForMib( 106 ) ); | ||
310 | #else | ||
311 | s.setEncoding( QTextStream::UnicodeUTF8 ); | ||
312 | #endif | ||
313 | QMap< QString, ConfigGroup >::Iterator g_it = groups.begin(); | ||
314 | for ( ; g_it != groups.end(); ++g_it ) { | ||
315 | s << "[" << g_it.key() << "]" << "\n"; | ||
316 | ConfigGroup::Iterator e_it = ( *g_it ).begin(); | ||
317 | for ( ; e_it != ( *g_it ).end(); ++e_it ) | ||
318 | s << e_it.key() << " = " << *e_it << "\n"; | ||
319 | } | ||
320 | |||
321 | f.close(); | ||
322 | } | ||
323 | |||
324 | /*! | ||
325 | Returns whether the Config is in a valid state. | ||
326 | */ | ||
327 | bool Config::isValid() const | ||
328 | { | ||
329 | return groups.end() != git; | ||
330 | } | ||
331 | |||
332 | /*! | ||
333 | \internal | ||
334 | */ | ||
335 | void Config::read() | ||
336 | { | ||
337 | changed = FALSE; | ||
338 | |||
339 | if ( !QFileInfo( filename ).exists() ) { | ||
340 | git = groups.end(); | ||
341 | return; | ||
342 | } | ||
343 | |||
344 | QFile f( filename ); | ||
345 | if ( !f.open( IO_ReadOnly ) ) { | ||
346 | git = groups.end(); | ||
347 | return; | ||
348 | } | ||
349 | |||
350 | QTextStream s( &f ); | ||
351 | #if QT_VERSION <= 230 && defined(QT_NO_CODECS) | ||
352 | // The below should work, but doesn't in Qt 2.3.0 | ||
353 | s.setCodec( QTextCodec::codecForMib( 106 ) ); | ||
354 | #else | ||
355 | s.setEncoding( QTextStream::UnicodeUTF8 ); | ||
356 | #endif | ||
357 | |||
358 | QString line; | ||
359 | while ( !s.atEnd() ) { | ||
360 | line = s.readLine(); | ||
361 | if ( !parse( line ) ) { | ||
362 | git = groups.end(); | ||
363 | return; | ||
364 | } | ||
365 | } | ||
366 | |||
367 | f.close(); | ||
368 | } | ||
369 | |||
370 | /*! | ||
371 | \internal | ||
372 | */ | ||
373 | bool Config::parse( const QString &l ) | ||
374 | { | ||
375 | QString line = l.stripWhiteSpace(); | ||
376 | if ( line[ 0 ] == QChar( '[' ) ) { | ||
377 | QString gname = line; | ||
378 | gname = gname.remove( 0, 1 ); | ||
379 | if ( gname[ (int)gname.length() - 1 ] == QChar( ']' ) ) | ||
380 | gname = gname.remove( gname.length() - 1, 1 ); | ||
381 | ConfigGroup *grp = new ConfigGroup; | ||
382 | git = groups.insert( gname, *grp ); | ||
383 | } else if ( !line.isEmpty() ) { | ||
384 | if ( git == groups.end() ) | ||
385 | return FALSE; | ||
386 | int eq = line.find( '=' ); | ||
387 | if ( eq == -1 ) | ||
388 | return FALSE; | ||
389 | QString key = line.left(eq).stripWhiteSpace(); | ||
390 | QString value = line.mid(eq+1).stripWhiteSpace(); | ||
391 | ( *git ).insert( key, value ); | ||
392 | } | ||
393 | return TRUE; | ||
394 | } | ||
diff --git a/noncore/games/kpacman/config.h b/noncore/games/kpacman/config.h deleted file mode 100644 index 3c26b5d..0000000 --- a/noncore/games/kpacman/config.h +++ b/dev/null | |||
@@ -1,74 +0,0 @@ | |||
1 | /********************************************************************** | ||
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | ||
3 | ** | ||
4 | ** This file is part of Qt Designer. | ||
5 | ** | ||
6 | ** This file may be distributed and/or modified under the terms of the | ||
7 | ** GNU General Public License version 2 as published by the Free Software | ||
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | ||
9 | ** packaging of this file. | ||
10 | ** | ||
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | ||
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | ||
13 | ** | ||
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | ||
15 | ** | ||
16 | ** Contact info@trolltech.com if any conditions of this licensing are | ||
17 | ** not clear to you. | ||
18 | ** | ||
19 | **********************************************************************/ | ||
20 | |||
21 | #ifndef CONFIG_H | ||
22 | #define CONFIG_H | ||
23 | |||
24 | // ##### could use QSettings with Qt 3.0 | ||
25 | |||
26 | #include <qmap.h> | ||
27 | #include <qstringlist.h> | ||
28 | |||
29 | class ConfigPrivate; | ||
30 | class Config | ||
31 | { | ||
32 | public: | ||
33 | typedef QMap< QString, QString > ConfigGroup; | ||
34 | |||
35 | enum Domain { File, User }; | ||
36 | Config( const QString &name, Domain domain=User ); | ||
37 | ~Config(); | ||
38 | |||
39 | bool isValid() const; | ||
40 | bool hasKey( const QString &key ) const; | ||
41 | |||
42 | void setGroup( const QString &gname ); | ||
43 | void writeEntry( const QString &key, const QString &value ); | ||
44 | void writeEntry( const QString &key, int num ); | ||
45 | #ifdef Q_HAS_BOOL_TYPE | ||
46 | void writeEntry( const QString &key, bool b ); | ||
47 | #endif | ||
48 | void writeEntry( const QString &key, const QStringList &lst, const QChar &sep ); | ||
49 | |||
50 | QString readEntry( const QString &key, const QString &deflt = QString::null ); | ||
51 | QString readEntryDirect( const QString &key, const QString &deflt = QString::null ); | ||
52 | int readNumEntry( const QString &key, int deflt = -1 ); | ||
53 | bool readBoolEntry( const QString &key, bool deflt = FALSE ); | ||
54 | QStringList readListEntry( const QString &key, const QChar &sep ); | ||
55 | |||
56 | void clearGroup(); | ||
57 | |||
58 | void write( const QString &fn = QString::null ); | ||
59 | |||
60 | protected: | ||
61 | void read(); | ||
62 | bool parse( const QString &line ); | ||
63 | |||
64 | QMap< QString, ConfigGroup > groups; | ||
65 | QMap< QString, ConfigGroup >::Iterator git; | ||
66 | QString filename; | ||
67 | QString lang; | ||
68 | QString glang; | ||
69 | bool changed; | ||
70 | ConfigPrivate *d; | ||
71 | static QString configFilename(const QString& name, Domain); | ||
72 | }; | ||
73 | |||
74 | #endif | ||
diff --git a/noncore/games/kpacman/keys.cpp b/noncore/games/kpacman/keys.cpp index 8b17785..07ce135 100644 --- a/noncore/games/kpacman/keys.cpp +++ b/noncore/games/kpacman/keys.cpp | |||
@@ -1,203 +1,205 @@ | |||
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 <klocale.h> | 7 | #include <klocale.h> |
8 | #include <kstddirs.h> | 8 | #include <kstddirs.h> |
9 | #include <kaccel.h> | 9 | #include <kaccel.h> |
10 | 10 | ||
11 | #include <keys.h> | 11 | #include <keys.h> |
12 | #include <keys.moc> | 12 | #include <keys.moc> |
13 | #elif defined( QPE_PORT ) | 13 | #elif defined( QPE_PORT ) |
14 | #include <qaccel.h> | 14 | #include <qaccel.h> |
15 | #include <qpe/qpeapplication.h> | 15 | #include <qpe/qpeapplication.h> |
16 | #include "config.h" | 16 | #include <qpe/config.h> |
17 | #include "keys.h" | 17 | #include "keys.h" |
18 | #endif | 18 | #endif |
19 | 19 | ||
20 | #include <qpushbt.h> | 20 | #include <qpushbt.h> |
21 | #include <qlabel.h> | 21 | #include <qlabel.h> |
22 | #include <qframe.h> | 22 | #include <qframe.h> |
23 | #include <qkeycode.h> | 23 | #include <qkeycode.h> |
24 | #include <qpixmap.h> | 24 | #include <qpixmap.h> |
25 | #include <qstring.h> | 25 | #include <qstring.h> |
26 | 26 | ||
27 | Keys::Keys( QWidget *parent, const char *name) | 27 | Keys::Keys( QWidget *parent, const char *name) |
28 | : QDialog( parent, name, TRUE ) | 28 | : QDialog( parent, name, TRUE ) |
29 | { | 29 | { |
30 | //KStandardDirs *dirs = KGlobal::dirs(); | 30 | //KStandardDirs *dirs = KGlobal::dirs(); |
31 | 31 | ||
32 | QPushButton *okButton = new QPushButton(this); | 32 | QPushButton *okButton = new QPushButton(this); |
33 | okButton->setText(tr("Ok")); | 33 | okButton->setText(tr("Ok")); |
34 | okButton->setFixedSize(okButton->size()); | 34 | okButton->setFixedSize(okButton->size()); |
35 | connect( okButton, SIGNAL(clicked()),this, SLOT(ok()) ); | 35 | connect( okButton, SIGNAL(clicked()),this, SLOT(ok()) ); |
36 | okButton->move(20,210); | 36 | okButton->move(20,210); |
37 | 37 | ||
38 | QPushButton *defaultButton = new QPushButton(this); | 38 | QPushButton *defaultButton = new QPushButton(this); |
39 | defaultButton->setText(tr("Defaults")); | 39 | defaultButton->setText(tr("Defaults")); |
40 | defaultButton->setFixedSize(defaultButton->size()); | 40 | defaultButton->setFixedSize(defaultButton->size()); |
41 | connect( defaultButton, SIGNAL(clicked()),this, SLOT(defaults()) ); | 41 | connect( defaultButton, SIGNAL(clicked()),this, SLOT(defaults()) ); |
42 | defaultButton->move(140,210); | 42 | defaultButton->move(140,210); |
43 | 43 | ||
44 | QPushButton *cancelButton = new QPushButton(this); | 44 | QPushButton *cancelButton = new QPushButton(this); |
45 | cancelButton->setText(tr("Cancel")); | 45 | cancelButton->setText(tr("Cancel")); |
46 | cancelButton->setFixedSize(cancelButton->size()); | 46 | cancelButton->setFixedSize(cancelButton->size()); |
47 | connect( cancelButton, SIGNAL(clicked()),this, SLOT(reject()) ); | 47 | connect( cancelButton, SIGNAL(clicked()),this, SLOT(reject()) ); |
48 | cancelButton->move(260,210); | 48 | cancelButton->move(260,210); |
49 | 49 | ||
50 | QFrame *separator = new QFrame(this); | 50 | QFrame *separator = new QFrame(this); |
51 | separator->setFrameStyle( QFrame::HLine | QFrame::Sunken ); | 51 | separator->setFrameStyle( QFrame::HLine | QFrame::Sunken ); |
52 | separator->setGeometry( 20, 190, 340, 4 ); | 52 | separator->setGeometry( 20, 190, 340, 4 ); |
53 | 53 | ||
54 | for ( int x = 0; x < 4; x++) { | 54 | for ( int x = 0; x < 4; x++) { |
55 | QLabel *l = new QLabel(this); | 55 | QLabel *l = new QLabel(this); |
56 | l->setAlignment(AlignCenter); | 56 | l->setAlignment(AlignCenter); |
57 | labels[x] = l; | 57 | labels[x] = l; |
58 | } | 58 | } |
59 | 59 | ||
60 | labels[0]->setGeometry(120, 20, 140, 20 ); | 60 | labels[0]->setGeometry(120, 20, 140, 20 ); |
61 | labels[1]->setGeometry(120,160, 140, 20 ); | 61 | labels[1]->setGeometry(120,160, 140, 20 ); |
62 | labels[2]->setGeometry( 20, 92, 100, 20 ); | 62 | labels[2]->setGeometry( 20, 92, 100, 20 ); |
63 | labels[3]->setGeometry(265, 92, 100, 20 ); | 63 | labels[3]->setGeometry(265, 92, 100, 20 ); |
64 | 64 | ||
65 | QString pixPath; | 65 | QString pixPath; |
66 | 66 | ||
67 | QPushButton *up = new QPushButton(this); | 67 | QPushButton *up = new QPushButton(this); |
68 | pixPath = FIND_APP_DATA( "pics/up.xpm" ); | 68 | pixPath = FIND_APP_DATA( "pics/up.xpm" ); |
69 | up->setPixmap( QPixmap(pixPath)); | 69 | up->setPixmap( QPixmap(pixPath)); |
70 | up->setFixedSize(up->pixmap()->size()); | 70 | up->setFixedSize(up->pixmap()->size()); |
71 | connect( up, SIGNAL(clicked()),this, SLOT(butUp()) ); | 71 | connect( up, SIGNAL(clicked()),this, SLOT(butUp()) ); |
72 | up->move(180, 50); | 72 | up->move(180, 50); |
73 | 73 | ||
74 | QPushButton *down = new QPushButton(this); | 74 | QPushButton *down = new QPushButton(this); |
75 | pixPath = FIND_APP_DATA( "pics/down.xpm"); | 75 | pixPath = FIND_APP_DATA( "pics/down.xpm"); |
76 | down->setPixmap( QPixmap(pixPath)); | 76 | down->setPixmap( QPixmap(pixPath)); |
77 | down->setFixedSize(down->pixmap()->size()); | 77 | down->setFixedSize(down->pixmap()->size()); |
78 | connect( down, SIGNAL(clicked()),this, SLOT(butDown()) ); | 78 | connect( down, SIGNAL(clicked()),this, SLOT(butDown()) ); |
79 | down->move(180, 130); | 79 | down->move(180, 130); |
80 | 80 | ||
81 | QPushButton *left = new QPushButton(this); | 81 | QPushButton *left = new QPushButton(this); |
82 | pixPath = FIND_APP_DATA( "pics/left.xpm"); | 82 | pixPath = FIND_APP_DATA( "pics/left.xpm"); |
83 | left->setPixmap( QPixmap(pixPath)); | 83 | left->setPixmap( QPixmap(pixPath)); |
84 | left->setFixedSize(left->pixmap()->size()); | 84 | left->setFixedSize(left->pixmap()->size()); |
85 | connect( left, SIGNAL(clicked()),this, SLOT(butLeft()) ); | 85 | connect( left, SIGNAL(clicked()),this, SLOT(butLeft()) ); |
86 | left->move(140, 90); | 86 | left->move(140, 90); |
87 | 87 | ||
88 | QPushButton *right = new QPushButton(this); | 88 | QPushButton *right = new QPushButton(this); |
89 | pixPath = FIND_APP_DATA( "pics/right.xpm"); | 89 | pixPath = FIND_APP_DATA( "pics/right.xpm"); |
90 | right->setPixmap( QPixmap(pixPath)); | 90 | right->setPixmap( QPixmap(pixPath)); |
91 | right->setFixedSize(right->pixmap()->size()); | 91 | right->setFixedSize(right->pixmap()->size()); |
92 | connect( right, SIGNAL(clicked()),this, SLOT(butRight()) ); | 92 | connect( right, SIGNAL(clicked()),this, SLOT(butRight()) ); |
93 | right->move(220, 90); | 93 | right->move(220, 90); |
94 | 94 | ||
95 | 95 | ||
96 | setCaption(tr("Change Direction Keys")); | 96 | setCaption(tr("Change Direction Keys")); |
97 | setFixedSize(380, 260); | 97 | setFixedSize(380, 260); |
98 | lab = 0; | 98 | lab = 0; |
99 | init(); | 99 | init(); |
100 | } | 100 | } |
101 | 101 | ||
102 | void Keys::keyPressEvent( QKeyEvent *e ) | 102 | void Keys::keyPressEvent( QKeyEvent *e ) |
103 | { | 103 | { |
104 | uint kCode = e->key() & ~(SHIFT | CTRL | ALT); | 104 | uint kCode = e->key() & ~(SHIFT | CTRL | ALT); |
105 | QString string = KAccel::keyToString(kCode); | 105 | QString string = KAccel::keyToString(kCode); |
106 | 106 | ||
107 | if (lab != 0) { | 107 | if (lab != 0) { |
108 | if ( string.isNull() ) | 108 | if ( string.isNull() ) |
109 | lab->setText(tr("Undefined key")); | 109 | lab->setText(tr("Undefined key")); |
110 | else | 110 | else |
111 | lab->setText(string); | 111 | lab->setText(string); |
112 | } | 112 | } |
113 | else if ( lab == 0 && e->key() == Key_Escape) | 113 | else if ( lab == 0 && e->key() == Key_Escape) |
114 | reject(); | 114 | reject(); |
115 | } | 115 | } |
116 | 116 | ||
117 | void Keys::butUp() | 117 | void Keys::butUp() |
118 | { | 118 | { |
119 | getKey(0); | 119 | getKey(0); |
120 | } | 120 | } |
121 | 121 | ||
122 | void Keys::butDown() | 122 | void Keys::butDown() |
123 | { | 123 | { |
124 | getKey(1); | 124 | getKey(1); |
125 | } | 125 | } |
126 | 126 | ||
127 | void Keys::butLeft() | 127 | void Keys::butLeft() |
128 | { | 128 | { |
129 | getKey(2); | 129 | getKey(2); |
130 | } | 130 | } |
131 | 131 | ||
132 | void Keys::butRight() | 132 | void Keys::butRight() |
133 | { | 133 | { |
134 | getKey(3); | 134 | getKey(3); |
135 | } | 135 | } |
136 | 136 | ||
137 | void Keys::getKey(int i) | 137 | void Keys::getKey(int i) |
138 | { | 138 | { |
139 | if ( lab != 0) | 139 | if ( lab != 0) |
140 | focusOut(lab); | 140 | focusOut(lab); |
141 | 141 | ||
142 | focusIn(labels[i]); | 142 | focusIn(labels[i]); |
143 | } | 143 | } |
144 | 144 | ||
145 | void Keys::focusOut(QLabel *l) | 145 | void Keys::focusOut(QLabel *l) |
146 | { | 146 | { |
147 | l->setFrameStyle( QFrame::NoFrame ); | 147 | l->setFrameStyle( QFrame::NoFrame ); |
148 | l->setBackgroundColor(backgroundColor()); | 148 | l->setBackgroundColor(backgroundColor()); |
149 | l->repaint(); | 149 | l->repaint(); |
150 | } | 150 | } |
151 | 151 | ||
152 | void Keys::focusIn(QLabel *l) | 152 | void Keys::focusIn(QLabel *l) |
153 | { | 153 | { |
154 | lab = l; | 154 | lab = l; |
155 | lab->setFrameStyle( QFrame::Panel | QFrame::Sunken ); | 155 | lab->setFrameStyle( QFrame::Panel | QFrame::Sunken ); |
156 | lab->setBackgroundColor(white); | 156 | lab->setBackgroundColor(white); |
157 | lab->repaint(); | 157 | lab->repaint(); |
158 | } | 158 | } |
159 | 159 | ||
160 | void Keys::defaults() | 160 | void Keys::defaults() |
161 | { | 161 | { |
162 | if ( lab != 0) | 162 | if ( lab != 0) |
163 | focusOut(lab); | 163 | focusOut(lab); |
164 | 164 | ||
165 | lab = 0; | 165 | lab = 0; |
166 | 166 | ||
167 | labels[0]->setText("Up"); | 167 | labels[0]->setText("Up"); |
168 | labels[1]->setText("Down"); | 168 | labels[1]->setText("Down"); |
169 | labels[2]->setText("Left"); | 169 | labels[2]->setText("Left"); |
170 | labels[3]->setText("Right"); | 170 | labels[3]->setText("Right"); |
171 | } | 171 | } |
172 | 172 | ||
173 | void Keys::init() | 173 | void Keys::init() |
174 | { | 174 | { |
175 | APP_CONFIG_BEGIN( cfg ); | 175 | APP_CONFIG_BEGIN( cfg ); |
176 | QString up("Up"); | 176 | QString up("Up"); |
177 | up = cfg->readEntry("upKey", (const char*) up); | 177 | up = cfg->readEntry("upKey", (const char*) up); |
178 | labels[0]->setText(up); | 178 | labels[0]->setText(up); |
179 | 179 | ||
180 | QString down("Down"); | 180 | QString down("Down"); |
181 | down = cfg->readEntry("downKey", (const char*) down); | 181 | down = cfg->readEntry("downKey", (const char*) down); |
182 | labels[1]->setText(down); | 182 | labels[1]->setText(down); |
183 | 183 | ||
184 | QString left("Left"); | 184 | QString left("Left"); |
185 | left = cfg->readEntry("leftKey", (const char*) left); | 185 | left = cfg->readEntry("leftKey", (const char*) left); |
186 | labels[2]->setText(left); | 186 | labels[2]->setText(left); |
187 | 187 | ||
188 | QString right("Right"); | 188 | QString right("Right"); |
189 | right = cfg->readEntry("rightKey", (const char*) right); | 189 | right = cfg->readEntry("rightKey", (const char*) right); |
190 | labels[3]->setText(right); | 190 | labels[3]->setText(right); |
191 | APP_CONFIG_END( cfg ); | 191 | APP_CONFIG_END( cfg ); |
192 | } | 192 | } |
193 | 193 | ||
194 | void Keys::ok() | 194 | void Keys::ok() |
195 | { | 195 | { |
196 | /* | ||
196 | APP_CONFIG_BEGIN( cfg ); | 197 | APP_CONFIG_BEGIN( cfg ); |
197 | cfg->writeEntry("upKey", (const char*) labels[0]->text() ); | 198 | cfg->writeEntry("upKey", (const char*) labels[0]->text() ); |
198 | cfg->writeEntry("downKey", (const char*) labels[1]->text() ); | 199 | cfg->writeEntry("downKey", (const char*) labels[1]->text() ); |
199 | cfg->writeEntry("leftKey", (const char*) labels[2]->text() ); | 200 | cfg->writeEntry("leftKey", (const char*) labels[2]->text() ); |
200 | cfg->writeEntry("rightKey",(const char*) labels[3]->text() ); | 201 | cfg->writeEntry("rightKey",(const char*) labels[3]->text() ); |
201 | APP_CONFIG_END( cfg ); | 202 | APP_CONFIG_END( cfg ); |
203 | */ | ||
202 | accept(); | 204 | accept(); |
203 | } | 205 | } |
diff --git a/noncore/games/kpacman/kpacman.cpp b/noncore/games/kpacman/kpacman.cpp index aee8eea..812e9ea 100644 --- a/noncore/games/kpacman/kpacman.cpp +++ b/noncore/games/kpacman/kpacman.cpp | |||
@@ -1,364 +1,368 @@ | |||
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 <qpe/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 | ||
21 | Kpacman::Kpacman(QWidget *parent, const char *name) | 21 | Kpacman::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 | ||
71 | Kpacman::~Kpacman() | 71 | Kpacman::~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 | */ | ||
78 | delete _menuBar; | 79 | delete _menuBar; |
79 | } | 80 | } |
80 | 81 | ||
81 | void Kpacman::menu() | 82 | void Kpacman::menu() |
82 | { | 83 | { |
83 | gamePopup = new QPopupMenu(); | 84 | gamePopup = new QPopupMenu(); |
84 | CHECK_PTR( gamePopup ); | 85 | CHECK_PTR( gamePopup ); |
85 | newID = gamePopup->insertItem(tr("&New"), this, SLOT(newKpacman()),Key_F2); | 86 | newID = gamePopup->insertItem(tr("&New"), this, SLOT(newKpacman()),Key_F2); |
86 | pauseID = gamePopup->insertItem(tr("&Pause"), | 87 | pauseID = gamePopup->insertItem(tr("&Pause"), |
87 | this, SLOT(pauseKpacman()), Key_F3); | 88 | this, SLOT(pauseKpacman()), Key_F3); |
88 | hofID = gamePopup->insertItem(tr("&Hall of fame"), | 89 | hofID = gamePopup->insertItem(tr("&Hall of fame"), |
89 | this, SLOT(toggleHallOfFame()), Key_F4); | 90 | this, SLOT(toggleHallOfFame()), Key_F4); |
90 | gamePopup->insertSeparator(); | 91 | gamePopup->insertSeparator(); |
91 | gamePopup->insertItem(tr("&Quit"), this, SLOT(quitKpacman()), CTRL+Key_Q); | 92 | gamePopup->insertItem(tr("&Quit"), this, SLOT(quitKpacman()), CTRL+Key_Q); |
92 | gamePopup->setCheckable(TRUE); | 93 | gamePopup->setCheckable(TRUE); |
93 | 94 | ||
94 | optionsPopup = new QPopupMenu(); | 95 | optionsPopup = new QPopupMenu(); |
95 | CHECK_PTR(optionsPopup); | 96 | CHECK_PTR(optionsPopup); |
96 | 97 | ||
97 | modesPopup = new QPopupMenu(); | 98 | modesPopup = new QPopupMenu(); |
98 | CHECK_PTR(modesPopup); | 99 | CHECK_PTR(modesPopup); |
99 | 100 | ||
100 | hideMouseCursorID = optionsPopup->insertItem(tr("&Hide Mousecursor"), | 101 | hideMouseCursorID = optionsPopup->insertItem(tr("&Hide Mousecursor"), |
101 | this, SLOT(toggleHideMouseCursor()), | 102 | this, SLOT(toggleHideMouseCursor()), |
102 | CTRL+Key_H); | 103 | CTRL+Key_H); |
103 | optionsPopup->insertSeparator(); | 104 | optionsPopup->insertSeparator(); |
104 | 105 | ||
105 | if (lookupSchemes() > 0) { | 106 | if (lookupSchemes() > 0) { |
106 | optionsPopup->insertItem(tr("&Select graphic scheme"), modesPopup); | 107 | optionsPopup->insertItem(tr("&Select graphic scheme"), modesPopup); |
107 | optionsPopup->insertSeparator(); | 108 | optionsPopup->insertSeparator(); |
108 | } | 109 | } |
109 | 110 | ||
110 | focusOutPauseID = optionsPopup->insertItem(tr("&Pause in Background"), | 111 | focusOutPauseID = optionsPopup->insertItem(tr("&Pause in Background"), |
111 | this, SLOT(toggleFocusOutPause())); | 112 | this, SLOT(toggleFocusOutPause())); |
112 | focusInContinueID = optionsPopup->insertItem(tr("&Continue in Foreground"), | 113 | focusInContinueID = optionsPopup->insertItem(tr("&Continue in Foreground"), |
113 | this, SLOT(toggleFocusInContinue())); | 114 | this, SLOT(toggleFocusInContinue())); |
114 | optionsPopup->insertSeparator(); | 115 | optionsPopup->insertSeparator(); |
115 | 116 | ||
116 | optionsPopup->insertItem(tr("Change &keys..."), this, SLOT(confKeys())); | 117 | optionsPopup->insertItem(tr("Change &keys..."), this, SLOT(confKeys())); |
117 | 118 | ||
118 | #ifndef QPE_PORT | 119 | #ifndef QPE_PORT |
119 | QString aboutText = tr("@PACKAGE@ - @VERSION@\n\n" | 120 | QString aboutText = tr("@PACKAGE@ - @VERSION@\n\n" |
120 | "Joerg Thoennissen (joe@dsite.de)\n\n" | 121 | "Joerg Thoennissen (joe@dsite.de)\n\n" |
121 | "A pacman game for the KDE Desktop\n\n" | 122 | "A pacman game for the KDE Desktop\n\n" |
122 | "The program based on the source of ksnake\n" | 123 | "The program based on the source of ksnake\n" |
123 | "by Michel Filippi (mfilippi@sade.rhein-main.de).\n" | 124 | "by Michel Filippi (mfilippi@sade.rhein-main.de).\n" |
124 | "The design was strongly influenced by the pacman\n" | 125 | "The design was strongly influenced by the pacman\n" |
125 | "(c) 1980 MIDWAY MFG.CO.\n\n" | 126 | "(c) 1980 MIDWAY MFG.CO.\n\n" |
126 | "I like to thank my girlfriend Elke Krueers for\n" | 127 | "I like to thank my girlfriend Elke Krueers for\n" |
127 | "the last 10 years of her friendship.\n"); | 128 | "the last 10 years of her friendship.\n"); |
128 | aboutText.replace(QRegExp("@PACKAGE@"), PACKAGE); | 129 | aboutText.replace(QRegExp("@PACKAGE@"), PACKAGE); |
129 | aboutText.replace(QRegExp("@VERSION@"), VERSION); | 130 | aboutText.replace(QRegExp("@VERSION@"), VERSION); |
130 | QPopupMenu *helpPopup = helpMenu(aboutText, FALSE); | 131 | QPopupMenu *helpPopup = helpMenu(aboutText, FALSE); |
131 | #endif | 132 | #endif |
132 | 133 | ||
133 | //_menuBar = new KMenuBar(this); | 134 | //_menuBar = new KMenuBar(this); |
134 | //CHECK_PTR( _menuBar ); | 135 | //CHECK_PTR( _menuBar ); |
135 | //_menuBar->insertItem(tr("&Game"), gamePopup); | 136 | //_menuBar->insertItem(tr("&Game"), gamePopup); |
136 | //_menuBar->insertItem(tr("&Options"), optionsPopup); | 137 | //_menuBar->insertItem(tr("&Options"), optionsPopup); |
137 | //_menuBar->insertSeparator(); | 138 | //_menuBar->insertSeparator(); |
138 | #ifndef QPE_PORT | 139 | #ifndef QPE_PORT |
139 | _menuBar->insertItem(tr("&Help"), helpPopup); | 140 | _menuBar->insertItem(tr("&Help"), helpPopup); |
140 | #endif | 141 | #endif |
141 | } | 142 | } |
142 | 143 | ||
143 | int Kpacman::lookupSchemes() | 144 | int Kpacman::lookupSchemes() |
144 | { | 145 | { |
145 | APP_CONFIG_BEGIN( cfg ); | 146 | APP_CONFIG_BEGIN( cfg ); |
146 | int ModeCount = cfg->readNumEntry("ModeCount", -1); | 147 | int ModeCount = cfg->readNumEntry("ModeCount", 0); |
147 | int Mode = cfg->readNumEntry("Mode", -1); | 148 | int Mode = cfg->readNumEntry("Mode", 0); |
148 | int SchemeCount = cfg->readNumEntry("SchemeCount"); | 149 | int SchemeCount = cfg->readNumEntry("SchemeCount", 0); |
149 | int Scheme = cfg->readNumEntry("Scheme", -1); | 150 | int Scheme = cfg->readNumEntry("Scheme", 0); |
150 | 151 | ||
152 | /* | ||
151 | if (SchemeCount == 0 || Scheme == -1) { | 153 | if (SchemeCount == 0 || Scheme == -1) { |
152 | QMessageBox::warning(this, tr("Configuration Error"), | 154 | QMessageBox::warning(this, tr("Configuration Error"), |
153 | tr("There are no schemes defined,\n" | 155 | tr("There are no schemes defined,\n" |
154 | "or no scheme is selected.")); | 156 | "or no scheme is selected.")); |
155 | APP_CONFIG_END( cfg ); | 157 | APP_CONFIG_END( cfg ); |
156 | return 0; | 158 | return 0; |
157 | } | 159 | } |
160 | */ | ||
158 | 161 | ||
159 | connect(modesPopup, SIGNAL(activated(int)), this, SLOT(schemeChecked(int))); | 162 | connect(modesPopup, SIGNAL(activated(int)), this, SLOT(schemeChecked(int))); |
160 | modeID.resize(ModeCount > 0 ? ModeCount : 0); | 163 | modeID.resize(ModeCount > 0 ? ModeCount : 0); |
161 | 164 | ||
162 | if (!schemesPopup->isEmpty()) | 165 | if (!schemesPopup->isEmpty()) |
163 | schemesPopup->clear(); | 166 | schemesPopup->clear(); |
164 | 167 | ||
165 | SAVE_CONFIG_GROUP( cfg, oldgroup ); | 168 | SAVE_CONFIG_GROUP( cfg, oldgroup ); |
166 | 169 | ||
167 | QString ModeGroup; | 170 | QString ModeGroup; |
168 | QString ModeName; | 171 | QString ModeName; |
169 | 172 | ||
170 | for (int m = 0; m < ModeCount; m++) { | 173 | for (int m = 0; m < ModeCount; m++) { |
171 | ModeGroup.sprintf("Mode %d", m); | 174 | ModeGroup.sprintf("Mode %d", m); |
172 | cfg->setGroup(ModeGroup); | 175 | cfg->setGroup(ModeGroup); |
173 | 176 | ||
174 | ModeName = cfg->readEntry("Description", ModeGroup); | 177 | ModeName = cfg->readEntry("Description", ModeGroup); |
175 | 178 | ||
176 | QPopupMenu *p = new QPopupMenu; | 179 | QPopupMenu *p = new QPopupMenu; |
177 | p->setCheckable(TRUE); | 180 | p->setCheckable(TRUE); |
178 | connect(p, SIGNAL(activated(int)), this, SLOT(schemeChecked(int))); | 181 | connect(p, SIGNAL(activated(int)), this, SLOT(schemeChecked(int))); |
179 | schemesPopup->append(p); | 182 | schemesPopup->append(p); |
180 | 183 | ||
181 | modeID[m] = modesPopup->insertItem(ModeName, schemesPopup->at(m)); | 184 | modeID[m] = modesPopup->insertItem(ModeName, schemesPopup->at(m)); |
182 | modesPopup->setItemEnabled(modeID[m], FALSE); | 185 | modesPopup->setItemEnabled(modeID[m], FALSE); |
183 | modesPopup->setItemChecked(modeID[m], m == Mode); | 186 | modesPopup->setItemChecked(modeID[m], m == Mode); |
184 | } | 187 | } |
185 | 188 | ||
186 | schemeID.resize(SchemeCount); | 189 | schemeID.resize(SchemeCount); |
187 | schemeMode.resize(SchemeCount); | 190 | schemeMode.resize(SchemeCount); |
188 | 191 | ||
189 | QString SchemeGroup; | 192 | QString SchemeGroup; |
190 | QString SchemeName; | 193 | QString SchemeName; |
191 | int SchemeMode; | 194 | int SchemeMode; |
192 | 195 | ||
193 | for (int i = 0; i < SchemeCount; i++) { | 196 | for (int i = 0; i < SchemeCount; i++) { |
194 | SchemeGroup.sprintf("Scheme %d", i); | 197 | SchemeGroup.sprintf("Scheme %d", i); |
195 | cfg->setGroup(SchemeGroup); | 198 | cfg->setGroup(SchemeGroup); |
196 | 199 | ||
197 | SchemeName = cfg->readEntry("Description", SchemeGroup); | 200 | SchemeName = cfg->readEntry("Description", SchemeGroup); |
198 | SchemeMode = cfg->readNumEntry("Mode", -1); | 201 | SchemeMode = cfg->readNumEntry("Mode", -1); |
199 | 202 | ||
200 | schemeMode[i] = SchemeMode; | 203 | schemeMode[i] = SchemeMode; |
201 | if (SchemeMode == -1) { | 204 | if (SchemeMode == -1) { |
202 | schemeID[i] = modesPopup->insertItem(SchemeName); | 205 | schemeID[i] = modesPopup->insertItem(SchemeName); |
203 | modesPopup->setItemChecked(schemeID[i], i == Scheme); | 206 | modesPopup->setItemChecked(schemeID[i], i == Scheme); |
204 | } else { | 207 | } else { |
205 | schemeID[i] = schemesPopup->at(SchemeMode)->insertItem(SchemeName); | 208 | schemeID[i] = schemesPopup->at(SchemeMode)->insertItem(SchemeName); |
206 | schemesPopup->at(SchemeMode)-> | 209 | schemesPopup->at(SchemeMode)-> |
207 | setItemChecked(schemeID[i], i == Scheme); | 210 | setItemChecked(schemeID[i], i == Scheme); |
208 | modesPopup->setItemEnabled(modeID[SchemeMode], TRUE); | 211 | modesPopup->setItemEnabled(modeID[SchemeMode], TRUE); |
209 | } | 212 | } |
210 | } | 213 | } |
211 | 214 | ||
212 | RESTORE_CONFIG_GROUP( cfg, oldgroup ); | 215 | RESTORE_CONFIG_GROUP( cfg, oldgroup ); |
213 | 216 | ||
214 | APP_CONFIG_END( cfg ); | 217 | APP_CONFIG_END( cfg ); |
215 | return SchemeCount; | 218 | return SchemeCount; |
216 | } | 219 | } |
217 | 220 | ||
218 | void Kpacman::quitKpacman() | 221 | void Kpacman::quitKpacman() |
219 | { | 222 | { |
220 | APP_QUIT(); | 223 | APP_QUIT(); |
221 | } | 224 | } |
222 | 225 | ||
223 | void Kpacman::newKpacman() | 226 | void Kpacman::newKpacman() |
224 | { | 227 | { |
225 | if (!gamePopup->isItemEnabled(hofID)) | 228 | if (!gamePopup->isItemEnabled(hofID)) |
226 | gamePopup->setItemEnabled(hofID, TRUE); | 229 | gamePopup->setItemEnabled(hofID, TRUE); |
227 | 230 | ||
228 | if (gamePopup->isItemChecked(hofID)) | 231 | if (gamePopup->isItemChecked(hofID)) |
229 | toggleHallOfFame(); | 232 | toggleHallOfFame(); |
230 | 233 | ||
231 | if (gamePopup->isItemChecked(pauseID)) | 234 | if (gamePopup->isItemChecked(pauseID)) |
232 | pauseKpacman(); | 235 | pauseKpacman(); |
233 | 236 | ||
234 | view->referee->play(); | 237 | view->referee->play(); |
235 | } | 238 | } |
236 | 239 | ||
237 | void Kpacman::pauseKpacman() | 240 | void Kpacman::pauseKpacman() |
238 | { | 241 | { |
239 | view->referee->pause(); | 242 | view->referee->pause(); |
240 | view->score->setPause(gamePopup->isItemChecked(pauseID)); | 243 | view->score->setPause(gamePopup->isItemChecked(pauseID)); |
241 | } | 244 | } |
242 | 245 | ||
243 | void Kpacman::toggleHallOfFame() | 246 | void Kpacman::toggleHallOfFame() |
244 | { | 247 | { |
245 | gamePopup->setItemChecked(hofID, !gamePopup->isItemChecked(hofID)); | 248 | gamePopup->setItemChecked(hofID, !gamePopup->isItemChecked(hofID)); |
246 | view->referee->toggleHallOfFame(); | 249 | view->referee->toggleHallOfFame(); |
247 | 250 | ||
248 | if (gamePopup->isItemChecked(hofID)) { | 251 | if (gamePopup->isItemChecked(hofID)) { |
249 | view->referee->lower(); | 252 | view->referee->lower(); |
250 | view->status->lower(); | 253 | view->status->lower(); |
251 | } else { | 254 | } else { |
252 | view->status->raise(); | 255 | view->status->raise(); |
253 | view->referee->raise(); | 256 | view->referee->raise(); |
254 | view->referee->setFocus(); | 257 | view->referee->setFocus(); |
255 | } | 258 | } |
256 | } | 259 | } |
257 | 260 | ||
258 | /* | 261 | /* |
259 | * Disable or enable the "Hall of fame"-menuitem if the referee says so. | 262 | * 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 | 263 | * 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 | 264 | * sequence of displaying the introduction, the demonstration (or playing) and the |
262 | * hall of fame. | 265 | * hall of fame. |
263 | * If on == TRUE then also lower the referee and the status widgets. | 266 | * If on == TRUE then also lower the referee and the status widgets. |
264 | */ | 267 | */ |
265 | void Kpacman::forcedHallOfFame(bool on) | 268 | void Kpacman::forcedHallOfFame(bool on) |
266 | { | 269 | { |
267 | if (!on && !gamePopup->isItemChecked(hofID)) | 270 | if (!on && !gamePopup->isItemChecked(hofID)) |
268 | return; | 271 | return; |
269 | 272 | ||
270 | gamePopup->setItemEnabled(hofID, !on); | 273 | gamePopup->setItemEnabled(hofID, !on); |
271 | gamePopup->setItemChecked(hofID, on); | 274 | gamePopup->setItemChecked(hofID, on); |
272 | 275 | ||
273 | view->referee->toggleHallOfFame(); | 276 | view->referee->toggleHallOfFame(); |
274 | if (on) { | 277 | if (on) { |
275 | view->referee->lower(); | 278 | view->referee->lower(); |
276 | view->status->lower(); | 279 | view->status->lower(); |
277 | } else { | 280 | } else { |
278 | view->status->raise(); | 281 | view->status->raise(); |
279 | view->referee->raise(); | 282 | view->referee->raise(); |
280 | view->referee->setFocus(); | 283 | view->referee->setFocus(); |
281 | view->referee->intro(); | 284 | view->referee->intro(); |
282 | } | 285 | } |
283 | } | 286 | } |
284 | 287 | ||
285 | void Kpacman::togglePaused() | 288 | void Kpacman::togglePaused() |
286 | { | 289 | { |
287 | static bool checked = FALSE; | 290 | static bool checked = FALSE; |
288 | checked = !checked; | 291 | checked = !checked; |
289 | gamePopup->setItemChecked( pauseID, checked ); | 292 | gamePopup->setItemChecked( pauseID, checked ); |
290 | view->score->setPause(gamePopup->isItemChecked(pauseID)); | 293 | view->score->setPause(gamePopup->isItemChecked(pauseID)); |
291 | } | 294 | } |
292 | 295 | ||
293 | /* | 296 | /* |
294 | * This disables the "New Game" menuitem to prevent interruptions of the current | 297 | * This disables the "New Game" menuitem to prevent interruptions of the current |
295 | * play. | 298 | * play. |
296 | */ | 299 | */ |
297 | void Kpacman::toggleNew() | 300 | void Kpacman::toggleNew() |
298 | { | 301 | { |
299 | gamePopup->setItemEnabled(newID, !gamePopup->isItemEnabled(newID)); | 302 | gamePopup->setItemEnabled(newID, !gamePopup->isItemEnabled(newID)); |
300 | } | 303 | } |
301 | 304 | ||
302 | void Kpacman::toggleHideMouseCursor() | 305 | void Kpacman::toggleHideMouseCursor() |
303 | { | 306 | { |
304 | hideMouseCursor = !hideMouseCursor; | 307 | hideMouseCursor = !hideMouseCursor; |
305 | optionsPopup->setItemChecked(hideMouseCursorID, hideMouseCursor); | 308 | optionsPopup->setItemChecked(hideMouseCursorID, hideMouseCursor); |
306 | if (hideMouseCursor) | 309 | if (hideMouseCursor) |
307 | view->setCursor(blankCursor); | 310 | view->setCursor(blankCursor); |
308 | else | 311 | else |
309 | view->setCursor(arrowCursor); | 312 | view->setCursor(arrowCursor); |
310 | } | 313 | } |
311 | 314 | ||
312 | void Kpacman::toggleFocusOutPause() | 315 | void Kpacman::toggleFocusOutPause() |
313 | { | 316 | { |
314 | focusOutPause = !focusOutPause; | 317 | focusOutPause = !focusOutPause; |
315 | optionsPopup->setItemChecked(focusOutPauseID, focusOutPause); | 318 | optionsPopup->setItemChecked(focusOutPauseID, focusOutPause); |
316 | view->referee->setFocusOutPause(focusOutPause); | 319 | view->referee->setFocusOutPause(focusOutPause); |
317 | } | 320 | } |
318 | 321 | ||
319 | void Kpacman::toggleFocusInContinue() | 322 | void Kpacman::toggleFocusInContinue() |
320 | { | 323 | { |
321 | focusInContinue = !focusInContinue; | 324 | focusInContinue = !focusInContinue; |
322 | optionsPopup->setItemChecked(focusInContinueID, focusInContinue); | 325 | optionsPopup->setItemChecked(focusInContinueID, focusInContinue); |
323 | view->referee->setFocusInContinue(focusInContinue); | 326 | view->referee->setFocusInContinue(focusInContinue); |
324 | } | 327 | } |
325 | 328 | ||
326 | void Kpacman::confKeys() | 329 | void Kpacman::confKeys() |
327 | { | 330 | { |
328 | Keys *keys = new Keys(); | 331 | Keys *keys = new Keys(); |
329 | if (keys->exec() == QDialog::Accepted) { | 332 | if (keys->exec() == QDialog::Accepted) { |
330 | view->referee->initKeys(); | 333 | view->referee->initKeys(); |
331 | view->score->initKeys(); | 334 | view->score->initKeys(); |
332 | } | 335 | } |
333 | delete keys; | 336 | delete keys; |
334 | } | 337 | } |
335 | 338 | ||
336 | void Kpacman::schemeChecked(int id) | 339 | void Kpacman::schemeChecked(int id) |
337 | { | 340 | { |
338 | int mode = 0, scheme = -1; | 341 | int mode = 0, scheme = -1; |
339 | 342 | ||
340 | for (uint s = 0; s < schemeID.size(); s++) { | 343 | for (uint s = 0; s < schemeID.size(); s++) { |
341 | if (schemeID[s] == id) { | 344 | if (schemeID[s] == id) { |
342 | scheme = s; | 345 | scheme = s; |
343 | mode = schemeMode[s]; | 346 | mode = schemeMode[s]; |
344 | } | 347 | } |
345 | if (schemeMode[s] == -1) { | 348 | if (schemeMode[s] == -1) { |
346 | modesPopup->setItemChecked(schemeID[s], schemeID[s] == id); | 349 | modesPopup->setItemChecked(schemeID[s], schemeID[s] == id); |
347 | } else { | 350 | } else { |
348 | modesPopup->setItemChecked(modeID[schemeMode[s]], schemeMode[s] == mode); | 351 | modesPopup->setItemChecked(modeID[schemeMode[s]], schemeMode[s] == mode); |
349 | schemesPopup->at(schemeMode[s])->setItemChecked(schemeID[s], schemeID[s] == id); | 352 | schemesPopup->at(schemeMode[s])->setItemChecked(schemeID[s], schemeID[s] == id); |
350 | } | 353 | } |
351 | } | 354 | } |
352 | 355 | /* | |
353 | APP_CONFIG_BEGIN( cfg ); | 356 | APP_CONFIG_BEGIN( cfg ); |
354 | cfg->writeEntry("Scheme", scheme); | 357 | cfg->writeEntry("Scheme", scheme); |
355 | cfg->writeEntry("Mode", mode); | 358 | cfg->writeEntry("Mode", mode); |
356 | APP_CONFIG_END( cfg ); | 359 | APP_CONFIG_END( cfg ); |
360 | */ | ||
357 | 361 | ||
358 | view->setScheme(scheme, mode); | 362 | view->setScheme(scheme, mode); |
359 | view->updateGeometry(); | 363 | view->updateGeometry(); |
360 | updateGeometry(); | 364 | updateGeometry(); |
361 | update(); | 365 | update(); |
362 | repaint(TRUE); | 366 | repaint(TRUE); |
363 | show(); | 367 | show(); |
364 | } | 368 | } |
diff --git a/noncore/games/kpacman/kpacman.pro b/noncore/games/kpacman/kpacman.pro index e193ebc..81d369a 100644 --- a/noncore/games/kpacman/kpacman.pro +++ b/noncore/games/kpacman/kpacman.pro | |||
@@ -1,63 +1,61 @@ | |||
1 | TEMPLATE= app | 1 | TEMPLATE= app |
2 | #CONFIG = qt warn_on debug | 2 | #CONFIG = qt warn_on debug |
3 | CONFIG = qt warn_on release | 3 | CONFIG = qt warn_on release |
4 | #TMAKE_CXXFLAGS+= | 4 | #TMAKE_CXXFLAGS+= |
5 | HEADERS = kpacmanwidget.h \ | 5 | HEADERS = kpacmanwidget.h \ |
6 | referee.h \ | 6 | referee.h \ |
7 | status.h \ | 7 | status.h \ |
8 | painter.h \ | 8 | painter.h \ |
9 | score.h \ | 9 | score.h \ |
10 | pacman.h \ | 10 | pacman.h \ |
11 | monster.h \ | 11 | monster.h \ |
12 | keys.h \ | 12 | keys.h \ |
13 | fruit.h \ | 13 | fruit.h \ |
14 | energizer.h \ | 14 | energizer.h \ |
15 | board.h \ | 15 | board.h \ |
16 | bitfont.h \ | 16 | bitfont.h \ |
17 | kpacman.h \ | 17 | kpacman.h \ |
18 | bitmaps.h \ | 18 | bitmaps.h \ |
19 | colors.h \ | 19 | colors.h \ |
20 | config.h \ | ||
21 | portable.h | 20 | portable.h |
22 | SOURCES = kpacmanwidget.cpp \ | 21 | SOURCES = kpacmanwidget.cpp \ |
23 | referee.cpp \ | 22 | referee.cpp \ |
24 | status.cpp \ | 23 | status.cpp \ |
25 | painter.cpp \ | 24 | painter.cpp \ |
26 | score.cpp \ | 25 | score.cpp \ |
27 | pacman.cpp \ | 26 | pacman.cpp \ |
28 | monster.cpp \ | 27 | monster.cpp \ |
29 | keys.cpp \ | 28 | keys.cpp \ |
30 | fruit.cpp \ | 29 | fruit.cpp \ |
31 | energizer.cpp \ | 30 | energizer.cpp \ |
32 | board.cpp \ | 31 | board.cpp \ |
33 | bitfont.cpp \ | 32 | bitfont.cpp \ |
34 | kpacman.cpp \ | 33 | kpacman.cpp \ |
35 | config.cpp \ | ||
36 | main.cpp | 34 | main.cpp |
37 | INCLUDEPATH+= $(OPIEDIR)/include | 35 | INCLUDEPATH+= $(OPIEDIR)/include |
38 | DEPENDPATH+= $(OPIEDIR)/include | 36 | DEPENDPATH+= $(OPIEDIR)/include |
39 | LIBS += -lqpe | 37 | LIBS += -lqpe |
40 | DESTDIR = $(OPIEDIR)/bin | 38 | DESTDIR = $(OPIEDIR)/bin |
41 | TARGET = kpacman | 39 | TARGET = kpacman |
42 | 40 | ||
43 | TRANSLATIONS = ../../../i18n/de/kpacman.ts \ | 41 | TRANSLATIONS = ../../../i18n/de/kpacman.ts \ |
44 | ../../../i18n/nl/kpacman.ts \ | 42 | ../../../i18n/nl/kpacman.ts \ |
45 | ../../../i18n/da/kpacman.ts \ | 43 | ../../../i18n/da/kpacman.ts \ |
46 | ../../../i18n/xx/kpacman.ts \ | 44 | ../../../i18n/xx/kpacman.ts \ |
47 | ../../../i18n/en/kpacman.ts \ | 45 | ../../../i18n/en/kpacman.ts \ |
48 | ../../../i18n/es/kpacman.ts \ | 46 | ../../../i18n/es/kpacman.ts \ |
49 | ../../../i18n/fr/kpacman.ts \ | 47 | ../../../i18n/fr/kpacman.ts \ |
50 | ../../../i18n/hu/kpacman.ts \ | 48 | ../../../i18n/hu/kpacman.ts \ |
51 | ../../../i18n/ja/kpacman.ts \ | 49 | ../../../i18n/ja/kpacman.ts \ |
52 | ../../../i18n/ko/kpacman.ts \ | 50 | ../../../i18n/ko/kpacman.ts \ |
53 | ../../../i18n/no/kpacman.ts \ | 51 | ../../../i18n/no/kpacman.ts \ |
54 | ../../../i18n/pl/kpacman.ts \ | 52 | ../../../i18n/pl/kpacman.ts \ |
55 | ../../../i18n/pt/kpacman.ts \ | 53 | ../../../i18n/pt/kpacman.ts \ |
56 | ../../../i18n/pt_BR/kpacman.ts \ | 54 | ../../../i18n/pt_BR/kpacman.ts \ |
57 | ../../../i18n/sl/kpacman.ts \ | 55 | ../../../i18n/sl/kpacman.ts \ |
58 | ../../../i18n/zh_CN/kpacman.ts \ | 56 | ../../../i18n/zh_CN/kpacman.ts \ |
59 | ../../../i18n/zh_TW/kpacman.ts | 57 | ../../../i18n/zh_TW/kpacman.ts |
60 | 58 | ||
61 | 59 | ||
62 | 60 | ||
63 | include ( $(OPIEDIR)/include.pro ) | 61 | include ( $(OPIEDIR)/include.pro ) |
diff --git a/noncore/games/kpacman/kpacmanwidget.cpp b/noncore/games/kpacman/kpacmanwidget.cpp index cf2aed9..823d2bf 100644 --- a/noncore/games/kpacman/kpacmanwidget.cpp +++ b/noncore/games/kpacman/kpacmanwidget.cpp | |||
@@ -1,158 +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 <qpe/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 | ||
23 | KpacmanWidget::KpacmanWidget( QWidget *parent, const char *name) | 23 | KpacmanWidget::KpacmanWidget( QWidget *parent, const char *name) |
24 | : QWidget( parent, name ) | 24 | : QWidget( parent, name ) |
25 | { | 25 | { |
26 | score = 0l; | 26 | score = 0l; |
27 | referee = 0l; | 27 | referee = 0l; |
28 | status = 0l; | 28 | status = 0l; |
29 | bitfont = NULL; | 29 | bitfont = NULL; |
30 | fontName = ""; | 30 | fontName = ""; |
31 | 31 | ||
32 | scheme = mode = -1; | 32 | scheme = mode = -1; |
33 | confScheme(); | 33 | confScheme(); |
34 | 34 | ||
35 | score = new Score(this, name, scheme, mode, bitfont); | 35 | score = new Score(this, name, scheme, mode, bitfont); |
36 | referee = new Referee( this, name, scheme, mode, bitfont); | 36 | referee = new Referee( this, name, scheme, mode, bitfont); |
37 | status = new Status(this, name, scheme, mode); | 37 | status = new Status(this, name, scheme, mode); |
38 | 38 | ||
39 | setBackgroundColor( black ); | 39 | setBackgroundColor( black ); |
40 | } | 40 | } |
41 | 41 | ||
42 | KpacmanWidget::~KpacmanWidget() | 42 | KpacmanWidget::~KpacmanWidget() |
43 | { | 43 | { |
44 | } | 44 | } |
45 | 45 | ||
46 | void KpacmanWidget::confMisc(bool defGroup) | 46 | void KpacmanWidget::confMisc(bool defGroup) |
47 | { | 47 | { |
48 | APP_CONFIG_BEGIN( cfg ); | 48 | APP_CONFIG_BEGIN( cfg ); |
49 | //KStandardDirs *dirs = KGlobal::dirs(); | 49 | //KStandardDirs *dirs = KGlobal::dirs(); |
50 | QString findPath; | 50 | QString findPath; |
51 | 51 | ||
52 | if (defGroup || cfg->hasKey("Font")) { | 52 | if (defGroup || cfg->hasKey("Font")) { |
53 | fontName = cfg->readEntry("Font"); | 53 | fontName = cfg->readEntry("Font"); |
54 | 54 | ||
55 | if (fontName.left(1) != "/" && fontName.left(1) != "~") | 55 | if (fontName.left(1) != "/" && fontName.left(1) != "~") |
56 | fontName.insert(0, "fonts/"); | 56 | fontName.insert(0, "fonts/"); |
57 | if (fontName.right(1) == "/") | 57 | if (fontName.right(1) == "/") |
58 | fontName.append("font.xbm"); | 58 | fontName.append("font.xbm"); |
59 | 59 | ||
60 | //findPath = dirs->findResource("appdata", fontName); | 60 | //findPath = dirs->findResource("appdata", fontName); |
61 | findPath = FIND_APP_DATA( fontName ); | 61 | findPath = FIND_APP_DATA( fontName ); |
62 | if (!findPath.isEmpty()) | 62 | if (!findPath.isEmpty()) |
63 | fontName = findPath; | 63 | fontName = findPath; |
64 | 64 | ||
65 | bitfontFirstChar = cfg->readNumEntry("FontFirstChar", 0x0e); | 65 | bitfontFirstChar = cfg->readNumEntry("FontFirstChar", 0x0e); |
66 | bitfontLastChar = cfg->readNumEntry("FontLastChar", 0x5f); | 66 | bitfontLastChar = cfg->readNumEntry("FontLastChar", 0x5f); |
67 | } | 67 | } |
68 | APP_CONFIG_END( cfg ); | 68 | APP_CONFIG_END( cfg ); |
69 | } | 69 | } |
70 | 70 | ||
71 | void KpacmanWidget::confScheme() | 71 | void KpacmanWidget::confScheme() |
72 | { | 72 | { |
73 | APP_CONFIG_BEGIN( cfg ); | 73 | APP_CONFIG_BEGIN( cfg ); |
74 | QString lastFontName = fontName; | 74 | QString lastFontName = fontName; |
75 | SAVE_CONFIG_GROUP( cfg, oldgroup ); | 75 | SAVE_CONFIG_GROUP( cfg, oldgroup ); |
76 | QString newgroup; | 76 | QString newgroup; |
77 | 77 | ||
78 | // if not set, read mode and scheme from the configfile | 78 | // if not set, read mode and scheme from the configfile |
79 | if (mode == -1 && scheme == -1) { | 79 | if (mode == -1 && scheme == -1) { |
80 | scheme = cfg->readNumEntry("Scheme", -1); | 80 | scheme = cfg->readNumEntry("Scheme", -1); |
81 | mode = cfg->readNumEntry("Mode", -1); | 81 | mode = cfg->readNumEntry("Mode", -1); |
82 | 82 | ||
83 | // 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 |
84 | if (scheme != -1 || mode == -1) { | 84 | if (scheme != -1 || mode == -1) { |
85 | newgroup.sprintf("Scheme %d", scheme); | 85 | newgroup.sprintf("Scheme %d", scheme); |
86 | cfg->setGroup(newgroup); | 86 | cfg->setGroup(newgroup); |
87 | 87 | ||
88 | mode = cfg->readNumEntry("Mode", -1); | 88 | mode = cfg->readNumEntry("Mode", -1); |
89 | RESTORE_CONFIG_GROUP( cfg, oldgroup ); | 89 | RESTORE_CONFIG_GROUP( cfg, oldgroup ); |
90 | } | 90 | } |
91 | } | 91 | } |
92 | 92 | ||
93 | confMisc(); | 93 | confMisc(); |
94 | 94 | ||
95 | if (mode != -1) { | 95 | if (mode != -1) { |
96 | newgroup.sprintf("Mode %d", mode); | 96 | newgroup.sprintf("Mode %d", mode); |
97 | cfg->setGroup(newgroup); | 97 | cfg->setGroup(newgroup); |
98 | 98 | ||
99 | confMisc(FALSE); | 99 | confMisc(FALSE); |
100 | } | 100 | } |
101 | 101 | ||
102 | if (scheme != -1) { | 102 | if (scheme != -1) { |
103 | newgroup.sprintf("Scheme %d", scheme); | 103 | newgroup.sprintf("Scheme %d", scheme); |
104 | cfg->setGroup(newgroup); | 104 | cfg->setGroup(newgroup); |
105 | 105 | ||
106 | confMisc(FALSE); | 106 | confMisc(FALSE); |
107 | } | 107 | } |
108 | 108 | ||
109 | if (lastFontName != fontName) { | 109 | if (lastFontName != fontName) { |
110 | 110 | ||
111 | if (bitfont != 0) | 111 | if (bitfont != 0) |
112 | delete bitfont; | 112 | delete bitfont; |
113 | 113 | ||
114 | bitfont = new Bitfont(fontName, bitfontFirstChar, bitfontLastChar); | 114 | bitfont = new Bitfont(fontName, bitfontFirstChar, bitfontLastChar); |
115 | if (bitfont->width() == 0 || bitfont->height() == 0) { | 115 | if (bitfont->width() == 0 || bitfont->height() == 0) { |
116 | QString msg = tr("The bitfont could not be contructed.\n\n" | 116 | QString msg = tr("The bitfont could not be contructed.\n\n" |
117 | "The file '@FONTNAME@' does not exist,\n" | 117 | "The file '@FONTNAME@' does not exist,\n" |
118 | "or is of an unknown format."); | 118 | "or is of an unknown format."); |
119 | msg.replace(QRegExp("@FONTNAME@"), fontName); | 119 | msg.replace(QRegExp("@FONTNAME@"), fontName); |
120 | // QMessageBox::critical(this, tr("Initialization Error"), msg); | 120 | // QMessageBox::critical(this, tr("Initialization Error"), msg); |
121 | printf("%s\n", msg.data()); | 121 | printf("%s\n", msg.data()); |
122 | } | 122 | } |
123 | } | 123 | } |
124 | 124 | ||
125 | RESTORE_CONFIG_GROUP( cfg, oldgroup ); | 125 | RESTORE_CONFIG_GROUP( cfg, oldgroup ); |
126 | APP_CONFIG_END( cfg ); | 126 | APP_CONFIG_END( cfg ); |
127 | } | 127 | } |
128 | 128 | ||
129 | void KpacmanWidget::setScheme(int Scheme, int Mode) | 129 | void KpacmanWidget::setScheme(int Scheme, int Mode) |
130 | { | 130 | { |
131 | mode = Mode; | 131 | mode = Mode; |
132 | scheme = Scheme; | 132 | scheme = Scheme; |
133 | 133 | ||
134 | confScheme(); | 134 | confScheme(); |
135 | 135 | ||
136 | score->setScheme(Scheme, Mode, bitfont); | 136 | score->setScheme(Scheme, Mode, bitfont); |
137 | referee->setScheme(Scheme, Mode, bitfont); | 137 | referee->setScheme(Scheme, Mode, bitfont); |
138 | status->setScheme(Scheme, Mode); | 138 | status->setScheme(Scheme, Mode); |
139 | 139 | ||
140 | score->repaint(FALSE); | 140 | score->repaint(FALSE); |
141 | referee->repaint(FALSE); | 141 | referee->repaint(FALSE); |
142 | status->repaint(FALSE); | 142 | status->repaint(FALSE); |
143 | } | 143 | } |
144 | 144 | ||
145 | void KpacmanWidget::resizeEvent( QResizeEvent * ) | 145 | void KpacmanWidget::resizeEvent( QResizeEvent * ) |
146 | { | 146 | { |
147 | qWarning("Resize"); | 147 | qWarning("Resize"); |
148 | referee->setGeometry(0, bitfont->height()*3, referee->width(), referee->height()); | 148 | referee->setGeometry(0, bitfont->height()*3, referee->width(), referee->height()); |
149 | referee->setBackgroundColor(BLACK); | 149 | referee->setBackgroundColor(BLACK); |
150 | 150 | ||
151 | if(!status ) return; | 151 | if(!status ) return; |
152 | status->setGeometry(0, bitfont->height()*3+referee->height(), referee->width(), | 152 | status->setGeometry(0, bitfont->height()*3+referee->height(), referee->width(), |
153 | status->height()); | 153 | status->height()); |
154 | status->setBackgroundColor(BLACK); | 154 | status->setBackgroundColor(BLACK); |
155 | 155 | ||
156 | 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()); |
157 | score->setBackgroundColor(BLACK); | 157 | score->setBackgroundColor(BLACK); |
158 | } | 158 | } |
diff --git a/noncore/games/kpacman/painter.cpp b/noncore/games/kpacman/painter.cpp index 80aeab0..d8c7460 100644 --- a/noncore/games/kpacman/painter.cpp +++ b/noncore/games/kpacman/painter.cpp | |||
@@ -1,394 +1,394 @@ | |||
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 | #elif defined( QPE_PORT ) | 8 | #elif defined( QPE_PORT ) |
9 | #include <qpe/qpeapplication.h> | 9 | #include <qpe/qpeapplication.h> |
10 | #include "config.h" | 10 | #include <qpe/config.h> |
11 | #endif | 11 | #endif |
12 | 12 | ||
13 | #include <qcolor.h> | 13 | #include <qcolor.h> |
14 | #include <qpainter.h> | 14 | #include <qpainter.h> |
15 | #include <qpixmap.h> | 15 | #include <qpixmap.h> |
16 | #include <qbitmap.h> | 16 | #include <qbitmap.h> |
17 | #include <qrect.h> | 17 | #include <qrect.h> |
18 | #include <qstring.h> | 18 | #include <qstring.h> |
19 | 19 | ||
20 | #include <qmessagebox.h> | 20 | #include <qmessagebox.h> |
21 | #include <qfileinfo.h> | 21 | #include <qfileinfo.h> |
22 | 22 | ||
23 | #include "painter.h" | 23 | #include "painter.h" |
24 | #include "board.h" | 24 | #include "board.h" |
25 | 25 | ||
26 | Painter::Painter( Board *b, QWidget *parent, int Scheme, int Mode, Bitfont *font) | 26 | Painter::Painter( Board *b, QWidget *parent, int Scheme, int Mode, Bitfont *font) |
27 | { | 27 | { |
28 | w = parent; | 28 | w = parent; |
29 | board = b; | 29 | board = b; |
30 | 30 | ||
31 | pointPix = NULL; | 31 | pointPix = NULL; |
32 | wallPix = NULL; | 32 | wallPix = NULL; |
33 | prisonPix = NULL; | 33 | prisonPix = NULL; |
34 | energizerPix = NULL; | 34 | energizerPix = NULL; |
35 | fruitPix = NULL; | 35 | fruitPix = NULL; |
36 | pacmanPix = NULL; | 36 | pacmanPix = NULL; |
37 | dyingPix = NULL; | 37 | dyingPix = NULL; |
38 | eyesPix = NULL; | 38 | eyesPix = NULL; |
39 | monsterPix = NULL; | 39 | monsterPix = NULL; |
40 | fruitScorePix = NULL; | 40 | fruitScorePix = NULL; |
41 | monsterScorePix = NULL; | 41 | monsterScorePix = NULL; |
42 | 42 | ||
43 | lastPointPixmapName = ""; | 43 | lastPointPixmapName = ""; |
44 | lastWallPixmapName = ""; | 44 | lastWallPixmapName = ""; |
45 | lastPrisonPixmapName = ""; | 45 | lastPrisonPixmapName = ""; |
46 | lastEnergizerPixmapName = ""; | 46 | lastEnergizerPixmapName = ""; |
47 | lastFruitPixmapName = ""; | 47 | lastFruitPixmapName = ""; |
48 | lastPacmanPixmapName = ""; | 48 | lastPacmanPixmapName = ""; |
49 | lastDyingPixmapName = ""; | 49 | lastDyingPixmapName = ""; |
50 | lastEyesPixmapName = ""; | 50 | lastEyesPixmapName = ""; |
51 | lastMonsterPixmapName = ""; | 51 | lastMonsterPixmapName = ""; |
52 | lastFruitScorePixmapName = ""; | 52 | lastFruitScorePixmapName = ""; |
53 | lastMonsterScorePixmapName = ""; | 53 | lastMonsterScorePixmapName = ""; |
54 | 54 | ||
55 | bitfont = font; | 55 | bitfont = font; |
56 | 56 | ||
57 | scheme = Scheme; | 57 | scheme = Scheme; |
58 | mode = Mode; | 58 | mode = Mode; |
59 | level = 0; | 59 | level = 0; |
60 | 60 | ||
61 | confScheme(); | 61 | confScheme(); |
62 | } | 62 | } |
63 | 63 | ||
64 | QList<QPixmap> *Painter::loadPixmap(QWidget*, QString pixmapName, | 64 | QList<QPixmap> *Painter::loadPixmap(QWidget*, QString pixmapName, |
65 | QList<QPixmap> *pixmaps) | 65 | QList<QPixmap> *pixmaps) |
66 | { | 66 | { |
67 | if (pixmaps == NULL) { | 67 | if (pixmaps == NULL) { |
68 | pixmaps = new QList<QPixmap>; | 68 | pixmaps = new QList<QPixmap>; |
69 | pixmaps->setAutoDelete(TRUE); | 69 | pixmaps->setAutoDelete(TRUE); |
70 | } | 70 | } |
71 | 71 | ||
72 | if (!pixmaps->isEmpty()) | 72 | if (!pixmaps->isEmpty()) |
73 | pixmaps->clear(); | 73 | pixmaps->clear(); |
74 | 74 | ||
75 | QPixmap PIXMAP(pixmapName); | 75 | QPixmap PIXMAP(pixmapName); |
76 | if (PIXMAP.isNull() || PIXMAP.mask() == NULL) { | 76 | if (PIXMAP.isNull() || PIXMAP.mask() == NULL) { |
77 | QString msg = "The pixmap could not be contructed.\n\n" | 77 | QString msg = "The pixmap could not be contructed.\n\n" |
78 | "The file '@PIXMAPNAME@' does not exist,\n" | 78 | "The file '@PIXMAPNAME@' does not exist,\n" |
79 | "or is of an unknown format."; | 79 | "or is of an unknown format."; |
80 | msg.replace(QRegExp("@PIXMAPNAME@"), pixmapName); | 80 | msg.replace(QRegExp("@PIXMAPNAME@"), pixmapName); |
81 | // QMessageBox::critical(parent, tr("Initialization Error"), msg); | 81 | // QMessageBox::critical(parent, tr("Initialization Error"), msg); |
82 | printf("%s\n", msg.data()); | 82 | printf("%s\n", msg.data()); |
83 | return 0; | 83 | return 0; |
84 | } | 84 | } |
85 | 85 | ||
86 | int height = PIXMAP.height(); | 86 | int height = PIXMAP.height(); |
87 | int width = (height == 0) ? 0 : PIXMAP.width()/(PIXMAP.width()/height); | 87 | int width = (height == 0) ? 0 : PIXMAP.width()/(PIXMAP.width()/height); |
88 | 88 | ||
89 | QBitmap BITMAP; | 89 | QBitmap BITMAP; |
90 | QBitmap MASK; | 90 | QBitmap MASK; |
91 | 91 | ||
92 | BITMAP = *PIXMAP.mask(); | 92 | BITMAP = *PIXMAP.mask(); |
93 | MASK.resize(width, height); | 93 | MASK.resize(width, height); |
94 | 94 | ||
95 | for (int x = 0; x < PIXMAP.width()/width; x++) { | 95 | for (int x = 0; x < PIXMAP.width()/width; x++) { |
96 | QPixmap *pixmap = new QPixmap(width, height); | 96 | QPixmap *pixmap = new QPixmap(width, height); |
97 | pixmaps->append(pixmap); | 97 | pixmaps->append(pixmap); |
98 | bitBlt(pixmap, 0, 0, &PIXMAP, x*width, 0, width, height, QPixmap::CopyROP, TRUE); | 98 | bitBlt(pixmap, 0, 0, &PIXMAP, x*width, 0, width, height, QPixmap::CopyROP, TRUE); |
99 | bitBlt(&MASK, 0, 0, &BITMAP, x*width, 0, width, height, QPixmap::CopyROP, TRUE); | 99 | bitBlt(&MASK, 0, 0, &BITMAP, x*width, 0, width, height, QPixmap::CopyROP, TRUE); |
100 | pixmap->setMask(MASK); | 100 | pixmap->setMask(MASK); |
101 | } | 101 | } |
102 | 102 | ||
103 | return pixmaps; | 103 | return pixmaps; |
104 | } | 104 | } |
105 | 105 | ||
106 | QList<QPixmap> *Painter::textPixmap(QStrList &str, QList<QPixmap> *pixmaps, | 106 | QList<QPixmap> *Painter::textPixmap(QStrList &str, QList<QPixmap> *pixmaps, |
107 | QColor fg, QColor bg) | 107 | QColor fg, QColor bg) |
108 | { | 108 | { |
109 | if (pixmaps == NULL) { | 109 | if (pixmaps == NULL) { |
110 | pixmaps = new QList<QPixmap>; | 110 | pixmaps = new QList<QPixmap>; |
111 | pixmaps->setAutoDelete(TRUE); | 111 | pixmaps->setAutoDelete(TRUE); |
112 | } | 112 | } |
113 | 113 | ||
114 | if (!pixmaps->isEmpty()) | 114 | if (!pixmaps->isEmpty()) |
115 | pixmaps->clear(); | 115 | pixmaps->clear(); |
116 | 116 | ||
117 | for (uint s = 0; s < str.count(); s++) { | 117 | for (uint s = 0; s < str.count(); s++) { |
118 | QPixmap *pixmap = new QPixmap(bitfont->text(str.at(s), fg, bg)); | 118 | QPixmap *pixmap = new QPixmap(bitfont->text(str.at(s), fg, bg)); |
119 | pixmaps->append(pixmap); | 119 | pixmaps->append(pixmap); |
120 | } | 120 | } |
121 | 121 | ||
122 | return pixmaps; | 122 | return pixmaps; |
123 | } | 123 | } |
124 | 124 | ||
125 | QList<QPixmap> *Painter::textPixmap(QString str, QList<QPixmap> *pixmaps, | 125 | QList<QPixmap> *Painter::textPixmap(QString str, QList<QPixmap> *pixmaps, |
126 | QColor fg, QColor bg) | 126 | QColor fg, QColor bg) |
127 | { | 127 | { |
128 | if (pixmaps == NULL) { | 128 | if (pixmaps == NULL) { |
129 | pixmaps = new QList<QPixmap>; | 129 | pixmaps = new QList<QPixmap>; |
130 | pixmaps->setAutoDelete(TRUE); | 130 | pixmaps->setAutoDelete(TRUE); |
131 | } | 131 | } |
132 | 132 | ||
133 | if (!pixmaps->isEmpty()) | 133 | if (!pixmaps->isEmpty()) |
134 | pixmaps->clear(); | 134 | pixmaps->clear(); |
135 | 135 | ||
136 | QPixmap *pixmap = new QPixmap(bitfont->text(str, fg, bg)); | 136 | QPixmap *pixmap = new QPixmap(bitfont->text(str, fg, bg)); |
137 | pixmaps->append(pixmap); | 137 | pixmaps->append(pixmap); |
138 | 138 | ||
139 | return pixmaps; | 139 | return pixmaps; |
140 | } | 140 | } |
141 | 141 | ||
142 | /* Return the point of the upperleft pixel of the block representing that position | 142 | /* Return the point of the upperleft pixel of the block representing that position |
143 | * on the board. | 143 | * on the board. |
144 | */ | 144 | */ |
145 | QPoint Painter::point(int pos) | 145 | QPoint Painter::point(int pos) |
146 | { | 146 | { |
147 | return QPoint((board->x(pos)-1)*BlockWidth, (board->y(pos)-1)*BlockHeight); | 147 | return QPoint((board->x(pos)-1)*BlockWidth, (board->y(pos)-1)*BlockHeight); |
148 | } | 148 | } |
149 | 149 | ||
150 | 150 | ||
151 | QRect Painter::rect(int pos, PixMap pix, uint i) | 151 | QRect Painter::rect(int pos, PixMap pix, uint i) |
152 | { | 152 | { |
153 | if (pos == OUT) | 153 | if (pos == OUT) |
154 | return QRect(); | 154 | return QRect(); |
155 | 155 | ||
156 | QPixmap *PIXMAP = NULL; | 156 | QPixmap *PIXMAP = NULL; |
157 | switch (pix) { | 157 | switch (pix) { |
158 | case PacmanPix : PIXMAP = pacmanPix-> | 158 | case PacmanPix : PIXMAP = pacmanPix-> |
159 | at(checkRange(i, pacmanPix->count()-1)); | 159 | at(checkRange(i, pacmanPix->count()-1)); |
160 | break; | 160 | break; |
161 | case DyingPix : PIXMAP = dyingPix-> | 161 | case DyingPix : PIXMAP = dyingPix-> |
162 | at(checkRange(i, dyingPix->count()-1)); | 162 | at(checkRange(i, dyingPix->count()-1)); |
163 | break; | 163 | break; |
164 | case MonsterPix : PIXMAP = monsterPix-> | 164 | case MonsterPix : PIXMAP = monsterPix-> |
165 | at(checkRange(i, monsterPix->count()-1)); | 165 | at(checkRange(i, monsterPix->count()-1)); |
166 | break; | 166 | break; |
167 | case EyesPix : PIXMAP = eyesPix-> | 167 | case EyesPix : PIXMAP = eyesPix-> |
168 | at(checkRange(i, eyesPix->count()-1)); | 168 | at(checkRange(i, eyesPix->count()-1)); |
169 | break; | 169 | break; |
170 | case FruitPix : PIXMAP = fruitPix-> | 170 | case FruitPix : PIXMAP = fruitPix-> |
171 | at(checkRange(i, fruitPix->count()-1)); | 171 | at(checkRange(i, fruitPix->count()-1)); |
172 | break; | 172 | break; |
173 | case PointPix : PIXMAP = pointPix-> | 173 | case PointPix : PIXMAP = pointPix-> |
174 | at(checkRange(i, pointPix->count()-1)); | 174 | at(checkRange(i, pointPix->count()-1)); |
175 | break; | 175 | break; |
176 | case EnergizerPix : PIXMAP = energizerPix-> | 176 | case EnergizerPix : PIXMAP = energizerPix-> |
177 | at(checkRange(i, energizerPix->count()-1)); | 177 | at(checkRange(i, energizerPix->count()-1)); |
178 | break; | 178 | break; |
179 | case FruitScorePix : PIXMAP = fruitScorePix-> | 179 | case FruitScorePix : PIXMAP = fruitScorePix-> |
180 | at(checkRange(i, fruitScorePix->count()-1)); | 180 | at(checkRange(i, fruitScorePix->count()-1)); |
181 | break; | 181 | break; |
182 | case MonsterScorePix : PIXMAP = monsterScorePix-> | 182 | case MonsterScorePix : PIXMAP = monsterScorePix-> |
183 | at(checkRange(i,monsterScorePix->count()-1)); | 183 | at(checkRange(i,monsterScorePix->count()-1)); |
184 | break; | 184 | break; |
185 | default : PIXMAP = wallPix-> | 185 | default : PIXMAP = wallPix-> |
186 | at(checkRange(i, wallPix->count()-1)); | 186 | at(checkRange(i, wallPix->count()-1)); |
187 | } | 187 | } |
188 | if (PIXMAP == NULL) | 188 | if (PIXMAP == NULL) |
189 | return QRect(); | 189 | return QRect(); |
190 | 190 | ||
191 | QRect rect = PIXMAP->rect(); | 191 | QRect rect = PIXMAP->rect(); |
192 | QPoint point = this->point(pos); | 192 | QPoint point = this->point(pos); |
193 | rect.moveCenter(QPoint(point.x()-1, point.y()-1)); | 193 | rect.moveCenter(QPoint(point.x()-1, point.y()-1)); |
194 | 194 | ||
195 | return rect; | 195 | return rect; |
196 | } | 196 | } |
197 | 197 | ||
198 | QRect Painter::rect(int pos, QString str, int align) | 198 | QRect Painter::rect(int pos, QString str, int align) |
199 | { | 199 | { |
200 | if (pos == OUT) // return an empty rect if the position | 200 | if (pos == OUT) // return an empty rect if the position |
201 | return QRect(); // is invalid | 201 | return QRect(); // is invalid |
202 | QPoint point = this->point(pos); | 202 | QPoint point = this->point(pos); |
203 | QRect rect = bitfont->rect(str); | 203 | QRect rect = bitfont->rect(str); |
204 | 204 | ||
205 | rect.moveCenter(QPoint(point.x()-1, point.y()-1)); | 205 | rect.moveCenter(QPoint(point.x()-1, point.y()-1)); |
206 | 206 | ||
207 | int dx = 0; | 207 | int dx = 0; |
208 | int dy = 0; | 208 | int dy = 0; |
209 | 209 | ||
210 | if (align & QLabel::AlignLeft || align & QLabel::AlignRight) { | 210 | if (align & QLabel::AlignLeft || align & QLabel::AlignRight) { |
211 | dx = (str.length()-1) * (bitfont->width()/2); | 211 | dx = (str.length()-1) * (bitfont->width()/2); |
212 | if (align & QLabel::AlignRight) | 212 | if (align & QLabel::AlignRight) |
213 | dx *= -1; | 213 | dx *= -1; |
214 | } | 214 | } |
215 | 215 | ||
216 | if (align & QLabel::AlignTop || align & QLabel::AlignBottom) { | 216 | if (align & QLabel::AlignTop || align & QLabel::AlignBottom) { |
217 | dy = bitfont->height()/2; | 217 | dy = bitfont->height()/2; |
218 | if (align & QLabel::AlignBottom) | 218 | if (align & QLabel::AlignBottom) |
219 | dy *= -1; | 219 | dy *= -1; |
220 | } | 220 | } |
221 | 221 | ||
222 | if (dx != 0 || dy != 0) | 222 | if (dx != 0 || dy != 0) |
223 | rect.moveBy(dx, dy); | 223 | rect.moveBy(dx, dy); |
224 | 224 | ||
225 | return rect; | 225 | return rect; |
226 | } | 226 | } |
227 | 227 | ||
228 | QRect Painter::rect(QRect r1, QRect r2) | 228 | QRect Painter::rect(QRect r1, QRect r2) |
229 | { | 229 | { |
230 | QRect rect; | 230 | QRect rect; |
231 | rect.setLeft(r1.left() < r2.left() ? r1.left() : r2.left()); | 231 | rect.setLeft(r1.left() < r2.left() ? r1.left() : r2.left()); |
232 | rect.setTop(r1.top() < r2.top() ? r1.top() : r2.top()); | 232 | rect.setTop(r1.top() < r2.top() ? r1.top() : r2.top()); |
233 | rect.setRight(r1.right() > r2.right() ? r1.right() : r2.right()); | 233 | rect.setRight(r1.right() > r2.right() ? r1.right() : r2.right()); |
234 | rect.setBottom(r1.bottom() > r2.bottom() ? r1.bottom() : r2.bottom()); | 234 | rect.setBottom(r1.bottom() > r2.bottom() ? r1.bottom() : r2.bottom()); |
235 | 235 | ||
236 | return rect; | 236 | return rect; |
237 | } | 237 | } |
238 | 238 | ||
239 | void Painter::erase(int pos, PixMap pix, uint i) | 239 | void Painter::erase(int pos, PixMap pix, uint i) |
240 | { | 240 | { |
241 | if (pos == OUT) | 241 | if (pos == OUT) |
242 | return; | 242 | return; |
243 | QRect rect = this->rect(pos, pix, i); | 243 | QRect rect = this->rect(pos, pix, i); |
244 | bitBlt(&roomPix, rect.x(), rect.y(), &backPix, | 244 | bitBlt(&roomPix, rect.x(), rect.y(), &backPix, |
245 | rect.x(), rect.y(), rect.width(), rect.height()); | 245 | rect.x(), rect.y(), rect.width(), rect.height()); |
246 | } | 246 | } |
247 | 247 | ||
248 | int Painter::maxPixmaps(PixMap pix) | 248 | int Painter::maxPixmaps(PixMap pix) |
249 | { | 249 | { |
250 | switch (pix) { | 250 | switch (pix) { |
251 | case WallPix : return (int) wallPix->count(); | 251 | case WallPix : return (int) wallPix->count(); |
252 | case PrisonPix : return (int) prisonPix->count(); | 252 | case PrisonPix : return (int) prisonPix->count(); |
253 | case PointPix : return (int) pointPix->count(); | 253 | case PointPix : return (int) pointPix->count(); |
254 | case EnergizerPix : return (int) energizerPix->count(); | 254 | case EnergizerPix : return (int) energizerPix->count(); |
255 | case FruitPix : return (int) fruitPix->count(); | 255 | case FruitPix : return (int) fruitPix->count(); |
256 | case PacmanPix : return (int) pacmanPix->count(); | 256 | case PacmanPix : return (int) pacmanPix->count(); |
257 | case DyingPix : return (int) dyingPix->count(); | 257 | case DyingPix : return (int) dyingPix->count(); |
258 | case EyesPix : return (int) eyesPix->count(); | 258 | case EyesPix : return (int) eyesPix->count(); |
259 | case MonsterPix : return (int) monsterPix->count(); | 259 | case MonsterPix : return (int) monsterPix->count(); |
260 | case FruitScorePix : return (int) fruitScorePix->count(); | 260 | case FruitScorePix : return (int) fruitScorePix->count(); |
261 | case MonsterScorePix : return (int) monsterScorePix->count(); | 261 | case MonsterScorePix : return (int) monsterScorePix->count(); |
262 | default : return 0; | 262 | default : return 0; |
263 | } | 263 | } |
264 | } | 264 | } |
265 | 265 | ||
266 | void Painter::draw(QPoint point, DrawWidget where, QPixmap pix) | 266 | void Painter::draw(QPoint point, DrawWidget where, QPixmap pix) |
267 | { | 267 | { |
268 | switch (where) { | 268 | switch (where) { |
269 | case Widget : bitBlt(w, point.x(), point.y(), &pix); | 269 | case Widget : bitBlt(w, point.x(), point.y(), &pix); |
270 | break; | 270 | break; |
271 | case RoomPix : bitBlt(&roomPix, point.x(), point.y(), &pix); | 271 | case RoomPix : bitBlt(&roomPix, point.x(), point.y(), &pix); |
272 | break; | 272 | break; |
273 | case BackPix : bitBlt(&backPix, point.x(), point.y(), &pix); | 273 | case BackPix : bitBlt(&backPix, point.x(), point.y(), &pix); |
274 | break; | 274 | break; |
275 | } | 275 | } |
276 | } | 276 | } |
277 | 277 | ||
278 | void Painter::draw(QRect rect, DrawWidget where, QPixmap pix) | 278 | void Painter::draw(QRect rect, DrawWidget where, QPixmap pix) |
279 | { | 279 | { |
280 | draw(QPoint(rect.x(), rect.y()), where, pix); | 280 | draw(QPoint(rect.x(), rect.y()), where, pix); |
281 | } | 281 | } |
282 | 282 | ||
283 | void Painter::draw(int pos, DrawWidget where, PixMap pix, uint i) | 283 | void Painter::draw(int pos, DrawWidget where, PixMap pix, uint i) |
284 | { | 284 | { |
285 | QPixmap *PIXMAP = NULL; | 285 | QPixmap *PIXMAP = NULL; |
286 | switch (pix) { | 286 | switch (pix) { |
287 | case PacmanPix : PIXMAP = pacmanPix-> | 287 | case PacmanPix : PIXMAP = pacmanPix-> |
288 | at(checkRange(i, pacmanPix->count()-1)); | 288 | at(checkRange(i, pacmanPix->count()-1)); |
289 | break; | 289 | break; |
290 | case DyingPix : PIXMAP = dyingPix-> | 290 | case DyingPix : PIXMAP = dyingPix-> |
291 | at(checkRange(i, dyingPix->count()-1)); | 291 | at(checkRange(i, dyingPix->count()-1)); |
292 | break; | 292 | break; |
293 | case MonsterPix : PIXMAP = monsterPix-> | 293 | case MonsterPix : PIXMAP = monsterPix-> |
294 | at(checkRange(i, monsterPix->count()-1)); | 294 | at(checkRange(i, monsterPix->count()-1)); |
295 | break; | 295 | break; |
296 | case EyesPix : PIXMAP = eyesPix-> | 296 | case EyesPix : PIXMAP = eyesPix-> |
297 | at(checkRange(i, eyesPix->count()-1)); | 297 | at(checkRange(i, eyesPix->count()-1)); |
298 | break; | 298 | break; |
299 | case FruitPix : PIXMAP = fruitPix-> | 299 | case FruitPix : PIXMAP = fruitPix-> |
300 | at(checkRange(i, fruitPix->count()-1)); | 300 | at(checkRange(i, fruitPix->count()-1)); |
301 | break; | 301 | break; |
302 | case EnergizerPix : PIXMAP = energizerPix-> | 302 | case EnergizerPix : PIXMAP = energizerPix-> |
303 | at(checkRange(i, energizerPix->count()-1)); | 303 | at(checkRange(i, energizerPix->count()-1)); |
304 | break; | 304 | break; |
305 | case FruitScorePix : PIXMAP = fruitScorePix-> | 305 | case FruitScorePix : PIXMAP = fruitScorePix-> |
306 | at(checkRange(i, fruitScorePix->count()-1)); | 306 | at(checkRange(i, fruitScorePix->count()-1)); |
307 | break; | 307 | break; |
308 | case MonsterScorePix : PIXMAP = monsterScorePix-> | 308 | case MonsterScorePix : PIXMAP = monsterScorePix-> |
309 | at(checkRange(i,monsterScorePix->count()-1)); | 309 | at(checkRange(i,monsterScorePix->count()-1)); |
310 | break; | 310 | break; |
311 | default : ; | 311 | default : ; |
312 | } | 312 | } |
313 | 313 | ||
314 | if (PIXMAP == NULL) | 314 | if (PIXMAP == NULL) |
315 | return; | 315 | return; |
316 | 316 | ||
317 | QRect rect = PIXMAP->rect(); | 317 | QRect rect = PIXMAP->rect(); |
318 | QPoint point = this->point(pos); | 318 | QPoint point = this->point(pos); |
319 | rect.moveCenter(QPoint(point.x()-1, point.y()-1)); | 319 | rect.moveCenter(QPoint(point.x()-1, point.y()-1)); |
320 | 320 | ||
321 | switch (where) { | 321 | switch (where) { |
322 | case Widget : bitBlt(w, rect.x(), rect.y(), PIXMAP); | 322 | case Widget : bitBlt(w, rect.x(), rect.y(), PIXMAP); |
323 | break; | 323 | break; |
324 | case RoomPix : bitBlt(&roomPix, rect.x(), rect.y(), PIXMAP); | 324 | case RoomPix : bitBlt(&roomPix, rect.x(), rect.y(), PIXMAP); |
325 | break; | 325 | break; |
326 | case BackPix : bitBlt(&backPix, rect.x(), rect.y(), PIXMAP); | 326 | case BackPix : bitBlt(&backPix, rect.x(), rect.y(), PIXMAP); |
327 | break; | 327 | break; |
328 | } | 328 | } |
329 | } | 329 | } |
330 | 330 | ||
331 | QPixmap Painter::draw(int pos, DrawWidget where, | 331 | QPixmap Painter::draw(int pos, DrawWidget where, |
332 | QString str, QColor fg, QColor bg, int align) | 332 | QString str, QColor fg, QColor bg, int align) |
333 | { | 333 | { |
334 | QPixmap TEXT = bitfont->text(str, fg, bg); | 334 | QPixmap TEXT = bitfont->text(str, fg, bg); |
335 | 335 | ||
336 | QRect rect = this->rect(pos, str, align); | 336 | QRect rect = this->rect(pos, str, align); |
337 | QPixmap SAVE = QPixmap(rect.width(), rect.height()); | 337 | QPixmap SAVE = QPixmap(rect.width(), rect.height()); |
338 | 338 | ||
339 | switch (where) { | 339 | switch (where) { |
340 | case Widget : bitBlt(&SAVE, 0, 0, w, rect.x(), rect.y()); | 340 | case Widget : bitBlt(&SAVE, 0, 0, w, rect.x(), rect.y()); |
341 | bitBlt(w, rect.x(), rect.y(), &TEXT); | 341 | bitBlt(w, rect.x(), rect.y(), &TEXT); |
342 | break; | 342 | break; |
343 | case RoomPix : bitBlt(&SAVE, 0, 0, &roomPix, rect.x(), rect.y()); | 343 | case RoomPix : bitBlt(&SAVE, 0, 0, &roomPix, rect.x(), rect.y()); |
344 | bitBlt(&roomPix, rect.x(), rect.y(), &TEXT); | 344 | bitBlt(&roomPix, rect.x(), rect.y(), &TEXT); |
345 | break; | 345 | break; |
346 | case BackPix : bitBlt(&SAVE, 0, 0, &backPix, rect.x(), rect.y()); | 346 | case BackPix : bitBlt(&SAVE, 0, 0, &backPix, rect.x(), rect.y()); |
347 | bitBlt(&backPix, rect.x(), rect.y(), &TEXT); | 347 | bitBlt(&backPix, rect.x(), rect.y(), &TEXT); |
348 | break; | 348 | break; |
349 | } | 349 | } |
350 | 350 | ||
351 | return SAVE; | 351 | return SAVE; |
352 | } | 352 | } |
353 | 353 | ||
354 | QRect Painter::draw(int col, int row, DrawWidget where, | 354 | QRect Painter::draw(int col, int row, DrawWidget where, |
355 | QString str, QColor fg, QColor bg, int align) | 355 | QString str, QColor fg, QColor bg, int align) |
356 | { | 356 | { |
357 | QPixmap TEXT = bitfont->text(str, fg, bg); | 357 | QPixmap TEXT = bitfont->text(str, fg, bg); |
358 | 358 | ||
359 | QRect rect = this->rect(row*BoardWidth+col, str, align); | 359 | QRect rect = this->rect(row*BoardWidth+col, str, align); |
360 | draw(rect, where, TEXT); | 360 | draw(rect, where, TEXT); |
361 | 361 | ||
362 | return rect; | 362 | return rect; |
363 | } | 363 | } |
364 | 364 | ||
365 | void Painter::initPixmaps() | 365 | void Painter::initPixmaps() |
366 | { | 366 | { |
367 | if (lastPointPixmapName != pointPixmapName.at(level)) { | 367 | if (lastPointPixmapName != pointPixmapName.at(level)) { |
368 | pointPix = loadPixmap(w, pointPixmapName.at(level), pointPix); | 368 | pointPix = loadPixmap(w, pointPixmapName.at(level), pointPix); |
369 | lastPointPixmapName = pointPixmapName.at(level); | 369 | lastPointPixmapName = pointPixmapName.at(level); |
370 | } | 370 | } |
371 | if (lastPrisonPixmapName != prisonPixmapName.at(level)) { | 371 | if (lastPrisonPixmapName != prisonPixmapName.at(level)) { |
372 | prisonPix = loadPixmap(w, prisonPixmapName.at(level), prisonPix); | 372 | prisonPix = loadPixmap(w, prisonPixmapName.at(level), prisonPix); |
373 | lastPrisonPixmapName = prisonPixmapName.at(level); | 373 | lastPrisonPixmapName = prisonPixmapName.at(level); |
374 | } | 374 | } |
375 | if (lastEnergizerPixmapName != energizerPixmapName.at(level)) { | 375 | if (lastEnergizerPixmapName != energizerPixmapName.at(level)) { |
376 | energizerPix = loadPixmap(w, energizerPixmapName.at(level), energizerPix); | 376 | energizerPix = loadPixmap(w, energizerPixmapName.at(level), energizerPix); |
377 | lastEnergizerPixmapName = energizerPixmapName.at(level); | 377 | lastEnergizerPixmapName = energizerPixmapName.at(level); |
378 | } | 378 | } |
379 | if (lastFruitPixmapName != fruitPixmapName.at(level)) { | 379 | if (lastFruitPixmapName != fruitPixmapName.at(level)) { |
380 | fruitPix = loadPixmap(w, fruitPixmapName.at(level), fruitPix); | 380 | fruitPix = loadPixmap(w, fruitPixmapName.at(level), fruitPix); |
381 | lastFruitPixmapName = fruitPixmapName.at(level); | 381 | lastFruitPixmapName = fruitPixmapName.at(level); |
382 | } | 382 | } |
383 | if (lastPacmanPixmapName != pacmanPixmapName.at(level)) { | 383 | if (lastPacmanPixmapName != pacmanPixmapName.at(level)) { |
384 | pacmanPix = loadPixmap(w, pacmanPixmapName.at(level), pacmanPix); | 384 | pacmanPix = loadPixmap(w, pacmanPixmapName.at(level), pacmanPix); |
385 | lastPacmanPixmapName = pacmanPixmapName.at(level); | 385 | lastPacmanPixmapName = pacmanPixmapName.at(level); |
386 | } | 386 | } |
387 | if (lastDyingPixmapName != dyingPixmapName.at(level)) { | 387 | if (lastDyingPixmapName != dyingPixmapName.at(level)) { |
388 | dyingPix = loadPixmap(w, dyingPixmapName.at(level), dyingPix); | 388 | dyingPix = loadPixmap(w, dyingPixmapName.at(level), dyingPix); |
389 | lastDyingPixmapName = dyingPixmapName.at(level); | 389 | lastDyingPixmapName = dyingPixmapName.at(level); |
390 | } | 390 | } |
391 | if (lastEyesPixmapName != eyesPixmapName.at(level)) { | 391 | if (lastEyesPixmapName != eyesPixmapName.at(level)) { |
392 | eyesPix = loadPixmap(w, eyesPixmapName.at(level), eyesPix); | 392 | eyesPix = loadPixmap(w, eyesPixmapName.at(level), eyesPix); |
393 | lastEyesPixmapName = eyesPixmapName.at(level); | 393 | lastEyesPixmapName = eyesPixmapName.at(level); |
394 | } | 394 | } |
diff --git a/noncore/games/kpacman/referee.cpp b/noncore/games/kpacman/referee.cpp index 6d8f3fb..1b810d8 100644 --- a/noncore/games/kpacman/referee.cpp +++ b/noncore/games/kpacman/referee.cpp | |||
@@ -1,398 +1,398 @@ | |||
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 <kaccel.h> | 8 | #include <kaccel.h> |
9 | #include <referee.h> | 9 | #include <referee.h> |
10 | #include <referee.moc> | 10 | #include <referee.moc> |
11 | #elif defined( QPE_PORT ) | 11 | #elif defined( QPE_PORT ) |
12 | #include <qaccel.h> | 12 | #include <qaccel.h> |
13 | #include <qpe/qpeapplication.h> | 13 | #include <qpe/qpeapplication.h> |
14 | #include "config.h" | 14 | #include <qpe/config.h> |
15 | #include "referee.h" | 15 | #include "referee.h" |
16 | #endif | 16 | #endif |
17 | 17 | ||
18 | #include <qdatetm.h> | 18 | #include <qdatetm.h> |
19 | #include <stdlib.h> | 19 | #include <stdlib.h> |
20 | #include <qtimer.h> | 20 | #include <qtimer.h> |
21 | #include <qevent.h> | 21 | #include <qevent.h> |
22 | #include <qcolor.h> | 22 | #include <qcolor.h> |
23 | #include <qkeycode.h> | 23 | #include <qkeycode.h> |
24 | #include <qfileinfo.h> | 24 | #include <qfileinfo.h> |
25 | 25 | ||
26 | #include "board.h" | 26 | #include "board.h" |
27 | #include "pacman.h" | 27 | #include "pacman.h" |
28 | #include "monster.h" | 28 | #include "monster.h" |
29 | #include "fruit.h" | 29 | #include "fruit.h" |
30 | #include "painter.h" | 30 | #include "painter.h" |
31 | 31 | ||
32 | Referee::Referee( QWidget *parent, const char *name, int Scheme, int Mode, Bitfont *font) | 32 | Referee::Referee( QWidget *parent, const char *name, int Scheme, int Mode, Bitfont *font) |
33 | : QWidget( parent, name ) | 33 | : QWidget( parent, name ) |
34 | { | 34 | { |
35 | gameState.resize(12); | 35 | gameState.resize(12); |
36 | gameTimer = 0; | 36 | gameTimer = 0; |
37 | energizerTimer = 0; | 37 | energizerTimer = 0; |
38 | 38 | ||
39 | focusedPause = FALSE; | 39 | focusedPause = FALSE; |
40 | setFocusPolicy(QWidget::StrongFocus); | 40 | setFocusPolicy(QWidget::StrongFocus); |
41 | 41 | ||
42 | initKeys(); | 42 | initKeys(); |
43 | 43 | ||
44 | scheme = Scheme; | 44 | scheme = Scheme; |
45 | mode = Mode; | 45 | mode = Mode; |
46 | confScheme(); | 46 | confScheme(); |
47 | 47 | ||
48 | board = new Board(BoardWidth*BoardHeight); | 48 | board = new Board(BoardWidth*BoardHeight); |
49 | 49 | ||
50 | pix = new Painter(board, this, scheme, mode, font); | 50 | pix = new Painter(board, this, scheme, mode, font); |
51 | setFixedSize(pix->levelPix().size()); | 51 | setFixedSize(pix->levelPix().size()); |
52 | 52 | ||
53 | pacman = new Pacman(board); | 53 | pacman = new Pacman(board); |
54 | 54 | ||
55 | fruit = new Fruit(board); | 55 | fruit = new Fruit(board); |
56 | 56 | ||
57 | monsters = new QList<Monster>; | 57 | monsters = new QList<Monster>; |
58 | monsters->setAutoDelete(TRUE); | 58 | monsters->setAutoDelete(TRUE); |
59 | 59 | ||
60 | monsterRect = new QList<QRect>; | 60 | monsterRect = new QList<QRect>; |
61 | monsterRect->setAutoDelete(TRUE); | 61 | monsterRect->setAutoDelete(TRUE); |
62 | 62 | ||
63 | energizers = new QList<Energizer>; | 63 | energizers = new QList<Energizer>; |
64 | energizers->setAutoDelete(TRUE); | 64 | energizers->setAutoDelete(TRUE); |
65 | 65 | ||
66 | energizerRect = new QList<QRect>; | 66 | energizerRect = new QList<QRect>; |
67 | energizerRect->setAutoDelete(TRUE); | 67 | energizerRect->setAutoDelete(TRUE); |
68 | 68 | ||
69 | pacmanRect.setRect(0, 0, 0, 0); | 69 | pacmanRect.setRect(0, 0, 0, 0); |
70 | fruitRect.setRect(0, 0, 0, 0); | 70 | fruitRect.setRect(0, 0, 0, 0); |
71 | 71 | ||
72 | QTime midnight( 0, 0, 0 ); | 72 | QTime midnight( 0, 0, 0 ); |
73 | srand( midnight.secsTo(QTime::currentTime()) ); | 73 | srand( midnight.secsTo(QTime::currentTime()) ); |
74 | 74 | ||
75 | lifes = 0; | 75 | lifes = 0; |
76 | points = 0; | 76 | points = 0; |
77 | 77 | ||
78 | emit setLifes(lifes); | 78 | emit setLifes(lifes); |
79 | emit setPoints(points); | 79 | emit setPoints(points); |
80 | 80 | ||
81 | intro(); | 81 | intro(); |
82 | } | 82 | } |
83 | 83 | ||
84 | void Referee::paintEvent( QPaintEvent *e) | 84 | void Referee::paintEvent( QPaintEvent *e) |
85 | { | 85 | { |
86 | if (gameState.testBit(HallOfFame)) | 86 | if (gameState.testBit(HallOfFame)) |
87 | return; | 87 | return; |
88 | 88 | ||
89 | QRect rect = e->rect(); | 89 | QRect rect = e->rect(); |
90 | 90 | ||
91 | if (!rect.isEmpty()) { | 91 | if (!rect.isEmpty()) { |
92 | QPixmap p = pix->levelPix(); | 92 | QPixmap p = pix->levelPix(); |
93 | bitBlt(this, rect.x(), rect.y(), | 93 | bitBlt(this, rect.x(), rect.y(), |
94 | &p, rect.x(), rect.y(), rect.width(), rect.height()); | 94 | &p, rect.x(), rect.y(), rect.width(), rect.height()); |
95 | } | 95 | } |
96 | 96 | ||
97 | if ((gameState.testBit(GameOver) || gameState.testBit(Demonstration)) && | 97 | if ((gameState.testBit(GameOver) || gameState.testBit(Demonstration)) && |
98 | rect.intersects(pix->rect(board->position(fruithome), tr("GAME OVER")))) | 98 | rect.intersects(pix->rect(board->position(fruithome), tr("GAME OVER")))) |
99 | pix->draw(board->position(fruithome), Widget, tr("GAME OVER"), RED); | 99 | pix->draw(board->position(fruithome), Widget, tr("GAME OVER"), RED); |
100 | 100 | ||
101 | for (Energizer *e = energizers->first(); e != 0; e = energizers->next()) { | 101 | for (Energizer *e = energizers->first(); e != 0; e = energizers->next()) { |
102 | if (e && e->state() == on && | 102 | if (e && e->state() == on && |
103 | rect.intersects(pix->rect(e->position(), EnergizerPix)) && | 103 | rect.intersects(pix->rect(e->position(), EnergizerPix)) && |
104 | !(e->position() == pacman->position() && gameState.testBit(Scoring))) { | 104 | !(e->position() == pacman->position() && gameState.testBit(Scoring))) { |
105 | if (e->pix() != -1) | 105 | if (e->pix() != -1) |
106 | pix->draw(e->position(), Widget, EnergizerPix, e->pix()); | 106 | pix->draw(e->position(), Widget, EnergizerPix, e->pix()); |
107 | } | 107 | } |
108 | } | 108 | } |
109 | 109 | ||
110 | if (!gameState.testBit(Init)) { | 110 | if (!gameState.testBit(Init)) { |
111 | 111 | ||
112 | if (!gameState.testBit(Dying) && (fruit->pix() != -1)) | 112 | if (!gameState.testBit(Dying) && (fruit->pix() != -1)) |
113 | if (fruit->state() != active) { | 113 | if (fruit->state() != active) { |
114 | if (rect.intersects(pix->rect(fruit->position(), FruitScorePix, fruit->pix()))) | 114 | if (rect.intersects(pix->rect(fruit->position(), FruitScorePix, fruit->pix()))) |
115 | pix->draw(fruit->position(), Widget, FruitScorePix, fruit->pix()); | 115 | pix->draw(fruit->position(), Widget, FruitScorePix, fruit->pix()); |
116 | } else { | 116 | } else { |
117 | if (rect.intersects(pix->rect(fruit->position(), FruitPix, fruit->pix()))) | 117 | if (rect.intersects(pix->rect(fruit->position(), FruitPix, fruit->pix()))) |
118 | pix->draw(fruit->position(), Widget, FruitPix, fruit->pix()); | 118 | pix->draw(fruit->position(), Widget, FruitPix, fruit->pix()); |
119 | } | 119 | } |
120 | 120 | ||
121 | for (Monster *m = monsters->first(); m != 0; m = monsters->next()) | 121 | for (Monster *m = monsters->first(); m != 0; m = monsters->next()) |
122 | if (m && m->state() == harmless && | 122 | if (m && m->state() == harmless && |
123 | rect.intersects(pix->rect(m->position(), MonsterPix)) && | 123 | rect.intersects(pix->rect(m->position(), MonsterPix)) && |
124 | !(m->position() == pacman->position() && gameState.testBit(Scoring))) { | 124 | !(m->position() == pacman->position() && gameState.testBit(Scoring))) { |
125 | if (m->body() != -1) | 125 | if (m->body() != -1) |
126 | pix->draw(m->position(), Widget, MonsterPix, m->body()); | 126 | pix->draw(m->position(), Widget, MonsterPix, m->body()); |
127 | if (m->eyes() != -1) | 127 | if (m->eyes() != -1) |
128 | pix->draw(m->position(), Widget, EyesPix, m->eyes()); | 128 | pix->draw(m->position(), Widget, EyesPix, m->eyes()); |
129 | } | 129 | } |
130 | 130 | ||
131 | if (!gameState.testBit(Scoring) && !gameState.testBit(LevelDone) && | 131 | if (!gameState.testBit(Scoring) && !gameState.testBit(LevelDone) && |
132 | rect.intersects(pix->rect(pacman->position(), PacmanPix)) && pacman->pix() != -1) | 132 | rect.intersects(pix->rect(pacman->position(), PacmanPix)) && pacman->pix() != -1) |
133 | pix->draw(pacman->position(), Widget, PacmanPix, pacman->pix()); | 133 | pix->draw(pacman->position(), Widget, PacmanPix, pacman->pix()); |
134 | 134 | ||
135 | for (Monster *m = monsters->first(); m != 0; m = monsters->next()) | 135 | for (Monster *m = monsters->first(); m != 0; m = monsters->next()) |
136 | if (m && m->state() != harmless && | 136 | if (m && m->state() != harmless && |
137 | rect.intersects(pix->rect(m->position(), MonsterPix)) && | 137 | rect.intersects(pix->rect(m->position(), MonsterPix)) && |
138 | !(m->position() == pacman->position() && gameState.testBit(Scoring))) { | 138 | !(m->position() == pacman->position() && gameState.testBit(Scoring))) { |
139 | if (m->body() != -1) | 139 | if (m->body() != -1) |
140 | pix->draw(m->position(), Widget, MonsterPix, m->body()); | 140 | pix->draw(m->position(), Widget, MonsterPix, m->body()); |
141 | if (m->eyes() != -1) | 141 | if (m->eyes() != -1) |
142 | pix->draw(m->position(), Widget, EyesPix, m->eyes()); | 142 | pix->draw(m->position(), Widget, EyesPix, m->eyes()); |
143 | } | 143 | } |
144 | } | 144 | } |
145 | 145 | ||
146 | if (gameState.testBit(Scoring) && | 146 | if (gameState.testBit(Scoring) && |
147 | rect.intersects(pix->rect(pacman->position(), MonsterScorePix, monstersEaten-1))) | 147 | rect.intersects(pix->rect(pacman->position(), MonsterScorePix, monstersEaten-1))) |
148 | pix->draw(pacman->position(), Widget, MonsterScorePix, monstersEaten-1); | 148 | pix->draw(pacman->position(), Widget, MonsterScorePix, monstersEaten-1); |
149 | 149 | ||
150 | if (gameState.testBit(Init) && gameState.testBit(Dying) && | 150 | if (gameState.testBit(Init) && gameState.testBit(Dying) && |
151 | timerCount < pix->maxPixmaps(DyingPix) && | 151 | timerCount < pix->maxPixmaps(DyingPix) && |
152 | rect.intersects(pix->rect(pacman->position(), PacmanPix))) | 152 | rect.intersects(pix->rect(pacman->position(), PacmanPix))) |
153 | pix->draw(pacman->position(), Widget, DyingPix, timerCount); | 153 | pix->draw(pacman->position(), Widget, DyingPix, timerCount); |
154 | 154 | ||
155 | if (gameState.testBit(LevelDone) && | 155 | if (gameState.testBit(LevelDone) && |
156 | rect.intersects(pix->rect(pacman->position(), PacmanPix))) | 156 | rect.intersects(pix->rect(pacman->position(), PacmanPix))) |
157 | pix->draw(pacman->position(), Widget, PacmanPix, pacman->pix()); | 157 | pix->draw(pacman->position(), Widget, PacmanPix, pacman->pix()); |
158 | 158 | ||
159 | if (gameState.testBit(Player) && | 159 | if (gameState.testBit(Player) && |
160 | rect.intersects(pix->rect(board->position(monsterhome, 0), tr("PLAYER ONE")))) | 160 | rect.intersects(pix->rect(board->position(monsterhome, 0), tr("PLAYER ONE")))) |
161 | pix->draw(board->position(monsterhome, 0), Widget, tr("PLAYER ONE"), CYAN); | 161 | pix->draw(board->position(monsterhome, 0), Widget, tr("PLAYER ONE"), CYAN); |
162 | 162 | ||
163 | if (gameState.testBit(Ready) && | 163 | if (gameState.testBit(Ready) && |
164 | rect.intersects(pix->rect(board->position(fruithome), tr("READY!")))) | 164 | rect.intersects(pix->rect(board->position(fruithome), tr("READY!")))) |
165 | pix->draw(board->position(fruithome), Widget, tr("READY!"), YELLOW); | 165 | pix->draw(board->position(fruithome), Widget, tr("READY!"), YELLOW); |
166 | 166 | ||
167 | if (gameState.testBit(Paused) && | 167 | if (gameState.testBit(Paused) && |
168 | rect.intersects(pix->rect((BoardWidth*BoardHeight)/2-BoardWidth, tr("PAUSED")))) | 168 | rect.intersects(pix->rect((BoardWidth*BoardHeight)/2-BoardWidth, tr("PAUSED")))) |
169 | pix->draw((BoardWidth*BoardHeight)/2-BoardWidth, Widget, tr("PAUSED"), RED, BLACK); | 169 | pix->draw((BoardWidth*BoardHeight)/2-BoardWidth, Widget, tr("PAUSED"), RED, BLACK); |
170 | } | 170 | } |
171 | 171 | ||
172 | void Referee::timerEvent( QTimerEvent *e ) | 172 | void Referee::timerEvent( QTimerEvent *e ) |
173 | { | 173 | { |
174 | if (gameState.testBit(HallOfFame)) | 174 | if (gameState.testBit(HallOfFame)) |
175 | return; | 175 | return; |
176 | 176 | ||
177 | QRect lastRect; | 177 | QRect lastRect; |
178 | int lastPix; | 178 | int lastPix; |
179 | bool moved = FALSE; | 179 | bool moved = FALSE; |
180 | int eated = 0; | 180 | int eated = 0; |
181 | 181 | ||
182 | if (e->timerId() == energizerTimer) { | 182 | if (e->timerId() == energizerTimer) { |
183 | for (int e = 0; e < board->energizers(); e++) { | 183 | for (int e = 0; e < board->energizers(); e++) { |
184 | lastRect = pix->rect(energizers->at(e)->position(), EnergizerPix); | 184 | lastRect = pix->rect(energizers->at(e)->position(), EnergizerPix); |
185 | lastPix = energizers->at(e)->pix(); | 185 | lastPix = energizers->at(e)->pix(); |
186 | if (energizers->at(e)->move()) { | 186 | if (energizers->at(e)->move()) { |
187 | moved = TRUE; | 187 | moved = TRUE; |
188 | *energizerRect->at(e) = pix->rect(energizers->at(e)->position(), EnergizerPix); | 188 | *energizerRect->at(e) = pix->rect(energizers->at(e)->position(), EnergizerPix); |
189 | if (lastPix == energizers->at(e)->pix() && | 189 | if (lastPix == energizers->at(e)->pix() && |
190 | lastRect == pix->rect(energizers->at(e)->position(), EnergizerPix)) | 190 | lastRect == pix->rect(energizers->at(e)->position(), EnergizerPix)) |
191 | energizerRect->at(e)->setRect(0, 0, 0, 0); | 191 | energizerRect->at(e)->setRect(0, 0, 0, 0); |
192 | else | 192 | else |
193 | *energizerRect->at(e) = pix->rect(*energizerRect->at(e), lastRect); | 193 | *energizerRect->at(e) = pix->rect(*energizerRect->at(e), lastRect); |
194 | } | 194 | } |
195 | } | 195 | } |
196 | 196 | ||
197 | for (int e = 0; e < board->energizers(); e++) | 197 | for (int e = 0; e < board->energizers(); e++) |
198 | if (!energizerRect->at(e)->isNull()) | 198 | if (!energizerRect->at(e)->isNull()) |
199 | repaint(*energizerRect->at(e), FALSE); | 199 | repaint(*energizerRect->at(e), FALSE); |
200 | 200 | ||
201 | return; | 201 | return; |
202 | } | 202 | } |
203 | 203 | ||
204 | timerCount++; | 204 | timerCount++; |
205 | 205 | ||
206 | lastRect = pix->rect(pacman->position(), PacmanPix); | 206 | lastRect = pix->rect(pacman->position(), PacmanPix); |
207 | lastPix = pacman->pix(); | 207 | lastPix = pacman->pix(); |
208 | 208 | ||
209 | if (moved = pacman->move()) { // pacman really moved | 209 | if (moved = pacman->move()) { // pacman really moved |
210 | pacmanRect = pix->rect(pacman->position(), PacmanPix); | 210 | pacmanRect = pix->rect(pacman->position(), PacmanPix); |
211 | if (lastPix == pacman->pix() && | 211 | if (lastPix == pacman->pix() && |
212 | lastRect == pix->rect(pacman->position(), PacmanPix)) | 212 | lastRect == pix->rect(pacman->position(), PacmanPix)) |
213 | pacmanRect.setRect(0, 0, 0, 0); // nothing to do, because the pixmap | 213 | pacmanRect.setRect(0, 0, 0, 0); // nothing to do, because the pixmap |
214 | else // and the position isn't changed. | 214 | else // and the position isn't changed. |
215 | pacmanRect = pix->rect(pacmanRect, lastRect); | 215 | pacmanRect = pix->rect(pacmanRect, lastRect); |
216 | } else | 216 | } else |
217 | pacmanRect.setRect(0, 0, 0, 0); | 217 | pacmanRect.setRect(0, 0, 0, 0); |
218 | 218 | ||
219 | int pos = pacman->position(); | 219 | int pos = pacman->position(); |
220 | 220 | ||
221 | if (moved && board->isMonster(pos) && !gameState.testBit(Dying)) { | 221 | if (moved && board->isMonster(pos) && !gameState.testBit(Dying)) { |
222 | for (Monster *m = monsters->first(); m != 0; m = monsters->next()) | 222 | for (Monster *m = monsters->first(); m != 0; m = monsters->next()) |
223 | if (m && m->position() == pos) { | 223 | if (m && m->position() == pos) { |
224 | if (m->state() == harmless && !gameState.testBit(Dying)) { | 224 | if (m->state() == harmless && !gameState.testBit(Dying)) { |
225 | m->setREM(remTicks[level]); | 225 | m->setREM(remTicks[level]); |
226 | m->setDirection(X); // prevent movement before eaten() | 226 | m->setDirection(X); // prevent movement before eaten() |
227 | eated++; | 227 | eated++; |
228 | if (gameState.testBit(Introducing)) | 228 | if (gameState.testBit(Introducing)) |
229 | m->setPosition(OUT); | 229 | m->setPosition(OUT); |
230 | } | 230 | } |
231 | if (m->state() == dangerous && !gameState.testBit(Dying)) | 231 | if (m->state() == dangerous && !gameState.testBit(Dying)) |
232 | killed(); | 232 | killed(); |
233 | } | 233 | } |
234 | } | 234 | } |
235 | 235 | ||
236 | if (moved && !gameState.testBit(Dying)) { | 236 | if (moved && !gameState.testBit(Dying)) { |
237 | if (board->isPoint(pos)) { | 237 | if (board->isPoint(pos)) { |
238 | board->reset(pos, Point); | 238 | board->reset(pos, Point); |
239 | score(pointScore); | 239 | score(pointScore); |
240 | pix->erase(pos, PointPix); | 240 | pix->erase(pos, PointPix); |
241 | } | 241 | } |
242 | if (board->isEnergizer(pos)) { | 242 | if (board->isEnergizer(pos)) { |
243 | for (int e = 0; e < board->energizers();e++) { | 243 | for (int e = 0; e < board->energizers();e++) { |
244 | if (energizers->at(e)->position() == pos) { | 244 | if (energizers->at(e)->position() == pos) { |
245 | energizers->at(e)->setOff(); | 245 | energizers->at(e)->setOff(); |
246 | energizers->remove(e); | 246 | energizers->remove(e); |
247 | energizerRect->remove(e); | 247 | energizerRect->remove(e); |
248 | e = board->energizers(); | 248 | e = board->energizers(); |
249 | } | 249 | } |
250 | } | 250 | } |
251 | board->reset(pos, energizer); | 251 | board->reset(pos, energizer); |
252 | score(energizerScore); | 252 | score(energizerScore); |
253 | monstersEaten = 0; | 253 | monstersEaten = 0; |
254 | for (Monster *m = monsters->first(); m != 0; m = monsters->next()) | 254 | for (Monster *m = monsters->first(); m != 0; m = monsters->next()) |
255 | if (m && m->state() != rem) { | 255 | if (m && m->state() != rem) { |
256 | m->setHarmless(harmlessTicks[level], harmlessDurTicks[level], | 256 | m->setHarmless(harmlessTicks[level], harmlessDurTicks[level], |
257 | harmlessWarnTicks[level]); | 257 | harmlessWarnTicks[level]); |
258 | if (gameState.testBit(Introducing)) | 258 | if (gameState.testBit(Introducing)) |
259 | m->setDirection(board->turn(m->direction())); | 259 | m->setDirection(board->turn(m->direction())); |
260 | } | 260 | } |
261 | } | 261 | } |
262 | if (pos == fruit->position() && fruit->state() == active) { | 262 | if (pos == fruit->position() && fruit->state() == active) { |
263 | fruit->setEaten(fruitScoreDurTicks[level]); | 263 | fruit->setEaten(fruitScoreDurTicks[level]); |
264 | initFruit(FALSE); | 264 | initFruit(FALSE); |
265 | score(fruitScore[fruit->pix()]); | 265 | score(fruitScore[fruit->pix()]); |
266 | } | 266 | } |
267 | } | 267 | } |
268 | 268 | ||
269 | if (!gameState.testBit(Introducing)) { | 269 | if (!gameState.testBit(Introducing)) { |
270 | if (fruit->state() != active && fruit->pix() >= 0) | 270 | if (fruit->state() != active && fruit->pix() >= 0) |
271 | lastRect = pix->rect(fruit->position(), FruitScorePix, fruit->pix()); | 271 | lastRect = pix->rect(fruit->position(), FruitScorePix, fruit->pix()); |
272 | else | 272 | else |
273 | lastRect = pix->rect(fruit->position(), FruitPix, fruit->pix()); | 273 | lastRect = pix->rect(fruit->position(), FruitPix, fruit->pix()); |
274 | 274 | ||
275 | lastPix = fruit->pix(); | 275 | lastPix = fruit->pix(); |
276 | if (fruit->move()) { | 276 | if (fruit->move()) { |
277 | if (pos == fruit->position() && fruit->state() == active) { | 277 | if (pos == fruit->position() && fruit->state() == active) { |
278 | fruit->setEaten(fruitScoreDurTicks[level]); | 278 | fruit->setEaten(fruitScoreDurTicks[level]); |
279 | initFruit(FALSE); | 279 | initFruit(FALSE); |
280 | score(fruitScore[fruit->pix()]); | 280 | score(fruitScore[fruit->pix()]); |
281 | } | 281 | } |
282 | if (fruit->state() != active && fruit->pix() >= 0) | 282 | if (fruit->state() != active && fruit->pix() >= 0) |
283 | fruitRect = pix->rect(fruit->position(), FruitScorePix, fruit->pix()); | 283 | fruitRect = pix->rect(fruit->position(), FruitScorePix, fruit->pix()); |
284 | else | 284 | else |
285 | fruitRect = pix->rect(fruit->position(), FruitPix, fruit->pix()); | 285 | fruitRect = pix->rect(fruit->position(), FruitPix, fruit->pix()); |
286 | if (lastPix == fruit->pix() && lastRect == fruitRect) | 286 | if (lastPix == fruit->pix() && lastRect == fruitRect) |
287 | fruitRect.setRect(0, 0, 0, 0); | 287 | fruitRect.setRect(0, 0, 0, 0); |
288 | else | 288 | else |
289 | fruitRect = pix->rect(fruitRect, lastRect); | 289 | fruitRect = pix->rect(fruitRect, lastRect); |
290 | } else | 290 | } else |
291 | fruitRect.setRect(0, 0, 0, 0); | 291 | fruitRect.setRect(0, 0, 0, 0); |
292 | } else | 292 | } else |
293 | fruitRect.setRect(0, 0, 0, 0); | 293 | fruitRect.setRect(0, 0, 0, 0); |
294 | 294 | ||
295 | int lastBodyPix; | 295 | int lastBodyPix; |
296 | int lastEyesPix; | 296 | int lastEyesPix; |
297 | 297 | ||
298 | for (Monster *m = monsters->first(); m != 0; m = monsters->next()) | 298 | for (Monster *m = monsters->first(); m != 0; m = monsters->next()) |
299 | if (m) { | 299 | if (m) { |
300 | lastRect = pix->rect(m->position(), MonsterPix); | 300 | lastRect = pix->rect(m->position(), MonsterPix); |
301 | lastBodyPix = m->body(); | 301 | lastBodyPix = m->body(); |
302 | lastEyesPix = m->eyes(); | 302 | lastEyesPix = m->eyes(); |
303 | if (m->move()) { | 303 | if (m->move()) { |
304 | moved = TRUE; | 304 | moved = TRUE; |
305 | *monsterRect->at(m->id()) = pix->rect(m->position(), MonsterPix); | 305 | *monsterRect->at(m->id()) = pix->rect(m->position(), MonsterPix); |
306 | if (lastBodyPix == m->body() && lastEyesPix == m->eyes() && | 306 | if (lastBodyPix == m->body() && lastEyesPix == m->eyes() && |
307 | lastRect == pix->rect(m->position(), MonsterPix)) | 307 | lastRect == pix->rect(m->position(), MonsterPix)) |
308 | monsterRect->at(m->id())->setRect(0, 0, 0, 0); | 308 | monsterRect->at(m->id())->setRect(0, 0, 0, 0); |
309 | else | 309 | else |
310 | *monsterRect->at(m->id()) = pix->rect(*monsterRect->at(m->id()), lastRect); | 310 | *monsterRect->at(m->id()) = pix->rect(*monsterRect->at(m->id()), lastRect); |
311 | if (m->position() == pos && !gameState.testBit(Dying)) { | 311 | if (m->position() == pos && !gameState.testBit(Dying)) { |
312 | if (m->state() == harmless && !gameState.testBit(Dying)) { | 312 | if (m->state() == harmless && !gameState.testBit(Dying)) { |
313 | m->setREM(remTicks[level]); | 313 | m->setREM(remTicks[level]); |
314 | eated++; | 314 | eated++; |
315 | if (gameState.testBit(Introducing)) { | 315 | if (gameState.testBit(Introducing)) { |
316 | m->setPosition(OUT); | 316 | m->setPosition(OUT); |
317 | m->setDirection(X); | 317 | m->setDirection(X); |
318 | } | 318 | } |
319 | } | 319 | } |
320 | if (m->state() == dangerous && !gameState.testBit(Dying)) | 320 | if (m->state() == dangerous && !gameState.testBit(Dying)) |
321 | killed(); | 321 | killed(); |
322 | } | 322 | } |
323 | } else | 323 | } else |
324 | monsterRect->at(m->id())->setRect(0, 0, 0, 0); | 324 | monsterRect->at(m->id())->setRect(0, 0, 0, 0); |
325 | } | 325 | } |
326 | 326 | ||
327 | for (int m = 0; m < board->monsters(); m++) | 327 | for (int m = 0; m < board->monsters(); m++) |
328 | if (pacmanRect.intersects(*monsterRect->at(m))) { | 328 | if (pacmanRect.intersects(*monsterRect->at(m))) { |
329 | pacmanRect = pix->rect(pacmanRect, *monsterRect->at(m)); | 329 | pacmanRect = pix->rect(pacmanRect, *monsterRect->at(m)); |
330 | monsterRect->at(m)->setRect(0, 0, 0, 0); | 330 | monsterRect->at(m)->setRect(0, 0, 0, 0); |
331 | } else | 331 | } else |
332 | for (int im = m+1; im < board->monsters(); im++) | 332 | for (int im = m+1; im < board->monsters(); im++) |
333 | if (monsterRect->at(m)->intersects(*monsterRect->at(im))) { | 333 | if (monsterRect->at(m)->intersects(*monsterRect->at(im))) { |
334 | *monsterRect->at(m) = pix->rect(*monsterRect->at(m), *monsterRect->at(im)); | 334 | *monsterRect->at(m) = pix->rect(*monsterRect->at(m), *monsterRect->at(im)); |
335 | monsterRect->at(im)->setRect(0, 0, 0, 0); | 335 | monsterRect->at(im)->setRect(0, 0, 0, 0); |
336 | } | 336 | } |
337 | 337 | ||
338 | if (!pacmanRect.isNull()) | 338 | if (!pacmanRect.isNull()) |
339 | repaint(pacmanRect, FALSE); | 339 | repaint(pacmanRect, FALSE); |
340 | 340 | ||
341 | if (!fruitRect.isNull()) | 341 | if (!fruitRect.isNull()) |
342 | repaint(fruitRect, FALSE); | 342 | repaint(fruitRect, FALSE); |
343 | 343 | ||
344 | for (int m = 0; m < board->monsters(); m++) | 344 | for (int m = 0; m < board->monsters(); m++) |
345 | if (!monsterRect->at(m)->isNull()) | 345 | if (!monsterRect->at(m)->isNull()) |
346 | repaint(*monsterRect->at(m), FALSE); | 346 | repaint(*monsterRect->at(m), FALSE); |
347 | 347 | ||
348 | if (board->points() == 0 && !gameState.testBit(Dying)) | 348 | if (board->points() == 0 && !gameState.testBit(Dying)) |
349 | levelUp(); | 349 | levelUp(); |
350 | 350 | ||
351 | if (eated > 0 && !gameState.testBit(Dying)) { | 351 | if (eated > 0 && !gameState.testBit(Dying)) { |
352 | timerCount = eated; | 352 | timerCount = eated; |
353 | eaten(); | 353 | eaten(); |
354 | } | 354 | } |
355 | 355 | ||
356 | if (gameState.testBit(Introducing) && moved) | 356 | if (gameState.testBit(Introducing) && moved) |
357 | introPlay(); | 357 | introPlay(); |
358 | } | 358 | } |
359 | 359 | ||
360 | void Referee::repaintFigures() | 360 | void Referee::repaintFigures() |
361 | { | 361 | { |
362 | pacmanRect = pix->rect(pacman->position(), PacmanPix); | 362 | pacmanRect = pix->rect(pacman->position(), PacmanPix); |
363 | 363 | ||
364 | for (int e = 0; e < board->energizers(); e++) { | 364 | for (int e = 0; e < board->energizers(); e++) { |
365 | *energizerRect->at(e) = pix->rect(board->position(energizer, e), EnergizerPix); | 365 | *energizerRect->at(e) = pix->rect(board->position(energizer, e), EnergizerPix); |
366 | 366 | ||
367 | if (pacmanRect.intersects(*energizerRect->at(e))) { | 367 | if (pacmanRect.intersects(*energizerRect->at(e))) { |
368 | pacmanRect = pix->rect(pacmanRect, *energizerRect->at(e)); | 368 | pacmanRect = pix->rect(pacmanRect, *energizerRect->at(e)); |
369 | energizerRect->at(e)->setRect(0, 0, 0, 0); | 369 | energizerRect->at(e)->setRect(0, 0, 0, 0); |
370 | } else | 370 | } else |
371 | for (int ie = e+1; ie < board->energizers(); ie++) | 371 | for (int ie = e+1; ie < board->energizers(); ie++) |
372 | if (energizerRect->at(e)->intersects(*energizerRect->at(ie))) { | 372 | if (energizerRect->at(e)->intersects(*energizerRect->at(ie))) { |
373 | *energizerRect->at(e) = pix->rect(*energizerRect->at(e), *energizerRect->at(ie)); | 373 | *energizerRect->at(e) = pix->rect(*energizerRect->at(e), *energizerRect->at(ie)); |
374 | energizerRect->at(ie)->setRect(0, 0, 0, 0); | 374 | energizerRect->at(ie)->setRect(0, 0, 0, 0); |
375 | } | 375 | } |
376 | } | 376 | } |
377 | 377 | ||
378 | if (fruit->pix() != -1 && fruit->state() != active) | 378 | if (fruit->pix() != -1 && fruit->state() != active) |
379 | fruitRect = pix->rect(fruit->position(), FruitScorePix, fruit->pix()); | 379 | fruitRect = pix->rect(fruit->position(), FruitScorePix, fruit->pix()); |
380 | else | 380 | else |
381 | fruitRect = pix->rect(fruit->position(), FruitPix, fruit->pix()); | 381 | fruitRect = pix->rect(fruit->position(), FruitPix, fruit->pix()); |
382 | 382 | ||
383 | if (pacmanRect.intersects(fruitRect)) { | 383 | if (pacmanRect.intersects(fruitRect)) { |
384 | pacmanRect = pix->rect(pacmanRect, fruitRect); | 384 | pacmanRect = pix->rect(pacmanRect, fruitRect); |
385 | fruitRect.setRect(0, 0, 0, 0); | 385 | fruitRect.setRect(0, 0, 0, 0); |
386 | } | 386 | } |
387 | 387 | ||
388 | for (int m = 0; m < board->monsters(); m++) { | 388 | for (int m = 0; m < board->monsters(); m++) { |
389 | *monsterRect->at(m) = pix->rect(board->position(monster, m), MonsterPix); | 389 | *monsterRect->at(m) = pix->rect(board->position(monster, m), MonsterPix); |
390 | 390 | ||
391 | if (pacmanRect.intersects(*monsterRect->at(m))) { | 391 | if (pacmanRect.intersects(*monsterRect->at(m))) { |
392 | pacmanRect = pix->rect(pacmanRect, *monsterRect->at(m)); | 392 | pacmanRect = pix->rect(pacmanRect, *monsterRect->at(m)); |
393 | monsterRect->at(m)->setRect(0, 0, 0, 0); | 393 | monsterRect->at(m)->setRect(0, 0, 0, 0); |
394 | } else | 394 | } else |
395 | for (int im = m+1; im < board->monsters(); im++) | 395 | for (int im = m+1; im < board->monsters(); im++) |
396 | if (monsterRect->at(m)->intersects(*monsterRect->at(im))) { | 396 | if (monsterRect->at(m)->intersects(*monsterRect->at(im))) { |
397 | *monsterRect->at(m) = pix->rect(*monsterRect->at(m), *monsterRect->at(im)); | 397 | *monsterRect->at(m) = pix->rect(*monsterRect->at(m), *monsterRect->at(im)); |
398 | monsterRect->at(im)->setRect(0, 0, 0, 0); | 398 | monsterRect->at(im)->setRect(0, 0, 0, 0); |
diff --git a/noncore/games/kpacman/status.cpp b/noncore/games/kpacman/status.cpp index 1ef910d..2a17c21 100644 --- a/noncore/games/kpacman/status.cpp +++ b/noncore/games/kpacman/status.cpp | |||
@@ -1,368 +1,368 @@ | |||
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 <qpe/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 | ||
22 | Status::Status( QWidget *parent, const char *name, int Scheme, int Mode ) : | 22 | Status::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 | qWarning("Status::Status"); |
26 | actualLifes = 0; | 26 | actualLifes = 0; |
27 | actualLevel = 0; | 27 | actualLevel = 0; |
28 | 28 | ||
29 | lifesPix = NULL; | 29 | lifesPix = NULL; |
30 | levelPix = NULL; | 30 | levelPix = NULL; |
31 | 31 | ||
32 | scheme = Scheme; | 32 | scheme = Scheme; |
33 | mode = Mode; | 33 | mode = Mode; |
34 | level = 0; | 34 | level = 0; |
35 | 35 | ||
36 | confScheme(); | 36 | confScheme(); |
37 | } | 37 | } |
38 | 38 | ||
39 | QList<QPixmap> *Status::loadPixmap(QWidget *parent, QString pixmapName, | 39 | QList<QPixmap> *Status::loadPixmap(QWidget *parent, QString pixmapName, |
40 | QList<QPixmap> *pixmaps) | 40 | QList<QPixmap> *pixmaps) |
41 | { | 41 | { |
42 | if (pixmaps == NULL) { | 42 | if (pixmaps == NULL) { |
43 | pixmaps = new QList<QPixmap>; | 43 | pixmaps = new QList<QPixmap>; |
44 | pixmaps->setAutoDelete(TRUE); | 44 | pixmaps->setAutoDelete(TRUE); |
45 | } | 45 | } |
46 | 46 | ||
47 | if (!pixmaps->isEmpty()) | 47 | if (!pixmaps->isEmpty()) |
48 | pixmaps->clear(); | 48 | pixmaps->clear(); |
49 | 49 | ||
50 | QPixmap PIXMAP(pixmapName); | 50 | QPixmap PIXMAP(pixmapName); |
51 | if (PIXMAP.isNull() || PIXMAP.mask() == NULL) { | 51 | if (PIXMAP.isNull() || PIXMAP.mask() == NULL) { |
52 | QString msg = tr("The pixmap could not be contructed.\n\n" | 52 | QString msg = tr("The pixmap could not be contructed.\n\n" |
53 | "The file '@PIXMAPNAME@' does not exist,\n" | 53 | "The file '@PIXMAPNAME@' does not exist,\n" |
54 | "or is of an unknown format."); | 54 | "or is of an unknown format."); |
55 | msg.replace(QRegExp("@PIXMAPNAME@"), pixmapName); | 55 | msg.replace(QRegExp("@PIXMAPNAME@"), pixmapName); |
56 | QMessageBox::information(parent, tr("Initialization Error"), | 56 | QMessageBox::information(parent, tr("Initialization Error"), |
57 | (const char *) msg); | 57 | (const char *) msg); |
58 | return 0; | 58 | return 0; |
59 | } | 59 | } |
60 | 60 | ||
61 | int height = PIXMAP.height(); | 61 | int height = PIXMAP.height(); |
62 | int width = (height == 0) ? 0 : PIXMAP.width()/(PIXMAP.width()/height); | 62 | int width = (height == 0) ? 0 : PIXMAP.width()/(PIXMAP.width()/height); |
63 | 63 | ||
64 | QBitmap BITMAP; | 64 | QBitmap BITMAP; |
65 | QBitmap MASK; | 65 | QBitmap MASK; |
66 | 66 | ||
67 | BITMAP = *PIXMAP.mask(); | 67 | BITMAP = *PIXMAP.mask(); |
68 | MASK.resize(width, height); | 68 | MASK.resize(width, height); |
69 | 69 | ||
70 | for (int x = 0; x < PIXMAP.width()/width; x++) { | 70 | for (int x = 0; x < PIXMAP.width()/width; x++) { |
71 | QPixmap *pixmap = new QPixmap(width, height); | 71 | QPixmap *pixmap = new QPixmap(width, height); |
72 | pixmaps->append(pixmap); | 72 | pixmaps->append(pixmap); |
73 | 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); |
74 | 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); |
75 | pixmap->setMask(MASK); | 75 | pixmap->setMask(MASK); |
76 | } | 76 | } |
77 | 77 | ||
78 | return pixmaps; | 78 | return pixmaps; |
79 | } | 79 | } |
80 | 80 | ||
81 | void Status::paintEvent( QPaintEvent *) | 81 | void Status::paintEvent( QPaintEvent *) |
82 | { | 82 | { |
83 | for (int x = 0; x < actualLifes && !lifesPix->isEmpty(); x++) | 83 | for (int x = 0; x < actualLifes && !lifesPix->isEmpty(); x++) |
84 | bitBlt(this, lifesPix->at(0)->width()+(lifesPix->at(0)->width()*x), | 84 | bitBlt(this, lifesPix->at(0)->width()+(lifesPix->at(0)->width()*x), |
85 | (height()-lifesPix->at(0)->height())/2, | 85 | (height()-lifesPix->at(0)->height())/2, |
86 | lifesPix->at(0), 0, 0, | 86 | lifesPix->at(0), 0, 0, |
87 | lifesPix->at(0)->width(), lifesPix->at(0)->height()); | 87 | lifesPix->at(0)->width(), lifesPix->at(0)->height()); |
88 | 88 | ||
89 | for (int x = 0; x < actualLevel && !levelPix->isEmpty(); x++) { | 89 | for (int x = 0; x < actualLevel && !levelPix->isEmpty(); x++) { |
90 | 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]), |
91 | (height()-levelPix->at(x)->height())/2, | 91 | (height()-levelPix->at(x)->height())/2, |
92 | levelPix->at(x)->width(), levelPix->at(x)->height()); | 92 | levelPix->at(x)->width(), levelPix->at(x)->height()); |
93 | 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]), |
94 | (height()-levelPix->at(x)->height())/2, | 94 | (height()-levelPix->at(x)->height())/2, |
95 | levelPix->at(x), 0, 0, | 95 | levelPix->at(x), 0, 0, |
96 | levelPix->at(x)->width(), levelPix->at(x)->height()); | 96 | levelPix->at(x)->width(), levelPix->at(x)->height()); |
97 | } | 97 | } |
98 | } | 98 | } |
99 | 99 | ||
100 | void Status::initPixmaps() | 100 | void Status::initPixmaps() |
101 | { | 101 | { |
102 | if (lastLifesPixmapName != lifesPixmapName.at(level)) { | 102 | if (lastLifesPixmapName != lifesPixmapName.at(level)) { |
103 | lifesPix = loadPixmap(this, lifesPixmapName.at(level), lifesPix); | 103 | lifesPix = loadPixmap(this, lifesPixmapName.at(level), lifesPix); |
104 | lastLifesPixmapName = lifesPixmapName.at(level); | 104 | lastLifesPixmapName = lifesPixmapName.at(level); |
105 | } | 105 | } |
106 | if (lastLevelPixmapName != levelPixmapName.at(level)) { | 106 | if (lastLevelPixmapName != levelPixmapName.at(level)) { |
107 | levelPix = loadPixmap(this, levelPixmapName.at(level), levelPix); | 107 | levelPix = loadPixmap(this, levelPixmapName.at(level), levelPix); |
108 | lastLevelPixmapName = levelPixmapName.at(level); | 108 | lastLevelPixmapName = levelPixmapName.at(level); |
109 | } | 109 | } |
110 | } | 110 | } |
111 | 111 | ||
112 | QString Status::decodeHexOctString(QString s) | 112 | QString Status::decodeHexOctString(QString s) |
113 | { | 113 | { |
114 | QString value; | 114 | QString value; |
115 | QString valids; | 115 | QString valids; |
116 | int pos, xpos = 0, opos = 0; | 116 | int pos, xpos = 0, opos = 0; |
117 | int v, len, leadin; | 117 | int v, len, leadin; |
118 | const char *ptr; | 118 | const char *ptr; |
119 | uchar c; | 119 | uchar c; |
120 | 120 | ||
121 | 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) || |
122 | ((opos = s.find(QRegExp("\\\\[0-7]+"), opos)) != -1)) { | 122 | ((opos = s.find(QRegExp("\\\\[0-7]+"), opos)) != -1)) { |
123 | if (xpos != -1) { | 123 | if (xpos != -1) { |
124 | valids = "0123456789abcdef"; | 124 | valids = "0123456789abcdef"; |
125 | leadin = 2; | 125 | leadin = 2; |
126 | pos = xpos; | 126 | pos = xpos; |
127 | } else { | 127 | } else { |
128 | valids = "01234567"; | 128 | valids = "01234567"; |
129 | leadin = 1; | 129 | leadin = 1; |
130 | pos = opos; | 130 | pos = opos; |
131 | } | 131 | } |
132 | 132 | ||
133 | c = '\0'; | 133 | c = '\0'; |
134 | len = 0; | 134 | len = 0; |
135 | value = s.mid(pos+leadin, 3); | 135 | value = s.mid(pos+leadin, 3); |
136 | ptr = (const char *) value; | 136 | ptr = (const char *) value; |
137 | 137 | ||
138 | while (*ptr != '\0' && (v = valids.find(*ptr++, 0, FALSE)) != -1) { | 138 | while (*ptr != '\0' && (v = valids.find(*ptr++, 0, FALSE)) != -1) { |
139 | c = (c * valids.length()) + v; | 139 | c = (c * valids.length()) + v; |
140 | len++; | 140 | len++; |
141 | } | 141 | } |
142 | 142 | ||
143 | value.fill(c, 1); | 143 | value.fill(c, 1); |
144 | s.replace(pos, len+leadin, value); | 144 | s.replace(pos, len+leadin, value); |
145 | } | 145 | } |
146 | 146 | ||
147 | return s; | 147 | return s; |
148 | } | 148 | } |
149 | 149 | ||
150 | void Status::fillArray(QArray<int> &array, QString values, int max) | 150 | void Status::fillArray(QArray<int> &array, QString values, int max) |
151 | { | 151 | { |
152 | array.resize(max); | 152 | array.resize(max); |
153 | int last = 0; | 153 | int last = 0; |
154 | bool ok; | 154 | bool ok; |
155 | QString value; | 155 | QString value; |
156 | 156 | ||
157 | for (uint i = 0; i < array.size(); i++) { | 157 | for (uint i = 0; i < array.size(); i++) { |
158 | if (values.find(',') < 0 && values.length() > 0) { | 158 | if (values.find(',') < 0 && values.length() > 0) { |
159 | value = values; | 159 | value = values; |
160 | values = ""; | 160 | values = ""; |
161 | } | 161 | } |
162 | if (values.find(',') >= 0) { | 162 | if (values.find(',') >= 0) { |
163 | value = values.left(values.find(',')); | 163 | value = values.left(values.find(',')); |
164 | values.remove(0,values.find(',')+1); | 164 | values.remove(0,values.find(',')+1); |
165 | } | 165 | } |
166 | array[i] = value.toInt(&ok); | 166 | array[i] = value.toInt(&ok); |
167 | if (ok) | 167 | if (ok) |
168 | last = array[i]; | 168 | last = array[i]; |
169 | else | 169 | else |
170 | array[i] = last; | 170 | array[i] = last; |
171 | } | 171 | } |
172 | } | 172 | } |
173 | 173 | ||
174 | void Status::fillStrList(QStrList &list, QString values, int max) | 174 | void Status::fillStrList(QStrList &list, QString values, int max) |
175 | { | 175 | { |
176 | if (!list.isEmpty()) | 176 | if (!list.isEmpty()) |
177 | list.clear(); | 177 | list.clear(); |
178 | 178 | ||
179 | QString last = ""; | 179 | QString last = ""; |
180 | QString value; | 180 | QString value; |
181 | 181 | ||
182 | for (uint i = 0; i < (uint) max; i++) { | 182 | for (uint i = 0; i < (uint) max; i++) { |
183 | if (values.find(',') < 0 && values.length() > 0) { | 183 | if (values.find(',') < 0 && values.length() > 0) { |
184 | value = values; | 184 | value = values; |
185 | values = ""; | 185 | values = ""; |
186 | } | 186 | } |
187 | if (values.find(',') >= 0) { | 187 | if (values.find(',') >= 0) { |
188 | value = values.left(values.find(',')); | 188 | value = values.left(values.find(',')); |
189 | values.remove(0,values.find(',')+1); | 189 | values.remove(0,values.find(',')+1); |
190 | } | 190 | } |
191 | if (!value.isEmpty()) | 191 | if (!value.isEmpty()) |
192 | last = decodeHexOctString(value); | 192 | last = decodeHexOctString(value); |
193 | list.append(last); | 193 | list.append(last); |
194 | } | 194 | } |
195 | } | 195 | } |
196 | 196 | ||
197 | void Status::fillPixmapName(QStrList &pixmapName) | 197 | void Status::fillPixmapName(QStrList &pixmapName) |
198 | { | 198 | { |
199 | QStrList list = pixmapName; | 199 | QStrList list = pixmapName; |
200 | 200 | ||
201 | if (!pixmapName.isEmpty()) | 201 | if (!pixmapName.isEmpty()) |
202 | pixmapName.clear(); | 202 | pixmapName.clear(); |
203 | 203 | ||
204 | QString pixmap; | 204 | QString pixmap; |
205 | 205 | ||
206 | QFileInfo fileInfo; | 206 | QFileInfo fileInfo; |
207 | 207 | ||
208 | for (uint i = 0; i < list.count(); i++) { | 208 | for (uint i = 0; i < list.count(); i++) { |
209 | pixmap = list.at(i); | 209 | pixmap = list.at(i); |
210 | 210 | ||
211 | if (pixmap.left(1) != "/" && pixmap.left(1) != "~") | 211 | if (pixmap.left(1) != "/" && pixmap.left(1) != "~") |
212 | pixmap = FIND_APP_DATA( pixmapDirectory+pixmap ); | 212 | pixmap = FIND_APP_DATA( pixmapDirectory+pixmap ); |
213 | 213 | ||
214 | fileInfo.setFile(pixmap); | 214 | fileInfo.setFile(pixmap); |
215 | if (!fileInfo.isReadable() || !fileInfo.isFile()) | 215 | if (!fileInfo.isReadable() || !fileInfo.isFile()) |
216 | pixmap = ""; | 216 | pixmap = ""; |
217 | 217 | ||
218 | pixmapName.append(pixmap); | 218 | pixmapName.append(pixmap); |
219 | } | 219 | } |
220 | } | 220 | } |
221 | 221 | ||
222 | void Status::confLevels(bool defGroup) | 222 | void Status::confLevels(bool defGroup) |
223 | { | 223 | { |
224 | APP_CONFIG_BEGIN( cfg ); | 224 | APP_CONFIG_BEGIN( cfg ); |
225 | if (defGroup || cfg->hasKey("Levels")) | 225 | if (defGroup || cfg->hasKey("Levels")) |
226 | maxLevel = cfg->readNumEntry("Levels", 13); | 226 | maxLevel = cfg->readNumEntry("Levels", 13); |
227 | APP_CONFIG_END( cfg ); | 227 | APP_CONFIG_END( cfg ); |
228 | } | 228 | } |
229 | 229 | ||
230 | void Status::confMisc(bool defGroup) | 230 | void Status::confMisc(bool defGroup) |
231 | { | 231 | { |
232 | APP_CONFIG_BEGIN( cfg ); | 232 | APP_CONFIG_BEGIN( cfg ); |
233 | if (defGroup || cfg->hasKey("LevelPosition")) | 233 | if (defGroup || cfg->hasKey("LevelPosition")) |
234 | fillArray(levelPos, cfg->readEntry("LevelPosition", "0,1,2,3,,4,,5,,6,,7"), maxLevel); | 234 | fillArray(levelPos, cfg->readEntry("LevelPosition", "0,1,2,3,,4,,5,,6,,7"), maxLevel); |
235 | 235 | ||
236 | if (defGroup || cfg->hasKey("PixmapDirectory")) { | 236 | if (defGroup || cfg->hasKey("PixmapDirectory")) { |
237 | pixmapDirectory = cfg->readEntry("PixmapDirectory"); | 237 | pixmapDirectory = cfg->readEntry("PixmapDirectory"); |
238 | 238 | ||
239 | if (pixmapDirectory.left(1) != "/" && pixmapDirectory.left(1) != "~") | 239 | if (pixmapDirectory.left(1) != "/" && pixmapDirectory.left(1) != "~") |
240 | pixmapDirectory.insert(0, "pics/"); | 240 | pixmapDirectory.insert(0, "pics/"); |
241 | if (pixmapDirectory.right(1) != "/") | 241 | if (pixmapDirectory.right(1) != "/") |
242 | pixmapDirectory.append("/"); | 242 | pixmapDirectory.append("/"); |
243 | } | 243 | } |
244 | 244 | ||
245 | if (defGroup || cfg->hasKey("LifesPixmapName")) | 245 | if (defGroup || cfg->hasKey("LifesPixmapName")) |
246 | fillStrList(lifesPixmapName, | 246 | fillStrList(lifesPixmapName, |
247 | cfg->readEntry("LifesPixmapName", "lifes.xpm"), maxLevel+1); | 247 | cfg->readEntry("LifesPixmapName", "lifes.xpm"), maxLevel+1); |
248 | if (defGroup || cfg->hasKey("LevelPixmapName")) | 248 | if (defGroup || cfg->hasKey("LevelPixmapName")) |
249 | fillStrList(levelPixmapName, | 249 | fillStrList(levelPixmapName, |
250 | cfg->readEntry("LevelPixmapName", "level.xpm"), maxLevel+1); | 250 | cfg->readEntry("LevelPixmapName", "fruit.xpm"), maxLevel+1); |
251 | APP_CONFIG_END( cfg ); | 251 | APP_CONFIG_END( cfg ); |
252 | } | 252 | } |
253 | 253 | ||
254 | void Status::confScheme() | 254 | void Status::confScheme() |
255 | { | 255 | { |
256 | APP_CONFIG_BEGIN( cfg ); | 256 | APP_CONFIG_BEGIN( cfg ); |
257 | SAVE_CONFIG_GROUP( cfg, oldgroup ); | 257 | SAVE_CONFIG_GROUP( cfg, oldgroup ); |
258 | QString newgroup; | 258 | QString newgroup; |
259 | 259 | ||
260 | // if not set, read mode and scheme from the configfile | 260 | // if not set, read mode and scheme from the configfile |
261 | if (mode == -1 && scheme == -1) { | 261 | if (mode == -1 && scheme == -1) { |
262 | scheme = cfg->readNumEntry("Scheme", -1); | 262 | scheme = cfg->readNumEntry("Scheme", -1); |
263 | mode = cfg->readNumEntry("Mode", -1); | 263 | mode = cfg->readNumEntry("Mode", -1); |
264 | 264 | ||
265 | // if mode is not set in the defGroup-group, lookup the scheme group | 265 | // if mode is not set in the defGroup-group, lookup the scheme group |
266 | if (scheme != -1 || mode == -1) { | 266 | if (scheme != -1 || mode == -1) { |
267 | newgroup.sprintf("Scheme %d", scheme); | 267 | newgroup.sprintf("Scheme %d", scheme); |
268 | cfg->setGroup(newgroup); | 268 | cfg->setGroup(newgroup); |
269 | 269 | ||
270 | mode = cfg->readNumEntry("Mode", -1); | 270 | mode = cfg->readNumEntry("Mode", -1); |
271 | RESTORE_CONFIG_GROUP( cfg, oldgroup ); | 271 | RESTORE_CONFIG_GROUP( cfg, oldgroup ); |
272 | } | 272 | } |
273 | } | 273 | } |
274 | 274 | ||
275 | confLevels(); | 275 | confLevels(); |
276 | 276 | ||
277 | if (mode != -1) { | 277 | if (mode != -1) { |
278 | newgroup.sprintf("Mode %d", mode); | 278 | newgroup.sprintf("Mode %d", mode); |
279 | cfg->setGroup(newgroup); | 279 | cfg->setGroup(newgroup); |
280 | 280 | ||
281 | confLevels(FALSE); | 281 | confLevels(FALSE); |
282 | } | 282 | } |
283 | 283 | ||
284 | if (scheme != -1) { | 284 | if (scheme != -1) { |
285 | newgroup.sprintf("Scheme %d", scheme); | 285 | newgroup.sprintf("Scheme %d", scheme); |
286 | cfg->setGroup(newgroup); | 286 | cfg->setGroup(newgroup); |
287 | 287 | ||
288 | confLevels(FALSE); | 288 | confLevels(FALSE); |
289 | } | 289 | } |
290 | 290 | ||
291 | RESTORE_CONFIG_GROUP( cfg, oldgroup ); | 291 | RESTORE_CONFIG_GROUP( cfg, oldgroup ); |
292 | 292 | ||
293 | confMisc(); | 293 | confMisc(); |
294 | 294 | ||
295 | if (mode != -1) { | 295 | if (mode != -1) { |
296 | newgroup.sprintf("Mode %d", mode); | 296 | newgroup.sprintf("Mode %d", mode); |
297 | cfg->setGroup(newgroup); | 297 | cfg->setGroup(newgroup); |
298 | 298 | ||
299 | confMisc(FALSE); | 299 | confMisc(FALSE); |
300 | } | 300 | } |
301 | 301 | ||
302 | if (scheme != -1) { | 302 | if (scheme != -1) { |
303 | newgroup.sprintf("Scheme %d", scheme); | 303 | newgroup.sprintf("Scheme %d", scheme); |
304 | cfg->setGroup(newgroup); | 304 | cfg->setGroup(newgroup); |
305 | 305 | ||
306 | confMisc(FALSE); | 306 | confMisc(FALSE); |
307 | } | 307 | } |
308 | 308 | ||
309 | fillPixmapName(lifesPixmapName); | 309 | fillPixmapName(lifesPixmapName); |
310 | fillPixmapName(levelPixmapName); | 310 | fillPixmapName(levelPixmapName); |
311 | 311 | ||
312 | initPixmaps(); | 312 | initPixmaps(); |
313 | 313 | ||
314 | setFixedHeight(minHeight()); | 314 | setFixedHeight(minHeight()); |
315 | 315 | ||
316 | RESTORE_CONFIG_GROUP( cfg, oldgroup ); | 316 | RESTORE_CONFIG_GROUP( cfg, oldgroup ); |
317 | APP_CONFIG_END( cfg ); | 317 | APP_CONFIG_END( cfg ); |
318 | } | 318 | } |
319 | 319 | ||
320 | void Status::setScheme(int Scheme, int Mode) | 320 | void Status::setScheme(int Scheme, int Mode) |
321 | { | 321 | { |
322 | mode = Mode; | 322 | mode = Mode; |
323 | scheme = Scheme; | 323 | scheme = Scheme; |
324 | 324 | ||
325 | confScheme(); | 325 | confScheme(); |
326 | 326 | ||
327 | repaint(); | 327 | repaint(); |
328 | } | 328 | } |
329 | 329 | ||
330 | int Status::minHeight() | 330 | int Status::minHeight() |
331 | { | 331 | { |
332 | if (lifesPix->isEmpty() && levelPix->isEmpty()) | 332 | if (lifesPix->isEmpty() && levelPix->isEmpty()) |
333 | return 0; | 333 | return 0; |
334 | if (levelPix->isEmpty()) | 334 | if (levelPix->isEmpty()) |
335 | return lifesPix->at(0)->height(); | 335 | return lifesPix->at(0)->height(); |
336 | if (lifesPix->isEmpty()) | 336 | if (lifesPix->isEmpty()) |
337 | return levelPix->at(0)->height(); | 337 | return levelPix->at(0)->height(); |
338 | return (lifesPix->at(0)->height() > levelPix->at(0)->height()) ? | 338 | return (lifesPix->at(0)->height() > levelPix->at(0)->height()) ? |
339 | lifesPix->at(0)->height() : levelPix->at(0)->height(); | 339 | lifesPix->at(0)->height() : levelPix->at(0)->height(); |
340 | } | 340 | } |
341 | 341 | ||
342 | int Status::minWidth() | 342 | int Status::minWidth() |
343 | { | 343 | { |
344 | if (lifesPix->isEmpty() && levelPix->isEmpty()) | 344 | if (lifesPix->isEmpty() && levelPix->isEmpty()) |
345 | return 0; | 345 | return 0; |
346 | if (levelPix->isEmpty()) | 346 | if (levelPix->isEmpty()) |
347 | return lifesPix->at(0)->width(); | 347 | return lifesPix->at(0)->width(); |
348 | if (lifesPix->isEmpty()) | 348 | if (lifesPix->isEmpty()) |
349 | return levelPix->at(0)->width(); | 349 | return levelPix->at(0)->width(); |
350 | return (lifesPix->at(0)->width() > levelPix->at(0)->width()) ? | 350 | return (lifesPix->at(0)->width() > levelPix->at(0)->width()) ? |
351 | lifesPix->at(0)->width() : levelPix->at(0)->width(); | 351 | lifesPix->at(0)->width() : levelPix->at(0)->width(); |
352 | } | 352 | } |
353 | 353 | ||
354 | void Status::setLifes(int lifes) | 354 | void Status::setLifes(int lifes) |
355 | { | 355 | { |
356 | actualLifes = lifes; | 356 | actualLifes = lifes; |
357 | repaint(); | 357 | repaint(); |
358 | } | 358 | } |
359 | 359 | ||
360 | void Status::setLevel(int Level) | 360 | void Status::setLevel(int Level) |
361 | { | 361 | { |
362 | level = Level; | 362 | level = Level; |
363 | 363 | ||
364 | initPixmaps(); | 364 | initPixmaps(); |
365 | 365 | ||
366 | actualLevel = (level > (int) levelPix->count()) ? (int) levelPix->count() : level; | 366 | actualLevel = (level > (int) levelPix->count()) ? (int) levelPix->count() : level; |
367 | repaint(); | 367 | repaint(); |
368 | } | 368 | } |