Diffstat (limited to 'noncore/games/fifteen/fifteen.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/games/fifteen/fifteen.cpp | 16 |
1 files changed, 4 insertions, 12 deletions
diff --git a/noncore/games/fifteen/fifteen.cpp b/noncore/games/fifteen/fifteen.cpp index bb57ee1..c41c0a4 100644 --- a/noncore/games/fifteen/fifteen.cpp +++ b/noncore/games/fifteen/fifteen.cpp @@ -1,183 +1,175 @@ /********************************************************************** ** 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 "fifteen.h" #include "fifteenconfigdialog.h" #include <opie2/ofileselector.h> +#include <opie2/oresource.h> -#include <qtopia/resource.h> #include <qtopia/config.h> #include <qtopia/qpeapplication.h> #include <qvbox.h> #include <qaction.h> #include <qpainter.h> #include <qmessagebox.h> #include <qtoolbar.h> #include <qmenubar.h> #include <qimage.h> #include <stdlib.h> #include <time.h> FifteenMainWindow::FifteenMainWindow(QWidget *parent, const char* name, WFlags fl) : QMainWindow( parent, name, fl ) { // random seed srand(time(0)); setCaption( tr("Fifteen Pieces") ); QToolBar *toolbar = new QToolBar(this); toolbar->setHorizontalStretchable( FALSE ); QMenuBar *menubar = new QMenuBar( toolbar ); menubar->setMargin(0); QPopupMenu *game = new QPopupMenu( this ); + menubar->insertItem( tr( "Game" ), game ); QWidget *spacer = new QWidget( toolbar ); spacer->setBackgroundMode( PaletteButton ); toolbar->setStretchableWidget( spacer ); setToolBarsMovable( FALSE ); QVBox *vbox = new QVBox( this ); PiecesTable *table = new PiecesTable( vbox ); setCentralWidget(vbox); - QAction *a = new QAction( tr( "Randomize" ), Resource::loadPixmap( "new" ), + QAction *a = new QAction( tr( "Randomize" ), Opie::Core::OResource::loadPixmap( "new", Opie::Core::OResource::SmallIcon ), QString::null, 0, this, 0 ); connect( a, SIGNAL( activated() ), table, SLOT( slotRandomize() ) ); a->addTo( game ); a->addTo( toolbar ); - a = new QAction( tr("Configure"), Resource::loadPixmap( "SettingsIcon" ), + a = new QAction( tr("Configure"), Opie::Core::OResource::loadPixmap( "SettingsIcon", Opie::Core::OResource::SmallIcon ), QString::null, 0, this, 0 ); connect( a, SIGNAL( activated()), table, SLOT( slotConfigure()) ); a->addTo( game ); - - /* This is pointless and confusing. - a = new QAction( tr( "Solve" ), Resource::loadIconSet( "repeat" ), - QString::null, 0, this, 0 ); - connect( a, SIGNAL( activated() ), table, SLOT( slotReset() ) ); - a->addTo( game ); - a->addTo( toolbar ); - */ - menubar->insertItem( tr( "Game" ), game ); } /////////////// /////// Pieces table Implementation /////// PiecesTable::PiecesTable(QWidget* parent, const char* name ) : QTableView(parent, name), _menu(0), _randomized(false), _dialog( 0l ) { // setup table view setFrameStyle(StyledPanel | Sunken); setBackgroundMode(NoBackground); setMouseTracking(true); setNumRows(4); setNumCols(4); // init arrays readConfig(); initColors(); } PiecesTable::~PiecesTable() { writeConfig(); clear(); } void PiecesTable::writeConfig() { Config cfg("Fifteen"); cfg.setGroup("Game"); QStringList map; int items = numRows()*numCols(); for (int i = 0; i < items; i++) map.append( QString::number( _map[i] ) ); cfg.writeEntry("Map", map, '-'); cfg.writeEntry("Randomized", _randomized ); cfg.writeEntry("Image", _image ); cfg.writeEntry("Rows", numRows() ); cfg.writeEntry("Cols", numCols() ); } void PiecesTable::readConfig() { Config cfg("Fifteen"); cfg.setGroup("Game"); QStringList map = cfg.readListEntry("Map", '-'); _randomized = cfg.readBoolEntry( "Randomized", FALSE ); _image = cfg.readEntry( "Image", QString::null ); int rows = cfg.readNumEntry( "Rows", 4 ); int cols = cfg.readNumEntry( "Cols", 4 ); uint items= rows*cols; setNumRows( rows ); setNumCols( cols ); initMap(); /* if we've more items than 'stones' don't restore the state */ if ( items > map.count() ) return; uint i = 0; for ( QStringList::Iterator it = map.begin(); it != map.end(); ++it ) { _map[i] = (*it).toInt(); i++; if ( i > items ) break; } } void PiecesTable::clear() { /* clean up and resize */ for (uint i = 0; i < _pixmap.count(); ++i ) delete _pixmap[i]; _pixmap.resize( numRows()*numCols() ); } /* * Let us pre-render the tiles. Either we've a Custom Image as * background or we use the drawRect to fill the background and * last we put the number on it */ void PiecesTable::slotCustomImage( const QString& _str ) { QString str = _str; |