-rw-r--r-- | noncore/games/wordgame/wordgame.cpp | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/noncore/games/wordgame/wordgame.cpp b/noncore/games/wordgame/wordgame.cpp index 47d6725..52e2be2 100644 --- a/noncore/games/wordgame/wordgame.cpp +++ b/noncore/games/wordgame/wordgame.cpp | |||
@@ -1,182 +1,190 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qtopia Environment. | 4 | ** This file is part of Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 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 | 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 | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 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. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | 20 | ||
21 | 21 | ||
22 | #include "wordgame.h" | 22 | #include "wordgame.h" |
23 | 23 | ||
24 | #include <opie2/oresource.h> | ||
25 | |||
24 | #include <qpe/global.h> | 26 | #include <qpe/global.h> |
25 | #include <qpe/resource.h> | ||
26 | #include <qpe/config.h> | 27 | #include <qpe/config.h> |
27 | 28 | ||
28 | #include <qapplication.h> | 29 | #include <qapplication.h> |
29 | #include <qmessagebox.h> | 30 | #include <qmessagebox.h> |
30 | #include <qcombobox.h> | 31 | #include <qcombobox.h> |
31 | #include <qdir.h> | 32 | #include <qdir.h> |
32 | #include <qlineedit.h> | 33 | #include <qlineedit.h> |
33 | #include <qpushbutton.h> | 34 | #include <qpushbutton.h> |
34 | #include <qtextstream.h> | 35 | #include <qtextstream.h> |
35 | #include <qtimer.h> | 36 | #include <qtimer.h> |
36 | #include <qtoolbar.h> | 37 | #include <qtoolbar.h> |
37 | #include <qtoolbutton.h> | 38 | #include <qtoolbutton.h> |
38 | #include <qvbox.h> | 39 | #include <qvbox.h> |
39 | #include <qwidgetstack.h> | 40 | #include <qwidgetstack.h> |
40 | #include <qlayout.h> | 41 | #include <qlayout.h> |
41 | 42 | ||
42 | #include <stdlib.h> | 43 | #include <stdlib.h> |
43 | #include <unistd.h> | 44 | #include <unistd.h> |
44 | #include <pwd.h> | 45 | #include <pwd.h> |
45 | #include <sys/types.h> | 46 | #include <sys/types.h> |
46 | 47 | ||
47 | enum RuleEffects { | 48 | enum RuleEffects { |
48 | Multiplier=15, | 49 | Multiplier=15, |
49 | MultiplyAll=64, | 50 | MultiplyAll=64, |
50 | Start=128 | 51 | Start=128 |
51 | }; | 52 | }; |
52 | 53 | ||
53 | static int tile_smallw = 16; | 54 | static int tile_smallw = 16; |
54 | static int tile_smallh = 16; | 55 | static int tile_smallh = 16; |
55 | static int tile_bigw = 22; | 56 | static int tile_bigw = 22; |
56 | static int tile_bigh = 22; | 57 | static int tile_bigh = 22; |
57 | static int tile_stweak = -2; | 58 | static int tile_stweak = -2; |
58 | static int tile_btweak = -1; | 59 | static int tile_btweak = -1; |
59 | 60 | ||
60 | static const int rack_tiles=7; | 61 | static const int rack_tiles=7; |
61 | 62 | ||
62 | const char* sampleWGR= | 63 | const char* sampleWGR= |
63 | "wordgame_shapes\n" | 64 | "wordgame_shapes\n" |
64 | "15 15\n" | 65 | "15 15\n" |
65 | "400001040100004\n" | 66 | "400001040100004\n" |
66 | "030000000000030\n" | 67 | "030000000000030\n" |
67 | "002002000200200\n" | 68 | "002002000200200\n" |
68 | "000300020003000\n" | 69 | "000300020003000\n" |
69 | "000020000020000\n" | 70 | "000020000020000\n" |
70 | "102001000100201\n" | 71 | "102001000100201\n" |
71 | "000000202000000\n" | 72 | "000000202000000\n" |
72 | "400200050002004\n" | 73 | "400200050002004\n" |
73 | "000000202000000\n" | 74 | "000000202000000\n" |
74 | "102001000100201\n" | 75 | "102001000100201\n" |
75 | "000020000020000\n" | 76 | "000020000020000\n" |
76 | "000300020003000\n" | 77 | "000300020003000\n" |
77 | "002002000200200\n" | 78 | "002002000200200\n" |
78 | "030000000000030\n" | 79 | "030000000000030\n" |
79 | "400001040100004\n" | 80 | "400001040100004\n" |
80 | "1 2 3 66 67 194 100 0\n" | 81 | "1 2 3 66 67 194 100 0\n" |
81 | "1 j 8\n" | 82 | "1 j 8\n" |
82 | "1 q 7\n" | 83 | "1 q 7\n" |
83 | "1 x 6\n" | 84 | "1 x 6\n" |
84 | "1 z 6\n" | 85 | "1 z 6\n" |
85 | "1 w 4\n" | 86 | "1 w 4\n" |
86 | "1 k 4\n" | 87 | "1 k 4\n" |
87 | "1 v 3\n" | 88 | "1 v 3\n" |
88 | "1 f 3\n" | 89 | "1 f 3\n" |
89 | "2 y 3\n" | 90 | "2 y 3\n" |
90 | "2 h 2\n" | 91 | "2 h 2\n" |
91 | "2 b 2\n" | 92 | "2 b 2\n" |
92 | "2 m 2\n" | 93 | "2 m 2\n" |
93 | "3 p 2\n" | 94 | "3 p 2\n" |
94 | "3 g 2\n" | 95 | "3 g 2\n" |
95 | "3 u 2\n" | 96 | "3 u 2\n" |
96 | "4 d 2\n" | 97 | "4 d 2\n" |
97 | "4 c 2\n" | 98 | "4 c 2\n" |
98 | "5 l 1\n" | 99 | "5 l 1\n" |
99 | "5 o 1\n" | 100 | "5 o 1\n" |
100 | "7 t 1\n" | 101 | "7 t 1\n" |
101 | "7 n 1\n" | 102 | "7 n 1\n" |
102 | "7 a 1\n" | 103 | "7 a 1\n" |
103 | "7 r 1\n" | 104 | "7 r 1\n" |
104 | "8 s 1\n" | 105 | "8 s 1\n" |
105 | "8 i 1\n" | 106 | "8 i 1\n" |
106 | "11 e 1\n" | 107 | "11 e 1\n" |
107 | "0\n"; | 108 | "0\n"; |
108 | 109 | ||
109 | WordGame::WordGame( QWidget* parent, const char* name, WFlags fl ) : | 110 | WordGame::WordGame( QWidget* parent, const char* name, WFlags fl ) : |
110 | QMainWindow(parent, name, fl) | 111 | QMainWindow(parent, name, fl) |
111 | { | 112 | { |
112 | if ( qApp->desktop()->width() < 240 ) { | 113 | if ( qApp->desktop()->width() < 240 ) { |
113 | tile_smallw = 10; | 114 | tile_smallw = 10; |
114 | tile_smallh = 10; | 115 | tile_smallh = 10; |
115 | tile_bigw = 16; | 116 | tile_bigw = 16; |
116 | tile_bigh = 16; | 117 | tile_bigh = 16; |
117 | tile_stweak = 0; | 118 | tile_stweak = 0; |
118 | tile_btweak = 0; | 119 | tile_btweak = 0; |
119 | } | 120 | } |
120 | 121 | ||
121 | setIcon( Resource::loadPixmap( "wordgame/WordGame.png" ) ); | 122 | setIcon( Opie::Core::OResource::loadPixmap( "wordgame/WordGame" ) ); |
122 | setCaption( tr("Word Game") ); | 123 | setCaption( tr("Word Game") ); |
123 | 124 | ||
124 | setToolBarsMovable( FALSE ); | 125 | setToolBarsMovable( FALSE ); |
125 | vbox = new QVBox(this); | 126 | vbox = new QVBox(this); |
126 | 127 | ||
127 | setCentralWidget(vbox); | 128 | setCentralWidget(vbox); |
128 | toolbar = new QToolBar(this); | 129 | toolbar = new QToolBar(this); |
129 | addToolBar(toolbar, Bottom); | 130 | addToolBar(toolbar, Bottom); |
130 | reset = new QToolButton(Resource::loadPixmap("back"), tr("Back"), "", this, SLOT(resetTurn()), toolbar); | 131 | bool useBigIcon = qApp->desktop()->size().width() > 330; |
131 | done = new QToolButton(Resource::loadPixmap("done"), tr("Done"), "", this, SLOT(endTurn()), toolbar); | 132 | reset = new QToolButton(Opie::Core::OResource::loadPixmap("back", Opie::Core::OResource::SmallIcon), |
133 | tr("Back"), "", this, SLOT(resetTurn()), toolbar); | ||
134 | reset->setUsesBigPixmap( useBigIcon ); | ||
135 | done = new QToolButton(Opie::Core::OResource::loadPixmap("done", Opie::Core::OResource::SmallIcon), | ||
136 | tr("Done"), "", this, SLOT(endTurn()), toolbar); | ||
137 | done->setUsesBigPixmap( useBigIcon ); | ||
132 | scoreinfo = new ScoreInfo(toolbar); | 138 | scoreinfo = new ScoreInfo(toolbar); |
133 | scoreinfo->setFont(QFont("Helvetica",10)); | 139 | scoreinfo->setFont(QFont("Helvetica",10)); |
134 | new QToolButton(Resource::loadPixmap("finish"), tr("Close"), "", this, SLOT(endGame()), toolbar); | 140 | QToolButton *btn = new QToolButton(Opie::Core::OResource::loadPixmap("finish", Opie::Core::OResource::SmallIcon), |
141 | tr("Close"), "", this, SLOT(endGame()), toolbar); | ||
142 | btn->setUsesBigPixmap( useBigIcon ); | ||
135 | toolbar->setStretchableWidget(scoreinfo); | 143 | toolbar->setStretchableWidget(scoreinfo); |
136 | 144 | ||
137 | cpu = 0; | 145 | cpu = 0; |
138 | board = 0; | 146 | board = 0; |
139 | bag = 0; | 147 | bag = 0; |
140 | racks = 0; | 148 | racks = 0; |
141 | 149 | ||
142 | aiheart = new QTimer(this); | 150 | aiheart = new QTimer(this); |
143 | connect(aiheart, SIGNAL(timeout()), this, SLOT(think())); | 151 | connect(aiheart, SIGNAL(timeout()), this, SLOT(think())); |
144 | 152 | ||
145 | readConfig(); | 153 | readConfig(); |
146 | } | 154 | } |
147 | 155 | ||
148 | WordGame::~WordGame() | 156 | WordGame::~WordGame() |
149 | { | 157 | { |
150 | writeConfig(); | 158 | writeConfig(); |
151 | } | 159 | } |
152 | 160 | ||
153 | void WordGame::writeConfig() | 161 | void WordGame::writeConfig() |
154 | { | 162 | { |
155 | Config cfg("WordGame"); | 163 | Config cfg("WordGame"); |
156 | cfg.setGroup("Game"); | 164 | cfg.setGroup("Game"); |
157 | cfg.writeEntry("NameList",namelist,';'); | 165 | cfg.writeEntry("NameList",namelist,';'); |
158 | cfg.writeEntry("CurrentPlayer",gameover ? 0 : player+1); | 166 | cfg.writeEntry("CurrentPlayer",gameover ? 0 : player+1); |
159 | if ( !gameover ) { | 167 | if ( !gameover ) { |
160 | cfg.writeEntry("Rules",rules); | 168 | cfg.writeEntry("Rules",rules); |
161 | bag->writeConfig(cfg); | 169 | bag->writeConfig(cfg); |
162 | board->writeConfig(cfg); | 170 | board->writeConfig(cfg); |
163 | scoreinfo->writeConfig(cfg); | 171 | scoreinfo->writeConfig(cfg); |
164 | } | 172 | } |
165 | for (int p=0; p<nplayers; p++) { | 173 | for (int p=0; p<nplayers; p++) { |
166 | cfg.setGroup("Player"+QString::number(p+1)); | 174 | cfg.setGroup("Player"+QString::number(p+1)); |
167 | if ( gameover ) cfg.clearGroup(); else rack(p)->writeConfig(cfg); | 175 | if ( gameover ) cfg.clearGroup(); else rack(p)->writeConfig(cfg); |
168 | } | 176 | } |
169 | } | 177 | } |
170 | 178 | ||
171 | void WordGame::readConfig() | 179 | void WordGame::readConfig() |
172 | { | 180 | { |
173 | Config cfg("WordGame"); | 181 | Config cfg("WordGame"); |
174 | cfg.setGroup("Game"); | 182 | cfg.setGroup("Game"); |
175 | int currentplayer = cfg.readNumEntry("CurrentPlayer",0); | 183 | int currentplayer = cfg.readNumEntry("CurrentPlayer",0); |
176 | QStringList pnames = cfg.readListEntry("NameList",';'); | 184 | QStringList pnames = cfg.readListEntry("NameList",';'); |
177 | if ( currentplayer ) { | 185 | if ( currentplayer ) { |
178 | gameover = FALSE; | 186 | gameover = FALSE; |
179 | rules = cfg.readEntry("Rules"); | 187 | rules = cfg.readEntry("Rules"); |
180 | if ( rules.find("x-wordgamerules") >= 0 ) { | 188 | if ( rules.find("x-wordgamerules") >= 0 ) { |
181 | // rules files moved | 189 | // rules files moved |
182 | rules = "Sample.rules"; | 190 | rules = "Sample.rules"; |
@@ -260,97 +268,97 @@ void WordGame::startGame(const QStringList& playerlist) | |||
260 | for (QStringList::ConstIterator it=playerlist.begin(); it!=playerlist.end(); ++it) | 268 | for (QStringList::ConstIterator it=playerlist.begin(); it!=playerlist.end(); ++it) |
261 | addPlayer(*it); | 269 | addPlayer(*it); |
262 | scoreinfo->init(namelist); | 270 | scoreinfo->init(namelist); |
263 | 271 | ||
264 | if ( nplayers ) { | 272 | if ( nplayers ) { |
265 | player=0; | 273 | player=0; |
266 | readyRack(player); | 274 | readyRack(player); |
267 | } | 275 | } |
268 | 276 | ||
269 | board->show(); | 277 | board->show(); |
270 | racks->show(); | 278 | racks->show(); |
271 | } | 279 | } |
272 | 280 | ||
273 | bool WordGame::loadRules(const QString &name) | 281 | bool WordGame::loadRules(const QString &name) |
274 | { | 282 | { |
275 | QString filename = Global::applicationFileName( "wordgame", name ); | 283 | QString filename = Global::applicationFileName( "wordgame", name ); |
276 | QFile file( filename ); | 284 | QFile file( filename ); |
277 | if ( !file.open( IO_ReadOnly ) ) | 285 | if ( !file.open( IO_ReadOnly ) ) |
278 | return FALSE; | 286 | return FALSE; |
279 | 287 | ||
280 | QTextStream ts( &file ); | 288 | QTextStream ts( &file ); |
281 | 289 | ||
282 | QString title = name; | 290 | QString title = name; |
283 | title.truncate( title.length() - 6 ); | 291 | title.truncate( title.length() - 6 ); |
284 | //setCaption( title ); | 292 | //setCaption( title ); |
285 | 293 | ||
286 | QString shapepixmap; | 294 | QString shapepixmap; |
287 | ts >> shapepixmap; | 295 | ts >> shapepixmap; |
288 | int htiles,vtiles; | 296 | int htiles,vtiles; |
289 | ts >> htiles >> vtiles; | 297 | ts >> htiles >> vtiles; |
290 | 298 | ||
291 | if ( htiles < 3 || vtiles < 3 ) | 299 | if ( htiles < 3 || vtiles < 3 ) |
292 | return FALSE; | 300 | return FALSE; |
293 | 301 | ||
294 | QString rule_shapes; | 302 | QString rule_shapes; |
295 | for (int i=0; i<vtiles; i++) { | 303 | for (int i=0; i<vtiles; i++) { |
296 | QString line; | 304 | QString line; |
297 | ts >> line; | 305 | ts >> line; |
298 | rule_shapes += line; | 306 | rule_shapes += line; |
299 | } | 307 | } |
300 | static int rule_effects[12]; | 308 | static int rule_effects[12]; |
301 | int re=0,e; | 309 | int re=0,e; |
302 | ts >> e; | 310 | ts >> e; |
303 | while ( e && re < 10 ) { | 311 | while ( e && re < 10 ) { |
304 | rule_effects[re] = e; | 312 | rule_effects[re] = e; |
305 | if ( re++ < 10 ) ts >> e; | 313 | if ( re++ < 10 ) ts >> e; |
306 | } | 314 | } |
307 | 315 | ||
308 | QImage shim = Resource::loadImage("wordgame/wordgame_shapes"); | 316 | QImage shim = Opie::Core::OResource::loadImage("wordgame/wordgame_shapes"); |
309 | shim = shim.smoothScale((re-1)*TileItem::smallWidth(),TileItem::smallHeight()); | 317 | shim = shim.smoothScale((re-1)*TileItem::smallWidth(),TileItem::smallHeight()); |
310 | QPixmap bgshapes; | 318 | QPixmap bgshapes; |
311 | bgshapes.convertFromImage(shim); | 319 | bgshapes.convertFromImage(shim); |
312 | 320 | ||
313 | rule_effects[re++] = 100; // default bonus | 321 | rule_effects[re++] = 100; // default bonus |
314 | board = new Board(bgshapes, htiles, vtiles, vbox); | 322 | board = new Board(bgshapes, htiles, vtiles, vbox); |
315 | board->setRules(rule_shapes, rule_effects); | 323 | board->setRules(rule_shapes, rule_effects); |
316 | connect(board, SIGNAL(temporaryScore(int)), scoreinfo, SLOT(showTemporaryScore(int))); | 324 | connect(board, SIGNAL(temporaryScore(int)), scoreinfo, SLOT(showTemporaryScore(int))); |
317 | 325 | ||
318 | bag = new Bag; | 326 | bag = new Bag; |
319 | 327 | ||
320 | int count; | 328 | int count; |
321 | ts >> count; | 329 | ts >> count; |
322 | while ( count ) { | 330 | while ( count ) { |
323 | QString text; | 331 | QString text; |
324 | int value; | 332 | int value; |
325 | ts >> text >> value; | 333 | ts >> text >> value; |
326 | if ( text == "_" ) | 334 | if ( text == "_" ) |
327 | text = ""; | 335 | text = ""; |
328 | 336 | ||
329 | Tile t(text, value); | 337 | Tile t(text, value); |
330 | for (int n=count; n--; ) | 338 | for (int n=count; n--; ) |
331 | bag->add(t); | 339 | bag->add(t); |
332 | 340 | ||
333 | ts >> count; | 341 | ts >> count; |
334 | } | 342 | } |
335 | 343 | ||
336 | return TRUE; | 344 | return TRUE; |
337 | } | 345 | } |
338 | 346 | ||
339 | 347 | ||
340 | NewGame::NewGame(QWidget* parent) : | 348 | NewGame::NewGame(QWidget* parent) : |
341 | NewGameBase(parent) | 349 | NewGameBase(parent) |
342 | { | 350 | { |
343 | } | 351 | } |
344 | 352 | ||
345 | void NewGame::updateRuleSets() | 353 | void NewGame::updateRuleSets() |
346 | { | 354 | { |
347 | rules->clear(); | 355 | rules->clear(); |
348 | 356 | ||
349 | QString rulesDir = Global::applicationFileName( "wordgame", "" ); | 357 | QString rulesDir = Global::applicationFileName( "wordgame", "" ); |
350 | QDir dir( rulesDir, "*.rules" ); | 358 | QDir dir( rulesDir, "*.rules" ); |
351 | ruleslist = dir.entryList(); | 359 | ruleslist = dir.entryList(); |
352 | if ( ruleslist.isEmpty() ) { | 360 | if ( ruleslist.isEmpty() ) { |
353 | // Provide a sample | 361 | // Provide a sample |
354 | QFile file( rulesDir + "Sample.rules" ); | 362 | QFile file( rulesDir + "Sample.rules" ); |
355 | if ( file.open( IO_WriteOnly ) ) { | 363 | if ( file.open( IO_WriteOnly ) ) { |
356 | file.writeBlock( sampleWGR, strlen(sampleWGR) ); | 364 | file.writeBlock( sampleWGR, strlen(sampleWGR) ); |
@@ -1317,97 +1325,97 @@ void Rack::remove(Tile t) | |||
1317 | if ( item[i]->tile() == t ) { | 1325 | if ( item[i]->tile() == t ) { |
1318 | remove(i); | 1326 | remove(i); |
1319 | return; | 1327 | return; |
1320 | } | 1328 | } |
1321 | } | 1329 | } |
1322 | 1330 | ||
1323 | void Rack::remove(int i) | 1331 | void Rack::remove(int i) |
1324 | { | 1332 | { |
1325 | delete item[i]; | 1333 | delete item[i]; |
1326 | n--; | 1334 | n--; |
1327 | for (;i<n;i++) | 1335 | for (;i<n;i++) |
1328 | item[i]=item[i+1]; | 1336 | item[i]=item[i+1]; |
1329 | layoutTiles(); | 1337 | layoutTiles(); |
1330 | } | 1338 | } |
1331 | 1339 | ||
1332 | void Rack::resizeEvent(QResizeEvent* e) | 1340 | void Rack::resizeEvent(QResizeEvent* e) |
1333 | { | 1341 | { |
1334 | canvas()->resize(width()-frameWidth()*2,height()-frameWidth()*2); | 1342 | canvas()->resize(width()-frameWidth()*2,height()-frameWidth()*2); |
1335 | QCanvasView::resizeEvent(e); | 1343 | QCanvasView::resizeEvent(e); |
1336 | } | 1344 | } |
1337 | 1345 | ||
1338 | void Rack::contentsMousePressEvent(QMouseEvent* e) | 1346 | void Rack::contentsMousePressEvent(QMouseEvent* e) |
1339 | { | 1347 | { |
1340 | if ( computerized() ) | 1348 | if ( computerized() ) |
1341 | return; | 1349 | return; |
1342 | QCanvasItemList list = canvas()->collisions(e->pos()); | 1350 | QCanvasItemList list = canvas()->collisions(e->pos()); |
1343 | if (list.count()) { | 1351 | if (list.count()) { |
1344 | dragging = list.first(); | 1352 | dragging = list.first(); |
1345 | dragstart = e->pos()-QPoint(int(dragging->x()),int(dragging->y())); | 1353 | dragstart = e->pos()-QPoint(int(dragging->x()),int(dragging->y())); |
1346 | } else { | 1354 | } else { |
1347 | dragging = 0; | 1355 | dragging = 0; |
1348 | } | 1356 | } |
1349 | } | 1357 | } |
1350 | 1358 | ||
1351 | void Rack::contentsMouseMoveEvent(QMouseEvent* e) | 1359 | void Rack::contentsMouseMoveEvent(QMouseEvent* e) |
1352 | { | 1360 | { |
1353 | if ( computerized() ) | 1361 | if ( computerized() ) |
1354 | return; | 1362 | return; |
1355 | //int w = TileItem::bigWidth()+2; | 1363 | //int w = TileItem::bigWidth()+2; |
1356 | if ( dragging ) { | 1364 | if ( dragging ) { |
1357 | dragging_adj = TileItem::bigWidth()/2; | 1365 | dragging_adj = TileItem::bigWidth()/2; |
1358 | if ( dragging->x() > e->x()-dragstart.x() ) | 1366 | if ( dragging->x() > e->x()-dragstart.x() ) |
1359 | dragging_adj = -dragging_adj; | 1367 | dragging_adj = -dragging_adj; |
1360 | dragging->move(e->x()-dragstart.x(),0); | 1368 | dragging->move(e->x()-dragstart.x(),0); |
1361 | layoutTiles(); | 1369 | layoutTiles(); |
1362 | } | 1370 | } |
1363 | } | 1371 | } |
1364 | 1372 | ||
1365 | void Rack::contentsMouseReleaseEvent(QMouseEvent* e) | 1373 | void Rack::contentsMouseReleaseEvent(QMouseEvent* /*e*/) |
1366 | { | 1374 | { |
1367 | if ( computerized() ) | 1375 | if ( computerized() ) |
1368 | return; | 1376 | return; |
1369 | if ( dragging ) { | 1377 | if ( dragging ) { |
1370 | dragging=0; | 1378 | dragging=0; |
1371 | layoutTiles(); | 1379 | layoutTiles(); |
1372 | } | 1380 | } |
1373 | } | 1381 | } |
1374 | 1382 | ||
1375 | Tile::Tile(const QString& key) | 1383 | Tile::Tile(const QString& key) |
1376 | { | 1384 | { |
1377 | int a=key.find('@'); | 1385 | int a=key.find('@'); |
1378 | txt = key.left(a); | 1386 | txt = key.left(a); |
1379 | val = key.mid(a+1).toInt(); | 1387 | val = key.mid(a+1).toInt(); |
1380 | blank = txt.isEmpty(); | 1388 | blank = txt.isEmpty(); |
1381 | } | 1389 | } |
1382 | 1390 | ||
1383 | QString Tile::key() const | 1391 | QString Tile::key() const |
1384 | { | 1392 | { |
1385 | return txt+"@"+QString::number(val); | 1393 | return txt+"@"+QString::number(val); |
1386 | } | 1394 | } |
1387 | 1395 | ||
1388 | Bag::Bag() | 1396 | Bag::Bag() |
1389 | { | 1397 | { |
1390 | tiles.setAutoDelete(TRUE); | 1398 | tiles.setAutoDelete(TRUE); |
1391 | } | 1399 | } |
1392 | 1400 | ||
1393 | void Bag::writeConfig(Config& cfg) | 1401 | void Bag::writeConfig(Config& cfg) |
1394 | { | 1402 | { |
1395 | QStringList t; | 1403 | QStringList t; |
1396 | for (QListIterator<Tile> it(tiles); it; ++it) | 1404 | for (QListIterator<Tile> it(tiles); it; ++it) |
1397 | t.append((*it)->key()); | 1405 | t.append((*it)->key()); |
1398 | cfg.writeEntry("Tiles",t,';'); | 1406 | cfg.writeEntry("Tiles",t,';'); |
1399 | } | 1407 | } |
1400 | 1408 | ||
1401 | void Bag::readConfig(Config& cfg) | 1409 | void Bag::readConfig(Config& cfg) |
1402 | { | 1410 | { |
1403 | tiles.clear(); | 1411 | tiles.clear(); |
1404 | QStringList t = cfg.readListEntry("Tiles",';'); | 1412 | QStringList t = cfg.readListEntry("Tiles",';'); |
1405 | for (QStringList::ConstIterator it=t.begin(); it!=t.end(); ++it ) | 1413 | for (QStringList::ConstIterator it=t.begin(); it!=t.end(); ++it ) |
1406 | add(Tile(*it)); | 1414 | add(Tile(*it)); |
1407 | } | 1415 | } |
1408 | 1416 | ||
1409 | void Bag::add(const Tile& t) | 1417 | void Bag::add(const Tile& t) |
1410 | { | 1418 | { |
1411 | tiles.append(new Tile(t)); | 1419 | tiles.append(new Tile(t)); |
1412 | } | 1420 | } |
1413 | 1421 | ||