• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdegames API Reference
  • KDE Home
  • Contact Us
 

libkdegames/highscore

  • sources
  • kde-4.14
  • kdegames
  • libkdegames
  • highscore
kexthighscore_item.h
Go to the documentation of this file.
1 /*
2  This file is part of the KDE games library
3  Copyright (C) 2001-2003 Nicolas Hadacek (hadacek@kde.org)
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Library General Public
7  License version 2 as published by the Free Software Foundation.
8 
9  This library is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  Library General Public License for more details.
13 
14  You should have received a copy of the GNU Library General Public License
15  along with this library; see the file COPYING.LIB. If not, write to
16  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  Boston, MA 02110-1301, USA.
18 */
19 
20 #ifndef KEXTHIGHSCORE_ITEM_H
21 #define KEXTHIGHSCORE_ITEM_H
22 
23 #include <QtCore/QVariant>
24 #include <QtCore/QMap>
25 #include <QtCore/QVector>
26 #include <libkdegames_export.h>
27 class QWidget;
28 
29 
30 namespace KExtHighscore
31 {
32 
33 //-----------------------------------------------------------------------------
39 class KDEGAMES_EXPORT Item
40 {
41  public:
54  enum Format { NoFormat, OneDecimal, Percentage, MinuteTime,
55  DateTime };
56 
71  enum Special { NoSpecial, ZeroNotDefined, NegativeNotDefined,
72  DefaultNotDefined, Anonymous };
73 
83  explicit Item(const QVariant &def = QVariant::Invalid,
84  const QString &label = QString(), Qt::AlignmentFlag alignment = Qt::AlignRight);
85 
86  virtual ~Item();
87 
92  void setPrettyFormat(Format format);
93 
98  void setPrettySpecial(Special special);
99 
103  bool isVisible() const { return !_label.isEmpty(); }
104 
108  void setLabel(const QString &label) { _label = label; }
109 
113  QString label() const { return _label; }
114 
118  int alignment() const { return _alignment; }
119 
123  void setDefaultValue(const QVariant &value) { _default = value; }
124 
128  QVariant defaultValue() const { return _default; }
129 
137  virtual QVariant read(uint i, const QVariant &value) const;
138 
146  virtual QString pretty(uint i, const QVariant &value) const;
147 
148  private:
149  QVariant _default;
150  QString _label;
151  Qt::AlignmentFlag _alignment;
152  Format _format;
153  Special _special;
154 
155  class ItemPrivate;
156  ItemPrivate *d;
157 
158  static QString timeFormat(uint);
159 };
160 
161 //-----------------------------------------------------------------------------
168 enum ScoreType { Won = 0, Lost = -1, Draw = -2 };
169 
170 class Score;
171 KDEGAMES_EXPORT QDataStream &operator <<(QDataStream &stream, const Score &score);
172 KDEGAMES_EXPORT QDataStream &operator >>(QDataStream &stream, Score &score);
173 
178 class KDEGAMES_EXPORT Score
179 {
180  public:
181  Score(ScoreType type = Won);
182 
183  ~Score();
184 
188  ScoreType type() const { return _type; }
189 
193  void setType(ScoreType type) { _type = type; }
194 
198  QVariant data(const QString &name) const;
199 
205  void setData(const QString &name, const QVariant &value);
206 
212  uint score() const { return data(QLatin1String("score")).toUInt(); }
213 
219  void setScore(uint score) { setData(QLatin1String("score"), score); }
220 
225  bool isTheWorst() const;
226 
232  bool operator <(const Score &score);
233 
234  private:
235  ScoreType _type;
236  QMap<QString, QVariant> _data;
237 
238  class ScorePrivate;
239  ScorePrivate *d;
240 
241  friend class MultiplayerScores;
242 
243  friend KDEGAMES_EXPORT QDataStream &operator <<(QDataStream &stream, const Score &score);
244  friend KDEGAMES_EXPORT QDataStream &operator >>(QDataStream &stream, Score &score);
245 };
246 
247 class MultiplayerScores;
248 KDEGAMES_EXPORT QDataStream &operator <<(QDataStream &stream, const MultiplayerScores &score);
249 KDEGAMES_EXPORT QDataStream &operator >>(QDataStream &stream, MultiplayerScores &score);
250 
271 class KDEGAMES_EXPORT MultiplayerScores
272 {
273  public:
274  MultiplayerScores();
275 
276  ~MultiplayerScores();
277 
281  void setPlayerCount(uint nb);
282 
286  void setName(uint player, const QString &name);
287 
291  void addScore(uint player, const Score &score);
292 
296  void clear();
297 
301  void show(QWidget *parent);
302 
303  private:
304  QVector<uint> _nbGames;
305  QVector<Score> _scores;
306 
307  class MultiplayerScoresPrivate;
308  MultiplayerScoresPrivate *d;
309 
310  friend KDEGAMES_EXPORT QDataStream &operator <<(QDataStream &stream,
311  const MultiplayerScores &score);
312  friend KDEGAMES_EXPORT QDataStream &operator >>(QDataStream &stream,
313  MultiplayerScores &score);
314 };
315 
316 } // namespace
317 
318 #endif
KExtHighscore::Lost
Definition: kexthighscore_item.h:168
QWidget
KExtHighscore::MultiplayerScores
This class is used to store and show scores for multiplayer games.
Definition: kexthighscore_item.h:271
KExtHighscore::Item::alignment
int alignment() const
Definition: kexthighscore_item.h:118
KExtHighscore::Score::score
uint score() const
Definition: kexthighscore_item.h:212
QDataStream
KExtHighscore::show
void show(QWidget *parent, int rank)
Definition: kexthighscore.cpp:59
KExtHighscore::Item::Format
Format
Possible display format.
Definition: kexthighscore_item.h:54
QMap< QString, QVariant >
KExtHighscore::Score::type
ScoreType type() const
Definition: kexthighscore_item.h:188
KExtHighscore::Item::setDefaultValue
void setDefaultValue(const QVariant &value)
Set default value.
Definition: kexthighscore_item.h:123
KExtHighscore::Draw
Definition: kexthighscore_item.h:168
KExtHighscore::Item::DefaultNotDefined
Definition: kexthighscore_item.h:72
KExtHighscore::Item::defaultValue
QVariant defaultValue() const
Definition: kexthighscore_item.h:128
KExtHighscore::Won
Definition: kexthighscore_item.h:168
KExtHighscore::Item
This class defines how to convert and how to display a highscore element (such as the score...
Definition: kexthighscore_item.h:39
KExtHighscore::Item::Percentage
Definition: kexthighscore_item.h:54
KExtHighscore::Item::Special
Special
Possible special value for display format.
Definition: kexthighscore_item.h:71
KExtHighscore::Item::isVisible
bool isVisible() const
Definition: kexthighscore_item.h:103
KExtHighscore::ScoreType
ScoreType
Possible score type.
Definition: kexthighscore_item.h:168
KExtHighscore::Score::setScore
void setScore(uint score)
Set the score value.
Definition: kexthighscore_item.h:219
QString
KExtHighscore::Item::ZeroNotDefined
Definition: kexthighscore_item.h:71
KExtHighscore::Score::setType
void setType(ScoreType type)
Set the game type.
Definition: kexthighscore_item.h:193
KExtHighscore::operator<<
QDataStream & operator<<(QDataStream &s, const Score &score)
Definition: kexthighscore_item.cpp:183
QVector< uint >
KExtHighscore::operator>>
QDataStream & operator>>(QDataStream &s, Score &score)
Definition: kexthighscore_item.cpp:190
QLatin1String
KExtHighscore::Item::setLabel
void setLabel(const QString &label)
Set the label.
Definition: kexthighscore_item.h:108
KExtHighscore::Score
This class contains data for a score.
Definition: kexthighscore_item.h:178
KExtHighscore::Item::label
QString label() const
Definition: kexthighscore_item.h:113
QVariant
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:18:46 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

libkdegames/highscore

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

kdegames API Reference

Skip menu "kdegames API Reference"
  • granatier
  • kapman
  • kblackbox
  • kgoldrunner
  • kigo
  • kmahjongg
  • KShisen
  • ksquares
  • libkdegames
  •   highscore
  •   libkdegamesprivate
  •     kgame
  • libkmahjongg
  • palapeli
  •   libpala

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal