Diffstat (limited to 'noncore/games/tetrix/qtetrix.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/games/tetrix/qtetrix.cpp | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/noncore/games/tetrix/qtetrix.cpp b/noncore/games/tetrix/qtetrix.cpp index a6a5f34..d949176 100644 --- a/noncore/games/tetrix/qtetrix.cpp +++ b/noncore/games/tetrix/qtetrix.cpp | |||
@@ -1,148 +1,148 @@ | |||
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 "qtetrix.h" | 22 | #include "qtetrix.h" |
23 | 23 | ||
24 | #include <qpe/resource.h> | 24 | #include <opie2/oresource.h> |
25 | 25 | ||
26 | #include <qlabel.h> | 26 | #include <qlabel.h> |
27 | #include <qdatetime.h> | 27 | #include <qdatetime.h> |
28 | #include <qlayout.h> | 28 | #include <qlayout.h> |
29 | #include <qtimer.h> | 29 | #include <qtimer.h> |
30 | 30 | ||
31 | #include "ohighscoredlg.h" | 31 | #include "ohighscoredlg.h" |
32 | 32 | ||
33 | 33 | ||
34 | void drawTetrixButton( QPainter *p, int x, int y, int w, int h, | 34 | void drawTetrixButton( QPainter *p, int x, int y, int w, int h, |
35 | const QColor *color ) | 35 | const QColor *color ) |
36 | { | 36 | { |
37 | QColor fc; | 37 | QColor fc; |
38 | if ( color ) { | 38 | if ( color ) { |
39 | QPointArray a; | 39 | QPointArray a; |
40 | a.setPoints( 3, x,y+h-1, x,y, x+w-1,y ); | 40 | a.setPoints( 3, x,y+h-1, x,y, x+w-1,y ); |
41 | p->setPen( color->light() ); | 41 | p->setPen( color->light() ); |
42 | p->drawPolyline( a ); | 42 | p->drawPolyline( a ); |
43 | a.setPoints( 3, x+1,y+h-1, x+w-1,y+h-1, x+w-1,y+1 ); | 43 | a.setPoints( 3, x+1,y+h-1, x+w-1,y+h-1, x+w-1,y+1 ); |
44 | p->setPen( color->dark() ); | 44 | p->setPen( color->dark() ); |
45 | p->drawPolyline( a ); | 45 | p->drawPolyline( a ); |
46 | x++; | 46 | x++; |
47 | y++; | 47 | y++; |
48 | w -= 2; | 48 | w -= 2; |
49 | h -= 2; | 49 | h -= 2; |
50 | fc = *color; | 50 | fc = *color; |
51 | } | 51 | } |
52 | else | 52 | else |
53 | fc = p->backgroundColor(); | 53 | fc = p->backgroundColor(); |
54 | p->fillRect( x, y, w, h, fc ); | 54 | p->fillRect( x, y, w, h, fc ); |
55 | } | 55 | } |
56 | 56 | ||
57 | 57 | ||
58 | ShowNextPiece::ShowNextPiece( QWidget *parent, const char *name ) | 58 | ShowNextPiece::ShowNextPiece( QWidget *parent, const char *name ) |
59 | : QFrame( parent, name ) | 59 | : QFrame( parent, name ) |
60 | { | 60 | { |
61 | setFrameStyle( QFrame::Panel | QFrame::Sunken ); | 61 | setFrameStyle( QFrame::Panel | QFrame::Sunken ); |
62 | xOffset = -1; // -1 until first resizeEvent. | 62 | xOffset = -1; // -1 until first resizeEvent. |
63 | } | 63 | } |
64 | 64 | ||
65 | void ShowNextPiece::resizeEvent( QResizeEvent *e ) | 65 | void ShowNextPiece::resizeEvent( QResizeEvent *e ) |
66 | { | 66 | { |
67 | QSize sz = e->size(); | 67 | QSize sz = e->size(); |
68 | blockWidth = (sz.width() - 3)/5; | 68 | blockWidth = (sz.width() - 3)/5; |
69 | blockHeight = (sz.height() - 3)/6; | 69 | blockHeight = (sz.height() - 3)/6; |
70 | xOffset = (sz.width() - 3)/5; | 70 | xOffset = (sz.width() - 3)/5; |
71 | yOffset = (sz.height() - 3)/6; | 71 | yOffset = (sz.height() - 3)/6; |
72 | } | 72 | } |
73 | 73 | ||
74 | 74 | ||
75 | void ShowNextPiece::paintEvent( QPaintEvent * ) | 75 | void ShowNextPiece::paintEvent( QPaintEvent * ) |
76 | { | 76 | { |
77 | QPainter p( this ); | 77 | QPainter p( this ); |
78 | drawFrame( &p ); | 78 | drawFrame( &p ); |
79 | p.end(); // explicit end() so any slots can paint too | 79 | p.end(); // explicit end() so any slots can paint too |
80 | emit update(); | 80 | emit update(); |
81 | } | 81 | } |
82 | 82 | ||
83 | 83 | ||
84 | void ShowNextPiece::drawNextSquare(int x, int y,QColor *color) | 84 | void ShowNextPiece::drawNextSquare(int x, int y,QColor *color) |
85 | { | 85 | { |
86 | if (xOffset == -1) // Before first resizeEvent? | 86 | if (xOffset == -1) // Before first resizeEvent? |
87 | return; | 87 | return; |
88 | 88 | ||
89 | QPainter paint; | 89 | QPainter paint; |
90 | paint.begin(this); | 90 | paint.begin(this); |
91 | drawTetrixButton( &paint, xOffset+x*blockWidth, yOffset+y*blockHeight, | 91 | drawTetrixButton( &paint, xOffset+x*blockWidth, yOffset+y*blockHeight, |
92 | blockWidth, blockHeight, color ); | 92 | blockWidth, blockHeight, color ); |
93 | paint.end(); | 93 | paint.end(); |
94 | } | 94 | } |
95 | 95 | ||
96 | 96 | ||
97 | QTetrix::QTetrix( QWidget *parent, const char *name, WFlags f ) | 97 | QTetrix::QTetrix( QWidget *parent, const char *name, WFlags f ) |
98 | : QMainWindow( parent, name, f ) | 98 | : QMainWindow( parent, name, f ) |
99 | { | 99 | { |
100 | setIcon( Resource::loadPixmap( "tetrix_icon" ) ); | 100 | setIcon( Opie::Core::OResource::loadPixmap( "tetrix_icon" ) ); |
101 | setCaption( tr("Tetrix" ) ); | 101 | setCaption( tr("Tetrix" ) ); |
102 | 102 | ||
103 | QTime t = QTime::currentTime(); | 103 | QTime t = QTime::currentTime(); |
104 | TetrixPiece::setRandomSeed( (((double)t.hour())+t.minute()+t.second())/ | 104 | TetrixPiece::setRandomSeed( (((double)t.hour())+t.minute()+t.second())/ |
105 | (24+60+60) ); | 105 | (24+60+60) ); |
106 | 106 | ||
107 | QWidget *gameArea = new QWidget( this ); | 107 | QWidget *gameArea = new QWidget( this ); |
108 | setCentralWidget( gameArea ); | 108 | setCentralWidget( gameArea ); |
109 | 109 | ||
110 | QGridLayout *gl = new QGridLayout( gameArea, 5, 3, 8 ); | 110 | QGridLayout *gl = new QGridLayout( gameArea, 5, 3, 8 ); |
111 | gl->setColStretch( 1, 5 ); | 111 | gl->setColStretch( 1, 5 ); |
112 | gl->setColStretch( 2, 10 ); | 112 | gl->setColStretch( 2, 10 ); |
113 | 113 | ||
114 | QLabel *l; | 114 | QLabel *l; |
115 | l = new QLabel( tr("Next"), gameArea ); | 115 | l = new QLabel( tr("Next"), gameArea ); |
116 | gl->addWidget( l, 0, 0 ); | 116 | gl->addWidget( l, 0, 0 ); |
117 | showNext = new ShowNextPiece(gameArea); | 117 | showNext = new ShowNextPiece(gameArea); |
118 | showNext->setBackgroundColor(QColor(0,0,0)); | 118 | showNext->setBackgroundColor(QColor(0,0,0)); |
119 | gl->addWidget( showNext, 0, 1 ); | 119 | gl->addWidget( showNext, 0, 1 ); |
120 | 120 | ||
121 | l = new QLabel( tr("Score"), gameArea ); | 121 | l = new QLabel( tr("Score"), gameArea ); |
122 | gl->addWidget( l, 1, 0 ); | 122 | gl->addWidget( l, 1, 0 ); |
123 | showScore = new QLabel(gameArea); | 123 | showScore = new QLabel(gameArea); |
124 | gl->addWidget( showScore, 1, 1 ); | 124 | gl->addWidget( showScore, 1, 1 ); |
125 | l = new QLabel( tr("Level"), gameArea ); | 125 | l = new QLabel( tr("Level"), gameArea ); |
126 | gl->addWidget( l, 2, 0 ); | 126 | gl->addWidget( l, 2, 0 ); |
127 | showLevel = new QLabel(gameArea); | 127 | showLevel = new QLabel(gameArea); |
128 | gl->addWidget( showLevel, 2, 1 ); | 128 | gl->addWidget( showLevel, 2, 1 ); |
129 | l = new QLabel( tr("Removed"), gameArea ); | 129 | l = new QLabel( tr("Removed"), gameArea ); |
130 | gl->addWidget( l, 3, 0 ); | 130 | gl->addWidget( l, 3, 0 ); |
131 | showLines = new QLabel(gameArea); | 131 | showLines = new QLabel(gameArea); |
132 | gl->addWidget( showLines, 3, 1 ); | 132 | gl->addWidget( showLines, 3, 1 ); |
133 | 133 | ||
134 | board = new QTetrixBoard(gameArea); | 134 | board = new QTetrixBoard(gameArea); |
135 | board->setBackgroundColor(QColor(0,0,0)); | 135 | board->setBackgroundColor(QColor(0,0,0)); |
136 | gl->addMultiCellWidget( board, 0, 4, 2, 2 ); | 136 | gl->addMultiCellWidget( board, 0, 4, 2, 2 ); |
137 | 137 | ||
138 | QPushButton *pb = new QPushButton( tr("Start"), gameArea ); | 138 | QPushButton *pb = new QPushButton( tr("Start"), gameArea ); |
139 | pb->setFocusPolicy( NoFocus ); | 139 | pb->setFocusPolicy( NoFocus ); |
140 | connect( pb, SIGNAL( clicked() ), board, SLOT( start() ) ); | 140 | connect( pb, SIGNAL( clicked() ), board, SLOT( start() ) ); |
141 | gl->addMultiCellWidget( pb, 4, 4, 0, 1 ); | 141 | gl->addMultiCellWidget( pb, 4, 4, 0, 1 ); |
142 | 142 | ||
143 | connect( board, SIGNAL(gameOverSignal()), SLOT(gameOver()) ); | 143 | connect( board, SIGNAL(gameOverSignal()), SLOT(gameOver()) ); |
144 | connect( board, SIGNAL(drawNextSquareSignal(int,int,QColor*)), this, | 144 | connect( board, SIGNAL(drawNextSquareSignal(int,int,QColor*)), this, |
145 | SLOT(setNext(int,int,QColor*)) ); | 145 | SLOT(setNext(int,int,QColor*)) ); |
146 | connect( showNext, SIGNAL(update()), board, SLOT(updateNext()) ); | 146 | connect( showNext, SIGNAL(update()), board, SLOT(updateNext()) ); |
147 | connect( board, SIGNAL(updateScoreSignal(int)), showScore, SLOT(setNum(int)) ); | 147 | connect( board, SIGNAL(updateScoreSignal(int)), showScore, SLOT(setNum(int)) ); |
148 | connect( board, SIGNAL(updateLevelSignal(int)), showLevel, SLOT(setNum(int)) ); | 148 | connect( board, SIGNAL(updateLevelSignal(int)), showLevel, SLOT(setNum(int)) ); |