author | drw <drw> | 2004-12-20 14:49:49 (UTC) |
---|---|---|
committer | drw <drw> | 2004-12-20 14:49:49 (UTC) |
commit | 29b27cf61a7cb862a0236c8b319ff1843669142c (patch) (unidiff) | |
tree | a2dee12e4241103259840385020ae317c8814d69 | |
parent | 480a3ae1b4ed502fbd75e345c41ad4c469eff140 (diff) | |
download | opie-29b27cf61a7cb862a0236c8b319ff1843669142c.zip opie-29b27cf61a7cb862a0236c8b319ff1843669142c.tar.gz opie-29b27cf61a7cb862a0236c8b319ff1843669142c.tar.bz2 |
Reapply fix for bug #1017 - Tetrix on high resolution screens
-rw-r--r-- | noncore/games/tetrix/qtetrix.cpp | 58 | ||||
-rw-r--r-- | noncore/games/tetrix/qtetrix.h | 8 | ||||
-rw-r--r-- | noncore/games/tetrix/qtetrixb.cpp | 4 |
3 files changed, 58 insertions, 12 deletions
diff --git a/noncore/games/tetrix/qtetrix.cpp b/noncore/games/tetrix/qtetrix.cpp index 20cf1a7..a6a5f34 100644 --- a/noncore/games/tetrix/qtetrix.cpp +++ b/noncore/games/tetrix/qtetrix.cpp | |||
@@ -23,12 +23,13 @@ | |||
23 | 23 | ||
24 | #include <qpe/resource.h> | 24 | #include <qpe/resource.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 | 30 | ||
30 | #include "ohighscoredlg.h" | 31 | #include "ohighscoredlg.h" |
31 | 32 | ||
32 | 33 | ||
33 | 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, |
34 | const QColor *color ) | 35 | const QColor *color ) |
@@ -104,12 +105,14 @@ QTetrix::QTetrix( QWidget *parent, const char *name, WFlags f ) | |||
104 | (24+60+60) ); | 105 | (24+60+60) ); |
105 | 106 | ||
106 | QWidget *gameArea = new QWidget( this ); | 107 | QWidget *gameArea = new QWidget( this ); |
107 | setCentralWidget( gameArea ); | 108 | setCentralWidget( gameArea ); |
108 | 109 | ||
109 | QGridLayout *gl = new QGridLayout( gameArea, 5, 3, 8 ); | 110 | QGridLayout *gl = new QGridLayout( gameArea, 5, 3, 8 ); |
111 | gl->setColStretch( 1, 5 ); | ||
112 | gl->setColStretch( 2, 10 ); | ||
110 | 113 | ||
111 | QLabel *l; | 114 | QLabel *l; |
112 | l = new QLabel( tr("Next"), gameArea ); | 115 | l = new QLabel( tr("Next"), gameArea ); |
113 | gl->addWidget( l, 0, 0 ); | 116 | gl->addWidget( l, 0, 0 ); |
114 | showNext = new ShowNextPiece(gameArea); | 117 | showNext = new ShowNextPiece(gameArea); |
115 | showNext->setBackgroundColor(QColor(0,0,0)); | 118 | showNext->setBackgroundColor(QColor(0,0,0)); |
@@ -127,39 +130,39 @@ QTetrix::QTetrix( QWidget *parent, const char *name, WFlags f ) | |||
127 | gl->addWidget( l, 3, 0 ); | 130 | gl->addWidget( l, 3, 0 ); |
128 | showLines = new QLabel(gameArea); | 131 | showLines = new QLabel(gameArea); |
129 | gl->addWidget( showLines, 3, 1 ); | 132 | gl->addWidget( showLines, 3, 1 ); |
130 | 133 | ||
131 | board = new QTetrixBoard(gameArea); | 134 | board = new QTetrixBoard(gameArea); |
132 | board->setBackgroundColor(QColor(0,0,0)); | 135 | board->setBackgroundColor(QColor(0,0,0)); |
133 | board->setFixedWidth( 124 ); | ||
134 | gl->addMultiCellWidget( board, 0, 4, 2, 2 ); | 136 | gl->addMultiCellWidget( board, 0, 4, 2, 2 ); |
135 | gl->addColSpacing( 2, 100 ); | ||
136 | gl->addColSpacing( 1, 35 ); | ||
137 | gl->addRowSpacing( 0, 35 ); | ||
138 | 137 | ||
139 | QPushButton *pb = new QPushButton( tr("Start"), gameArea ); | 138 | QPushButton *pb = new QPushButton( tr("Start"), gameArea ); |
140 | pb->setFocusPolicy( NoFocus ); | 139 | pb->setFocusPolicy( NoFocus ); |
141 | connect( pb, SIGNAL( clicked() ), board, SLOT( start() ) ); | 140 | connect( pb, SIGNAL( clicked() ), board, SLOT( start() ) ); |
142 | gl->addMultiCellWidget( pb, 4, 4, 0, 1 ); | 141 | gl->addMultiCellWidget( pb, 4, 4, 0, 1 ); |
143 | 142 | ||
144 | connect( board, SIGNAL(gameOverSignal()), SLOT(gameOver()) ); | 143 | connect( board, SIGNAL(gameOverSignal()), SLOT(gameOver()) ); |
145 | connect( board, SIGNAL(drawNextSquareSignal(int,int,QColor*)), showNext, | 144 | connect( board, SIGNAL(drawNextSquareSignal(int,int,QColor*)), this, |
146 | SLOT(drawNextSquare(int,int,QColor*)) ); | 145 | SLOT(setNext(int,int,QColor*)) ); |
147 | connect( showNext, SIGNAL(update()), board, SLOT(updateNext()) ); | 146 | connect( showNext, SIGNAL(update()), board, SLOT(updateNext()) ); |
148 | connect( board, SIGNAL(updateScoreSignal(int)), showScore, | 147 | connect( board, SIGNAL(updateScoreSignal(int)), showScore, SLOT(setNum(int)) ); |
149 | SLOT(setNum(int)) ); | 148 | connect( board, SIGNAL(updateLevelSignal(int)), showLevel, SLOT(setNum(int)) ); |
150 | connect( board, SIGNAL(updateLevelSignal(int)), showLevel, | 149 | connect( board, SIGNAL(updateRemovedSignal(int)), showLines, SLOT(setNum(int)) ); |
151 | SLOT(setNum(int))); | ||
152 | connect( board, SIGNAL(updateRemovedSignal(int)), showLines, | ||
153 | SLOT(setNum(int))); | ||
154 | 150 | ||
155 | showScore->setNum( 0 ); | 151 | showScore->setNum( 0 ); |
156 | showLevel->setNum( 0 ); | 152 | showLevel->setNum( 0 ); |
157 | showLines->setNum( 0 ); | 153 | showLines->setNum( 0 ); |
158 | board->revealNextPiece(TRUE); | 154 | board->revealNextPiece(TRUE); |
159 | board->setFocusPolicy( StrongFocus ); | 155 | board->setFocusPolicy( StrongFocus ); |
156 | |||
157 | QTimer::singleShot( -1, this, SLOT(setup()) ); | ||
158 | } | ||
159 | |||
160 | void QTetrix::setup() | ||
161 | { | ||
162 | resizeEvent( 0x0 ); | ||
160 | } | 163 | } |
161 | 164 | ||
162 | void QTetrix::gameOver() | 165 | void QTetrix::gameOver() |
163 | { | 166 | { |
164 | OHighscore *hs = new OHighscore( showScore->text().toInt() , showLevel->text().toInt() ); | 167 | OHighscore *hs = new OHighscore( showScore->text().toInt() , showLevel->text().toInt() ); |
165 | if ( hs->isNewhighscore ) | 168 | if ( hs->isNewhighscore ) |
@@ -169,6 +172,37 @@ void QTetrix::gameOver() | |||
169 | } | 172 | } |
170 | 173 | ||
171 | void QTetrix::quit() | 174 | void QTetrix::quit() |
172 | { | 175 | { |
173 | close(); | 176 | close(); |
174 | } | 177 | } |
178 | |||
179 | void QTetrix::setNext( int x, int y, QColor *color ) | ||
180 | { | ||
181 | resizeEvent( 0x0 ); | ||
182 | showNext->drawNextSquare( x, y, color ); | ||
183 | } | ||
184 | |||
185 | void QTetrix::resizeEvent( QResizeEvent * ) | ||
186 | { | ||
187 | // Set size of board | ||
188 | int widthFactor = board->QFrame::width() / board->boardWidth(); | ||
189 | if ( widthFactor < 1 ) | ||
190 | widthFactor = 1; | ||
191 | int heightFactor = board->QFrame::height() / board->boardHeight(); | ||
192 | if ( heightFactor < 1 ) | ||
193 | heightFactor = 1; | ||
194 | widthFactor > heightFactor ? board->resize( heightFactor * board->boardWidth() + 2, | ||
195 | heightFactor * board->boardHeight() + 2 ) | ||
196 | : board->resize( widthFactor * board->boardWidth() + 2, | ||
197 | widthFactor * board->boardHeight() + 2 ); | ||
198 | |||
199 | // Set size of preview widget | ||
200 | widthFactor = showNext->width() / 5; | ||
201 | if ( widthFactor < 1 ) | ||
202 | widthFactor = 1; | ||
203 | heightFactor = showNext->height() / 6; | ||
204 | if ( heightFactor < 1 ) | ||
205 | heightFactor = 1; | ||
206 | widthFactor > heightFactor ? showNext->resize( heightFactor * 5 + 2, heightFactor * 6 + 2 ) | ||
207 | : showNext->resize( widthFactor * 5 + 2, widthFactor * 6 + 2 ); | ||
208 | } | ||
diff --git a/noncore/games/tetrix/qtetrix.h b/noncore/games/tetrix/qtetrix.h index c8959c5..8c44b77 100644 --- a/noncore/games/tetrix/qtetrix.h +++ b/noncore/games/tetrix/qtetrix.h | |||
@@ -54,16 +54,24 @@ class QTetrix : public QMainWindow | |||
54 | public: | 54 | public: |
55 | static QString appName() { return QString::fromLatin1("tetrix"); } | 55 | static QString appName() { return QString::fromLatin1("tetrix"); } |
56 | QTetrix( QWidget *parent=0, const char *name=0, WFlags f=0 ); | 56 | QTetrix( QWidget *parent=0, const char *name=0, WFlags f=0 ); |
57 | void startGame() { board->startGame(); } | 57 | void startGame() { board->startGame(); } |
58 | 58 | ||
59 | public slots: | 59 | public slots: |
60 | void setup(); | ||
60 | void gameOver(); | 61 | void gameOver(); |
61 | void quit(); | 62 | void quit(); |
63 | |||
64 | void setNext( int x, int y, QColor *color ); | ||
65 | // void setScore( int score ); | ||
66 | // void setLevel( int level ); | ||
67 | // void setLines( int lines ); | ||
68 | |||
62 | private: | 69 | private: |
63 | void keyPressEvent( QKeyEvent *e ) { board->keyPressEvent(e); } | 70 | void keyPressEvent( QKeyEvent *e ) { board->keyPressEvent(e); } |
71 | void resizeEvent( QResizeEvent * ); | ||
64 | 72 | ||
65 | QTetrixBoard *board; | 73 | QTetrixBoard *board; |
66 | ShowNextPiece *showNext; | 74 | ShowNextPiece *showNext; |
67 | QLabel *showScore; | 75 | QLabel *showScore; |
68 | QLabel *showLevel; | 76 | QLabel *showLevel; |
69 | QLabel *showLines; | 77 | QLabel *showLines; |
diff --git a/noncore/games/tetrix/qtetrixb.cpp b/noncore/games/tetrix/qtetrixb.cpp index 3c179df..8c41fb2 100644 --- a/noncore/games/tetrix/qtetrixb.cpp +++ b/noncore/games/tetrix/qtetrixb.cpp | |||
@@ -53,12 +53,13 @@ QTetrixBoard::QTetrixBoard( QWidget *p, const char *name ) | |||
53 | 53 | ||
54 | void QTetrixBoard::startGame(int gameType,int fillRandomLines) | 54 | void QTetrixBoard::startGame(int gameType,int fillRandomLines) |
55 | { | 55 | { |
56 | if ( isPaused ) | 56 | if ( isPaused ) |
57 | return; // ignore if game is paused | 57 | return; // ignore if game is paused |
58 | noGame = FALSE; | 58 | noGame = FALSE; |
59 | |||
59 | GenericTetrix::startGame( gameType, fillRandomLines ); | 60 | GenericTetrix::startGame( gameType, fillRandomLines ); |
60 | // Note that the timer is started by updateLevel! | 61 | // Note that the timer is started by updateLevel! |
61 | } | 62 | } |
62 | 63 | ||
63 | 64 | ||
64 | void QTetrixBoard::pause() | 65 | void QTetrixBoard::pause() |
@@ -203,14 +204,17 @@ void QTetrixBoard::drawContents( QPainter *p ) | |||
203 | return; | 204 | return; |
204 | } | 205 | } |
205 | 206 | ||
206 | void QTetrixBoard::resizeEvent(QResizeEvent *e) | 207 | void QTetrixBoard::resizeEvent(QResizeEvent *e) |
207 | { | 208 | { |
208 | QSize sz = e->size(); | 209 | QSize sz = e->size(); |
210 | |||
209 | blockWidth = (sz.width() - 2)/10; | 211 | blockWidth = (sz.width() - 2)/10; |
210 | blockHeight = (sz.height() - 2)/22; | 212 | blockHeight = (sz.height() - 2)/22; |
213 | /* blockWidth > blockHeight ? blockWidth = blockHeight | ||
214 | : blockHeight = blockWidth;*/ | ||
211 | xOffset = 1; | 215 | xOffset = 1; |
212 | //yOffset = 1; | 216 | //yOffset = 1; |
213 | yOffset = (sz.height() - 2) - (blockHeight *22); | 217 | yOffset = (sz.height() - 2) - (blockHeight *22); |
214 | } | 218 | } |
215 | 219 | ||
216 | void QTetrixBoard::keyPressEvent( QKeyEvent *e ) | 220 | void QTetrixBoard::keyPressEvent( QKeyEvent *e ) |