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., 51 Franklin Street, Fifth Floor, 00017 Boston, MA 02110-1301, USA. 00018 */ 00019 00020 #ifndef KEXTHIGHSCORE_ITEM_H 00021 #define KEXTHIGHSCORE_ITEM_H 00022 00023 #include <tqvariant.h> 00024 #include <tqnamespace.h> 00025 #include <tqmap.h> 00026 #include <tqvaluevector.h> 00027 #include <kdemacros.h> 00028 class TQWidget; 00029 00030 00031 namespace KExtHighscore 00032 { 00033 00034 //----------------------------------------------------------------------------- 00040 class KDE_EXPORT 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 TQVariant &def = TQVariant::Invalid, 00085 const TQString &label = TQString(), int alignment = TQt::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 TQString &label) { _label = label; } 00110 00114 TQString label() const { return _label; } 00115 00119 int alignment() const { return _alignment; } 00120 00124 void setDefaultValue(const TQVariant &value) { _default = value; } 00125 00129 const TQVariant &defaultValue() const { return _default; } 00130 00138 virtual TQVariant read(uint i, const TQVariant &value) const; 00139 00147 virtual TQString pretty(uint i, const TQVariant &value) const; 00148 00149 private: 00150 TQVariant _default; 00151 TQString _label; 00152 int _alignment; 00153 Format _format; 00154 Special _special; 00155 00156 class ItemPrivate; 00157 ItemPrivate *d; 00158 00159 static TQString timeFormat(uint); 00160 }; 00161 00162 //----------------------------------------------------------------------------- 00169 enum ScoreType { Won = 0, Lost = -1, Draw = -2 }; 00170 00175 class KDE_EXPORT 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 TQVariant &data(const TQString &name) const; 00196 00202 void setData(const TQString &name, const TQVariant &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 TQMap<TQString, TQVariant> _data; 00234 00235 class ScorePrivate; 00236 ScorePrivate *d; 00237 00238 friend class MultiplayerScores; 00239 00240 friend TQDataStream &operator <<(TQDataStream &stream, const Score &score); 00241 friend TQDataStream &operator >>(TQDataStream &stream, Score &score); 00242 }; 00243 00244 KDE_EXPORT TQDataStream &operator <<(TQDataStream &stream, const Score &score); 00245 KDE_EXPORT TQDataStream &operator >>(TQDataStream &stream, Score &score); 00246 00267 class KDE_EXPORT MultiplayerScores 00268 { 00269 public: 00270 MultiplayerScores(); 00271 00272 ~MultiplayerScores(); 00273 00277 void setPlayerCount(uint nb); 00278 00282 void setName(uint player, const TQString &name); 00283 00287 void addScore(uint player, const Score &score); 00288 00292 void clear(); 00293 00297 void show(TQWidget *parent); 00298 00299 private: 00300 TQValueVector<uint> _nbGames; 00301 TQValueVector<Score> _scores; 00302 00303 class MultiplayerScoresPrivate; 00304 MultiplayerScoresPrivate *d; 00305 00306 friend TQDataStream &operator <<(TQDataStream &stream, 00307 const MultiplayerScores &score); 00308 friend TQDataStream &operator >>(TQDataStream &stream, 00309 MultiplayerScores &score); 00310 }; 00311 00312 KDE_EXPORT TQDataStream &operator <<(TQDataStream &stream, const MultiplayerScores &score); 00313 KDE_EXPORT TQDataStream &operator >>(TQDataStream &stream, MultiplayerScores &score); 00314 00315 } // namespace 00316 00317 #endif