libkdegames Library API Documentation

kexthighscore_item.h

00001 /* 00002 This file is part of the KDE games library 00003 Copyright (C) 2001-2003 Nicolas Hadacek (hadacek@kde.org) 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 version 2 as published by the Free Software Foundation. 00008 00009 This library is distributed in the hope that it will be useful, 00010 but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 Library General Public License for more details. 00013 00014 You should have received a copy of the GNU Library General Public License 00015 along with this library; see the file COPYING.LIB. If not, write to 00016 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 00017 Boston, MA 02111-1307, USA. 00018 */ 00019 00020 #ifndef KEXTHIGHSCORE_ITEM_H 00021 #define KEXTHIGHSCORE_ITEM_H 00022 00023 #include <qvariant.h> 00024 #include <qnamespace.h> 00025 #include <qmap.h> 00026 #include <qvaluevector.h> 00027 00028 class QWidget; 00029 00030 00031 namespace KExtHighscore 00032 { 00033 00034 //----------------------------------------------------------------------------- 00040 class Item 00041 { 00042 public: 00055 enum Format { NoFormat, OneDecimal, Percentage, MinuteTime, 00056 DateTime }; 00057 00072 enum Special { NoSpecial, ZeroNotDefined, NegativeNotDefined, 00073 DefaultNotDefined, Anonymous }; 00074 00084 Item(const QVariant &def = QVariant::Invalid, 00085 const QString &label = QString::null, int alignment = Qt::AlignRight); 00086 00087 virtual ~Item(); 00088 00093 void setPrettyFormat(Format format); 00094 00099 void setPrettySpecial(Special special); 00100 00104 bool isVisible() const { return !_label.isEmpty(); } 00105 00109 void setLabel(const QString &label) { _label = label; } 00110 00114 QString label() const { return _label; } 00115 00119 int alignment() const { return _alignment; } 00120 00124 void setDefaultValue(const QVariant &value) { _default = value; } 00125 00129 const QVariant &defaultValue() const { return _default; } 00130 00138 virtual QVariant read(uint i, const QVariant &value) const; 00139 00147 virtual QString pretty(uint i, const QVariant &value) const; 00148 00149 private: 00150 QVariant _default; 00151 QString _label; 00152 int _alignment; 00153 Format _format; 00154 Special _special; 00155 00156 class ItemPrivate; 00157 ItemPrivate *d; 00158 00159 static QString timeFormat(uint); 00160 }; 00161 00162 //----------------------------------------------------------------------------- 00169 enum ScoreType { Won = 0, Lost = -1, Draw = -2 }; 00170 00175 class Score 00176 { 00177 public: 00178 Score(ScoreType type = Won); 00179 00180 ~Score(); 00181 00185 ScoreType type() const { return _type; } 00186 00190 void setType(ScoreType type) { _type = type; } 00191 00195 const QVariant &data(const QString &name) const; 00196 00202 void setData(const QString &name, const QVariant &value); 00203 00209 uint score() const { return data("score").toUInt(); } 00210 00216 void setScore(uint score) { setData("score", score); } 00217 00222 bool isTheWorst() const; 00223 00229 bool operator <(const Score &score); 00230 00231 private: 00232 ScoreType _type; 00233 QMap<QString, QVariant> _data; 00234 00235 class ScorePrivate; 00236 ScorePrivate *d; 00237 00238 friend class MultiplayerScores; 00239 00240 friend QDataStream &operator <<(QDataStream &stream, const Score &score); 00241 friend QDataStream &operator >>(QDataStream &stream, Score &score); 00242 }; 00243 00244 QDataStream &operator <<(QDataStream &stream, const Score &score); 00245 QDataStream &operator >>(QDataStream &stream, Score &score); 00246 00267 class MultiplayerScores 00268 { 00269 public: 00270 MultiplayerScores(); 00271 00272 ~MultiplayerScores(); 00273 00277 void setPlayerCount(uint nb); 00278 00282 void setName(uint player, const QString &name); 00283 00287 void addScore(uint player, const Score &score); 00288 00292 void clear(); 00293 00297 void show(QWidget *parent); 00298 00299 private: 00300 QValueVector<uint> _nbGames; 00301 QValueVector<Score> _scores; 00302 00303 class MultiplayerScoresPrivate; 00304 MultiplayerScoresPrivate *d; 00305 00306 friend QDataStream &operator <<(QDataStream &stream, 00307 const MultiplayerScores &score); 00308 friend QDataStream &operator >>(QDataStream &stream, 00309 MultiplayerScores &score); 00310 }; 00311 00312 QDataStream &operator <<(QDataStream &stream, const MultiplayerScores &score); 00313 QDataStream &operator >>(QDataStream &stream, MultiplayerScores &score); 00314 00315 } // namespace 00316 00317 #endif
KDE Logo
This file is part of the documentation for libkdegames Library Version 3.3.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Thu Aug 26 00:21:39 2004 by doxygen 1.3.8 written by Dimitri van Heesch, © 1997-2003