diff options
author | Timothy Pearson <[email protected]> | 2011-11-08 12:31:36 -0600 |
---|---|---|
committer | Timothy Pearson <[email protected]> | 2011-11-08 12:31:36 -0600 |
commit | d796c9dd933ab96ec83b9a634feedd5d32e1ba3f (patch) | |
tree | 6e3dcca4f77e20ec8966c666aac7c35bd4704053 /examples/tetrix/qtetrix.cpp | |
download | tqt3-d796c9dd933ab96ec83b9a634feedd5d32e1ba3f.tar.gz tqt3-d796c9dd933ab96ec83b9a634feedd5d32e1ba3f.zip |
Test conversion to TQt3 from Qt3 8c6fc1f8e35fd264dd01c582ca5e7549b32ab731
Diffstat (limited to 'examples/tetrix/qtetrix.cpp')
-rw-r--r-- | examples/tetrix/qtetrix.cpp | 176 |
1 files changed, 176 insertions, 0 deletions
diff --git a/examples/tetrix/qtetrix.cpp b/examples/tetrix/qtetrix.cpp new file mode 100644 index 000000000..68b49c254 --- /dev/null +++ b/examples/tetrix/qtetrix.cpp @@ -0,0 +1,176 @@ +/**************************************************************************** +** +** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. +** +** This file is part of an example program for TQt. This example +** program may be used, distributed and modified without limitation. +** +*****************************************************************************/ + +#include "qtetrix.h" +#include <qapplication.h> +#include <qlabel.h> +#include <qdatetime.h> + + +void drawTetrixButton( TQPainter *p, int x, int y, int w, int h, + const TQColor *color, TQWidget *widg) +{ + if ( color ) { + TQPointArray a; + a.setPoints( 3, x,y+h-1, x,y, x+w-1,y ); + p->setPen( color->light() ); + p->drawPolyline( a ); + a.setPoints( 3, x+1,y+h-1, x+w-1,y+h-1, x+w-1,y+1 ); + p->setPen( color->dark() ); + p->drawPolyline( a ); + x++; + y++; + w -= 2; + h -= 2; + p->fillRect( x, y, w, h, *color ); + } + else if(widg) { + widg->erase(x, y, w, h); + } else { + p->fillRect(x, y, w, h, p->backgroundColor()); + } +} + + +ShowNextPiece::ShowNextPiece( TQWidget *parent, const char *name ) + : TQFrame( parent, name ) +{ + setFrameStyle( TQFrame::Panel | TQFrame::Sunken ); + xOffset = -1; // -1 until first resizeEvent. +} + +void ShowNextPiece::resizeEvent( TQResizeEvent *e ) +{ + TQSize sz = e->size(); + blockWidth = (sz.width() - 3)/5; + blockHeight = (sz.height() - 3)/6; + xOffset = (sz.width() - 3)/5; + yOffset = (sz.height() - 3)/6; +} + + +void ShowNextPiece::paintEvent( TQPaintEvent * ) +{ + TQPainter p( this ); + drawFrame( &p ); + p.end(); // explicit end() so any slots can paint too + emit update(); +} + + +void ShowNextPiece::drawNextSquare(int x, int y,TQColor *color) +{ + if (xOffset == -1) // Before first resizeEvent? + return; + + TQPainter paint; + paint.begin(this); + drawTetrixButton( &paint, xOffset+x*blockWidth, yOffset+y*blockHeight, + blockWidth, blockHeight, color, this ); + paint.end(); +} + + +TQTetrix::TQTetrix( TQWidget *parent, const char *name ) + : TQWidget( parent, name ) +{ + TQTime t = TQTime::currentTime(); + TetrixPiece::setRandomSeed( (((double)t.hour())+t.minute()+t.second())/ + (24+60+60) ); + +#define ADD_LABEL( str, x, y, w, h ) \ + { TQLabel *label = new TQLabel(str,this); \ + label->setGeometry(x,y,w,h); \ + label->setAlignment(AlignCenter|AlignVCenter); } + + ADD_LABEL( "NEXT", 50, 10, 78, 30 ); + ADD_LABEL( "SCORE", 330, 10, 178, 30 ); + ADD_LABEL( "LEVEL", 50, 130, 78, 30 ); + ADD_LABEL( "LINES REMOVED", 330, 130, 178, 30 ); + + board = new TQTetrixBoard(this); + showNext = new ShowNextPiece(this); +#ifndef QT_NO_LCDNUMBER + showScore = new TQLCDNumber(5,this); + showLevel = new TQLCDNumber(2,this); + showLines = new TQLCDNumber(5,this); +#else + showScore = new TQLabel("0",this); + showLevel = new TQLabel("0",this); + showLines = new TQLabel("0",this); + showScore->setAlignment(AlignCenter); + showLines->setAlignment(AlignCenter); + showLevel->setAlignment(AlignCenter); + showScore->setFrameStyle(TQFrame::Sunken|TQFrame::Box); + showLines->setFrameStyle(TQFrame::Sunken|TQFrame::Box); + showLevel->setFrameStyle(TQFrame::Sunken|TQFrame::Box); +#endif + tquitButton = new TQPushButton("&Quit",this); + startButton = new TQPushButton("&New Game",this); + pauseButton = new TQPushButton("&Pause",this); + + // Don't let the buttons get keyboard focus + tquitButton->setFocusPolicy( TQWidget::NoFocus ); + startButton->setFocusPolicy( TQWidget::NoFocus ); + pauseButton->setFocusPolicy( TQWidget::NoFocus ); + + connect( board, SIGNAL(gameOverSignal()), SLOT(gameOver()) ); + connect( board, SIGNAL(drawNextSquareSignal(int,int,TQColor*)), showNext, + SLOT(drawNextSquare(int,int,TQColor*)) ); + connect( showNext, SIGNAL(update()), board, SLOT(updateNext()) ); +#ifndef QT_NO_LCDNUMBER + connect( board, SIGNAL(updateScoreSignal(int)), showScore, + SLOT(display(int)) ); + connect( board, SIGNAL(updateLevelSignal(int)), showLevel, + SLOT(display(int))); + connect( board, SIGNAL(updateRemovedSignal(int)), showLines, + SLOT(display(int))); +#else + connect( board, SIGNAL(updateScoreSignal(int)), showScore, + SLOT(setNum(int)) ); + connect( board, SIGNAL(updateLevelSignal(int)), showLevel, + SLOT(setNum(int))); + connect( board, SIGNAL(updateRemovedSignal(int)), showLines, + SLOT(setNum(int))); +#endif + connect( startButton, SIGNAL(clicked()), board, SLOT(start()) ); + connect( tquitButton , SIGNAL(clicked()), SLOT(tquit())); + connect( pauseButton, SIGNAL(clicked()), board, SLOT(pause()) ); + + board->setGeometry( 150, 20, 153, 333 ); + showNext->setGeometry( 50, 40, 78, 94 ); + showScore->setGeometry( 330, 40, 178, 93 ); + showLevel->setGeometry( 50, 160, 78, 93 ); + showLines->setGeometry( 330, 160, 178, 93 ); +#ifndef QT_NO_LCDNUMBER + showScore->display( 0 ); + showLevel->display( 0 ); + showLines->display( 0 ); +#else + showScore->setNum( 0 ); + showLevel->setNum( 0 ); + showLines->setNum( 0 ); +#endif + startButton->setGeometry( 46, 288, 90, 30 ); + tquitButton->setGeometry( 370, 265, 90, 30 ); + pauseButton->setGeometry( 370, 310, 90, 30 ); + board->revealNextPiece(TRUE); + + resize( 550, 370 ); +} + +void TQTetrix::gameOver() +{ +} + + +void TQTetrix::tquit() +{ + qApp->tquit(); +} |