scoresprite.cpp

Go to the documentation of this file.
00001 /*
00002    This file is part of the KDE games lskat program
00003    Copyright (c) 2006 Martin Heni <kde@heni-online.de>
00004 
00005    This library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Library General Public
00007    License as published by the Free Software Foundation; either
00008    version 2 of the License, or (at your option) any later version.
00009 
00010    This library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Library General Public License for more details.
00014 
00015    You should have received a copy of the GNU Library General Public License
00016    along with this library; see the file COPYING.LIB.  If not, write to
00017    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00018    Boston, MA 02110-1301, USA.
00019 */
00020 
00021 // General includes
00022 #include <math.h>
00023 
00024 // Qt includes
00025 #include <QSizeF>
00026 #include <QFont>
00027 
00028 // KDE includes
00029 #include <kdebug.h>
00030 #include <kconfig.h>
00031 #include <klocale.h>
00032 
00033 // Local includes
00034 #include "scoresprite.h"
00035 
00036 
00037 // Constructor for the score sprite
00038 ScoreSprite::ScoreSprite(QString id, ThemeManager* theme, int advancePeriod, int no, QGraphicsScene* scene)
00039            :  Themable(id, theme), PixmapSprite(advancePeriod, no, scene)
00040 {
00041   // Create all sub sprites
00042   mName    = new QGraphicsTextItem(this, scene);
00043   mPoints  = new QGraphicsTextItem(this, scene);
00044   mScore   = new QGraphicsTextItem(this, scene);
00045   mGames   = new QGraphicsTextItem(this, scene);
00046   mInput   = new PixmapSprite("scoreinput", theme, advancePeriod, 0, scene);
00047   if (!mInput) kFatal() << "Cannot load sprite " << "scoreinput" << endl;
00048   mInput->setParentItem(this);
00049   mInputFrame = 0;
00050 
00051   mTrump   = new PixmapSprite("scoretrump", theme, advancePeriod, 0, scene);
00052   if (!mTrump) kFatal() << "Cannot load sprite " << "scoretrump" << endl;
00053   mTrump->setParentItem(this);
00054   mTrumpFrame = 0;
00055 
00056   // Redraw us
00057   if (theme) theme->updateTheme(this);
00058 
00059 }
00060 
00061 
00062 // Destructor
00063 ScoreSprite::~ScoreSprite()
00064 {
00065   // Clean up
00066 
00067   delete mName;
00068   delete mPoints;
00069   delete mScore;
00070   delete mGames;
00071   delete mInput;
00072   delete mTrump;
00073 }
00074 
00075 
00076 // Redraw the theme.
00077 void ScoreSprite::changeTheme()
00078 {
00079   // The main display is handled by theparent
00080   PixmapSprite::changeTheme();
00081   
00082   // Retrieve our size
00083   double width  = this->boundingRect().width();
00084   double height = this->boundingRect().height();
00085 
00086   // Retrieve theme data
00087   KConfigGroup config = thememanager()->config(id());
00088   QPointF posName     = config.readEntry("posName", QPointF(1.0,1.0));
00089   QPointF posPoints   = config.readEntry("posPoints", QPointF(1.0,1.0));
00090   QPointF posScore    = config.readEntry("posScore", QPointF(1.0,1.0));
00091   QPointF posGames    = config.readEntry("posGames", QPointF(1.0,1.0));
00092 
00093   // Calculate proper font size
00094   double fontHeightPoints = config.readEntry("fontHeightPoints", 1.0);
00095   fontHeightPoints       *= height;
00096   double fontHeight       = config.readEntry("fontHeight", 1.0);
00097   fontHeight             *= height;
00098   double fontWidthUpper   = config.readEntry("fontWidthUpper", 1.0);
00099   double fontWidthLower   = config.readEntry("fontWidthLower", 1.0);
00100   fontWidthUpper         *= width;
00101   fontWidthLower         *= width;
00102 
00103   
00104   // Retrieve font color
00105   QColor fontColor;
00106   fontColor = config.readEntry("fontColorPlayer", QColor(Qt::white));
00107 
00108   // Set position of sub sprites
00109   mName->setPos(posName.x()*width, posName.y()*height);
00110   mPoints->setPos(posPoints.x()*width, posPoints.y()*height);
00111   mScore->setPos(posScore.x()*width, posScore.y()*height);
00112   mGames->setPos(posGames.x()*width, posGames.y()*height);
00113 
00114   // Create and set current font
00115   QFont fontPoints;
00116   fontPoints.setPixelSize(int(fontHeightPoints));
00117   QFont font;
00118   font.setPixelSize(int(fontHeight));
00119 
00120   // Set font and color for all text items
00121   mName->setFont(font);   
00122   mPoints->setFont(fontPoints); 
00123   mScore->setFont(font);
00124   mGames->setFont(font);
00125   
00126   mName->setDefaultTextColor(fontColor);   
00127   mPoints->setDefaultTextColor(fontColor);
00128   mScore->setDefaultTextColor(fontColor);
00129   mGames->setDefaultTextColor(fontColor);
00130 
00131   mName->setTextWidth(fontWidthUpper);   
00132   mPoints->setTextWidth(fontWidthUpper);
00133   mScore->setTextWidth(fontWidthLower);
00134   mGames->setTextWidth(fontWidthLower);
00135 
00136   // Restore the frame of the input device sprite
00137   if (mInputFrame>=0) mInput->setFrame(mInputFrame);
00138 }
00139 
00140 
00141 // QGI advance method 
00142 void ScoreSprite::advance(int phase)
00143 {
00144   // Advance time and animation etc
00145   PixmapSprite::advance(phase);
00146 }
00147 
00148 
00149 // Store and display the name of a player
00150 void ScoreSprite::setPlayerName(QString s)
00151 {
00152   mName->setPlainText(s);
00153   update();
00154 }
00155 
00156 
00157 // Store and display amount of points
00158 void ScoreSprite::setPoints(int points)
00159 {
00160   QString s = QString("%1").arg(points,3);
00161   mPoints->setPlainText(s);
00162   update();
00163 }
00164 
00165 
00166 // Store and display score
00167 void ScoreSprite::setScore(int score)
00168 {
00169   QString s = i18nc("Score in score widget", "Score: %1", score);
00170   mScore->setPlainText(s);
00171   update();
00172 }
00173 
00174 
00175 // Store and display amount of games
00176 void ScoreSprite::setGames(int won, int all)
00177 {
00178   QString s = i18nc("Won and overall games in score widget", "Games: %1 / %2", won, all);
00179   mGames->setPlainText(s);
00180   update();
00181 }
00182 
00183 
00184 // Store and display input device
00185 void ScoreSprite::setInput(int device)
00186 {
00187   mInputFrame = device;
00188   mInput->setFrame(mInputFrame);
00189   mInput->show();
00190   update();
00191 }
00192 
00193 
00194 // Store and display trump icon
00195 void ScoreSprite::setTrump(int suite)
00196 {
00197   mTrumpFrame = suite;
00198   mTrump->setFrame(mTrumpFrame);
00199   mTrump->show();
00200   update();
00201 }
00202 
00203 
00204 
00205 

Generated on Tue May 1 09:34:40 2007 for LSkat by  doxygen 1.4.6