summaryrefslogtreecommitdiffstats
path: root/libtdegames/highscore/kscoredialog.h
blob: 99a9f70b0f873aa74843b148c2a904eb7934f4db (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/****************************************************************
Copyright (c) 1998 Sandro Sigala <ssigala@globalnet.it>.
Copyright (c) 2001 Waldo Bastian <bastian@kde.org>
All rights reserved.

Permission to use, copy, modify, and distribute this software
and its documentation for any purpose and without fee is hereby
granted, provided that the above copyright notice appear in all
copies and that both that the copyright notice and this
permission notice and warranty disclaimer appear in supporting
documentation, and that the name of the author not be used in
advertising or publicity pertaining to distribution of the
software without specific, written prior permission.

The author disclaim all warranties with regard to this
software, including all implied warranties of merchantability
and fitness.  In no event shall the author be liable for any
special, indirect or consequential damages or any damages
whatsoever resulting from loss of use, data or profits, whether
in an action of contract, negligence or other tortious action,
arising out of or in connection with the use or performance of
this software.
****************************************************************/

#ifndef KSCOREDIALOG_H
#define KSCOREDIALOG_H

#include <tqmap.h>
#include <tqptrlist.h>

#include <kdialogbase.h>
#include <kdemacros.h>
class TQGridLayout;
class TQLineEdit;
class TQWidgetStack;

/**
 * A simple high score dialog.
 */
class KDE_EXPORT KScoreDialog : public KDialogBase {
   Q_OBJECT
  TQ_OBJECT
   
public:
   enum Fields { Name = 1 << 0, 
                 Level = 1 << 1, 
                 
                 Custom1 = 1 << 10,
                 Custom2 = 1 << 11,
                 Custom3 = 1 << 12,   	
                 
                 Date = 1 << 27, 
                 Time = 1 << 28, 
                 Score = 1 << 29 };
        
   typedef TQMap<int, TQString> FieldInfo;

   /**
    * @param fields Which fields should be listed.
    * @param parent passed to parent TQWidget constructor
    * @param name passed to parent TQWidget constructor
    */
   KScoreDialog(int fields, TQWidget *parent=0, const char *name=0);

   ~KScoreDialog();

   /**
    * @param group to use for reading/writing highscores from/to. By default
    * the class will use "High Score"
    */
   void setConfigGroup(const TQString &group);

   /**
    * @param comment to add when showing high-scores.
    * The comment is only used once.  
    */
   void setComment(const TQString &comment);

   /**
    * Define an extra FieldInfo entry.
    * @param field Id of this field
    * @param header Header shown in the dialog for this field
    * @param key used to store this field with.
    */
   void addField(int field, const TQString &header, const TQString &key); 

   /**
    * Adds a new score to the list.
    *
    * @param newScore the score of this game.
    * @param newInfo additional info about the score.
    * @param askName Whether to prompt for the players name.
    * @param lessIsMore If true, the lowest score is the best score.
    *
    * @returns The highscore position if the score was good enough to 
    * make it into the list (1 being topscore) or 0 otherwise.
    */   
   int addScore(int newScore, const FieldInfo &newInfo, bool askName, bool lessIsMore);
   int addScore(int newScore, const FieldInfo &newInfo, bool askName=true);

   /**
    * Returns the current best score.
    */
   int highScore();

   virtual void show();

private slots:
   void slotGotReturn();
   void slotGotName();

private:
   /* read scores */
   void loadScores();   
   void saveScores();
   
   void aboutToShow();
   void setupDialog();
   void keyPressEvent( TQKeyEvent *ev);

private:           
   class KScoreDialogPrivate;
   KScoreDialogPrivate *d;
};

#endif // !KSCOREDIALOG_H