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

libkdegames/highscore

KScoreDialog Class Reference

#include <kscoredialog.h>

Inheritance diagram for KScoreDialog:

Inheritance graph
[legend]

List of all members.


Detailed Description

A simple high score implementation.

This class can be used both for displaying the current high scores and also for adding new highscores. It is the recommended way of implementing a simple highscore table.

To display the current highscores it is simply a case of creating a KScoreDialog object and calling exec(). This example code will display the Name and Score (the score is always added automatically unless hidden hideField since it is used for sorting) of the top 10 players:

 KScoreDialog ksdialog(this);
 ksdialog.exec();

To add a new highscore, e.g. at the end of a game you simply create an object with the Fields you want to write (i.e. KScoreDialog::Name | KScoreDialog::Score), call addScore and then (optionally) display the dialog. This code will allow you to add a highscore with a Name and Score field. If it's the first time a player has a score on the table, they will be prompted for their name but subsequent times they will have their name filled in automatically.

 KScoreDialog ksdialog(this);
 ksdialog.addScore(playersScore);
 ksdialog.exec();

Or if you want to fill the name in from the code you can pass a default name by doing

 KScoreDialog::FieldInfo scoreInfo;
 scoreInfo[KScoreDialog::Name] = "Matt";
 scoreInfo[KScoreDialog::Score].setNum(playersScore);
 ksdialog.addScore(scoreInfo);

If you want to add an extra field (e.g. the number of moves taken) then do

 KScoreDialog::FieldInfo scoreInfo;
 scoreInfo[KScoreDialog::Name] = "Matt";
 scoreInfo[KScoreDialog::Score].setNum(playersScore);
 
 ksdialog.addField(KScoreDialog::Custom1, "Num of Moves", "moves");
 scoreInfo[KScoreDialog::Custom1].setNum(42);
 
 ksdialog.addScore(scoreInfo);
You can define up to 5 Custom fields.
Author:
Matt Williams <matt@milliams.com>

Definition at line 91 of file kscoredialog.h.


Public Types

enum  Fields {
  Name = 1 << 0, Level = 1 << 1, Date = 1 << 2, Time = 1 << 3,
  Score = 1 << 4, Custom1 = 1 << 10, Custom2 = 1 << 11, Custom3 = 1 << 12,
  Custom4 = 1 << 13, Custom5 = 1 << 14, Max = 1 << 30
}
enum  AddScoreFlag { AskName = 0x1, LessIsMore = 0x2 }
typedef QMap< int, QString > FieldInfo

Public Member Functions

 KScoreDialog (int fields=Name, QWidget *parent=0)
 ~KScoreDialog ()
void setConfigGroup (const QString &group=QString())
void setComment (const QString &comment)
void addField (int field, const QString &header, const QString &key)
void hideField (int field)
int addScore (const FieldInfo &newInfo=FieldInfo(), const AddScoreFlags &flags=0)
int addScore (int newScore, const AddScoreFlags &flags=0)
int highScore ()
virtual void show ()
virtual void exec ()

Member Typedef Documentation

typedef QMap<int, QString> KScoreDialog::FieldInfo

Definition at line 121 of file kscoredialog.h.


Member Enumeration Documentation

enum KScoreDialog::Fields

Highscore fields.

Enumerator:
Name 
Level 
Date 
Time 
Score 
Custom1  Field for custom information.
Custom2 
Custom3 
Custom4 
Custom5 
Max  Only for setting a maximum.

Definition at line 97 of file kscoredialog.h.

enum KScoreDialog::AddScoreFlag

Flags for setting preferences for adding scores.

Enumerator:
AskName  Promt the player for their name.
LessIsMore  A lower numerical score means higher placing on the table.

Definition at line 114 of file kscoredialog.h.


Constructor & Destructor Documentation

KScoreDialog::KScoreDialog ( int  fields = Name,
QWidget *  parent = 0 
) [explicit]

Parameters:
fields Bitwise OR of the Fields that should be listed (Score is always present)

Parameters:
parent passed to parent QWidget constructor.

Definition at line 92 of file kscoredialog.cpp.

KScoreDialog::~KScoreDialog (  ) 

Definition at line 136 of file kscoredialog.cpp.


Member Function Documentation

void KScoreDialog::setConfigGroup ( const QString &  group = QString()  ) 

Parameters:
group to use for reading/writing highscores from/to.

If you set a group, it will be prefixed by 'KHighscore_' otherwise the group will simply be 'KHighscore'

Definition at line 143 of file kscoredialog.cpp.

void KScoreDialog::setComment ( const QString &  comment  ) 

Parameters:
comment to add when showing high-scores.

The comment is only used once.

Definition at line 149 of file kscoredialog.cpp.

void KScoreDialog::addField ( int  field,
const QString &  header,
const QString &  key 
)

Define an extra FieldInfo entry.

Parameters:
field id of this field Fields e.g. KScoreDialog::Custom1
header text shown in the header in the dialog for this field. e.g. "Number of Moves"
key unique key used to store this field. e.g. "moves"

Definition at line 154 of file kscoredialog.cpp.

void KScoreDialog::hideField ( int  field  ) 

Hide a field so that it is not shown on the table (but is still stored in the configuration file).

Parameters:
field id of this field Fields e.g. KScoreDialog::Score

Definition at line 161 of file kscoredialog.cpp.

int KScoreDialog::addScore ( const FieldInfo &  newInfo = FieldInfo(),
const AddScoreFlags &  flags = 0 
)

Adds a new score to the list.

Parameters:
newInfo info about the score.
flags set whether the user should be prompted for their name and how the scores should be sorted
Returns:
The highscore position if the score was good enough to make it into the list (1 being topscore) or 0 otherwise.

Definition at line 423 of file kscoredialog.cpp.

int KScoreDialog::addScore ( int  newScore,
const AddScoreFlags &  flags = 0 
)

Convenience function for ease of use.

Parameters:
newScore the score of the player.
flags set whether the user should be prompted for their name and how the scores should be sorted
Returns:
The highscore position if the score was good enough to make it into the list (1 being topscore) or 0 otherwise.

Definition at line 475 of file kscoredialog.cpp.

int KScoreDialog::highScore (  ) 

Returns:
the current best score in the group

Definition at line 520 of file kscoredialog.cpp.

void KScoreDialog::show (  )  [virtual]

Display the dialog.

Definition at line 482 of file kscoredialog.cpp.

void KScoreDialog::exec (  )  [virtual]

Display the dialog.

Definition at line 488 of file kscoredialog.cpp.


The documentation for this class was generated from the following files:
  • kscoredialog.h
  • kscoredialog.cpp

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