summaryrefslogtreecommitdiff
path: root/noncore
Unidiff
Diffstat (limited to 'noncore') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/games/fifteen/fifteen.cpp83
-rw-r--r--noncore/games/fifteen/fifteen.h12
-rw-r--r--noncore/games/fifteen/fifteen.pro4
-rw-r--r--noncore/games/fifteen/main.cpp20
4 files changed, 70 insertions, 49 deletions
diff --git a/noncore/games/fifteen/fifteen.cpp b/noncore/games/fifteen/fifteen.cpp
index 2e4ed94..b4e0308 100644
--- a/noncore/games/fifteen/fifteen.cpp
+++ b/noncore/games/fifteen/fifteen.cpp
@@ -1,5 +1,5 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved. 2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qtopia Environment. 4** This file is part of the Qtopia Environment.
5** 5**
@@ -22,4 +22,4 @@
22 22
23#include <qpe/resource.h> 23#include <qtopia/resource.h>
24#include <qpe/config.h> 24#include <qtopia/config.h>
25 25
@@ -31,3 +31,3 @@
31#include <qmessagebox.h> 31#include <qmessagebox.h>
32#include <qpe/qpetoolbar.h> 32#include <qtoolbar.h>
33#include <qmenubar.h> 33#include <qmenubar.h>
@@ -35,2 +35,3 @@
35#include <qapplication.h> 35#include <qapplication.h>
36#include <qtoolbutton.h>
36 37
@@ -39,4 +40,4 @@
39 40
40FifteenMainWindow::FifteenMainWindow(QWidget *parent, const char* name) 41FifteenMainWindow::FifteenMainWindow(QWidget *parent, const char* name, WFlags fl)
41 : QMainWindow( parent, name ) 42 : QMainWindow( parent, name, fl )
42{ 43{
@@ -44,15 +45,8 @@ FifteenMainWindow::FifteenMainWindow(QWidget *parent, const char* name)
44 srand(time(0)); 45 srand(time(0));
45 46 setCaption( tr("Fifteen Pieces") );
46 setToolBarsMovable( FALSE );
47 QVBox *vbox = new QVBox( this );
48 PiecesTable *table = new PiecesTable( vbox );
49 setCentralWidget(vbox);
50 47
51 QToolBar *toolbar = new QToolBar(this); 48 QToolBar *toolbar = new QToolBar(this);
52 toolbar->setHorizontalStretchable( TRUE ); 49 toolbar->setHorizontalStretchable( FALSE );
53 addToolBar(toolbar);
54
55 QMenuBar *menubar = new QMenuBar( toolbar ); 50 QMenuBar *menubar = new QMenuBar( toolbar );
56 menubar->setMargin(0); 51 menubar->setMargin(0);
57
58 QPopupMenu *game = new QPopupMenu( this ); 52 QPopupMenu *game = new QPopupMenu( this );
@@ -63,2 +57,10 @@ FifteenMainWindow::FifteenMainWindow(QWidget *parent, const char* name)
63 57
58
59 setToolBarsMovable( FALSE );
60 QVBox *vbox = new QVBox( this );
61 PiecesTable *table = new PiecesTable( vbox );
62 setCentralWidget(vbox);
63
64
65
64 QAction *a = new QAction( tr( "Randomize" ), Resource::loadPixmap( "new" ), 66 QAction *a = new QAction( tr( "Randomize" ), Resource::loadPixmap( "new" ),
@@ -69,3 +71,4 @@ FifteenMainWindow::FifteenMainWindow(QWidget *parent, const char* name)
69 71
70 a = new QAction( tr( "Solve" ), Resource::loadPixmap( "repeat" ), 72 /* This is pointless and confusing.
73 a = new QAction( tr( "Solve" ), Resource::loadIconSet( "repeat" ),
71 QString::null, 0, this, 0 ); 74 QString::null, 0, this, 0 );
@@ -74,3 +77,3 @@ FifteenMainWindow::FifteenMainWindow(QWidget *parent, const char* name)
74 a->addTo( toolbar ); 77 a->addTo( toolbar );
75 78 */
76 menubar->insertItem( tr( "Game" ), game ); 79 menubar->insertItem( tr( "Game" ), game );
@@ -111,3 +114,3 @@ void PiecesTable::writeConfig()
111 QStringList map; 114 QStringList map;
112 for (unsigned int i = 0; i < 16; i++) 115 for (int i = 0; i < 16; i++)
113 map.append( QString::number( _map[i] ) ); 116 map.append( QString::number( _map[i] ) );
@@ -123,3 +126,3 @@ void PiecesTable::readConfig()
123 _randomized = cfg.readBoolEntry( "Randomized", FALSE ); 126 _randomized = cfg.readBoolEntry( "Randomized", FALSE );
124 unsigned int i = 0; 127 int i = 0;
125 for ( QStringList::Iterator it = map.begin(); it != map.end(); ++it ) { 128 for ( QStringList::Iterator it = map.begin(); it != map.end(); ++it ) {
@@ -148,10 +151,11 @@ void PiecesTable::paintCell(QPainter *p, int row, int col)
148 151
152 if (number == 16) return;
153
149 // draw borders 154 // draw borders
150 if (height() > 40) { 155 if (height() > 40) {
151 p->setPen(colorGroup().text()); 156 p->setBrush(_colors[number-1].light(130));
152 if(col < numCols()-1) 157 p->drawPolygon(light_border);
153 p->drawLine(x2, 0, x2, y2); // right border line
154 158
155 if(row < numRows()-1) 159 p->setBrush(_colors[number-1].dark(130));
156 p->drawLine(0, y2, x2, y2); // bottom boder line 160 p->drawPolygon(dark_border);
157 } 161 }
@@ -159,3 +163,2 @@ void PiecesTable::paintCell(QPainter *p, int row, int col)
159 // draw number 163 // draw number
160 if (number == 16) return;
161 p->setPen(black); 164 p->setPen(black);
@@ -170,2 +173,26 @@ void PiecesTable::resizeEvent(QResizeEvent *e)
170 setCellHeight(contentsRect().height() / numCols()); 173 setCellHeight(contentsRect().height() / numCols());
174
175 //
176 // Calculate 3d-effect borders
177 //
178 intcell_w = cellWidth();
179 intcell_h = cellHeight();
180 int x_offset = cell_w - int(cell_w * 0.9);// 10% should be enough
181 inty_offset = cell_h - int(cell_h * 0.9);
182
183 light_border.setPoints(6,
184 0, 0,
185 cell_w, 0,
186 cell_w - x_offset, y_offset,
187 x_offset, y_offset,
188 x_offset, cell_h - y_offset,
189 0, cell_h);
190
191 dark_border.setPoints(6,
192 cell_w, 0,
193 cell_w, cell_h,
194 0, cell_h,
195 x_offset, cell_h - y_offset,
196 cell_w - x_offset, cell_h - y_offset,
197 cell_w - x_offset, y_offset);
171} 198}
@@ -183,3 +210,3 @@ void PiecesTable::initMap()
183 _map.resize(16); 210 _map.resize(16);
184 for (unsigned int i = 0; i < 16; i++) 211 for ( int i = 0; i < 16; i++)
185 _map[i] = i; 212 _map[i] = i;
@@ -243,4 +270,4 @@ void PiecesTable::randomizeMap()
243 _map[pos=(col + row * numCols())] = 15; 270 _map[pos=(col + row * numCols())] = 15;
244 repaint();
245 } 271 }
272 repaint();
246} 273}
diff --git a/noncore/games/fifteen/fifteen.h b/noncore/games/fifteen/fifteen.h
index 703a8a7..58eb756 100644
--- a/noncore/games/fifteen/fifteen.h
+++ b/noncore/games/fifteen/fifteen.h
@@ -1,5 +1,5 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved. 2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qtopia Environment. 4** This file is part of the Qtopia Environment.
5** 5**
@@ -26,2 +26,3 @@
26#include <qarray.h> 26#include <qarray.h>
27#include <qpointarray.h>
27 28
@@ -59,2 +60,4 @@ class PiecesTable : public QTableView
59 bool _randomized; 60 bool _randomized;
61 QPointArraylight_border;
62 QPointArraydark_border;
60 63
@@ -79,3 +82,6 @@ class FifteenMainWindow : public QMainWindow
79public: 82public:
80 FifteenMainWindow(QWidget *parent=0, const char* name=0); 83 static QString appName() {
84 return QString::fromLatin1("fifteen");
85 }
86 FifteenMainWindow(QWidget *parent=0, const char* name=0, WFlags fl=0);
81}; 87};
diff --git a/noncore/games/fifteen/fifteen.pro b/noncore/games/fifteen/fifteen.pro
index 43d336d..14ea3c9 100644
--- a/noncore/games/fifteen/fifteen.pro
+++ b/noncore/games/fifteen/fifteen.pro
@@ -1,4 +1,2 @@
1 DESTDIR = $(OPIEDIR)/bin 1 CONFIG = qt warn_on release quick-app
2 TEMPLATE= app
3 CONFIG = qt warn_on release
4 HEADERS = fifteen.h 2 HEADERS = fifteen.h
diff --git a/noncore/games/fifteen/main.cpp b/noncore/games/fifteen/main.cpp
index 4838a36..74a7368 100644
--- a/noncore/games/fifteen/main.cpp
+++ b/noncore/games/fifteen/main.cpp
@@ -1,5 +1,5 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved. 2** Copyright (C) 2004 Holger Freyther. All rights reserved.
3** 3**
4** This file is part of Qtopia Environment. 4** This file is part of Opie Environment.
5** 5**
@@ -15,5 +15,2 @@
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/ 16**********************************************************************/
@@ -22,12 +19,5 @@
22 19
23#include <qpe/qpeapplication.h> 20#include <opie/oapplicationfactory.h>
21
22OPIE_EXPORT_APP( OApplicationFactory<FifteenMainWindow> )
24 23
25int main( int argc, char ** argv)
26{
27 QPEApplication app( argc, argv );
28
29 FifteenMainWindow mw;
30 mw.setCaption( FifteenMainWindow::tr("Fifteen Pieces") );
31 app.showMainWidget( &mw );
32 return app.exec();
33}