summaryrefslogtreecommitdiff
path: root/noncore
authorkergoth <kergoth>2002-06-07 18:53:14 (UTC)
committer kergoth <kergoth>2002-06-07 18:53:14 (UTC)
commit640d964cfdc7467f6cacb513087cd3acda2c04f0 (patch) (side-by-side diff)
tree9a784686c1795f8b1f81eb344598f3b549d43467 /noncore
parentdfb9c76738bb68e235114c5ad43dbd26a59b98ab (diff)
downloadopie-640d964cfdc7467f6cacb513087cd3acda2c04f0.zip
opie-640d964cfdc7467f6cacb513087cd3acda2c04f0.tar.gz
opie-640d964cfdc7467f6cacb513087cd3acda2c04f0.tar.bz2
Backing out unintentional merge from TT branch.
Diffstat (limited to 'noncore') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/games/go/gowidget.cpp15
-rw-r--r--noncore/games/minesweep/minefield.h30
-rw-r--r--noncore/games/minesweep/minesweep.cpp35
-rw-r--r--noncore/games/snake/interface.h2
-rw-r--r--noncore/games/snake/obstacle.cpp35
-rw-r--r--noncore/games/snake/obstacle.h4
-rw-r--r--noncore/games/solitaire/canvascard.cpp71
-rw-r--r--noncore/games/solitaire/canvasshapes.cpp52
-rw-r--r--noncore/games/solitaire/freecellcardgame.cpp11
-rw-r--r--noncore/games/solitaire/patiencecardgame.cpp49
-rw-r--r--noncore/games/solitaire/patiencecardgame.h7
-rw-r--r--noncore/games/wordgame/wordgame.cpp71
-rw-r--r--noncore/games/wordgame/wordgame.h6
-rw-r--r--noncore/multimedia/showimg/settingsdialog.cpp57
-rw-r--r--noncore/multimedia/showimg/settingsdialog.h42
-rw-r--r--noncore/multimedia/showimg/settingsdialogbase.ui149
16 files changed, 291 insertions, 345 deletions
diff --git a/noncore/games/go/gowidget.cpp b/noncore/games/go/gowidget.cpp
index fca9797..8567b30 100644
--- a/noncore/games/go/gowidget.cpp
+++ b/noncore/games/go/gowidget.cpp
@@ -4,96 +4,98 @@
** This file is part of Qtopia Environment.
**
** This file may be distributed and/or modified under the terms of the
** GNU General Public License version 2 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.trolltech.com/gpl/ for GPL licensing information.
**
** Contact info@trolltech.com if any conditions of this licensing are
** not clear to you.
**
**********************************************************************/
#include "gowidget.h"
#include <qpe/config.h>
#include <qpe/resource.h>
#include <qpainter.h>
#include <qpixmap.h>
#include <qpe/qpetoolbar.h>
#include <qpe/qpemenubar.h>
#include <qpopupmenu.h>
#include <qaction.h>
#include <qapplication.h> //processEvents()
#include <qlabel.h>
//#include <stdio.h>
#include "amigo.h"
#include "goplayutils.h"
static const enum bVal computer_color = BLACK;
static int current_handicap = 1;
static QBrush *goBrush;
//static QImage *newBlackStone;
//static QImage *blackStone;
//static QImage *whiteStone;
static QPixmap *newBlackStone;
static QPixmap *blackStone;
static QPixmap *whiteStone;
+static bool smallStones = FALSE;
+
GoMainWidget::GoMainWidget( QWidget *parent, const char* name) :
QMainWindow( parent, name )
{
setToolBarsMovable( FALSE );
GoWidget *go = new GoWidget(this);
setCentralWidget(go);
toolbar = new QPEToolBar(this);
toolbar->setHorizontalStretchable( TRUE );
addToolBar(toolbar);
QPEMenuBar *mb = new QPEMenuBar( toolbar );
mb->setMargin(0);
QPopupMenu *file = new QPopupMenu( this );
QAction *a = new QAction( tr( "New Game" ), QString::null, 0, this, 0 );
connect( a, SIGNAL( activated() ), go, SLOT( newGame() ) );
a->addTo( file );
a = new QAction( tr( "Pass" ), Resource::loadPixmap( "pass" ), QString::null, 0, this, 0 );
connect( a, SIGNAL( activated() ), go, SLOT( pass() ) );
a->addTo( file );
a->addTo( toolbar );
a = new QAction( tr( "Resign" ), Resource::loadPixmap( "reset" ), QString::null, 0, this, 0 );
connect( a, SIGNAL( activated() ), go, SLOT( resign() ) );
a->addTo( file );
a = new QAction( tr( "Two player option" ), QString::null, 0, this, 0 );
a->setToggleAction( TRUE );
connect( a, SIGNAL( toggled(bool) ), go, SLOT( setTwoplayer(bool) ) );
a->addTo( file );
mb->insertItem( tr( "Game" ), file );
QLabel *turnLabel = new QLabel( toolbar );
turnLabel->setBackgroundMode( PaletteButton );
connect( go, SIGNAL(showTurn(const QPixmap&)),
turnLabel, SLOT(setPixmap(const QPixmap&)) );
QLabel * scoreLabel = new QLabel( toolbar );
scoreLabel->setBackgroundMode( PaletteButton );
connect( go, SIGNAL(showScore(const QString&)),
scoreLabel, SLOT(setText(const QString&)) );
toolbar->setStretchableWidget( scoreLabel );
@@ -152,96 +154,109 @@ void GoWidget::writeConfig()
Config cfg("Go");
cfg.setGroup("Game");
cfg.writeEntry("TwoPlayer", twoplayer);
cfg.writeEntry("CurrentPlayer", currentPlayer);
cfg.writeEntry("NPassed", nPassed);
QString b;
for (int i=0; i<19; i++)
for (int j=0; j<19; j++)
b += board[i][j] == BLACK ? 'B' : board[i][j] == WHITE ? 'W' : '.';
cfg.writeEntry("Board", b);
cfg.writeEntry("LastX", lastX);
cfg.writeEntry("LastY", lastY);
extern int blackPrisoners, whitePrisoners;
cfg.writeEntry("BlackPrisoners", blackPrisoners);
cfg.writeEntry("WhitePrisoners", whitePrisoners);
}
void GoWidget::readConfig()
{
init();
Config cfg("Go");
cfg.setGroup("Game");
twoplayer = cfg.readBoolEntry("TwoPlayer");
currentPlayer = (bVal)cfg.readNumEntry("CurrentPlayer",1);
nPassed = cfg.readNumEntry("NPassed",0);
QString b = cfg.readEntry("Board");
if ( b.length() == 19*19 )
for (int i=0; i<19; i++)
for (int j=0; j<19; j++) {
QChar ch = b[j+19*i];
if ( ch != '.' )
GoPlaceStone( ch == 'B' ? BLACK : WHITE, i, j );
}
lastX = cfg.readNumEntry("LastX");
lastY = cfg.readNumEntry("LastY");
extern int blackPrisoners, whitePrisoners;
blackPrisoners = cfg.readNumEntry("BlackPrisoners",0);
whitePrisoners = cfg.readNumEntry("WhitePrisoners",0);
reportPrisoners(blackPrisoners,whitePrisoners);
emit showTurn( currentPlayer == WHITE ? *whiteStone : *blackStone );
}
void GoWidget::resizeEvent( QResizeEvent * )
{
d = QMIN(width(),height())/19;
// int r = (d/2-1);
bx = (width() - 18*d)/2 ;
by = (height() - 18*d)/2 ;
+
+ if ( d < 10 && !smallStones ) {
+ blackStone->convertFromImage( blackStone->convertToImage().smoothScale(8,8) );
+ whiteStone->convertFromImage( whiteStone->convertToImage().smoothScale(8,8) );
+ newBlackStone->convertFromImage( newBlackStone->convertToImage().smoothScale(8,8) );
+
+ smallStones = TRUE;
+ } else if ( d >= 10 && smallStones ) {
+ blackStone = new QPixmap(Resource::loadPixmap( "Go-black" ));
+ whiteStone = new QPixmap(Resource::loadPixmap( "Go-white" ));
+ newBlackStone = new QPixmap(Resource::loadPixmap( "Go-black-highlight" ));
+ smallStones = FALSE;
+ }
}
void GoWidget::init()
{
lastX = lastY = newX = newY = -1;
nPassed = 0;
for ( int i = 0; i < 19; i++ )
for ( int j = 0; j < 19; j++ )
board[i][j]=-1;
gameActive = TRUE;
goRestart(current_handicap);
if ( twoplayer ) {
currentPlayer = BLACK;
} else {
doComputerMove();
currentPlayer = WHITE;
}
emit showTurn( currentPlayer == WHITE ? *whiteStone : *blackStone );
}
void GoWidget::paintEvent( QPaintEvent *e )
{
int i,j;
int r = whiteStone->width()/2;
QPainter p(this);
p.fillRect( bx - d/2, by - d/2, 19*d, 19*d, *goBrush );
int xMin = QMAX( x2board(e->rect().left()), 0 );
int xMax = QMIN( x2board(e->rect().right()), 18 );
int yMin = QMAX( y2board(e->rect().top()), 0 );
int yMax = QMIN( y2board(e->rect().bottom()), 18 );
QColor pine( 255, 186, 89 );
p.setPen( pine.dark() );
for ( i = xMin; i < xMax+1 ; i ++ ) {
p.drawLine( bx+i*d, by, bx+i*d, by+18*d );
}
for ( j = yMin; j < yMax+1 ; j ++ ) {
p.drawLine( bx, by+j*d, bx+18*d, by+j*d);
}
// dots are at (3,3), (3,9), (3,15) and so on
p.setBrush( black );
for ( i = 3; i < xMax+1; i+=6 )
diff --git a/noncore/games/minesweep/minefield.h b/noncore/games/minesweep/minefield.h
index 4ede435..1349c35 100644
--- a/noncore/games/minesweep/minefield.h
+++ b/noncore/games/minesweep/minefield.h
@@ -1,87 +1,101 @@
/**********************************************************************
** Copyright (C) 2000 Trolltech AS. All rights reserved.
**
** This file is part of Qtopia Environment.
**
** This file may be distributed and/or modified under the terms of the
** GNU General Public License version 2 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.trolltech.com/gpl/ for GPL licensing information.
**
** Contact info@trolltech.com if any conditions of this licensing are
** not clear to you.
**
**********************************************************************/
#ifndef MINEFIELD_H
#define MINEFIELD_H
-#include <qtable.h>
+#include <qscrollview.h>
class Mine;
class Config;
-class MineField : public QTable
+class MineField : public QScrollView
{
Q_OBJECT
public:
MineField( QWidget* parent = 0, const char* name = 0 );
~MineField();
enum State { Waiting, Playing, GameOver };
State state() const { return stat; }
void readConfig(Config&);
void writeConfig(Config&) const;
int level() const { return lev; }
+ void setAvailableRect( const QRect & );
public slots:
void setup( int level );
void showMines();
signals:
void gameOver( bool won );
void gameStarted();
void mineCount( int );
protected:
- void paintFocus( QPainter*, const QRect& );
- void viewportMousePressEvent( QMouseEvent* );
- void viewportMouseReleaseEvent( QMouseEvent* );
+
+ void contentsMousePressEvent( QMouseEvent* );
+ void contentsMouseReleaseEvent( QMouseEvent* );
void keyPressEvent( QKeyEvent* );
void keyReleaseEvent( QKeyEvent* );
-
+ void drawContents( QPainter * p, int clipx, int clipy, int clipw, int cliph );
+
int getHint( int row, int col );
- void setHint( Mine* );
+ void setHint( int r, int c );
void updateMine( int row, int col );
void paletteChange( const QPalette & );
-
+ void updateCell( int r, int c );
+ bool onBoard( int r, int c ) const { return r >= 0 && r < numRows && c >= 0 && c < numCols; }
+ Mine *mine( int row, int col ) { return onBoard(row, col ) ? mines[row+numCols*col] : 0; }
+ const Mine *mine( int row, int col ) const { return onBoard(row, col ) ? mines[row+numCols*col] : 0; }
+
protected slots:
void cellPressed( int row, int col );
void cellClicked( int row, int col );
void held();
private:
+ int findCellSize();
+ void setCellSize( int );
+
State stat;
void MineField::setState( State st );
void MineField::placeMines();
enum FlagAction { NoAction, FlagOn, FlagNext };
FlagAction flagAction;
bool ignoreClick;
int currRow;
int currCol;
+ int numRows, numCols;
+
int minecount;
int mineguess;
int nonminecount;
int lev;
+ QRect availableRect;
+ int cellSize;
QTimer *holdTimer;
+ Mine **mines;
};
#endif // MINEFIELD_H
diff --git a/noncore/games/minesweep/minesweep.cpp b/noncore/games/minesweep/minesweep.cpp
index 6492462..c84fe53 100644
--- a/noncore/games/minesweep/minesweep.cpp
+++ b/noncore/games/minesweep/minesweep.cpp
@@ -174,153 +174,168 @@ void ResultIndicator::showResult( QWidget *ref, bool won )
r->setAlignment( AlignCenter );
r->setFrameStyle( Sunken|StyledPanel );
if ( won ) {
r->setText( MineSweep::tr("You won!") );
r->center();
r->show();
r->twoStage = FALSE;
r->timerId = r->startTimer(1500);
} else {
QPalette p( red );
r->setPalette( p );
r->setText( MineSweep::tr("You exploded!") );
r->resize( ref->size() );
r->move( ref->mapToGlobal(QPoint(0,0)) );
r->show();
r->twoStage = TRUE;
r->timerId =r->startTimer(200);
}
}
void ResultIndicator::center()
{
QWidget *w = parentWidget();
QPoint pp = w->mapToGlobal( QPoint(0,0) );
QSize s = sizeHint()*3;
pp = QPoint( pp.x() + w->width()/2 - s.width()/2,
pp.y() + w->height()/ 2 - s.height()/2 );
setGeometry( QRect(pp, s) );
}
void ResultIndicator::timerEvent( QTimerEvent *te )
{
if ( te->timerId() != timerId )
return;
killTimer( timerId );
if ( twoStage ) {
center();
twoStage = FALSE;
timerId = startTimer( 1000 );
} else {
delete this;
}
}
+class MineFrame : public QFrame
+{
+public:
+ MineFrame( QWidget *parent, const char *name = 0 )
+ :QFrame( parent, name ) {}
+ void setField( MineField *f ) { field = f; }
+protected:
+ void resizeEvent( QResizeEvent *e ) {
+ field->setAvailableRect( contentsRect());
+ QFrame::resizeEvent(e);
+ }
+private:
+ MineField *field;
+};
+
+
+
MineSweep::MineSweep( QWidget* parent, const char* name, WFlags f )
: QMainWindow( parent, name, f )
{
srand(::time(0));
setCaption( tr("Mine Hunt") );
setIcon( Resource::loadPixmap( "minesweep_icon" ) );
- QPEToolBar *menuToolBar = new QPEToolBar( this );
- QPEMenuBar *menuBar = new QPEMenuBar( menuToolBar );
+ QPEToolBar *toolBar = new QPEToolBar( this );
+ toolBar->setHorizontalStretchable( TRUE );
+
+ QPEMenuBar *menuBar = new QPEMenuBar( toolBar );
QPopupMenu *gameMenu = new QPopupMenu( this );
gameMenu->insertItem( tr("Beginner"), this, SLOT( beginner() ) );
gameMenu->insertItem( tr("Advanced"), this, SLOT( advanced() ) );
gameMenu->insertItem( tr("Expert"), this, SLOT( expert() ) );
menuBar->insertItem( tr("Game"), gameMenu );
-
- QPEToolBar *toolBar = new QPEToolBar( this );
- toolBar->setHorizontalStretchable( TRUE );
guessLCD = new QLCDNumber( toolBar );
toolBar->setStretchableWidget( guessLCD );
QPalette lcdPal( red );
lcdPal.setColor( QColorGroup::Background, QApplication::palette().active().background() );
lcdPal.setColor( QColorGroup::Button, QApplication::palette().active().button() );
// guessLCD->setPalette( lcdPal );
guessLCD->setSegmentStyle( QLCDNumber::Flat );
guessLCD->setFrameStyle( QFrame::NoFrame );
guessLCD->setNumDigits( 2 );
guessLCD->setBackgroundMode( PaletteButton );
newGameButton = new QPushButton( toolBar );
newGameButton->setPixmap( QPixmap( pix_new ) );
newGameButton->setFocusPolicy(QWidget::NoFocus);
connect( newGameButton, SIGNAL(clicked()), this, SLOT(newGame()) );
timeLCD = new QLCDNumber( toolBar );
// timeLCD->setPalette( lcdPal );
timeLCD->setSegmentStyle( QLCDNumber::Flat );
timeLCD->setFrameStyle( QFrame::NoFrame );
timeLCD->setNumDigits( 5 ); // "mm:ss"
timeLCD->setBackgroundMode( PaletteButton );
setToolBarsMovable ( FALSE );
- addToolBar( menuToolBar );
addToolBar( toolBar );
- QFrame *mainframe = new QFrame( this );
+ MineFrame *mainframe = new MineFrame( this );
mainframe->setFrameShape( QFrame::Box );
mainframe->setFrameShadow( QFrame::Raised );
- mainframe->setMargin(5);
+
mainframe->setLineWidth(2);
- QBoxLayout *box = new QVBoxLayout( mainframe );
+
field = new MineField( mainframe );
- box->addWidget( field, 0, AlignCenter );
+ mainframe->setField( field );
QFont fnt = field->font();
fnt.setBold( TRUE );
field->setFont( QFont( fnt ) );
field->setFocus();
setCentralWidget( mainframe );
connect( field, SIGNAL( gameOver( bool ) ), this, SLOT( gameOver( bool ) ) );
connect( field, SIGNAL( mineCount( int ) ), this, SLOT( setCounter( int ) ) );
connect( field, SIGNAL( gameStarted()), this, SLOT( startPlaying() ) );
timer = new QTimer( this );
connect( timer, SIGNAL( timeout() ), this, SLOT( updateTime() ) );
readConfig();
}
MineSweep::~MineSweep()
{
writeConfig();
}
void MineSweep::gameOver( bool won )
{
field->showMines();
if ( won ) {
newGameButton->setPixmap( QPixmap( happy_xpm ) );
} else {
newGameButton->setPixmap( QPixmap( dead_xpm ) );
}
ResultIndicator::showResult( this, won );
timer->stop();
}
void MineSweep::newGame()
{
newGame(field->level());
}
void MineSweep::newGame(int level)
{
timeLCD->display( "0:00" );
field->setup( level );
newGameButton->setPixmap( QPixmap( pix_new ) );
timer->stop();
}
void MineSweep::startPlaying()
diff --git a/noncore/games/snake/interface.h b/noncore/games/snake/interface.h
index 30c7f84..454d4ee 100644
--- a/noncore/games/snake/interface.h
+++ b/noncore/games/snake/interface.h
@@ -1,69 +1,69 @@
/**********************************************************************
** Copyright (C) 2000 Trolltech AS. All rights reserved.
**
** This file is part of Qtopia Environment.
**
** This file may be distributed and/or modified under the terms of the
** GNU General Public License version 2 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.trolltech.com/gpl/ for GPL licensing information.
**
** Contact info@trolltech.com if any conditions of this licensing are
** not clear to you.
**
**********************************************************************/
#include <qmainwindow.h>
#include <qcanvas.h>
#include <qlabel.h>
#include "snake.h"
#include "target.h"
#include "obstacle.h"
// class QCanvas;
class SnakeGame : public QMainWindow {
Q_OBJECT
public:
SnakeGame(QWidget* parent=0, const char* name=0, WFlags f=0);
~SnakeGame();
void clear();
void createTargets();
- void welcomescreen();
protected:
virtual void keyPressEvent(QKeyEvent*);
virtual void resizeEvent(QResizeEvent *e);
signals:
void moveFaster();
private slots:
void newGame();
void gameOver();
void wait();
void levelUp();
void scoreInc();
+ void welcomescreen();
private:
void showScore(int);
QCanvasView* cv;
QLabel* scorelabel;
QCanvas canvas;
QTimer* pauseTimer;
Snake* snake;
int last;
int level;
int stage;
int targetamount;
int notargets;
bool waitover;
bool gamestopped;
};
diff --git a/noncore/games/snake/obstacle.cpp b/noncore/games/snake/obstacle.cpp
index 2d07fe7..4bdefa5 100644
--- a/noncore/games/snake/obstacle.cpp
+++ b/noncore/games/snake/obstacle.cpp
@@ -1,51 +1,70 @@
/**********************************************************************
** Copyright (C) 2000 Trolltech AS. All rights reserved.
**
** This file is part of Qtopia Environment.
**
** This file may be distributed and/or modified under the terms of the
** GNU General Public License version 2 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.trolltech.com/gpl/ for GPL licensing information.
**
** Contact info@trolltech.com if any conditions of this licensing are
** not clear to you.
**
**********************************************************************/
#include "obstacle.h"
#include "codes.h"
#include <qpe/resource.h>
-Obstacle::Obstacle(QCanvas* canvas, int x, int y)
- : QCanvasSprite(0, canvas)
+
+
+Obstacle::Obstacle(QCanvas* canvas, int y)
+ : QCanvasSprite(0,canvas)
{
- newObstacle(x, y);
+ newObstacle(y);
}
-void Obstacle::newObstacle(int x, int y)
+void Obstacle::newObstacle(int y)
{
- QCanvasPixmapArray* obstaclearray = new QCanvasPixmapArray(Resource::findPixmap("snake/wall.png"));
-
+ QPixmap obstaclePix( Resource::findPixmap("snake/wall.png") );
+
+ if ( obstaclePix.width() > canvas()->width()*3/5 ) {
+ int w = canvas()->width()*3/5;
+ w = w - w % 16;
+ obstaclePix.resize( w, obstaclePix.height() );
+ }
+
+ QList<QPixmap> pixl;
+ pixl.append( &obstaclePix );
+
+ QPoint nullp;
+ QList<QPoint> pl;
+ pl.append( &nullp );
+
+ QCanvasPixmapArray* obstaclearray = new QCanvasPixmapArray(pixl, pl);
setSequence(obstaclearray);
-
+
+ int x = ( canvas()->width() - obstaclePix.width() )/2;
+ x = x - x % 16;
+ y = y - y % 16;
move(x, y);
-
+ setZ( -100 );
show();
canvas()->update();
}
int Obstacle::rtti() const
{
return obstacle_rtti;
}
Obstacle::~Obstacle()
{
}
diff --git a/noncore/games/snake/obstacle.h b/noncore/games/snake/obstacle.h
index 838917f..b3c7846 100644
--- a/noncore/games/snake/obstacle.h
+++ b/noncore/games/snake/obstacle.h
@@ -1,30 +1,30 @@
/**********************************************************************
** Copyright (C) 2000 Trolltech AS. All rights reserved.
**
** This file is part of Qtopia Environment.
**
** This file may be distributed and/or modified under the terms of the
** GNU General Public License version 2 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.trolltech.com/gpl/ for GPL licensing information.
**
** Contact info@trolltech.com if any conditions of this licensing are
** not clear to you.
**
**********************************************************************/
#include <qcanvas.h>
class Obstacle : public QCanvasSprite
{
public:
- Obstacle(QCanvas*, int x, int y);
+ Obstacle(QCanvas*, int y);
~Obstacle();
- void newObstacle(int x, int y);
+ void newObstacle(int y);
int rtti() const;
};
diff --git a/noncore/games/solitaire/canvascard.cpp b/noncore/games/solitaire/canvascard.cpp
index ae3c859..7c4a5ba 100644
--- a/noncore/games/solitaire/canvascard.cpp
+++ b/noncore/games/solitaire/canvascard.cpp
@@ -1,236 +1,267 @@
/**********************************************************************
** Copyright (C) 2000 Trolltech AS. All rights reserved.
**
** This file is part of Qtopia Environment.
**
** This file may be distributed and/or modified under the terms of the
** GNU General Public License version 2 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.trolltech.com/gpl/ for GPL licensing information.
**
** Contact info@trolltech.com if any conditions of this licensing are
** not clear to you.
**
**********************************************************************/
#include "cardgame.h"
#include "canvascard.h"
#include <qpe/resource.h>
#include <qpainter.h>
#include <qimage.h>
#include <qpaintdevice.h>
#include <qbitmap.h>
+#include <qgfx_qws.h> // Needed to get the device's width
#include <math.h>
#if defined( QT_QWS_CASSIOPEIA )
#define SLOW_HARDWARE
#endif
// Seems to be fast enough to me even without Transformations in the library
//#if defined( QT_NO_TRANSFORMATIONS ) && defined( QT_QWS_IPAQ )
//#define SLOW_HARDWARE
//#endif
QBitmap *Create180RotatedBitmap(QBitmap *srcBitmap)
{
#ifdef QT_NO_TRANSFORMATIONS
int w = srcBitmap->width();
int h = srcBitmap->height();
QBitmap *dstBitmap = new QBitmap( w, h );
// ### this is very poorly implemented and probably could be much faster
for (int i = 0; i < w; i++)
for (int j = 0; j < h; j++)
bitBlt( dstBitmap, i, j, srcBitmap, w - i - 1, h - j - 1, 1, 1 );
return dstBitmap;
#else
QWMatrix m;
m.rotate( 180.0 );
return new QBitmap( srcBitmap->xForm( m ) );
#endif
}
QPixmap *CreateScaledPixmap(QPixmap *srcPixmap, double scaleX, double scaleY)
{
#ifdef QT_NO_TRANSFORMATIONS
int w = srcPixmap->width();
int h = srcPixmap->height();
int newW = (int)(w * scaleX);
int newH = (int)(h * scaleY);
QPixmap *dstPixmap = new QPixmap( newW, newH );
// ### this is very poorly implemented and probably could be much faster
for (int i = 0; i < newW; i++) {
int srcX = w * i / newW;
if (newH == h) {
// Optimise for scaleing in the X-axis only
bitBlt( dstPixmap, i, 0, srcPixmap, srcX, 0, 1, h );
} else {
for (int j = 0; j < newH; j++) {
int srcY = h * j / newH;
bitBlt( dstPixmap, i, j, srcPixmap, srcX, srcY, 1, 1 );
}
}
}
return dstPixmap;
#else
QWMatrix s;
s.scale( scaleX, scaleY );
return new QPixmap( srcPixmap->xForm( s ) );
#endif
}
// Initialise static member variables to NULL
QPixmap *CanvasCard::cardsFaces = NULL;
QPixmap *CanvasCard::cardsBacks = NULL;
QBitmap *CanvasCard::cardsChars = NULL;
QBitmap *CanvasCard::cardsSuits = NULL;
QBitmap *CanvasCard::cardsCharsUpsideDown = NULL;
QBitmap *CanvasCard::cardsSuitsUpsideDown = NULL;
CanvasCard::CanvasCard( eValue v, eSuit s, bool f, QCanvas *canvas ) :
Card(v, s, f), QCanvasRectangle( 0, 0, 1, 1, canvas ), cardBack(1), scaleX(1.0), scaleY(1.0)
{
if ( !cardsFaces ) {
- cardsFaces = new QPixmap( Resource::loadPixmap( "cards/card_face" ) );
- cardsBacks = new QPixmap( Resource::loadPixmap( "cards/card_back0001" ) );
- cardsChars = new QBitmap( Resource::loadBitmap( "cards/card_chars" ) );
- cardsSuits = new QBitmap( Resource::loadBitmap( "cards/card_suits" ) );
+ if ( qt_screen->deviceWidth() < 200 ) {
+ cardsFaces = new QPixmap( Resource::loadPixmap( "cards/card_face_small" ) );
+ cardsBacks = new QPixmap( Resource::loadPixmap( "cards/card_back0001_small" ) );
+ cardsChars = new QBitmap( Resource::loadBitmap( "cards/card_chars_small" ) );
+ cardsSuits = new QBitmap( Resource::loadBitmap( "cards/card_suits_small" ) );
+ } else {
+ cardsFaces = new QPixmap( Resource::loadPixmap( "cards/card_face" ) );
+ cardsBacks = new QPixmap( Resource::loadPixmap( "cards/card_back0001" ) );
+ cardsChars = new QBitmap( Resource::loadBitmap( "cards/card_chars" ) );
+ cardsSuits = new QBitmap( Resource::loadBitmap( "cards/card_suits" ) );
+ }
cardsCharsUpsideDown = Create180RotatedBitmap( cardsChars );
cardsSuitsUpsideDown = Create180RotatedBitmap( cardsSuits );
}
xOff = cardsFaces->width() / 2;
yOff = cardsFaces->height() / 2;
setSize( cardsFaces->width(), cardsFaces->height() );
setPen( NoPen );
flipping = FALSE;
}
void CanvasCard::setCardBack(int b)
{
if ( cardBack != b ) {
cardBack = b;
if ( cardsBacks )
delete cardsBacks;
- switch (cardBack) {
- case 0:
- cardsBacks = new QPixmap( Resource::loadPixmap( "cards/card_back0001" ) ); break;
- case 1:
- cardsBacks = new QPixmap( Resource::loadPixmap( "cards/card_back0002" ) ); break;
- case 2:
- cardsBacks = new QPixmap( Resource::loadPixmap( "cards/card_back0003" ) ); break;
- case 3:
- cardsBacks = new QPixmap( Resource::loadPixmap( "cards/card_back0004" ) ); break;
- case 4:
- cardsBacks = new QPixmap( Resource::loadPixmap( "cards/card_back0005" ) ); break;
+ if ( qt_screen->deviceWidth() < 200 ) {
+ switch (cardBack) {
+ case 0:
+ cardsBacks = new QPixmap( Resource::loadPixmap( "cards/card_back0001_small" ) ); break;
+ case 1:
+ cardsBacks = new QPixmap( Resource::loadPixmap( "cards/card_back0002_small" ) ); break;
+ case 2:
+ cardsBacks = new QPixmap( Resource::loadPixmap( "cards/card_back0003_small" ) ); break;
+ case 3:
+ cardsBacks = new QPixmap( Resource::loadPixmap( "cards/card_back0004_small" ) ); break;
+ case 4:
+ cardsBacks = new QPixmap( Resource::loadPixmap( "cards/card_back0005_small" ) ); break;
+ }
+ } else {
+ switch (cardBack) {
+ case 0:
+ cardsBacks = new QPixmap( Resource::loadPixmap( "cards/card_back0001" ) ); break;
+ case 1:
+ cardsBacks = new QPixmap( Resource::loadPixmap( "cards/card_back0002" ) ); break;
+ case 2:
+ cardsBacks = new QPixmap( Resource::loadPixmap( "cards/card_back0003" ) ); break;
+ case 3:
+ cardsBacks = new QPixmap( Resource::loadPixmap( "cards/card_back0004" ) ); break;
+ case 4:
+ cardsBacks = new QPixmap( Resource::loadPixmap( "cards/card_back0005" ) ); break;
+ }
}
if ( !isFacing() )
redraw();
}
}
void CanvasCard::draw(QPainter &painter)
{
int ix = (int)x(), iy = (int)y();
QPainter *p = &painter;
QPixmap *unscaledCard = NULL;
if ((scaleX <= 0.98) || (scaleY <= 0.98))
{
p = new QPainter();
unscaledCard = new QPixmap( cardsFaces->width(), cardsFaces->height() );
p->begin(unscaledCard);
ix = 0;
iy = 0;
}
if ( isFacing() ) {
/*
// Now add the joker and card backs to the list of pixmaps
QPixmap *CardsBack = new QPixmap( Resource::loadPixmap( "cards/card_joker.png" ) );
QPoint *newBackHotspot = new QPoint( 0, 0 );
pixmaps->append((const QPixmap *)CardsBack);
hotspots->append((const QPoint *)newBackHotspot);
*/
int w = cardsFaces->width(), h = cardsFaces->height();
// p->setBrush( NoBrush );
p->setBrush( QColor( 0xFF, 0xFF, 0xFF ) );
if ( isRed() == TRUE )
p->setPen( QColor( 0xFF, 0, 0 ) );
else
p->setPen( QColor( 0, 0, 0 ) );
- p->drawPixmap( ix + 0, iy + 0, *cardsFaces );
- p->drawPixmap( ix + 4, iy + 4, *cardsChars, 7*(getValue()-1), 0, 7, 7 );
- p->drawPixmap( ix + 12, iy + 4, *cardsSuits, 7*(getSuit()-1), 0, 7, 8 );
- p->drawPixmap( ix + w-4-7, iy + h-4-7, *cardsCharsUpsideDown, 7*(12-getValue()+1), 0, 7, 7 );
- p->drawPixmap( ix + w-12-7, iy + h-5-7, *cardsSuitsUpsideDown, 7*(3-getSuit()+1), 0, 7, 8 );
+ if ( qt_screen->deviceWidth() < 200 ) {
+ p->drawPixmap( ix + 0, iy + 0, *cardsFaces );
+ p->drawPixmap( ix + 3, iy + 3, *cardsChars, 5*(getValue()-1), 0, 5, 6 );
+ p->drawPixmap( ix + 11, iy + 3, *cardsSuits, 5*(getSuit()-1), 0, 5, 6 );
+ p->drawPixmap( ix + w-3-5, iy + h-3-6, *cardsCharsUpsideDown, 5*(12-getValue()+1), 0, 5, 6 );
+ p->drawPixmap( ix + w-11-5, iy + h-3-6, *cardsSuitsUpsideDown, 5*(3-getSuit()+1), 0, 5, 6 );
+ } else {
+ p->drawPixmap( ix + 0, iy + 0, *cardsFaces );
+ p->drawPixmap( ix + 4, iy + 4, *cardsChars, 7*(getValue()-1), 0, 7, 7 );
+ p->drawPixmap( ix + 12, iy + 4, *cardsSuits, 7*(getSuit()-1), 0, 7, 8 );
+ p->drawPixmap( ix + w-4-7, iy + h-4-7, *cardsCharsUpsideDown, 7*(12-getValue()+1), 0, 7, 7 );
+ p->drawPixmap( ix + w-12-7, iy + h-5-7, *cardsSuitsUpsideDown, 7*(3-getSuit()+1), 0, 7, 8 );
+ }
} else {
p->drawPixmap( ix, iy, *cardsBacks );
}
if (p != &painter)
{
p->end();
QPixmap *scaledCard = CreateScaledPixmap( unscaledCard, scaleX, scaleY );
int xoff = scaledCard->width() / 2;
int yoff = scaledCard->height() / 2;
painter.drawPixmap( (int)x() + xOff - xoff, (int)y() + yOff - yoff, *scaledCard );
delete p;
delete unscaledCard;
delete scaledCard;
}
}
static const double flipLift = 1.5;
void CanvasCard::flipTo(int x2, int y2, int steps)
{
flipSteps = steps;
#ifdef SLOW_HARDWARE
move(x2,y2);
Card::flipTo(x2,y2,steps);
#else
int x1 = (int)x();
int y1 = (int)y();
double dx = x2 - x1;
double dy = y2 - y1;
flipping = TRUE;
destX = x2;
destY = y2;
animSteps = flipSteps;
setVelocity(dx/animSteps, dy/animSteps-flipLift);
setAnimated(TRUE);
#endif
}
void CanvasCard::advance(int stage)
diff --git a/noncore/games/solitaire/canvasshapes.cpp b/noncore/games/solitaire/canvasshapes.cpp
index 28d0b4e..6ccd4a4 100644
--- a/noncore/games/solitaire/canvasshapes.cpp
+++ b/noncore/games/solitaire/canvasshapes.cpp
@@ -1,92 +1,114 @@
/**********************************************************************
** Copyright (C) 2000 Trolltech AS. All rights reserved.
**
** This file is part of Qtopia Environment.
**
** This file may be distributed and/or modified under the terms of the
** GNU General Public License version 2 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.trolltech.com/gpl/ for GPL licensing information.
**
** Contact info@trolltech.com if any conditions of this licensing are
** not clear to you.
**
**********************************************************************/
#include <qpainter.h>
#include <qcanvas.h>
+#include <qgfx_qws.h>
#include "canvasshapes.h"
CanvasRoundRect::CanvasRoundRect(int x, int y, QCanvas *canvas) :
- QCanvasRectangle( x, y, 23, 36, canvas)
+ QCanvasRectangle( x, y, ( qt_screen->deviceWidth() < 200 ) ? 20 : 23, ( qt_screen->deviceWidth() < 200 ) ? 27 : 36, canvas)
{
setZ(0);
show();
}
void CanvasRoundRect::redraw()
{
hide();
show();
}
void CanvasRoundRect::drawShape(QPainter &p)
{
- p.drawRoundRect( (int)x(), (int)y(), 23, 36);
+ if ( qt_screen->deviceWidth() < 200 )
+ p.drawRoundRect( (int)x() + 1, (int)y() + 1, 18, 25);
+ else
+ p.drawRoundRect( (int)x(), (int)y(), 23, 36);
}
CanvasCircleOrCross::CanvasCircleOrCross(int x, int y, QCanvas *canvas) :
QCanvasRectangle( x, y, 21, 21, canvas), circleShape(TRUE)
{
show();
}
void CanvasCircleOrCross::redraw()
{
hide();
show();
}
void CanvasCircleOrCross::setCircle()
{
circleShape = TRUE;
redraw();
}
void CanvasCircleOrCross::setCross()
{
circleShape = FALSE;
redraw();
}
void CanvasCircleOrCross::drawShape(QPainter &p)
{
- int x1 = (int)x(), y1 = (int)y();
- // Green circle
- if (circleShape == TRUE) {
- p.setPen( QPen( QColor(0x10, 0xE0, 0x10), 1 ) );
- p.drawEllipse( x1 - 1, y1 - 1, 21, 21);
- p.drawEllipse( x1 - 1, y1 - 0, 21, 19);
- p.drawEllipse( x1 + 0, y1 + 0, 19, 19);
- p.drawEllipse( x1 + 1, y1 + 0, 17, 19);
- p.drawEllipse( x1 + 1, y1 + 1, 17, 17);
- // Red cross
+ if ( qt_screen->deviceWidth() < 200 ) {
+ int x1 = (int)x(), y1 = (int)y();
+ // Green circle
+ if (circleShape == TRUE) {
+ p.setPen( QPen( QColor(0x10, 0xE0, 0x10), 1 ) );
+ p.drawEllipse( x1 - 1, y1 - 1, 17, 17);
+ p.drawEllipse( x1 - 1, y1 - 0, 17, 15);
+ p.drawEllipse( x1 + 0, y1 + 0, 15, 15);
+ p.drawEllipse( x1 + 1, y1 + 0, 13, 15);
+ p.drawEllipse( x1 + 1, y1 + 1, 13, 13);
+ // Red cross
+ } else {
+ p.setPen( QPen( QColor(0xE0, 0x10, 0x10), 4 ) );
+ p.drawLine( x1, y1, x1 + 14, y1 + 14);
+ p.drawLine( x1 + 14, y1, x1, y1 + 14);
+ }
} else {
- p.setPen( QPen( QColor(0xE0, 0x10, 0x10), 5 ) );
- p.drawLine( x1, y1, x1 + 20, y1 + 20);
- p.drawLine( x1 + 20, y1, x1, y1 + 20);
+ int x1 = (int)x(), y1 = (int)y();
+ // Green circle
+ if (circleShape == TRUE) {
+ p.setPen( QPen( QColor(0x10, 0xE0, 0x10), 1 ) );
+ p.drawEllipse( x1 - 1, y1 - 1, 21, 21);
+ p.drawEllipse( x1 - 1, y1 - 0, 21, 19);
+ p.drawEllipse( x1 + 0, y1 + 0, 19, 19);
+ p.drawEllipse( x1 + 1, y1 + 0, 17, 19);
+ p.drawEllipse( x1 + 1, y1 + 1, 17, 17);
+ // Red cross
+ } else {
+ p.setPen( QPen( QColor(0xE0, 0x10, 0x10), 5 ) );
+ p.drawLine( x1, y1, x1 + 20, y1 + 20);
+ p.drawLine( x1 + 20, y1, x1, y1 + 20);
+ }
}
}
diff --git a/noncore/games/solitaire/freecellcardgame.cpp b/noncore/games/solitaire/freecellcardgame.cpp
index e82afd4..98415aa 100644
--- a/noncore/games/solitaire/freecellcardgame.cpp
+++ b/noncore/games/solitaire/freecellcardgame.cpp
@@ -1,89 +1,94 @@
/**********************************************************************
** Copyright (C) 2000 Trolltech AS. All rights reserved.
**
** This file is part of Qtopia Environment.
**
** This file may be distributed and/or modified under the terms of the
** GNU General Public License version 2 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.trolltech.com/gpl/ for GPL licensing information.
**
** Contact info@trolltech.com if any conditions of this licensing are
** not clear to you.
**
**********************************************************************/
+#include <qgfx_qws.h>
#include "freecellcardgame.h"
extern int highestZ;
int numberOfFreeCells = 4;
FreecellCardGame::FreecellCardGame(QCanvas *c, bool snap, QWidget *parent) : CanvasCardGame(*c, snap, parent)
{
numberOfFreeCells = 4;
highestZ = 0;
+ int spaceBetweenPiles = ( qt_screen->deviceWidth() < 200 ) ? 21 : 28;
+ int xOrigin = ( qt_screen->deviceWidth() < 200 ) ? 0 : 5;
+ int spacing = ( qt_screen->deviceWidth() < 200 ) ? 0 : 0;
+
for (int i = 0; i < 4; i++) {
- freecellPiles[i] = new FreecellFreecellPile( 5 + i * 28, 10, canvas() );
+ freecellPiles[i] = new FreecellFreecellPile( xOrigin + i * spaceBetweenPiles, 10, canvas() );
addCardPile(freecellPiles[i]);
}
for (int i = 0; i < 4; i++) {
- discardPiles[i] = new FreecellDiscardPile( 125 + i * 28, 10, canvas() );
+ discardPiles[i] = new FreecellDiscardPile( xOrigin + spacing + 6 + (i + 4) * spaceBetweenPiles, 10, canvas() );
addCardPile(discardPiles[i]);
}
for (int i = 0; i < 8; i++) {
- workingPiles[i] = new FreecellWorkingPile( 10 + i * 28, 50, canvas() );
+ workingPiles[i] = new FreecellWorkingPile( xOrigin + spacing + 2 + i * spaceBetweenPiles, 50, canvas() );
addCardPile(workingPiles[i]);
}
}
void FreecellCardGame::deal(void)
{
highestZ = 1;
beginDealing();
for (int i = 0; i < 52; i++) {
Card *card = cards[i];
card->setFace( TRUE );
card->setPos( 0, 0, highestZ );
card->setCardPile( workingPiles[i%8] );
workingPiles[i%8]->addCardToTop( card );
card->move( workingPiles[i%8]->getCardPos( card ) );
card->showCard();
highestZ++;
}
endDealing();
}
bool FreecellCardGame::mousePressCard( Card *c, QPoint p )
{
Q_UNUSED(p);
if ( !c->getCardPile()->isAllowedToBeMoved(c) ) {
moving = NULL;
return TRUE;
}
return FALSE;
}
void FreecellCardGame::readConfig( Config& cfg )
{
cfg.setGroup("GameState");
// Create Cards, but don't shuffle or deal them yet
createDeck();
// Move the cards to their piles (deal them to their previous places)
beginDealing();
diff --git a/noncore/games/solitaire/patiencecardgame.cpp b/noncore/games/solitaire/patiencecardgame.cpp
index 5a9326a..1501d2f 100644
--- a/noncore/games/solitaire/patiencecardgame.cpp
+++ b/noncore/games/solitaire/patiencecardgame.cpp
@@ -1,91 +1,108 @@
/**********************************************************************
** Copyright (C) 2000 Trolltech AS. All rights reserved.
**
** This file is part of Qtopia Environment.
**
** This file may be distributed and/or modified under the terms of the
** GNU General Public License version 2 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.trolltech.com/gpl/ for GPL licensing information.
**
** Contact info@trolltech.com if any conditions of this licensing are
** not clear to you.
**
**********************************************************************/
+#include <qgfx_qws.h>
#include "patiencecardgame.h"
int highestZ = 0;
PatienceCardGame::PatienceCardGame(QCanvas *c, bool snap, QWidget *parent) : CanvasCardGame(*c, snap, parent)
{
numberOfTimesThroughDeck = 0;
highestZ = 0;
- circleCross = new CanvasCircleOrCross( 7, 18, canvas() );
- rectangle = new CanvasRoundRect( 35, 10, canvas() );
+ if ( qt_screen->deviceWidth() < 200 ) {
+ circleCross = new CanvasCircleOrCross( 7, 16, canvas() );
+ rectangle = new CanvasRoundRect( 30, 10, canvas() );
- for (int i = 0; i < 4; i++) {
- discardPiles[i] = new PatienceDiscardPile( 110 + i * 30, 10, canvas() );
- addCardPile(discardPiles[i]);
- }
- for (int i = 0; i < 7; i++) {
- workingPiles[i] = new PatienceWorkingPile( 10 + i * 30, 50, canvas() );
- addCardPile(workingPiles[i]);
+ for (int i = 0; i < 4; i++) {
+ discardPiles[i] = new PatienceDiscardPile( 78 + i * 23, 10, canvas() );
+ addCardPile(discardPiles[i]);
+ }
+ for (int i = 0; i < 7; i++) {
+ workingPiles[i] = new PatienceWorkingPile( 5 + i * 23, 50, canvas() );
+ addCardPile(workingPiles[i]);
+ }
+ faceDownDealingPile = new PatienceFaceDownDeck( 5, 10, canvas() );
+ faceUpDealingPile = new PatienceFaceUpDeck( 30, 10, canvas() );
+ } else {
+ circleCross = new CanvasCircleOrCross( 7, 18, canvas() );
+ rectangle = new CanvasRoundRect( 35, 10, canvas() );
+
+ for (int i = 0; i < 4; i++) {
+ discardPiles[i] = new PatienceDiscardPile( 110 + i * 30, 10, canvas() );
+ addCardPile(discardPiles[i]);
+ }
+ for (int i = 0; i < 7; i++) {
+ workingPiles[i] = new PatienceWorkingPile( 10 + i * 30, 50, canvas() );
+ addCardPile(workingPiles[i]);
+ }
+ faceDownDealingPile = new PatienceFaceDownDeck( 5, 10, canvas() );
+ faceUpDealingPile = new PatienceFaceUpDeck( 35, 10, canvas() );
}
- faceDownDealingPile = new PatienceFaceDownDeck( 5, 10, canvas() );
- faceUpDealingPile = new PatienceFaceUpDeck( 35, 10, canvas() );
}
PatienceCardGame::~PatienceCardGame()
{
delete circleCross;
delete rectangle;
delete faceDownDealingPile;
delete faceUpDealingPile;
}
void PatienceCardGame::deal(void)
{
highestZ = 1;
int t = 0;
beginDealing();
for (int i = 0; i < 7; i++) {
cards[t]->setFace(TRUE);
for (int k = i; k < 7; k++, t++) {
Card *card = cards[t];
workingPiles[k]->addCardToTop(card);
card->setCardPile( workingPiles[k] );
QPoint p = workingPiles[k]->getCardPos( card );
card->setPos( p.x(), p.y(), highestZ );
card->showCard();
highestZ++;
}
}
for ( ; t < 52; t++) {
Card *card = cards[t];
faceDownDealingPile->addCardToTop(card);
card->setCardPile( faceDownDealingPile );
QPoint p = faceDownDealingPile->getCardPos( card );
card->setPos( p.x(), p.y(), highestZ );
card->showCard();
highestZ++;
}
endDealing();
}
void PatienceCardGame::readConfig( Config& cfg )
{
@@ -128,107 +145,113 @@ void PatienceCardGame::readConfig( Config& cfg )
readPile( cfg, discardPiles[k], pile, highestZ );
}
readPile( cfg, faceDownDealingPile, "FaceDownDealingPile", highestZ );
readPile( cfg, faceUpDealingPile, "FaceUpDealingPile", highestZ );
highestZ++;
endDealing();
}
void PatienceCardGame::writeConfig( Config& cfg )
{
cfg.setGroup("GameState");
cfg.writeEntry("numberOfTimesThroughDeck", numberOfTimesThroughDeck);
for ( int i = 0; i < 7; i++ ) {
QString pile;
pile.sprintf( "WorkingPile%i", i );
workingPiles[i]->writeConfig( cfg, pile );
}
for ( int i = 0; i < 4; i++ ) {
QString pile;
pile.sprintf( "DiscardPile%i", i );
discardPiles[i]->writeConfig( cfg, pile );
}
faceDownDealingPile->writeConfig( cfg, "FaceDownDealingPile" );
faceUpDealingPile->writeConfig( cfg, "FaceUpDealingPile" );
}
bool PatienceCardGame::mousePressCard( Card *card, QPoint p )
{
Q_UNUSED(p);
CanvasCard *item = (CanvasCard *)card;
if (item->isFacing() != TRUE) {
// From facedown stack
if ((item->x() == 5) && ((int)item->y() == 10)) {
item->setZ(highestZ);
highestZ++;
// Added Code
faceDownDealingPile->removeCard(item);
faceUpDealingPile->addCardToTop(item);
item->setCardPile( faceUpDealingPile );
- item->flipTo( 35, (int)item->y() );
+ if ( qt_screen->deviceWidth() < 200 )
+ item->flipTo( 30, (int)item->y() );
+ else
+ item->flipTo( 35, (int)item->y() );
}
moving = NULL;
moved = FALSE;
// move two other cards if we flip three at a time
int flipped = 1;
QCanvasItemList l = canvas()->collisions( p );
for (QCanvasItemList::Iterator it = l.begin(); (it != l.end()) && (flipped != cardsDrawn()); ++it) {
if ( (*it)->rtti() == canvasCardId ) {
CanvasCard *item = (CanvasCard *)*it;
if (item->animated())
continue;
item->setZ(highestZ);
highestZ++;
flipped++;
// Added Code
faceDownDealingPile->removeCard(item);
faceUpDealingPile->addCardToTop(item);
item->setCardPile( faceUpDealingPile );
- item->flipTo( 35, (int)item->y(), 8 * flipped );
+ if ( qt_screen->deviceWidth() < 200 )
+ item->flipTo( 30, (int)item->y(), 8 * flipped );
+ else
+ item->flipTo( 35, (int)item->y(), 8 * flipped );
}
}
return TRUE;
}
return FALSE;
}
void PatienceCardGame::mousePress(QPoint p)
{
if ( canTurnOverDeck() &&
(p.x() > 5) && (p.x() < 28) &&
(p.y() > 10) && (p.y() < 46) ) {
beginDealing();
Card *card = faceUpDealingPile->cardOnTop();
while ( card ) {
card->setPos( 5, 10, highestZ );
card->setFace( FALSE );
faceUpDealingPile->removeCard( card );
faceDownDealingPile->addCardToTop( card );
card->setCardPile( faceDownDealingPile );
card = faceUpDealingPile->cardOnTop();
highestZ++;
}
endDealing();
throughDeck();
moved = TRUE;
}
}
diff --git a/noncore/games/solitaire/patiencecardgame.h b/noncore/games/solitaire/patiencecardgame.h
index c4f6c48..0d0e3d5 100644
--- a/noncore/games/solitaire/patiencecardgame.h
+++ b/noncore/games/solitaire/patiencecardgame.h
@@ -1,75 +1,76 @@
/**********************************************************************
** Copyright (C) 2000 Trolltech AS. All rights reserved.
**
** This file is part of Qtopia Environment.
**
** This file may be distributed and/or modified under the terms of the
** GNU General Public License version 2 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.trolltech.com/gpl/ for GPL licensing information.
**
** Contact info@trolltech.com if any conditions of this licensing are
** not clear to you.
**
**********************************************************************/
#ifndef PATIENCE_CARD_GAME_H
#define PATIENCE_CARD_GAME_H
#include <qpopupmenu.h>
#include <qmainwindow.h>
#include <qintdict.h>
#include <qcanvas.h>
+#include <qgfx_qws.h>
// #include "canvascardshapes.h"
// #include "canvascard.h"
#include "canvascardgame.h"
class PatienceFaceDownDeck : public CardPile, public CanvasRoundRect
{
public:
PatienceFaceDownDeck(int x, int y, QCanvas *canvas)
: CardPile(x, y), CanvasRoundRect(x, y, canvas) { }
virtual bool isAllowedOnTop(Card *card) {
Q_UNUSED(card);
// Need to check it is from the faceUpDealingPile
return TRUE;
}
virtual bool isAllowedToBeMoved(Card *card) {
Q_UNUSED(card);
//if ( ( !card->isFacing() ) && ( card == cardOnTop() ) )
if ( card == cardOnTop() )
return TRUE;
return FALSE;
}
};
class PatienceFaceUpDeck : public CardPile, public CanvasRoundRect
{
public:
PatienceFaceUpDeck(int x, int y, QCanvas *canvas)
: CardPile(x, y), CanvasRoundRect(x, y, canvas) { }
virtual bool isAllowedOnTop(Card *card) {
Q_UNUSED(card);
// Need to check it is from the faceDownDealingPile
return TRUE;
}
virtual bool isAllowedToBeMoved(Card *card) {
Q_UNUSED(card);
//if ( ( card->isFacing() ) && ( card == cardOnTop() ) )
if ( card == cardOnTop() )
return TRUE;
return FALSE;
}
};
class PatienceDiscardPile : public CardPile, public CanvasRoundRect
{
public:
@@ -85,112 +86,114 @@ public:
return FALSE;
}
virtual bool isAllowedToBeMoved(Card *card) {
if ( card->isFacing() && ( card == cardOnTop() ) )
return TRUE;
return FALSE;
}
};
class PatienceWorkingPile : public CardPile, public CanvasRoundRect
{
public:
PatienceWorkingPile(int x, int y, QCanvas *canvas)
: CardPile(x, y), CanvasRoundRect(x, y, canvas), top(x, y) { }
virtual bool isAllowedOnTop(Card *card) {
if ( card->isFacing() &&
( ( ( cardOnTop() == NULL ) && (card->getValue() == king) ) ||
( ( cardOnTop() != NULL ) &&
( (int)card->getValue() + 1 == (int)cardOnTop()->getValue() ) &&
( card->isRed() != cardOnTop()->isRed() ) ) ) )
return TRUE;
return FALSE;
}
virtual bool isAllowedToBeMoved(Card *card) {
if ( card->isFacing() )
return TRUE;
return FALSE;
}
virtual void cardAddedToTop(Card *card) {
Q_UNUSED(card);
top = getCardPos(NULL);
setNextX( top.x() );
setNextY( top.y() );
}
virtual void cardRemoved(Card *card) {
Q_UNUSED(card);
Card *newTopCard = cardOnTop();
if ( !newTopCard ) {
top = QPoint( pileX, pileY );
setNextX( pileX );
setNextY( pileY );
return;
} else {
top = getCardPos(NULL);
if ( newTopCard->isFacing() == FALSE ) {
+ int offsetDown = ( qt_screen->deviceWidth() < 200 ) ? 9 : 13;
// correct the position taking in to account the card is not
// yet flipped, but will become flipped
top = QPoint( top.x() - 1, top.y() - 3 );
newTopCard->flipTo( top.x(), top.y() );
- top = QPoint( top.x(), top.y() + 13 );
+ top = QPoint( top.x(), top.y() + offsetDown );
}
setNextX( top.x() );
setNextY( top.y() );
}
}
virtual QPoint getCardPos(Card *c) {
int x = pileX, y = pileY;
Card *card = cardOnBottom();
while ((card != c) && (card != NULL)) {
if (card->isFacing()) {
- y += 13;
+ int offsetDown = ( qt_screen->deviceWidth() < 200 ) ? 9 : 13;
+ y += offsetDown;
} else {
x += 1;
y += 3;
}
card = cardInfront(card);
}
return QPoint( x, y );
}
virtual QPoint getHypertheticalNextCardPos(void) {
return top;
// return QPoint( getNextX(), getNextY() );
}
private:
QPoint top;
};
class PatienceCardGame : public CanvasCardGame
{
public:
PatienceCardGame(QCanvas *c, bool snap, QWidget *parent = 0);
virtual ~PatienceCardGame();
virtual void deal(void);
virtual bool haveWeWon() {
return ( discardPiles[0]->kingOnTop() &&
discardPiles[1]->kingOnTop() &&
discardPiles[2]->kingOnTop() &&
discardPiles[3]->kingOnTop() );;
}
virtual void mousePress(QPoint p);
virtual void mouseRelease(QPoint p) { Q_UNUSED(p); }
// virtual void mouseMove(QPoint p);
virtual bool mousePressCard(Card *card, QPoint p);
virtual void mouseReleaseCard(Card *card, QPoint p) { Q_UNUSED(card); Q_UNUSED(p); }
// virtual void mouseMoveCard(Card *card, QPoint p) { Q_UNUSED(card); Q_UNUSED(p); }
bool canTurnOverDeck(void) { return (numberOfTimesThroughDeck != 3); }
void throughDeck(void) {
numberOfTimesThroughDeck++;
if (numberOfTimesThroughDeck == 3)
circleCross->setCross();
}
bool snapOn;
virtual void writeConfig( Config& cfg );
virtual void readConfig( Config& cfg );
private:
CanvasCircleOrCross *circleCross;
CanvasRoundRect *rectangle;
diff --git a/noncore/games/wordgame/wordgame.cpp b/noncore/games/wordgame/wordgame.cpp
index ca4352d..16d37b3 100644
--- a/noncore/games/wordgame/wordgame.cpp
+++ b/noncore/games/wordgame/wordgame.cpp
@@ -14,148 +14,164 @@
** See http://www.trolltech.com/gpl/ for GPL licensing information.
**
** Contact info@trolltech.com if any conditions of this licensing are
** not clear to you.
**
**********************************************************************/
#include "wordgame.h"
#include <qpe/applnk.h>
#include <qpe/global.h>
#include <qpe/filemanager.h>
#include <qpe/resource.h>
#include <qpe/config.h>
#include <qapplication.h>
#include <qmessagebox.h>
#include <qcombobox.h>
#include <qdatetime.h>
#include <qfileinfo.h>
#include <qfile.h>
#include <qdir.h>
#include <qiconset.h>
#include <qlabel.h>
#include <qlineedit.h>
#include <qpushbutton.h>
#include <qtextstream.h>
#include <qtimer.h>
#include <qpe/qpetoolbar.h>
#include <qtoolbutton.h>
#include <qvbox.h>
#include <qwidgetstack.h>
#include <qpainter.h>
#include <qlayout.h>
#include <qregexp.h>
#include <stdlib.h>
#include <unistd.h>
#include <pwd.h>
#include <sys/types.h>
enum RuleEffects {
Multiplier=15,
MultiplyAll=64,
Start=128
};
+static int tile_smallw = 16;
+static int tile_smallh = 16;
+static int tile_bigw = 22;
+static int tile_bigh = 22;
+static int tile_stweak = -2;
+static int tile_btweak = -1;
+
static const int rack_tiles=7;
const char* sampleWGR=
"wordgame_shapes\n"
"15 15\n"
"400001040100004\n"
"030000000000030\n"
"002002000200200\n"
"000300020003000\n"
"000020000020000\n"
"102001000100201\n"
"000000202000000\n"
"400200050002004\n"
"000000202000000\n"
"102001000100201\n"
"000020000020000\n"
"000300020003000\n"
"002002000200200\n"
"030000000000030\n"
"400001040100004\n"
"1 2 3 66 67 194 100 0\n"
"1 j 8\n"
"1 q 7\n"
"1 x 6\n"
"1 z 6\n"
"1 w 4\n"
"1 k 4\n"
"1 v 3\n"
"1 f 3\n"
"2 y 3\n"
"2 h 2\n"
"2 b 2\n"
"2 m 2\n"
"3 p 2\n"
"3 g 2\n"
"3 u 2\n"
"4 d 2\n"
"4 c 2\n"
"5 l 1\n"
"5 o 1\n"
"7 t 1\n"
"7 n 1\n"
"7 a 1\n"
"7 r 1\n"
"8 s 1\n"
"8 i 1\n"
"11 e 1\n"
"0\n";
WordGame::WordGame( QWidget* parent, const char* name, WFlags fl ) :
QMainWindow(parent, name, fl)
{
+ if ( qApp->desktop()->width() < 240 ) {
+ tile_smallw = 10;
+ tile_smallh = 10;
+ tile_bigw = 16;
+ tile_bigh = 16;
+ tile_stweak = 0;
+ tile_btweak = 0;
+ }
+
setIcon( Resource::loadPixmap( "wordgame" ) );
setCaption( tr("Word Game") );
setToolBarsMovable( FALSE );
vbox = new QVBox(this);
setCentralWidget(vbox);
toolbar = new QPEToolBar(this);
addToolBar(toolbar, Bottom);
reset = new QToolButton(Resource::loadPixmap("back"), tr("Back"), "", this, SLOT(resetTurn()), toolbar);
done = new QToolButton(Resource::loadPixmap("done"), tr("Done"), "", this, SLOT(endTurn()), toolbar);
scoreinfo = new ScoreInfo(toolbar);
scoreinfo->setFont(QFont("Helvetica",10));
new QToolButton(Resource::loadPixmap("finish"), tr("Close"), "", this, SLOT(endGame()), toolbar);
toolbar->setStretchableWidget(scoreinfo);
cpu = 0;
board = 0;
bag = 0;
racks = 0;
aiheart = new QTimer(this);
connect(aiheart, SIGNAL(timeout()), this, SLOT(think()));
readConfig();
}
WordGame::~WordGame()
{
writeConfig();
}
void WordGame::writeConfig()
{
Config cfg("WordGame");
cfg.setGroup("Game");
cfg.writeEntry("NameList",namelist,';');
cfg.writeEntry("CurrentPlayer",gameover ? 0 : player+1);
if ( !gameover ) {
cfg.writeEntry("Rules",rules);
bag->writeConfig(cfg);
board->writeConfig(cfg);
scoreinfo->writeConfig(cfg);
}
for (int p=0; p<nplayers; p++) {
cfg.setGroup("Player"+QString::number(p+1));
if ( gameover ) cfg.clearGroup(); else rack(p)->writeConfig(cfg);
}
@@ -202,146 +218,152 @@ void WordGame::openGameSelector(const QStringList& initnames)
delete racks;
racks = 0;
delete cpu;
cpu = 0;
newgame = new NewGame(vbox);
//Rules rules(this);
//connect(game.editrules, SIGNAL(clicked()), &rules, SLOT(editRules()));
//connect(&rules, SIGNAL(rulesChanged()), &game, SLOT(updateRuleSets()));
struct passwd* n = getpwuid(getuid());
QString playername = n ? n->pw_name : "";
if ( playername.isEmpty() ) {
playername = "Player";
}
newgame->player0->changeItem(playername,0);
newgame->player1->setCurrentItem(1);
newgame->updateRuleSets();
newgame->show();
connect(newgame->buttonOk, SIGNAL(clicked()), this, SLOT(startGame()));
}
void WordGame::startGame()
{
rules = newgame->ruleslist[newgame->rules->currentItem()];
if ( loadRules(rules) ) {
QStringList names;
names.append(newgame->player0->currentText());
names.append(newgame->player1->currentText());
names.append(newgame->player2->currentText());
names.append(newgame->player3->currentText());
names.append(newgame->player4->currentText());
names.append(newgame->player5->currentText());
delete newgame;
startGame(names);
} else {
// error...
delete newgame;
close();
}
}
void WordGame::startGame(const QStringList& playerlist)
{
toolbar->show();
racks = new QWidgetStack(vbox);
+ racks->setFixedHeight(TileItem::bigHeight()+2);
namelist.clear();
nplayers=0;
for (QStringList::ConstIterator it=playerlist.begin(); it!=playerlist.end(); ++it)
addPlayer(*it);
scoreinfo->init(namelist);
if ( nplayers ) {
player=0;
readyRack(player);
}
board->show();
racks->show();
}
bool WordGame::loadRules(const QString &name)
{
QString filename = Global::applicationFileName( "wordgame", name );
QFile file( filename );
if ( !file.open( IO_ReadOnly ) )
return FALSE;
QTextStream ts( &file );
QString title = name;
title.truncate( title.length() - 6 );
setCaption( title );
QString shapepixmap;
ts >> shapepixmap;
int htiles,vtiles;
ts >> htiles >> vtiles;
if ( htiles < 3 || vtiles < 3 )
return FALSE;
- QPixmap bgshapes = Resource::loadPixmap(shapepixmap);
QString rule_shapes;
for (int i=0; i<vtiles; i++) {
QString line;
ts >> line;
rule_shapes += line;
}
static int rule_effects[12];
int re=0,e;
ts >> e;
while ( e && re < 10 ) {
rule_effects[re] = e;
if ( re++ < 10 ) ts >> e;
}
+
+ QImage shim = Resource::loadImage(shapepixmap);
+ shim = shim.smoothScale((re-1)*TileItem::smallWidth(),TileItem::smallHeight());
+ QPixmap bgshapes;
+ bgshapes.convertFromImage(shim);
+
rule_effects[re++] = 100; // default bonus
board = new Board(bgshapes, htiles, vtiles, vbox);
board->setRules(rule_shapes, rule_effects);
connect(board, SIGNAL(temporaryScore(int)), scoreinfo, SLOT(showTemporaryScore(int)));
bag = new Bag;
int count;
ts >> count;
while ( count ) {
QString text;
int value;
ts >> text >> value;
if ( text == "_" )
text = "";
Tile t(text, value);
for (int n=count; n--; )
bag->add(t);
ts >> count;
}
return TRUE;
}
NewGame::NewGame(QWidget* parent) :
NewGameBase(parent)
{
}
void NewGame::updateRuleSets()
{
rules->clear();
QString rulesDir = Global::applicationFileName( "wordgame", "" );
QDir dir( rulesDir, "*.rules" );
ruleslist = dir.entryList();
if ( ruleslist.isEmpty() ) {
// Provide a sample
QFile file( rulesDir + "Sample.rules" );
if ( file.open( IO_WriteOnly ) ) {
file.writeBlock( sampleWGR, strlen(sampleWGR) );
file.close();
updateRuleSets();
}
return;
@@ -636,179 +658,195 @@ void ComputerPlayer::findBest(QPoint at, const QPoint& d, const QDawg::Node* nod
if ( nextok )
findBest(at+d, d, node->jump(), used, nletter, tiles, n, blankvalues, blused);
n--;
nletter[t->text()[0].unicode()]++;
if ( t->isBlank() ) {
// keep looking
blused--;
used &= ~msk; // unmark
} else {
break;
}
}
}
msk <<= 1;
}
}
// #### text()[1]...
}
findBest(at, d, node->next(), used, nletter, tiles, n, blankvalues, blused);
}
void ComputerPlayer::noteChoice(const Tile** tiles, int n, const QPoint& d, const Tile* blankvalues, int blused)
{
int s = board->score(current, tiles, n, blankvalues, d, TRUE, 0);
/*
if (s>0 || current==QPoint(5,1)){
QString st;
for ( int i=0; i<n; i++ )
st += tiles[i]->text();
qDebug("%d,%d: %s (%d) for %d",current.x(),current.y(),st.latin1(),n,s);
}
*/
if ( s > best_score ) {
int i;
for ( i=0; i<n; i++ )
best[i] = tiles[i];
for ( i=0; i<blused; i++ )
best_blankvalues[i] = blankvalues[i];
best_n = n;
best_blused = blused;
best_score = s;
best_dir = d;
best_start = current;
}
}
int TileItem::smallWidth()
{
- return 16;
+ return tile_smallw;
}
int TileItem::smallHeight()
{
- return 16;
+ return tile_smallh;
}
int TileItem::bigWidth()
{
- return 22;
+ return tile_bigw;
}
int TileItem::bigHeight()
{
- return 22;
+ return tile_bigh;
}
void TileItem::setState( State state )
{
hide();
s = state;
show(); // ### use update() in Qt 3.0
}
void TileItem::setTile(const Tile& tile)
{
hide();
t = tile;
show(); // ### use update() in Qt 3.0
}
void TileItem::setBig(bool b)
{
big = b;
}
void TileItem::drawShape(QPainter& p)
{
- static QFont value_font("heletica",8);
- static QFont big_font("smoothtimes",17);
- static QFont small_font("smoothtimes",10);
+ static QFont *value_font=0;
+ static QFont *big_font=0;
+ static QFont *small_font=0;
+ if ( !value_font ) {
+ value_font = new QFont("helvetica",8);
+ if ( TileItem::bigWidth() < 20 ) {
+ big_font = new QFont("helvetica",12);
+ small_font = new QFont("helvetica",8);
+ } else {
+ big_font = new QFont("smoothtimes",17);
+ small_font = new QFont("smoothtimes",10);
+ }
+ }
QRect area(x(),y(),width(),height());
p.setBrush(s == Floating ? yellow/*lightGray*/ : white);
p.drawRect(area);
if ( big ) {
- p.setFont(value_font);
+ p.setFont(*value_font);
QString n = QString::number(t.value());
int w = p.fontMetrics().width('1');
int h = p.fontMetrics().height();
w *= n.length();
- QRect valuearea(x()+width()-w-2,y()+height()-h+1,w,h);
+ QRect valuearea(x()+width()-w-1,y()+height()-h,w,h);
p.drawText(valuearea,AlignCenter,n);
- p.setFont(big_font);
- area = QRect(x(),y(),width()-2,height()-1);
+ p.setFont(*big_font);
+ area = QRect(x(),y()+tile_btweak,width()-4,height()-1);
} else {
- p.setFont(small_font);
- area = QRect(x(),y()+2,width(),height()-2);
+ p.setFont(*small_font);
+ area = QRect(x()+1+tile_stweak,y()+1,width(),height()-3);
}
if ( t.value() == 0 )
p.setPen(darkGray);
p.drawText(area,AlignCenter,t.text().upper());
}
Board::Board(QPixmap bgshapes, int w, int h, QWidget* parent) :
QCanvasView(new QCanvas(bgshapes,w,h, TileItem::smallWidth(), TileItem::smallHeight()),
parent)
{
+ setFixedSize(w*TileItem::smallWidth(),h*TileItem::smallHeight());
grid = new TileItem*[w*h];
memset(grid,0,w*h*sizeof(TileItem*));
setFrameStyle(0);
setHScrollBarMode(AlwaysOff);
setVScrollBarMode(AlwaysOff);
current_rack = 0;
shown_n = 0;
}
Board::~Board()
{
delete canvas();
}
+QSize Board::sizeHint() const
+{
+ return QSize(canvas()->width(),canvas()->height());
+}
+
void Board::writeConfig(Config& cfg)
{
QStringList t;
int n=canvas()->tilesHorizontally()*canvas()->tilesVertically();
for (int i=0; i<n; i++)
t.append( grid[i] ? grid[i]->tile().key() : QString(".") );
cfg.writeEntry("Board",t,';');
}
void Board::readConfig(Config& cfg)
{
clear();
QStringList t = cfg.readListEntry("Board",';');
int i=0;
int h=canvas()->tilesHorizontally();
for (QStringList::ConstIterator it=t.begin(); it!=t.end(); ++it) {
if ( *it != "." ) {
QPoint p(i%h,i/h);
setTile(p,Tile(*it));
}
i++;
}
canvas()->update();
}
void Board::clear()
{
int n=canvas()->tilesHorizontally()*canvas()->tilesVertically();
for (int i=0; i<n; i++) {
delete grid[i];
grid[i]=0;
}
}
void Board::setCurrentRack(Rack* r)
{
turn_score = -1;
current_rack = r;
}
void Board::resetRack()
{
unshowTurn();
canvas()->update();
}
void Board::contentsMousePressEvent(QMouseEvent* e)
@@ -1136,96 +1174,101 @@ void Board::setRules(const QString& shapes, const int* effects)
int re = shapes[i++]-'0';
if ( re > maxre ) maxre = re;
canvas()->setTile(x,y,re);
}
}
rack_tiles_bonus=effects[maxre+1];
}
void Board::unsetTile(const QPoint& p)
{
delete item(p);
grid[idx(p)] = 0;
}
void Board::setTile(const QPoint& p, const Tile& t)
{
TileItem* it=item(p);
if ( !it ) {
it = grid[idx(p)] = new TileItem(t,FALSE,canvas());
it->move(p.x()*canvas()->tileWidth(), p.y()*canvas()->tileHeight());
it->show();
} else {
it->setTile(t);
}
}
Rack::Rack(int ntiles, QWidget* parent) : QCanvasView(
new QCanvas(ntiles*TileItem::bigWidth(),TileItem::bigHeight()),
parent),
item(ntiles)
{
setLineWidth(1);
setFixedHeight(sizeHint().height());
n = 0;
for (int i=0; i<ntiles; i++)
item[i]=0;
setHScrollBarMode(AlwaysOff);
setVScrollBarMode(AlwaysOff);
canvas()->setBackgroundColor(gray);
dragging = 0;
}
Rack::~Rack()
{
clear();
delete canvas();
}
+QSize Rack::sizeHint() const
+{
+ return QSize(-1,TileItem::bigHeight()+2);
+}
+
void Rack::clear()
{
for (int i=0; i<n; i++)
delete item[i];
n=0;
}
void Rack::writeConfig(Config& cfg)
{
QStringList l;
for (int i=0; i<n; i++)
l.append(tile(i).key());
cfg.writeEntry("Tiles",l,';');
}
void Rack::readConfig(Config& cfg)
{
clear();
int x=0;
QStringList l = cfg.readListEntry("Tiles",';');
for (QStringList::ConstIterator it=l.begin(); it!=l.end(); ++it) {
TileItem *i = new TileItem(Tile(*it),TRUE,canvas());
i->move(x++,0);
i->show();
item[n++] = i;
}
layoutTiles();
}
static int cmp_tileitem(const void *a, const void *b)
{
const TileItem* ia = *(TileItem**)a;
const TileItem* ib = *(TileItem**)b;
return int(ia->x() - ib->x());
}
void Rack::layoutTiles()
{
int w = TileItem::bigWidth()+2;
if ( dragging ) dragging->moveBy(dragging_adj,0);
qsort(item.data(), n, sizeof(TileItem*), cmp_tileitem);
if ( dragging ) dragging->moveBy(-dragging_adj,0);
for (int i=0; i<n ;i++)
if ( item[i] == dragging ) {
item[i]->setZ(1);
} else {
diff --git a/noncore/games/wordgame/wordgame.h b/noncore/games/wordgame/wordgame.h
index 0ffa56a..f73c85a 100644
--- a/noncore/games/wordgame/wordgame.h
+++ b/noncore/games/wordgame/wordgame.h
@@ -103,159 +103,163 @@ public:
{
}
static int smallWidth();
static int smallHeight();
static int bigWidth();
static int bigHeight();
enum State { Firm, Floating };
void setState( State state );
State state() const { return s; }
const Tile& tile() const { return t; }
void setTile(const Tile&);
void setBig(bool);
protected:
void drawShape(QPainter&);
private:
Tile t;
bool big;
State s;
};
class Rack : public QCanvasView {
public:
Rack(int ntiles, QWidget* parent);
~Rack();
void readConfig(Config&);
void writeConfig(Config&);
bool isFull() const { return count()==max(); }
int max() const { return item.count(); }
int count() const { return n; }
void addTile(const Tile& t);
Tile tile(int i) const { return item[i]->tile(); }
const Tile* tileRef(int i) const { return &item[i]->tile(); }
void remove(int i);
void remove(Tile);
bool arrangeTiles(const Tile** s, int sn);
void setBlanks(const Tile*);
void setPlayerName(const QString& name) { nm = name; }
QString playerName() const { return nm; }
void setComputerization(int level) { cpu=level; }
bool computerized() const { return cpu>0; }
+ QSize sizeHint() const;
+
protected:
void resizeEvent(QResizeEvent*e);
void contentsMousePressEvent(QMouseEvent*);
void contentsMouseMoveEvent(QMouseEvent*);
void contentsMouseReleaseEvent(QMouseEvent*);
private:
void clear();
void layoutTiles();
int n;
QArray<TileItem*> item;
int dragging_adj;
QPoint dragstart;
QCanvasItem* dragging;
QString nm;
int cpu;
};
class Board : public QCanvasView {
Q_OBJECT
public:
Board(QPixmap bgshapes, int w, int h, QWidget* parent);
~Board();
void readConfig(Config&);
void writeConfig(Config&);
int xTiles() const { return canvas()->tilesHorizontally(); }
int yTiles() const { return canvas()->tilesVertically(); }
bool contains(const QPoint& p) const
{ return p.x() >= 0 && p.y() >= 0
&& p.x() < canvas()->tilesHorizontally()
&& p.y() < canvas()->tilesVertically(); }
const Tile* tile(const QPoint& p) const
{ TileItem* it=item(p); return it ? &it->tile() : 0; }
void setRules(const QString& shapes, const int* effects);
void clear();
void unsetTile(const QPoint& p);
void setTile(const QPoint& p, const Tile& t);
void setTileState(const QPoint& p, TileItem::State s)
{
TileItem* it=item(p);
if (it) it->setState(s);
}
void setCurrentRack(Rack*);
void resetRack();
void finalizeTurn();
void showTurn();
void scoreTurn(const QPoint& at, int n, const QPoint& d);
bool checkTurn();
int score(QPoint at, const Tile** tiles, int n,
const Tile* blankvalue,
const QPoint& d, bool ignoredict, QStringList* words) const;
int bonussedValue(const QPoint& at, int base, int& all_mult) const;
bool isStart(const QPoint& at) const;
int turnScore() const { return turn_score; }
+ QSize sizeHint() const;
+
signals:
void temporaryScore(int);
protected:
void contentsMousePressEvent(QMouseEvent*);
void contentsMouseMoveEvent(QMouseEvent*);
void contentsMouseReleaseEvent(QMouseEvent*);
private:
int idx(const QPoint& p) const
{ return p.x()+p.y()*canvas()->tilesHorizontally(); }
TileItem*& item(const QPoint& p) const
{ return grid[idx(p)]; }
TileItem **grid;
QString rule_shape;
const int* rule_effect;
int rack_tiles_bonus;
Rack* current_rack;
QPoint boardPos(const QPoint&) const;
QPoint dragstart;
QPoint shown_at;
int shown_n;
QPoint shown_step;
void unshowTurn();
int turn_score;
};
class ComputerPlayer
{
Board* board;
Rack* rack;
bool across;
int dict;
QPoint current;
const Tile** best;
int best_n;
Tile* best_blankvalues;
int best_blused;
int best_score;
QPoint best_dir;
QPoint best_start;
public:
ComputerPlayer(Board* b, Rack* r);
~ComputerPlayer();
@@ -286,91 +290,91 @@ protected:
public slots:
void showTemporaryScore(int amount);
private slots:
void showScores();
private:
QStringList names;
int *score;
QTimer* msgtimer;
bool showwinner;
int boldone;
};
class NewGame;
class WordGame : public QMainWindow {
Q_OBJECT
public:
WordGame( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 );
~WordGame();
private slots:
void endTurn();
void resetTurn();
void passTurn();
void think();
void endGame();
void startGame();
private:
void writeConfig();
void readConfig();
void startGame(const QStringList& pnames);
bool mayEndGame();
void openGameSelector(const QStringList& initnames);
bool loadRules(const QString& filename);
void addPlayer(const QString& name);
void addPlayer(const QString& name, int cpu);
void nextPlayer();
bool refillRack(int i);
void readyRack(int i);
Rack* rack(int i) const;
QWidgetStack *racks;
QToolBar* toolbar;
- QVBox *vbox;
+ QWidget *vbox;
Board *board;
Bag *bag;
ScoreInfo *scoreinfo;
QToolButton *done;
QToolButton *reset;
QTimer* aiheart;
ComputerPlayer *cpu;
int player;
int nplayers;
QStringList namelist;
bool gameover;
QString rules;
NewGame* newgame;
};
class NewGame : public NewGameBase {
Q_OBJECT
public:
NewGame(QWidget* parent);
QStringList ruleslist;
public slots:
void updateRuleSets();
};
class Rules : public RulesBase {
Q_OBJECT
public:
Rules(QWidget* parent);
signals:
void rulesChanged();
public slots:
void editRules();
private:
void deleteRuleSet();
};
#endif // WORDGAME_H
diff --git a/noncore/multimedia/showimg/settingsdialog.cpp b/noncore/multimedia/showimg/settingsdialog.cpp
deleted file mode 100644
index d21f4cb..0000000
--- a/noncore/multimedia/showimg/settingsdialog.cpp
+++ b/dev/null
@@ -1,57 +0,0 @@
-/**********************************************************************
-** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
-**
-** This file is part of the Qtopia Environment.
-**
-** This file may be distributed and/or modified under the terms of the
-** GNU General Public License version 2 as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL included in the
-** packaging of this file.
-**
-** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
-** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
-**
-** See http://www.trolltech.com/gpl/ for GPL licensing information.
-**
-** Contact info@trolltech.com if any conditions of this licensing are
-** not clear to you.
-**
-**********************************************************************/
-
-#include "settingsdialog.h"
-#include <qslider.h>
-#include <qlabel.h>
-#include <qcheckbox.h>
-
-SettingsDialog::SettingsDialog( QWidget *parent, const char *name, bool modal, WFlags f )
- : SettingsDialogBase( parent, name, modal, f )
-{
- connect( delaySlider, SIGNAL(valueChanged(int)), this, SLOT(delayChanged(int)) );
-}
-
-void SettingsDialog::setDelay( int d )
-{
- delaySlider->setValue( d );
- delayChanged( d );
-}
-
-int SettingsDialog::delay() const
-{
- return delaySlider->value();
-}
-
-void SettingsDialog::setRepeat( bool r )
-{
- repeatCheck->setChecked( r );
-}
-
-bool SettingsDialog::repeat() const
-{
- return repeatCheck->isChecked();
-}
-
-void SettingsDialog::delayChanged( int d )
-{
- delayText->setText( QString::number( d ) + " s" );
-}
-
diff --git a/noncore/multimedia/showimg/settingsdialog.h b/noncore/multimedia/showimg/settingsdialog.h
deleted file mode 100644
index 6dfd2c4..0000000
--- a/noncore/multimedia/showimg/settingsdialog.h
+++ b/dev/null
@@ -1,42 +0,0 @@
-/**********************************************************************
-** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
-**
-** This file is part of the Qtopia Environment.
-**
-** This file may be distributed and/or modified under the terms of the
-** GNU General Public License version 2 as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL included in the
-** packaging of this file.
-**
-** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
-** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
-**
-** See http://www.trolltech.com/gpl/ for GPL licensing information.
-**
-** Contact info@trolltech.com if any conditions of this licensing are
-** not clear to you.
-**
-**********************************************************************/
-
-#ifndef SETTINGSDIALOG_H
-#define SETTINGSDIALOG_H
-
-#include "settingsdialogbase.h"
-
-class SettingsDialog : public SettingsDialogBase
-{
- Q_OBJECT
-public:
- SettingsDialog( QWidget * parent=0, const char * name=0, bool modal=FALSE, WFlags f=0 );
-
- void setDelay( int d );
- int delay() const;
- void setRepeat( bool r );
- bool repeat() const;
-
-private slots:
- void delayChanged( int );
-};
-
-
-#endif
diff --git a/noncore/multimedia/showimg/settingsdialogbase.ui b/noncore/multimedia/showimg/settingsdialogbase.ui
deleted file mode 100644
index ed404d8..0000000
--- a/noncore/multimedia/showimg/settingsdialogbase.ui
+++ b/dev/null
@@ -1,149 +0,0 @@
-<!DOCTYPE UI><UI>
-<class>SettingsDialogBase</class>
-<widget>
- <class>QDialog</class>
- <property stdset="1">
- <name>name</name>
- <cstring>SettingsDialogBase</cstring>
- </property>
- <property stdset="1">
- <name>geometry</name>
- <rect>
- <x>0</x>
- <y>0</y>
- <width>227</width>
- <height>258</height>
- </rect>
- </property>
- <property stdset="1">
- <name>caption</name>
- <string>Preferences</string>
- </property>
- <vbox>
- <property stdset="1">
- <name>margin</name>
- <number>11</number>
- </property>
- <property stdset="1">
- <name>spacing</name>
- <number>6</number>
- </property>
- <widget>
- <class>QGroupBox</class>
- <property stdset="1">
- <name>name</name>
- <cstring>GroupBox1</cstring>
- </property>
- <property stdset="1">
- <name>title</name>
- <string>Slide Show</string>
- </property>
- <vbox>
- <property stdset="1">
- <name>margin</name>
- <number>11</number>
- </property>
- <property stdset="1">
- <name>spacing</name>
- <number>6</number>
- </property>
- <widget>
- <class>QCheckBox</class>
- <property stdset="1">
- <name>name</name>
- <cstring>repeatCheck</cstring>
- </property>
- <property stdset="1">
- <name>text</name>
- <string>Repeat</string>
- </property>
- </widget>
- <widget>
- <class>QLayoutWidget</class>
- <property stdset="1">
- <name>name</name>
- <cstring>Layout1</cstring>
- </property>
- <hbox>
- <property stdset="1">
- <name>margin</name>
- <number>0</number>
- </property>
- <property stdset="1">
- <name>spacing</name>
- <number>6</number>
- </property>
- <widget>
- <class>QLabel</class>
- <property stdset="1">
- <name>name</name>
- <cstring>TextLabel1</cstring>
- </property>
- <property stdset="1">
- <name>text</name>
- <string>Delay</string>
- </property>
- </widget>
- <widget>
- <class>QSlider</class>
- <property stdset="1">
- <name>name</name>
- <cstring>delaySlider</cstring>
- </property>
- <property stdset="1">
- <name>minValue</name>
- <number>5</number>
- </property>
- <property stdset="1">
- <name>maxValue</name>
- <number>60</number>
- </property>
- <property stdset="1">
- <name>lineStep</name>
- <number>5</number>
- </property>
- <property stdset="1">
- <name>orientation</name>
- <enum>Horizontal</enum>
- </property>
- <property stdset="1">
- <name>tickmarks</name>
- <enum>Right</enum>
- </property>
- <property stdset="1">
- <name>tickInterval</name>
- <number>10</number>
- </property>
- </widget>
- <widget>
- <class>QLabel</class>
- <property stdset="1">
- <name>name</name>
- <cstring>delayText</cstring>
- </property>
- <property stdset="1">
- <name>minimumSize</name>
- <size>
- <width>25</width>
- <height>0</height>
- </size>
- </property>
- <property stdset="1">
- <name>text</name>
- <string>s</string>
- </property>
- <property stdset="1">
- <name>alignment</name>
- <set>AlignVCenter|AlignRight</set>
- </property>
- <property>
- <name>hAlign</name>
- </property>
- </widget>
- </hbox>
- </widget>
- </vbox>
- </widget>
- </vbox>
-</widget>
-</UI>