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

libkdegames/highscore

Public Types | Public Member Functions | List of all members
KScoreDialog Class Reference

#include <KScoreDialog>

Inheritance diagram for KScoreDialog:
Inheritance graph
[legend]

Public Types

enum  AddScoreFlag { AskName = 0x1, LessIsMore = 0x2 }
 
typedef QMap< int, QString > FieldInfo
 
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
}
 

Public Member Functions

 KScoreDialog (int fields=Name, QWidget *parent=0)
 
 ~KScoreDialog ()
 
void addField (int field, const QString &header, const QString &key)
 
void addLocalizedConfigGroupName (const QPair< QByteArray, QString > &group)
 
void addLocalizedConfigGroupNames (const QMap< QByteArray, QString > &groups)
 
int addScore (const FieldInfo &newInfo=FieldInfo(), const AddScoreFlags &flags=0)
 
int addScore (int newScore, const AddScoreFlags &flags=0)
 
virtual void exec ()
 
void hideField (int field)
 
int highScore ()
 
void initFromDifficulty (const KgDifficulty *difficulty, bool setConfigGroup=true)
 
void setComment (const QString &comment)
 
void KDE_DEPRECATED setConfigGroup (const QString &group=QString())
 
void setConfigGroup (const QPair< QByteArray, QString > &group)
 
void setConfigGroupWeights (const QMap< int, QByteArray > &weights)
 
void setHiddenConfigGroups (const QList< QByteArray > &hiddenGroups)
 
virtual void show ()
 

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@.nosp@m.mill.nosp@m.iams..nosp@m.com

Definition at line 96 of file kscoredialog.h.

Member Typedef Documentation

typedef QMap<int, QString> KScoreDialog::FieldInfo

Definition at line 126 of file kscoredialog.h.

Member Enumeration Documentation

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 119 of file kscoredialog.h.

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 102 of file kscoredialog.h.

Constructor & Destructor Documentation

KScoreDialog::KScoreDialog ( int  fields = Name,
QWidget *  parent = 0 
)
explicit
Parameters
fieldsBitwise OR of the Fields that should be listed (Score is always present)
parentpassed to parent QWidget constructor.

Definition at line 101 of file kscoredialog.cpp.

KScoreDialog::~KScoreDialog ( )

Definition at line 144 of file kscoredialog.cpp.

Member Function Documentation

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

Define an extra FieldInfo entry.

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

Definition at line 222 of file kscoredialog.cpp.

void KScoreDialog::addLocalizedConfigGroupName ( const QPair< QByteArray, QString > &  group)

You must add the translations of all group names to the dialog.

This is best done by passing the name through ki18n(). The group set through setConfigGroup(const KLocalizedString& group) will be added automatically

Parameters
groupthe translated group name

Definition at line 164 of file kscoredialog.cpp.

void KScoreDialog::addLocalizedConfigGroupNames ( const QMap< QByteArray, QString > &  groups)

You must add the translations of all group names to the dialog.

This is best done by passing the name through ki18n(). The group set through setConfigGroup(const KLocalizedString& group) will be added automatically.

This function can be used directly with KGameDifficulty::localizedLevelStrings().

Parameters
groupthe list of translated group names

Definition at line 173 of file kscoredialog.cpp.

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

Adds a new score to the list.

Parameters
newInfoinfo about the score.
flagsset 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 515 of file kscoredialog.cpp.

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

Convenience function for ease of use.

Parameters
newScorethe score of the player.
flagsset 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 594 of file kscoredialog.cpp.

void KScoreDialog::exec ( )
virtual

Display the dialog as modal.

Definition at line 607 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
fieldid of this field Fields e.g. KScoreDialog::Score

Definition at line 229 of file kscoredialog.cpp.

int KScoreDialog::highScore ( )
Returns
the current best score in the group

Definition at line 663 of file kscoredialog.cpp.

void KScoreDialog::initFromDifficulty ( const KgDifficulty *  difficulty,
bool  setConfigGroup = true 
)

Assume that config groups (incl.

current selection) are equal to difficulty levels, and initialize them. This is usually equal to the following code using KGameDifficulty:

addLocalizedConfigGroupNames(KGameDifficulty::localizedLevelStrings());
setConfigGroupWeights(KGameDifficulty::levelWeights());
setConfigGroup(KGameDifficulty::localizedLevelString());

Definition at line 182 of file kscoredialog.cpp.

void KScoreDialog::setComment ( const QString &  comment)
Parameters
commentto add when showing high-scores. The comment is only used once.

Definition at line 217 of file kscoredialog.cpp.

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

The group name must be passed though I18N_NOOP() in order for the group name to be translated.

i.e.

ksdialog.setConfigGroup(I18N_NOOP("Easy"));

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

Parameters
groupto use for reading/writing highscores from/to.
Deprecated:
since 4.1

Definition at line 151 of file kscoredialog.cpp.

void KScoreDialog::setConfigGroup ( const QPair< QByteArray, QString > &  group)

The group name must be passed though ki18n() in order for the group name to be translated.

i.e.

ksdialog.setConfigGroup(ki18n("Easy"));

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

Parameters
groupto use for reading/writing highscores from/to.

Definition at line 157 of file kscoredialog.cpp.

void KScoreDialog::setConfigGroupWeights ( const QMap< int, QByteArray > &  weights)

It is a good idea giving config group weigths, otherwise tabs get ordered by their tab name that is not probably what you want.

This function can be used directly with KGameDifficulty::levelWeights().

Parameters
groupthe list of untranslated group names and their weights
Since
KDE 4.2

Definition at line 205 of file kscoredialog.cpp.

void KScoreDialog::setHiddenConfigGroups ( const QList< QByteArray > &  hiddenGroups)

Hide some config groups so that they are not shown on the dialog (but are still stored in the configuration file).

ksdialog.setHiddenConfigGroups(QList<QByteArray>() << "Very Easy" << "Easy");
Parameters
hiddenGroupsthe list of group names you want to hide
Since
KDE 4.6

Definition at line 200 of file kscoredialog.cpp.

void KScoreDialog::show ( )
virtual

Display the dialog as non-modal.

Definition at line 601 of file kscoredialog.cpp.


The documentation for this class was generated from the following files:
  • kscoredialog.h
  • kscoredialog.cpp
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