summaryrefslogtreecommitdiff
path: root/noncore/games/wordgame
authorkergoth <kergoth>2002-06-07 18:53:14 (UTC)
committer kergoth <kergoth>2002-06-07 18:53:14 (UTC)
commit640d964cfdc7467f6cacb513087cd3acda2c04f0 (patch) (unidiff)
tree9a784686c1795f8b1f81eb344598f3b549d43467 /noncore/games/wordgame
parentdfb9c76738bb68e235114c5ad43dbd26a59b98ab (diff)
downloadopie-640d964cfdc7467f6cacb513087cd3acda2c04f0.zip
opie-640d964cfdc7467f6cacb513087cd3acda2c04f0.tar.gz
opie-640d964cfdc7467f6cacb513087cd3acda2c04f0.tar.bz2
Backing out unintentional merge from TT branch.
Diffstat (limited to 'noncore/games/wordgame') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/games/wordgame/wordgame.cpp71
-rw-r--r--noncore/games/wordgame/wordgame.h6
2 files changed, 62 insertions, 15 deletions
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
@@ -59,6 +59,13 @@ enum RuleEffects {
59 Start=128 59 Start=128
60}; 60};
61 61
62static int tile_smallw = 16;
63static int tile_smallh = 16;
64static int tile_bigw = 22;
65static int tile_bigh = 22;
66static int tile_stweak = -2;
67static int tile_btweak = -1;
68
62static const int rack_tiles=7; 69static const int rack_tiles=7;
63 70
64const char* sampleWGR= 71const char* sampleWGR=
@@ -111,6 +118,15 @@ const char* sampleWGR=
111WordGame::WordGame( QWidget* parent, const char* name, WFlags fl ) : 118WordGame::WordGame( QWidget* parent, const char* name, WFlags fl ) :
112 QMainWindow(parent, name, fl) 119 QMainWindow(parent, name, fl)
113{ 120{
121 if ( qApp->desktop()->width() < 240 ) {
122 tile_smallw = 10;
123 tile_smallh = 10;
124 tile_bigw = 16;
125 tile_bigh = 16;
126 tile_stweak = 0;
127 tile_btweak = 0;
128 }
129
114 setIcon( Resource::loadPixmap( "wordgame" ) ); 130 setIcon( Resource::loadPixmap( "wordgame" ) );
115 setCaption( tr("Word Game") ); 131 setCaption( tr("Word Game") );
116 132
@@ -247,6 +263,7 @@ void WordGame::startGame(const QStringList& playerlist)
247{ 263{
248 toolbar->show(); 264 toolbar->show();
249 racks = new QWidgetStack(vbox); 265 racks = new QWidgetStack(vbox);
266 racks->setFixedHeight(TileItem::bigHeight()+2);
250 namelist.clear(); 267 namelist.clear();
251 nplayers=0; 268 nplayers=0;
252 for (QStringList::ConstIterator it=playerlist.begin(); it!=playerlist.end(); ++it) 269 for (QStringList::ConstIterator it=playerlist.begin(); it!=playerlist.end(); ++it)
@@ -283,7 +300,6 @@ bool WordGame::loadRules(const QString &name)
283 if ( htiles < 3 || vtiles < 3 ) 300 if ( htiles < 3 || vtiles < 3 )
284 return FALSE; 301 return FALSE;
285 302
286 QPixmap bgshapes = Resource::loadPixmap(shapepixmap);
287 QString rule_shapes; 303 QString rule_shapes;
288 for (int i=0; i<vtiles; i++) { 304 for (int i=0; i<vtiles; i++) {
289 QString line; 305 QString line;
@@ -297,6 +313,12 @@ bool WordGame::loadRules(const QString &name)
297 rule_effects[re] = e; 313 rule_effects[re] = e;
298 if ( re++ < 10 ) ts >> e; 314 if ( re++ < 10 ) ts >> e;
299 } 315 }
316
317 QImage shim = Resource::loadImage(shapepixmap);
318 shim = shim.smoothScale((re-1)*TileItem::smallWidth(),TileItem::smallHeight());
319 QPixmap bgshapes;
320 bgshapes.convertFromImage(shim);
321
300 rule_effects[re++] = 100; // default bonus 322 rule_effects[re++] = 100; // default bonus
301 board = new Board(bgshapes, htiles, vtiles, vbox); 323 board = new Board(bgshapes, htiles, vtiles, vbox);
302 board->setRules(rule_shapes, rule_effects); 324 board->setRules(rule_shapes, rule_effects);
@@ -681,22 +703,22 @@ qDebug("%d,%d: %s (%d) for %d",current.x(),current.y(),st.latin1(),n,s);
681 703
682int TileItem::smallWidth() 704int TileItem::smallWidth()
683{ 705{
684 return 16; 706 return tile_smallw;
685} 707}
686 708
687int TileItem::smallHeight() 709int TileItem::smallHeight()
688{ 710{
689 return 16; 711 return tile_smallh;
690} 712}
691 713
692int TileItem::bigWidth() 714int TileItem::bigWidth()
693{ 715{
694 return 22; 716 return tile_bigw;
695} 717}
696 718
697int TileItem::bigHeight() 719int TileItem::bigHeight()
698{ 720{
699 return 22; 721 return tile_bigh;
700} 722}
701 723
702void TileItem::setState( State state ) 724void TileItem::setState( State state )
@@ -720,26 +742,36 @@ void TileItem::setBig(bool b)
720 742
721void TileItem::drawShape(QPainter& p) 743void TileItem::drawShape(QPainter& p)
722{ 744{
723 static QFont value_font("heletica",8); 745 static QFont *value_font=0;
724 static QFont big_font("smoothtimes",17); 746 static QFont *big_font=0;
725 static QFont small_font("smoothtimes",10); 747 static QFont *small_font=0;
748 if ( !value_font ) {
749 value_font = new QFont("helvetica",8);
750 if ( TileItem::bigWidth() < 20 ) {
751 big_font = new QFont("helvetica",12);
752 small_font = new QFont("helvetica",8);
753 } else {
754 big_font = new QFont("smoothtimes",17);
755 small_font = new QFont("smoothtimes",10);
756 }
757 }
726 758
727 QRect area(x(),y(),width(),height()); 759 QRect area(x(),y(),width(),height());
728 p.setBrush(s == Floating ? yellow/*lightGray*/ : white); 760 p.setBrush(s == Floating ? yellow/*lightGray*/ : white);
729 p.drawRect(area); 761 p.drawRect(area);
730 if ( big ) { 762 if ( big ) {
731 p.setFont(value_font); 763 p.setFont(*value_font);
732 QString n = QString::number(t.value()); 764 QString n = QString::number(t.value());
733 int w = p.fontMetrics().width('1'); 765 int w = p.fontMetrics().width('1');
734 int h = p.fontMetrics().height(); 766 int h = p.fontMetrics().height();
735 w *= n.length(); 767 w *= n.length();
736 QRect valuearea(x()+width()-w-2,y()+height()-h+1,w,h); 768 QRect valuearea(x()+width()-w-1,y()+height()-h,w,h);
737 p.drawText(valuearea,AlignCenter,n); 769 p.drawText(valuearea,AlignCenter,n);
738 p.setFont(big_font); 770 p.setFont(*big_font);
739 area = QRect(x(),y(),width()-2,height()-1); 771 area = QRect(x(),y()+tile_btweak,width()-4,height()-1);
740 } else { 772 } else {
741 p.setFont(small_font); 773 p.setFont(*small_font);
742 area = QRect(x(),y()+2,width(),height()-2); 774 area = QRect(x()+1+tile_stweak,y()+1,width(),height()-3);
743 } 775 }
744 if ( t.value() == 0 ) 776 if ( t.value() == 0 )
745 p.setPen(darkGray); 777 p.setPen(darkGray);
@@ -750,6 +782,7 @@ Board::Board(QPixmap bgshapes, int w, int h, QWidget* parent) :
750 QCanvasView(new QCanvas(bgshapes,w,h, TileItem::smallWidth(), TileItem::smallHeight()), 782 QCanvasView(new QCanvas(bgshapes,w,h, TileItem::smallWidth(), TileItem::smallHeight()),
751 parent) 783 parent)
752{ 784{
785 setFixedSize(w*TileItem::smallWidth(),h*TileItem::smallHeight());
753 grid = new TileItem*[w*h]; 786 grid = new TileItem*[w*h];
754 memset(grid,0,w*h*sizeof(TileItem*)); 787 memset(grid,0,w*h*sizeof(TileItem*));
755 setFrameStyle(0); 788 setFrameStyle(0);
@@ -764,6 +797,11 @@ Board::~Board()
764 delete canvas(); 797 delete canvas();
765} 798}
766 799
800QSize Board::sizeHint() const
801{
802 return QSize(canvas()->width(),canvas()->height());
803}
804
767void Board::writeConfig(Config& cfg) 805void Board::writeConfig(Config& cfg)
768{ 806{
769 QStringList t; 807 QStringList t;
@@ -1181,6 +1219,11 @@ Rack::~Rack()
1181 delete canvas(); 1219 delete canvas();
1182} 1220}
1183 1221
1222QSize Rack::sizeHint() const
1223{
1224 return QSize(-1,TileItem::bigHeight()+2);
1225}
1226
1184void Rack::clear() 1227void Rack::clear()
1185{ 1228{
1186 for (int i=0; i<n; i++) 1229 for (int i=0; i<n; i++)
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
@@ -148,6 +148,8 @@ public:
148 void setComputerization(int level) { cpu=level; } 148 void setComputerization(int level) { cpu=level; }
149 bool computerized() const { return cpu>0; } 149 bool computerized() const { return cpu>0; }
150 150
151 QSize sizeHint() const;
152
151protected: 153protected:
152 void resizeEvent(QResizeEvent*e); 154 void resizeEvent(QResizeEvent*e);
153 void contentsMousePressEvent(QMouseEvent*); 155 void contentsMousePressEvent(QMouseEvent*);
@@ -211,6 +213,8 @@ public:
211 213
212 int turnScore() const { return turn_score; } 214 int turnScore() const { return turn_score; }
213 215
216 QSize sizeHint() const;
217
214signals: 218signals:
215 void temporaryScore(int); 219 void temporaryScore(int);
216 220
@@ -331,7 +335,7 @@ private:
331 335
332 QWidgetStack *racks; 336 QWidgetStack *racks;
333 QToolBar* toolbar; 337 QToolBar* toolbar;
334 QVBox *vbox; 338 QWidget *vbox;
335 Board *board; 339 Board *board;
336 Bag *bag; 340 Bag *bag;
337 ScoreInfo *scoreinfo; 341 ScoreInfo *scoreinfo;