author | zecke <zecke> | 2004-02-06 10:33:09 (UTC) |
---|---|---|
committer | zecke <zecke> | 2004-02-06 10:33:09 (UTC) |
commit | 46ce5afcfbe7be19f4d5ac0fed6886a0759f1a25 (patch) (side-by-side diff) | |
tree | ab868f654bd296d693b74c43e166a8403aa9ede4 /noncore | |
parent | 5b2b3a4147742e7053539d3c58a2a552eb830815 (diff) | |
download | opie-46ce5afcfbe7be19f4d5ac0fed6886a0759f1a25.zip opie-46ce5afcfbe7be19f4d5ac0fed6886a0759f1a25.tar.gz opie-46ce5afcfbe7be19f4d5ac0fed6886a0759f1a25.tar.bz2 |
Update from Qtopia1.7 (borders on the items)
make it quicklaunchable
-rw-r--r-- | noncore/games/fifteen/fifteen.cpp | 83 | ||||
-rw-r--r-- | noncore/games/fifteen/fifteen.h | 12 | ||||
-rw-r--r-- | noncore/games/fifteen/fifteen.pro | 4 | ||||
-rw-r--r-- | noncore/games/fifteen/main.cpp | 20 |
4 files changed, 70 insertions, 49 deletions
diff --git a/noncore/games/fifteen/fifteen.cpp b/noncore/games/fifteen/fifteen.cpp index 2e4ed94..b4e0308 100644 --- a/noncore/games/fifteen/fifteen.cpp +++ b/noncore/games/fifteen/fifteen.cpp @@ -1,12 +1,12 @@ /********************************************************************** -** Copyright (C) 2000 Trolltech AS. All rights reserved. +** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. ** -** This file is part of Qtopia Environment. +** 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. @@ -15,69 +15,72 @@ ** ** Contact info@trolltech.com if any conditions of this licensing are ** not clear to you. ** **********************************************************************/ #include "fifteen.h" -#include <qpe/resource.h> -#include <qpe/config.h> +#include <qtopia/resource.h> +#include <qtopia/config.h> #include <qvbox.h> #include <qaction.h> #include <qlayout.h> #include <qpainter.h> #include <qpopupmenu.h> #include <qmessagebox.h> -#include <qpe/qpetoolbar.h> +#include <qtoolbar.h> #include <qmenubar.h> #include <qstringlist.h> #include <qapplication.h> +#include <qtoolbutton.h> #include <stdlib.h> #include <time.h> -FifteenMainWindow::FifteenMainWindow(QWidget *parent, const char* name) - : QMainWindow( parent, name ) +FifteenMainWindow::FifteenMainWindow(QWidget *parent, const char* name, WFlags fl) + : QMainWindow( parent, name, fl ) { // random seed srand(time(0)); - - setToolBarsMovable( FALSE ); - QVBox *vbox = new QVBox( this ); - PiecesTable *table = new PiecesTable( vbox ); - setCentralWidget(vbox); + setCaption( tr("Fifteen Pieces") ); QToolBar *toolbar = new QToolBar(this); - toolbar->setHorizontalStretchable( TRUE ); - addToolBar(toolbar); - + toolbar->setHorizontalStretchable( FALSE ); QMenuBar *menubar = new QMenuBar( toolbar ); menubar->setMargin(0); - QPopupMenu *game = new QPopupMenu( this ); 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" ), QString::null, 0, this, 0 ); connect( a, SIGNAL( activated() ), table, SLOT( slotRandomize() ) ); a->addTo( game ); a->addTo( toolbar ); - a = new QAction( tr( "Solve" ), Resource::loadPixmap( "repeat" ), + /* 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 ); } PiecesTable::PiecesTable(QWidget* parent, const char* name ) : QTableView(parent, name), _menu(0), _randomized(false) { // setup table view setFrameStyle(StyledPanel | Sunken); @@ -104,29 +107,29 @@ PiecesTable::~PiecesTable() writeConfig(); } void PiecesTable::writeConfig() { Config cfg("Fifteen"); cfg.setGroup("Game"); QStringList map; - for (unsigned int i = 0; i < 16; i++) + for (int i = 0; i < 16; i++) map.append( QString::number( _map[i] ) ); cfg.writeEntry("Map", map, '-'); cfg.writeEntry("Randomized", _randomized ); } void PiecesTable::readConfig() { Config cfg("Fifteen"); cfg.setGroup("Game"); QStringList map = cfg.readListEntry("Map", '-'); _randomized = cfg.readBoolEntry( "Randomized", FALSE ); - unsigned int i = 0; + int i = 0; for ( QStringList::Iterator it = map.begin(); it != map.end(); ++it ) { _map[i] = (*it).toInt(); i++; if ( i > 15 ) break; } } void PiecesTable::paintCell(QPainter *p, int row, int col) @@ -141,52 +144,76 @@ void PiecesTable::paintCell(QPainter *p, int row, int col) // draw cell background if(number == 16) p->setBrush(colorGroup().background()); else p->setBrush(_colors[number-1]); p->setPen(NoPen); p->drawRect(0, 0, w, h); + if (number == 16) return; + // draw borders if (height() > 40) { - p->setPen(colorGroup().text()); - if(col < numCols()-1) - p->drawLine(x2, 0, x2, y2); // right border line + p->setBrush(_colors[number-1].light(130)); + p->drawPolygon(light_border); - if(row < numRows()-1) - p->drawLine(0, y2, x2, y2); // bottom boder line + p->setBrush(_colors[number-1].dark(130)); + p->drawPolygon(dark_border); } // draw number - if (number == 16) return; p->setPen(black); p->drawText(0, 0, x2, y2, AlignHCenter | AlignVCenter, QString::number(number)); } void PiecesTable::resizeEvent(QResizeEvent *e) { QTableView::resizeEvent(e); setCellWidth(contentsRect().width()/ numRows()); setCellHeight(contentsRect().height() / numCols()); + + // + // Calculate 3d-effect borders + // + int cell_w = cellWidth(); + int cell_h = cellHeight(); + int x_offset = cell_w - int(cell_w * 0.9); // 10% should be enough + int y_offset = cell_h - int(cell_h * 0.9); + + light_border.setPoints(6, + 0, 0, + cell_w, 0, + cell_w - x_offset, y_offset, + x_offset, y_offset, + x_offset, cell_h - y_offset, + 0, cell_h); + + dark_border.setPoints(6, + cell_w, 0, + cell_w, cell_h, + 0, cell_h, + x_offset, cell_h - y_offset, + cell_w - x_offset, cell_h - y_offset, + cell_w - x_offset, y_offset); } void PiecesTable::initColors() { _colors.resize(numRows() * numCols()); for (int r = 0; r < numRows(); r++) for (int c = 0; c < numCols(); c++) _colors[c + r *numCols()] = QColor(255 - 70 * c,255 - 70 * r, 150); } void PiecesTable::initMap() { _map.resize(16); - for (unsigned int i = 0; i < 16; i++) + for ( int i = 0; i < 16; i++) _map[i] = i; _randomized = false; } void PiecesTable::randomizeMap() { initMap(); @@ -236,18 +263,18 @@ void PiecesTable::randomizeMap() else if (row > frow) { for(int r = frow; r < row; r++) { _map[col + r * numCols()] = _map[ col + (r+1) *numCols()]; } } } // move free cell to click position _map[pos=(col + row * numCols())] = 15; - repaint(); } + repaint(); } void PiecesTable::checkwin() { if(!_randomized) return; int i; for (i = 0; i < 16; i++) diff --git a/noncore/games/fifteen/fifteen.h b/noncore/games/fifteen/fifteen.h index 703a8a7..58eb756 100644 --- a/noncore/games/fifteen/fifteen.h +++ b/noncore/games/fifteen/fifteen.h @@ -1,12 +1,12 @@ /********************************************************************** -** Copyright (C) 2000 Trolltech AS. All rights reserved. +** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. ** -** This file is part of Qtopia Environment. +** 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. @@ -19,16 +19,17 @@ **********************************************************************/ #ifndef __fifteenapplet_h__ #define __fifteenapplet_h__ #include <qmainwindow.h> #include <qtableview.h> #include <qarray.h> +#include <qpointarray.h> class QPopupMenu; class PiecesTable : public QTableView { Q_OBJECT public: @@ -52,16 +53,18 @@ class PiecesTable : public QTableView void readConfig(); void writeConfig(); private: QArray<int> _map; QArray<QColor> _colors; QPopupMenu *_menu; bool _randomized; + QPointArray light_border; + QPointArray dark_border; enum MenuOp { mRandomize = 1, mReset = 2 }; }; class FifteenWidget : public QWidget { Q_OBJECT @@ -72,12 +75,15 @@ private: PiecesTable *_table; }; class FifteenMainWindow : public QMainWindow { Q_OBJECT public: - FifteenMainWindow(QWidget *parent=0, const char* name=0); + static QString appName() { + return QString::fromLatin1("fifteen"); + } + FifteenMainWindow(QWidget *parent=0, const char* name=0, WFlags fl=0); }; #endif diff --git a/noncore/games/fifteen/fifteen.pro b/noncore/games/fifteen/fifteen.pro index 43d336d..14ea3c9 100644 --- a/noncore/games/fifteen/fifteen.pro +++ b/noncore/games/fifteen/fifteen.pro @@ -1,11 +1,9 @@ -DESTDIR = $(OPIEDIR)/bin -TEMPLATE = app -CONFIG = qt warn_on release +CONFIG = qt warn_on release quick-app HEADERS = fifteen.h SOURCES = fifteen.cpp \ main.cpp INCLUDEPATH += $(OPIEDIR)/include DEPENDPATH += $(OPIEDIR)/include LIBS += -lqpe TARGET = fifteen diff --git a/noncore/games/fifteen/main.cpp b/noncore/games/fifteen/main.cpp index 4838a36..74a7368 100644 --- a/noncore/games/fifteen/main.cpp +++ b/noncore/games/fifteen/main.cpp @@ -1,33 +1,23 @@ /********************************************************************** -** Copyright (C) 2000 Trolltech AS. All rights reserved. +** Copyright (C) 2004 Holger Freyther. All rights reserved. ** -** This file is part of Qtopia Environment. +** This file is part of Opie 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 <qpe/qpeapplication.h> +#include <opie/oapplicationfactory.h> + +OPIE_EXPORT_APP( OApplicationFactory<FifteenMainWindow> ) -int main( int argc, char ** argv) -{ - QPEApplication app( argc, argv ); - - FifteenMainWindow mw; - mw.setCaption( FifteenMainWindow::tr("Fifteen Pieces") ); - app.showMainWidget( &mw ); - return app.exec(); -} |