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 //----------------------------------------------------------------------------- 00168 enum ScoreType { Won = 0, Lost = -1 }; 00169 00174 class Score 00175 { 00176 public: 00177 Score(ScoreType type = Won); 00178 00179 ~Score(); 00180 00184 ScoreType type() const { return _type; } 00185 00189 void setType(ScoreType type) { _type = type; } 00190 00194 const QVariant &data(const QString &name) const; 00195 00201 void setData(const QString &name, const QVariant &value); 00202 00208 uint score() const { return data("score").toUInt(); } 00209 00215 void setScore(uint score) { setData("score", score); } 00216 00221 bool isTheWorst() const; 00222 00228 bool operator <(const Score &score); 00229 00230 private: 00231 ScoreType _type; 00232 QMap<QString, QVariant> _data; 00233 00234 class ScorePrivate; 00235 ScorePrivate *d; 00236 00237 friend class MultiplayerScores; 00238 00239 friend QDataStream &operator <<(QDataStream &stream, const Score &score); 00240 friend QDataStream &operator >>(QDataStream &stream, Score &score); 00241 }; 00242 00243 QDataStream &operator <<(QDataStream &stream, const Score &score); 00244 QDataStream &operator >>(QDataStream &stream, Score &score); 00245 00266 class MultiplayerScores 00267 { 00268 public: 00269 MultiplayerScores(); 00270 00271 ~MultiplayerScores(); 00272 00276 void setPlayerCount(uint nb); 00277 00281 void setName(uint player, const QString &name); 00282 00286 void addScore(uint player, const Score &score); 00287 00291 void clear(); 00292 00296 void show(QWidget *parent); 00297 00298 private: 00299 QValueVector<uint> _nbGames; 00300 QValueVector<Score> _scores; 00301 00302 class MultiplayerScoresPrivate; 00303 MultiplayerScoresPrivate *d; 00304 00305 friend QDataStream &operator <<(QDataStream &stream, 00306 const MultiplayerScores &score); 00307 friend QDataStream &operator >>(QDataStream &stream, 00308 MultiplayerScores &score); 00309 }; 00310 00311 QDataStream &operator <<(QDataStream &stream, const MultiplayerScores &score); 00312 QDataStream &operator >>(QDataStream &stream, MultiplayerScores &score); 00313 00314 } // namespace 00315 00316 #endif
KDE Logo
This file is part of the documentation for libkdegames Library Version 3.2.3.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Fri Aug 13 12:48:51 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003