00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include <math.h>
00023
00024
00025 #include <QSizeF>
00026 #include <QFont>
00027
00028
00029 #include <kdebug.h>
00030 #include <kconfig.h>
00031 #include <klocale.h>
00032
00033
00034 #include "scoresprite.h"
00035
00036
00037
00038 ScoreSprite::ScoreSprite(QString id, ThemeManager* theme, int advancePeriod, int no, QGraphicsScene* scene)
00039 : Themable(id, theme), PixmapSprite(advancePeriod, no, scene)
00040 {
00041
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
00057 if (theme) theme->updateTheme(this);
00058
00059 }
00060
00061
00062
00063 ScoreSprite::~ScoreSprite()
00064 {
00065
00066
00067 delete mName;
00068 delete mPoints;
00069 delete mScore;
00070 delete mGames;
00071 delete mInput;
00072 delete mTrump;
00073 }
00074
00075
00076
00077 void ScoreSprite::changeTheme()
00078 {
00079
00080 PixmapSprite::changeTheme();
00081
00082
00083 double width = this->boundingRect().width();
00084 double height = this->boundingRect().height();
00085
00086
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
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
00105 QColor fontColor;
00106 fontColor = config.readEntry("fontColorPlayer", QColor(Qt::white));
00107
00108
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
00115 QFont fontPoints;
00116 fontPoints.setPixelSize(int(fontHeightPoints));
00117 QFont font;
00118 font.setPixelSize(int(fontHeight));
00119
00120
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
00137 if (mInputFrame>=0) mInput->setFrame(mInputFrame);
00138 }
00139
00140
00141
00142 void ScoreSprite::advance(int phase)
00143 {
00144
00145 PixmapSprite::advance(phase);
00146 }
00147
00148
00149
00150 void ScoreSprite::setPlayerName(QString s)
00151 {
00152 mName->setPlainText(s);
00153 update();
00154 }
00155
00156
00157
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
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
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
00185 void ScoreSprite::setInput(int device)
00186 {
00187 mInputFrame = device;
00188 mInput->setFrame(mInputFrame);
00189 mInput->show();
00190 update();
00191 }
00192
00193
00194
00195 void ScoreSprite::setTrump(int suite)
00196 {
00197 mTrumpFrame = suite;
00198 mTrump->setFrame(mTrumpFrame);
00199 mTrump->show();
00200 update();
00201 }
00202
00203
00204
00205