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 ScoreSprite::ScoreSprite(QString id, ThemeManager* theme, int advancePeriod, int no, QGraphicsScene* scene)
00038 : Themable(id, theme), PixmapSprite(advancePeriod, no, scene)
00039 {
00040
00041 for (int i=0; i<2; i++)
00042 {
00043 mWon[i] = new QGraphicsTextItem(this, scene);
00044 mDraw[i] = new QGraphicsTextItem(this, scene);
00045 mLoss[i] = new QGraphicsTextItem(this, scene);
00046 mBreak[i] = new QGraphicsTextItem(this, scene);
00047 mName[i] = new QGraphicsTextItem(this, scene);
00048 mInput[i] = new PixmapSprite(QString("scoreinput%1").arg(i), theme, advancePeriod, i, scene);
00049 if (!mInput[i]) kFatal() << "Cannot load sprite " << "scoreinput"<<i << endl;
00050 mInput[i]->setParentItem(this);
00051 mInputFrame[i] = 0;
00052 }
00053
00054
00055 mTurn = -1;
00056
00057
00058 if (theme) theme->updateTheme(this);
00059
00060 }
00061
00062
00063
00064 ScoreSprite::~ScoreSprite()
00065 {
00066
00067 for (int i=0; i<2; i++)
00068 {
00069 delete mWon[i];
00070 delete mDraw[i];
00071 delete mLoss[i];
00072 delete mBreak[i];
00073 delete mName[i];
00074 delete mInput[i];
00075 }
00076 }
00077
00078
00079
00080 void ScoreSprite::changeTheme()
00081 {
00082
00083 PixmapSprite::changeTheme();
00084
00085
00086 double width = this->boundingRect().width();
00087 double height = this->boundingRect().height();
00088
00089
00090 KConfigGroup config = thememanager()->config(id());
00091 QPointF posWon0 = config.readEntry("posWon0", QPointF(1.0,1.0));
00092 QPointF posWon1 = config.readEntry("posWon1", QPointF(1.0,1.0));
00093 QPointF posDraw0 = config.readEntry("posDraw0", QPointF(1.0,1.0));
00094 QPointF posDraw1 = config.readEntry("posDraw1", QPointF(1.0,1.0));
00095 QPointF posLoss0 = config.readEntry("posLoss0", QPointF(1.0,1.0));
00096 QPointF posLoss1 = config.readEntry("posLoss1", QPointF(1.0,1.0));
00097 QPointF posBreak0 = config.readEntry("posBreak0", QPointF(1.0,1.0));
00098 QPointF posBreak1 = config.readEntry("posBreak1", QPointF(1.0,1.0));
00099 QPointF posName0 = config.readEntry("posName0", QPointF(1.0,1.0));
00100 QPointF posName1 = config.readEntry("posName1", QPointF(1.0,1.0));
00101 QPointF posAI = config.readEntry("posAI", QPointF(1.0,1.0));
00102
00103
00104 double fontHeight = config.readEntry("fontHeight", 1.0);
00105 fontHeight *= height;
00106 double fontWidth = config.readEntry("fontWidth", 1.0);
00107 fontWidth *= width;
00108
00109
00110 QColor fontColor[2];
00111 fontColor[0] = config.readEntry("fontColorPlayer0", Qt::white);
00112 fontColor[1] = config.readEntry("fontColorPlayer1", Qt::white);
00113
00114
00115 mWon[0]->setPos(posWon0.x()*width, posWon0.y()*height);
00116 mWon[1]->setPos(posWon1.x()*width, posWon1.y()*height);
00117 mDraw[0]->setPos(posDraw0.x()*width, posDraw0.y()*height);
00118 mDraw[1]->setPos(posDraw1.x()*width, posDraw1.y()*height);
00119 mLoss[0]->setPos(posLoss0.x()*width, posLoss0.y()*height);
00120 mLoss[1]->setPos(posLoss1.x()*width, posLoss1.y()*height);
00121 mBreak[0]->setPos(posBreak0.x()*width, posBreak0.y()*height);
00122 mBreak[1]->setPos(posBreak1.x()*width, posBreak1.y()*height);
00123 mName[0]->setPos(posName0.x()*width, posName0.y()*height);
00124 mName[1]->setPos(posName1.x()*width, posName1.y()*height);
00125
00126
00127
00128 QFont font;
00129 font.setPixelSize(int(fontHeight));
00130
00131
00132 for (int i=0; i<2; i++)
00133 {
00134 mWon[i]->setFont(font);
00135 mDraw[i]->setFont(font);
00136 mLoss[i]->setFont(font);
00137 mBreak[i]->setFont(font);
00138 mName[i]->setFont(font);
00139
00140 mWon[i]->setDefaultTextColor(fontColor[i]);
00141 mDraw[i]->setDefaultTextColor(fontColor[i]);
00142 mLoss[i]->setDefaultTextColor(fontColor[i]);
00143 mBreak[i]->setDefaultTextColor(fontColor[i]);
00144 mName[i]->setDefaultTextColor(fontColor[i]);
00145
00146 mWon[i]->setTextWidth(fontWidth);
00147 mDraw[i]->setTextWidth(fontWidth);
00148 mLoss[i]->setTextWidth(fontWidth);
00149 mBreak[i]->setTextWidth(fontWidth);
00150 mName[i]->setTextWidth(fontWidth);
00151
00152
00153 if (mInputFrame[i]>=0) mInput[i]->setFrame(mInputFrame[i]);
00154 }
00155
00156
00157 if (mTurn>=0) setTurn(mTurn);
00158 }
00159
00160
00161
00162 void ScoreSprite::advance(int phase)
00163 {
00164
00165 PixmapSprite::advance(phase);
00166 }
00167
00168
00169
00170 void ScoreSprite::setLevel(int level, int no)
00171 {
00172 if (level >= 0)
00173 {
00174 mName[no]->setPlainText(i18nc("computer level","Level %1", level));
00175 update();
00176 }
00177 }
00178
00179
00180
00181 void ScoreSprite::setPlayerName(QString s,int no)
00182 {
00183 mName[no]->setPlainText(s);
00184 update();
00185 }
00186
00187
00188
00189 void ScoreSprite::setWon(QString s,int no)
00190 {
00191 mWon[no]->setPlainText(s);
00192 update();
00193 }
00194
00195
00196
00197 void ScoreSprite::setDraw(QString s,int no)
00198 {
00199 mDraw[no]->setPlainText(s);
00200 update();
00201 }
00202
00203
00204
00205 void ScoreSprite::setLoss(QString s,int no)
00206 {
00207 mLoss[no]->setPlainText(s);
00208 update();
00209 }
00210
00211
00212
00213 void ScoreSprite::setBreak(QString s,int no)
00214 {
00215 mBreak[no]->setPlainText(s);
00216 update();
00217 }
00218
00219
00220
00221
00222 void ScoreSprite::setInput(int device, int no)
00223 {
00224
00225 int frame;
00226 if (device == 8) frame = 2;
00227 else if (device == 4) frame = 0;
00228 else if (device == 2) frame = 1;
00229 else frame = 3;
00230
00231 mInputFrame[no] = frame;
00232 mInput[no]->setFrame(frame);
00233 update();
00234 }
00235
00236
00237
00238
00239
00240 void ScoreSprite::setTurn(int no)
00241 {
00242
00243 KConfigGroup config = thememanager()->config(id());
00244 QColor fontColorActive = config.readEntry("fontColorActive", Qt::white);
00245 QColor fontColor0 = config.readEntry("fontColorPlayer0", Qt::white);
00246 QColor fontColor1 = config.readEntry("fontColorPlayer1", Qt::white);
00247
00248
00249 mTurn = no;
00250
00251
00252 if (no==0)
00253 {
00254 mName[0]->setDefaultTextColor(fontColorActive);
00255 mName[1]->setDefaultTextColor(fontColor1);
00256 }
00257 else
00258 {
00259 mName[0]->setDefaultTextColor(fontColor0);
00260 mName[1]->setDefaultTextColor(fontColorActive);
00261 }
00262
00263 update();
00264 }
00265
00266