libkdegames/highscore
kexthighscore_item.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef KEXTHIGHSCORE_ITEM_H
00021 #define KEXTHIGHSCORE_ITEM_H
00022
00023 #include <QtCore/QVariant>
00024 #include <QtCore/QMap>
00025 #include <QtCore/QVector>
00026 #include <libkdegames_export.h>
00027 class QWidget;
00028
00029
00030 namespace KExtHighscore
00031 {
00032
00033
00039 class KDEGAMES_EXPORT Item
00040 {
00041 public:
00054 enum Format { NoFormat, OneDecimal, Percentage, MinuteTime,
00055 DateTime };
00056
00071 enum Special { NoSpecial, ZeroNotDefined, NegativeNotDefined,
00072 DefaultNotDefined, Anonymous };
00073
00083 explicit Item(const QVariant &def = QVariant::Invalid,
00084 const QString &label = QString(), Qt::AlignmentFlag alignment = Qt::AlignRight);
00085
00086 virtual ~Item();
00087
00092 void setPrettyFormat(Format format);
00093
00098 void setPrettySpecial(Special special);
00099
00103 bool isVisible() const { return !_label.isEmpty(); }
00104
00108 void setLabel(const QString &label) { _label = label; }
00109
00113 QString label() const { return _label; }
00114
00118 int alignment() const { return _alignment; }
00119
00123 void setDefaultValue(const QVariant &value) { _default = value; }
00124
00128 QVariant defaultValue() const { return _default; }
00129
00137 virtual QVariant read(uint i, const QVariant &value) const;
00138
00146 virtual QString pretty(uint i, const QVariant &value) const;
00147
00148 private:
00149 QVariant _default;
00150 QString _label;
00151 Qt::AlignmentFlag _alignment;
00152 Format _format;
00153 Special _special;
00154
00155 class ItemPrivate;
00156 ItemPrivate *d;
00157
00158 static QString timeFormat(uint);
00159 };
00160
00161
00168 enum ScoreType { Won = 0, Lost = -1, Draw = -2 };
00169
00170 class Score;
00171 KDEGAMES_EXPORT QDataStream &operator <<(QDataStream &stream, const Score &score);
00172 KDEGAMES_EXPORT QDataStream &operator >>(QDataStream &stream, Score &score);
00173
00178 class KDEGAMES_EXPORT Score
00179 {
00180 public:
00181 Score(ScoreType type = Won);
00182
00183 ~Score();
00184
00188 ScoreType type() const { return _type; }
00189
00193 void setType(ScoreType type) { _type = type; }
00194
00198 QVariant data(const QString &name) const;
00199
00205 void setData(const QString &name, const QVariant &value);
00206
00212 uint score() const { return data(QLatin1String("score")).toUInt(); }
00213
00219 void setScore(uint score) { setData(QLatin1String("score"), score); }
00220
00225 bool isTheWorst() const;
00226
00232 bool operator <(const Score &score);
00233
00234 private:
00235 ScoreType _type;
00236 QMap<QString, QVariant> _data;
00237
00238 class ScorePrivate;
00239 ScorePrivate *d;
00240
00241 friend class MultiplayerScores;
00242
00243 friend KDEGAMES_EXPORT QDataStream &operator <<(QDataStream &stream, const Score &score);
00244 friend KDEGAMES_EXPORT QDataStream &operator >>(QDataStream &stream, Score &score);
00245 };
00246
00247 class MultiplayerScores;
00248 KDEGAMES_EXPORT QDataStream &operator <<(QDataStream &stream, const MultiplayerScores &score);
00249 KDEGAMES_EXPORT QDataStream &operator >>(QDataStream &stream, MultiplayerScores &score);
00250
00271 class KDEGAMES_EXPORT MultiplayerScores
00272 {
00273 public:
00274 MultiplayerScores();
00275
00276 ~MultiplayerScores();
00277
00281 void setPlayerCount(uint nb);
00282
00286 void setName(uint player, const QString &name);
00287
00291 void addScore(uint player, const Score &score);
00292
00296 void clear();
00297
00301 void show(QWidget *parent);
00302
00303 private:
00304 QVector<uint> _nbGames;
00305 QVector<Score> _scores;
00306
00307 class MultiplayerScoresPrivate;
00308 MultiplayerScoresPrivate *d;
00309
00310 friend KDEGAMES_EXPORT QDataStream &operator <<(QDataStream &stream,
00311 const MultiplayerScores &score);
00312 friend KDEGAMES_EXPORT QDataStream &operator >>(QDataStream &stream,
00313 MultiplayerScores &score);
00314 };
00315
00316 }
00317
00318 #endif