summaryrefslogtreecommitdiff
path: root/noncore/games/wordgame/wordgame.cpp
Unidiff
Diffstat (limited to 'noncore/games/wordgame/wordgame.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/games/wordgame/wordgame.cpp71
1 files changed, 57 insertions, 14 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
@@ -60,4 +60,11 @@ enum RuleEffects {
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
@@ -112,4 +119,13 @@ WordGame::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") );
@@ -248,4 +264,5 @@ void WordGame::startGame(const QStringList& playerlist)
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;
@@ -284,5 +301,4 @@ bool WordGame::loadRules(const QString &name)
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++) {
@@ -298,4 +314,10 @@ bool WordGame::loadRules(const QString &name)
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);
@@ -682,20 +704,20 @@ qDebug("%d,%d: %s (%d) for %d",current.x(),current.y(),st.latin1(),n,s);
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
@@ -721,7 +743,17 @@ void TileItem::setBig(bool b)
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());
@@ -729,16 +761,16 @@ void TileItem::drawShape(QPainter& p)
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 )
@@ -751,4 +783,5 @@ Board::Board(QPixmap bgshapes, int w, int h, QWidget* parent) :
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*));
@@ -765,4 +798,9 @@ Board::~Board()
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{
@@ -1182,4 +1220,9 @@ Rack::~Rack()
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{