• Skip to content
  • Skip to link menu
KDE 4.0 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

libkdegames/highscore

kexthighscore_item.h

Go to the documentation of this file.
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 <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 } // namespace
00317 
00318 #endif

libkdegames/highscore

Skip menu "libkdegames/highscore"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

API Reference

Skip menu "API Reference"
  • kblackbox
  • kgoldrunner
  • kmahjongg
  • ksquares
  • libkdegames
  •   highscore
  •   kgame
  •   kggzgames
  •   kggzmod
  •   kggznet
  • libkmahjongg
Generated for API Reference by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal