• 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
kscoredialog.cpp
Go to the documentation of this file.
1 /****************************************************************
2 Copyright (c) 1998 Sandro Sigala <ssigala@globalnet.it>.
3 Copyright (c) 2001 Waldo Bastian <bastian@kde.org>
4 Copyright (c) 2007 Matt Williams <matt@milliams.com>
5 All rights reserved.
6 
7 Permission to use, copy, modify, and distribute this software
8 and its documentation for any purpose and without fee is hereby
9 granted, provided that the above copyright notice appear in all
10 copies and that both that the copyright notice and this
11 permission notice and warranty disclaimer appear in supporting
12 documentation, and that the name of the author not be used in
13 advertising or publicity pertaining to distribution of the
14 software without specific, written prior permission.
15 
16 The author disclaim all warranties with regard to this
17 software, including all implied warranties of merchantability
18 and fitness. In no event shall the author be liable for any
19 special, indirect or consequential damages or any damages
20 whatsoever resulting from loss of use, data or profits, whether
21 in an action of contract, negligence or other tortious action,
22 arising out of or in connection with the use or performance of
23 this software.
24 ****************************************************************/
25 
26 #include "kscoredialog.h"
27 #include "khighscore.h"
28 #include "../kgdifficulty.h"
29 
30 #include <KConfig>
31 #include <KUser>
32 #include <KLocale>
33 #include <KSeparator>
34 #include <KGlobal>
35 #include <KConfigGroup>
36 #include <KTabWidget>
37 #include <KDebug>
38 #include <KLineEdit>
39 
40 #include <QtCore/QTimer>
41 #include <QtCore/QList>
42 #include <QtCore/QByteArray>
43 #include <QtGui/QGridLayout>
44 #include <QtGui/QKeyEvent>
45 #include <QtGui/QLabel>
46 #include <QtGui/QLayout>
47 #include <QtGui/QStackedWidget>
48 
49 #define DEFAULT_GROUP_NAME I18N_NOOP("High Scores")
50 
51 typedef QList<KScoreDialog::FieldInfo> GroupScores;
52 
53 class KScoreDialog::KScoreDialogPrivate
54 {
55  public:
56  //QList<FieldInfo*> scores;
57  QMap<QByteArray, GroupScores> scores;
58  QList<QByteArray> hiddenGroups;
59  QMap<int, QByteArray> configGroupWeights;
60  KTabWidget *tabWidget;
61  //QWidget *page;
62  //QGridLayout *layout;
63  KLineEdit *edit;
64  QMap<QByteArray, QList<QStackedWidget*> > stack;
65  QMap<QByteArray, QList<QLabel*> > labels;
66  QLabel *commentLabel;
67  QString comment;
68  int fields;
69  int hiddenFields;
70  QPair<QByteArray, int> newName; //index of the new name to add (groupKey, position)
71  QPair<QByteArray, int> latest; //index of the latest addition (groupKey, position)
72  int nrCols;
73  bool loaded;
74  QByteArray configGroup;
75  KHighscore* highscoreObject;
76  QMap<QByteArray, QString> translatedGroupNames;
77  QMap<QByteArray, QWidget*> tabs;
78 
79  QMap<int, int> col;
80  QMap<int, QString> header;
81  QMap<int, QString> key;
82  QString player;
83  int lastHighPosition;
84 
85  //Q-Pointer
86  KScoreDialogPrivate(KScoreDialog* parent):q(parent){}
87  KScoreDialog* const q;
88 
89  //Functions
90  void loadScores();
91  void saveScores();
92 
93  void setupDialog();
94  void setupGroup(const QByteArray& groupName);
95  void aboutToShow();
96 
97  QString findTranslatedGroupName(const QByteArray& name);
98 };
99 
100 
101 KScoreDialog::KScoreDialog(int fields, QWidget *parent)
102  : KDialog(parent), d(new KScoreDialogPrivate(this))
103 {
104  setCaption( i18n(DEFAULT_GROUP_NAME) );
105  setModal( true );
106  d->highscoreObject = new KHighscore();
107  d->edit = 0;
108  fields |= Score; //Make 'Score' field automatic (it can be hidden if necessary)
109  d->fields = fields;
110  d->hiddenFields = 0;
111  d->newName = QPair<QByteArray,int>(QByteArray(),-1);
112  d->latest = QPair<QByteArray,int>("Null",-1);
113  d->loaded = false;
114  d->nrCols = 0;
115  d->configGroup=QByteArray();
116 
117  //Set up the default table headers
118  d->header[Name] = i18n("Name");
119  d->key[Name] = QLatin1String( "Name" );
120  d->header[Date] = i18n("Date");
121  d->key[Date] = QLatin1String( "Date" );
122  d->header[Level] = i18n("Level");
123  d->key[Level] = QLatin1String( "Level" );
124  d->header[Score] = i18n("Score");
125  d->key[Score] = QLatin1String( "Score" );
126  d->header[Time] = i18n("Time");
127  d->key[Time] = QLatin1String( "Time" );
128 
129  //d->page = new QWidget(this);
130 
131  d->tabWidget = new KTabWidget(this);
132  d->tabWidget->setTabPosition(QTabWidget::West);
133 
134  setMainWidget(d->tabWidget);
135  if(d->newName.second == -1)
136  setButtons(Close);
137  else
138  {
139  setButtons(Ok|Cancel);
140  connect(this, SIGNAL(okClicked()), SLOT(slotGotName()));
141  }
142 }
143 
144 KScoreDialog::~KScoreDialog()
145 {
146  delete d->highscoreObject;
147 
148  delete d;
149 }
150 
151 void KScoreDialog::setConfigGroup(const QString &group) //DEPRECATED!
152 {
153  d->configGroup = group.toUtf8();
154  d->loaded = false;
155 }
156 
157 void KScoreDialog::setConfigGroup(const QPair<QByteArray, QString>& group)
158 {
159  d->configGroup = group.first; //untranslated string
160  addLocalizedConfigGroupName(group); //add the translation to the list
161  d->loaded = false;
162 }
163 
164 void KScoreDialog::addLocalizedConfigGroupName(const QPair<QByteArray, QString>& group)
165 {
166  if (!d->translatedGroupNames.contains(group.first))
167  {
168  d->translatedGroupNames.insert(group.first, group.second);
169  kDebug() << "adding" << group.first << "->" << group.second;
170  }
171 }
172 
173 void KScoreDialog::addLocalizedConfigGroupNames(const QMap<QByteArray, QString>& groups)
174 {
175  QMap<QByteArray, QString>::const_iterator it = groups.begin();
176  for (; it != groups.end(); ++it)
177  {
178  addLocalizedConfigGroupName(qMakePair(it.key(), it.value()));
179  }
180 }
181 
182 void KScoreDialog::initFromDifficulty(const KgDifficulty* diff, bool doSetConfigGroup)
183 {
184  QMap<QByteArray, QString> localizedLevelStrings;
185  QMap<int, QByteArray> levelWeights;
186  foreach (const KgDifficultyLevel* level, diff->levels())
187  {
188  localizedLevelStrings.insert(level->key(), level->title());
189  levelWeights.insert(level->hardness(), level->key());
190  }
191  addLocalizedConfigGroupNames(localizedLevelStrings);
192  setConfigGroupWeights(levelWeights);
193  if (doSetConfigGroup)
194  {
195  const KgDifficultyLevel* curLvl = diff->currentLevel();
196  setConfigGroup(qMakePair(curLvl->key(), curLvl->title()));
197  }
198 }
199 
200 void KScoreDialog::setHiddenConfigGroups(const QList<QByteArray>& hiddenGroups)
201 {
202  d->hiddenGroups = hiddenGroups;
203 }
204 
205 void KScoreDialog::setConfigGroupWeights(const QMap<int, QByteArray>& weights)
206 {
207  d->configGroupWeights = weights;
208 }
209 
210 QString KScoreDialog::KScoreDialogPrivate::findTranslatedGroupName(const QByteArray& name)
211 {
212  const QString lookupResult = translatedGroupNames.value(name);
213  //If it wasn't found then just try i18n( to see if it happens to be in the database
214  return lookupResult.isEmpty() ? i18n(name) : lookupResult; //FIXME?
215 }
216 
217 void KScoreDialog::setComment(const QString &comment)
218 {
219  d->comment = comment;
220 }
221 
222 void KScoreDialog::addField(int field, const QString &header, const QString &key)
223 {
224  d->fields |= field;
225  d->header[field] = header;
226  d->key[field] = key;
227 }
228 
229 void KScoreDialog::hideField(int field)
230 {
231  d->hiddenFields |= field;
232 }
233 
234 /*
235 Create the widgets and layouts etc. for the dialog
236 */
237 
238 void KScoreDialog::KScoreDialogPrivate::setupDialog()
239 {
240  nrCols = 1;
241  for(int field = 1; field < fields; field = field * 2)
242  {
243  if ( (fields & field) && !(hiddenFields & field ) )
244  col[field] = nrCols++;
245  }
246 
247  tabWidget->clear();
248  QList<QByteArray> keysToConfigure = scores.keys();
249  foreach(const QByteArray &groupName, configGroupWeights)
250  {
251  int index = keysToConfigure.indexOf(groupName);
252  if (index != -1)
253  {
254  setupGroup(groupName);
255  keysToConfigure.removeAt(index);
256  }
257  }
258  foreach(const QByteArray &groupName, keysToConfigure)
259  {
260  setupGroup(groupName);
261  }
262 }
263 
264 void KScoreDialog::KScoreDialogPrivate::setupGroup(const QByteArray& groupKey)
265 {
266  if (hiddenGroups.contains(groupKey))
267  return;
268  QWidget* widget = new QWidget(q);
269  tabs[groupKey] = widget;
270 
271  QString tabName = groupKey.isEmpty() ? i18n(DEFAULT_GROUP_NAME) : findTranslatedGroupName(groupKey);
272  tabWidget->addTab(widget, tabName);
273 
274  QGridLayout* layout = new QGridLayout(widget);
275  //layout->setObjectName( QLatin1String("ScoreTab-" )+groupName);
276  layout->setMargin(marginHint()+20);
277  layout->setSpacing(spacingHint());
278  layout->addItem(new QSpacerItem(0, 15), 4, 0);
279 
280  commentLabel = new QLabel(tabWidget);
281  commentLabel->setAlignment(Qt::AlignVCenter | Qt::AlignHCenter);
282 
283  QFont bold = q->font();
284  bold.setBold(true);
285 
286  QLabel *label;
287  layout->addItem(new QSpacerItem(50, 0), 0, 0);
288  label = new QLabel(i18n("Rank"), widget);
289  layout->addWidget(label, 3, 0);
290  label->setFont(bold);
291 
292  for(int field = 1; field < fields; field = field * 2)
293  {
294  if ( (fields & field) && !(hiddenFields & field ) ) //If it's used and not hidden
295  {
296  layout->addItem( new QSpacerItem( 50, 0 ), 0, col[field] );
297  label = new QLabel(header[field], widget);
298  layout->addWidget(label, 3, col[field], field <= Name ? Qt::AlignLeft : Qt::AlignRight);
299  label->setFont(bold);
300  }
301  }
302 
303  KSeparator *sep = new KSeparator(Qt::Horizontal, tabWidget->widget(tabWidget->currentIndex()));
304  layout->addWidget(sep, 4, 0, 1, nrCols);
305 
306  QString num;
307  for (int i = 1; i <= 10; ++i)
308  {
309  QLabel *label;
310  num.setNum(i);
311  label = new QLabel(i18nc("Enumeration (#1, #2 ...) of the highscore entries", "#%1", num), widget);
312  labels[groupKey].insert((i-1)*nrCols + 0, label); //Fill up column zero
313  layout->addWidget(label, i+4, 0);
314  if (fields & Name) //If we have a Name field
315  {
316  QStackedWidget *localStack = new QStackedWidget(widget);
317  stack[groupKey].insert(i-1, localStack);
318  layout->addWidget(localStack, i+4, col[Name]);
319  label = new QLabel(localStack);
320  labels[groupKey].insert((i-1)*nrCols + col[Name], label);
321  localStack->addWidget(label);
322  localStack->setCurrentWidget(label);
323  }
324  for(int field = Name * 2; field < fields; field = field * 2)
325  {
326  if ( (fields & field) && !(hiddenFields & field ) ) //Maybe disable for Name?
327  {
328  label = new QLabel(widget);
329  labels[groupKey].insert((i-1)*nrCols + col[field], label);
330  layout->addWidget(label, i+4, col[field], Qt::AlignRight);
331  }
332  }
333  }
334 }
335 
336 /*
337 Fill the dialog with the correct data
338 */
339 
340 void KScoreDialog::KScoreDialogPrivate::aboutToShow()
341 {
342  if (!loaded)
343  loadScores();
344 
345  if (!nrCols)
346  setupDialog();
347 
348  int tabIndex=0; //Index of the current tab
349 
350  QMap<QByteArray, GroupScores>::const_iterator it = scores.constBegin();
351  for (; it != scores.constEnd(); ++it)
352  {
353  const QByteArray &groupKey = it.key();
354  if (hiddenGroups.contains(groupKey))
355  continue;
356  kDebug() << latest.first << tabWidget->tabText(tabIndex);
357 
358  //Only display the comment on the page with the new score (or) this one if there's only one tab
359  if(latest.first == groupKey || ( latest.first.isEmpty() && groupKey == DEFAULT_GROUP_NAME ) )
360  {
361  QWidget* widget = tabs.value(groupKey);
362  QGridLayout* layout = qobject_cast<QGridLayout*>(widget->layout());
363 
364  commentLabel->setText(comment);
365  if (comment.isEmpty())
366  {
367  commentLabel->setMinimumSize(QSize(1,1));
368  commentLabel->hide();
369  layout->addItem( new QSpacerItem( 0, -15 ), 0, 0 );
370  layout->addItem( new QSpacerItem( 0, -15 ), 2, 0 );
371  }
372  else
373  {
374  layout->addWidget(commentLabel, 1, 0, 1, nrCols);
375  commentLabel->setMinimumSize(commentLabel->sizeHint());
376  commentLabel->show();
377  layout->addItem( new QSpacerItem( 0, -10 ), 0, 0 );
378  layout->addItem( new QSpacerItem( 0, 10 ), 2, 0 );
379  }
380  comment.clear();
381 
382  tabWidget->setCurrentWidget(widget);
383  }
384 
385  QFont normal = q->font();
386  QFont bold = normal;
387  bold.setBold(true);
388 
389  QString num;
390  for (int i = 1; i <= 10; ++i)
391  {
392  QLabel *label;
393  num.setNum(i);
394 
395  //kDebug() << "groupName:" << groupName << "id:" << i-1;
396 
397  FieldInfo score = scores[groupKey].at(i-1);
398  label = labels[groupKey].at((i-1)*nrCols + 0); //crash! FIXME
399  if ( (i == latest.second) && (groupKey == latest.first) )
400  label->setFont(bold);
401  else
402  label->setFont(normal);
403 
404  if (fields & Name)
405  {
406  if ( (newName.second == i) && (groupKey == newName.first) )
407  {
408  QStackedWidget *localStack = stack[groupKey].at(i-1);
409  edit = new KLineEdit(player, localStack);
410  edit->setMinimumWidth(40);
411  localStack->addWidget(edit);
412  localStack->setCurrentWidget(edit);
413  edit->setFocus();
414  connect(edit, SIGNAL(returnPressed()), q, SLOT(slotGotReturn()));
415  }
416  else
417  {
418  label = labels[groupKey].at((i-1)*nrCols + col[Name]);
419  if ( (i == latest.second) && (groupKey == latest.first) )
420  label->setFont(bold);
421  else
422  label->setFont(normal);
423  label->setText(score[Name]);
424  }
425 
426  }
427  for(int field = Name * 2; field < fields; field = field * 2)
428  {
429  if ( (fields & field) && !(hiddenFields & field ) )
430  {
431  label = labels[groupKey].at((i-1)*nrCols + col[field]);
432  if ( (i == latest.second) && (groupKey == latest.first) )
433  label->setFont(bold);
434  else
435  label->setFont(normal);
436  label->setText(score[field]);
437  }
438  }
439  }
440  tabIndex++;
441  }
442  latest = QPair<QByteArray,int>(QByteArray(),-1);
443  q->setFixedSize(q->minimumSizeHint()); //NOTE Remove this line to make dialog resizable
444 }
445 
446 void KScoreDialog::KScoreDialogPrivate::loadScores()
447 {
448  scores.clear();
449 
450  QList<QByteArray> groupKeyList; //This will be a list of all the groups in the config fie
451  foreach( const QString & groupString, highscoreObject->groupList())
452  {
453  groupKeyList << groupString.toUtf8(); //Convert all the QStrings to QByteArrays
454  }
455 
456  QByteArray tempCurrentGroup = configGroup; //temp to store the user-set group name
457 
458  if (!groupKeyList.contains( configGroup) ) //If the current group doesn't have any entries, add it to the list to process
459  {
460  kDebug(11002) << "The current high score group " << configGroup << " isn't in the list, adding it";
461  groupKeyList << configGroup;
462  setupGroup(configGroup);
463  }
464 
465  foreach(const QByteArray &groupKey, groupKeyList)
466  {
467  highscoreObject->setHighscoreGroup(QLatin1String( groupKey ));
468  player = highscoreObject->readEntry(0, QLatin1String( "LastPlayer" )); //FIXME
469 
470  for (int i = 1; i <= 10; ++i)
471  {
472  FieldInfo score;
473  for(int field = 1; field < fields; field = field * 2)
474  {
475  if (fields & field)
476  {
477  score[field] = highscoreObject->readEntry(i, key[field], QLatin1String("-"));
478  }
479  }
480  scores[groupKey].append(score);
481  }
482  }
483  highscoreObject->setHighscoreGroup(QLatin1String( tempCurrentGroup )); //reset to the user-set group name
484  foreach(const QByteArray &groupKey, scores.keys())
485  {
486  if( (scores[groupKey][0].value(Score)==QLatin1String( "-" )) && (scores.size() > 1) && (latest.first != groupKey) )
487  {
488  kDebug(11002) << "Removing group " << groupKey << " since it's unused.";
489  scores.remove(groupKey);
490  }
491  }
492  loaded = true;
493 }
494 
495 void KScoreDialog::KScoreDialogPrivate::saveScores()
496 {
497  highscoreObject->setHighscoreGroup(QLatin1String( configGroup ));
498 
499  highscoreObject->writeEntry(0,QLatin1String( "LastPlayer" ), player);
500 
501  for (int i = 1; i <= 10; ++i)
502  {
503  FieldInfo score = scores[configGroup].at(i-1);
504  for(int field = 1; field < fields; field = field * 2)
505  {
506  if (fields & field)
507  {
508  highscoreObject->writeEntry(i, key[field], score[field]);
509  }
510  }
511  }
512  highscoreObject->writeAndUnlock();
513 }
514 
515 int KScoreDialog::addScore(const FieldInfo& newInfo, const AddScoreFlags& flags)
516 {
517  kDebug() << "adding new score";
518 
519  bool askName=false, lessIsMore=false;
520  if(flags.testFlag(KScoreDialog::AskName))
521  askName = true;
522  if(flags.testFlag(KScoreDialog::LessIsMore))
523  lessIsMore = true;
524 
525  d->latest.first = d->configGroup; //Temporarily set this so loadScores() knows not to delete this group
526  if (!d->loaded)
527  d->loadScores();
528  d->latest.first = "Null"; //and reset it.
529 
530  for(int i=0; i<d->scores[d->configGroup].size(); i++)
531  {
532  FieldInfo score = d->scores[d->configGroup].at(i); //First look at the score in the config file
533  bool ok; //will be false if there isn't any score yet in position i
534  int num_score = score[Score].toLong(&ok); //test if the stored score is a number
535 
536  score = FieldInfo(newInfo); //now look at the submitted score
537  int newScore = score[Score].toInt();
538 
539  kDebug() << "num_score =" << num_score << " - newScore =" << newScore;
540 
541  if (((newScore > num_score) && !lessIsMore) ||
542  ((newScore < num_score) && lessIsMore) || !ok)
543  {
544  d->latest = QPair<QByteArray,int>(d->configGroup,i+1);
545  d->scores[d->configGroup].insert(i, score);
546  // Save the position to delete in case of Forget
547  d->lastHighPosition = i;
548 
549  if(score[Name].isEmpty()) //If we don't have a name, prompt the player.
550  {
551  if(!d->player.isEmpty()) //d->player should be filled out by d->loadScores()
552  {
553  score[Name] = d->player;
554  }
555  else
556  {
557  KUser user;
558  score[Name] = user.property(KUser::FullName).toString();
559  if (score[Name].isEmpty())
560  {
561  score[Name] = user.loginName();
562  }
563  }
564  askName = true;
565  }
566 
567  if (askName)
568  {
569  d->player=score[Name];
570  d->newName = QPair<QByteArray,int>(d->configGroup,i+1);
571 
572  setButtons(Ok|Cancel);
573  setButtonText(Ok, i18n("&Remember"));
574  setButtonText(Cancel, i18n("&Forget"));
575  setButtonToolTip(Ok, i18n("Remember this high score"));
576  setButtonToolTip(Cancel, i18n("Forget this high score"));
577  connect(this, SIGNAL(okClicked()), SLOT(slotGotName()));
578  connect(this, SIGNAL(cancelClicked()), SLOT(slotForgetScore()));
579  }
580  else
581  d->saveScores();
582 
583  if (i == 0)
584  d->comment = i18n("Excellent!\nYou have a new high score!");
585  else
586  d->comment = i18n("Well done!\nYou made it to the high score list!");
587  return i+1;
588  }
589  }
590  d->latest = qMakePair(d->configGroup, 0);
591  return 0;
592 }
593 
594 int KScoreDialog::addScore(int newScore, const AddScoreFlags& flags)
595 {
596  FieldInfo scoreInfo;
597  scoreInfo[Score]=QString::number(newScore);
598  return addScore(scoreInfo, AskName | flags);
599 }
600 
601 void KScoreDialog::show()
602 {
603  d->aboutToShow();
604  KDialog::show();
605 }
606 
607 void KScoreDialog::exec()
608 {
609  d->aboutToShow();
610  KDialog::exec();
611 }
612 
613 void KScoreDialog::slotGotReturn()
614 {
615  QTimer::singleShot(0, this, SLOT(slotGotName()));
616  // TODO: Is it better to hide the window, as if any button where pressed?
617 }
618 
619 void KScoreDialog::slotGotName()
620 {
621  if (d->newName.second == -1) return;
622 
623  d->player = d->edit->text();
624 
625  d->scores[d->newName.first][d->newName.second-1][Name] = d->player;
626  d->saveScores();
627 
628  QFont bold = font();
629  bold.setBold(true);
630 
631  QLabel *label = d->labels[d->newName.first].at((d->newName.second-1)*d->nrCols + d->col[Name]);
632  label->setFont(bold);
633  label->setText(d->player);
634  d->stack[d->newName.first].at((d->newName.second-1))->setCurrentWidget(label);
635  d->stack[d->newName.first].at((d->newName.second-1))->removeWidget(d->edit);
636  delete d->edit;
637  d->edit = 0;
638  d->newName = QPair<QByteArray,int>(QByteArray(),-1);
639  d->scores[d->configGroup].removeAt(10);
640  d->comment.clear(); // hide the congratulations
641  d->commentLabel->hide();
642  setButtons(Close);
643 }
644 
645 void KScoreDialog::slotForgetScore()
646 {
647  if (d->newName.second == -1) return;
648  // remove the editor from the stack
649  d->stack[d->newName.first].at((d->newName.second-1))->removeWidget(d->edit);
650  // delete the editor
651  delete d->edit;
652  d->edit = 0;
653  // avoid to recreate the KTextEdit widget
654  d->newName = QPair<QByteArray,int>(QByteArray(),-1);
655  // delete the highscore to forget
656  d->scores[d->configGroup].removeAt(d->lastHighPosition);
657  d->comment.clear();
658  d->commentLabel->hide();
659  setButtons(Close);
660 }
661 
662 
663 int KScoreDialog::highScore()
664 {
665  if (!d->loaded)
666  d->loadScores();
667 
668  if (!d->scores[d->configGroup].isEmpty())
669  return d->scores[d->configGroup].first()[Score].toInt();
670  else
671  return 0;
672 }
673 
674 void KScoreDialog::keyPressEvent(QKeyEvent *ev)
675 {
676  if ((d->newName.second != -1) && (ev->key() == Qt::Key_Return))
677  {
678  ev->ignore();
679  return;
680  }
681  KDialog::keyPressEvent(ev);
682 }
683 
684 #include "kscoredialog.moc"
QWidget::layout
QLayout * layout() const
QSpacerItem
KHighscore
Class for managing highscore tables.
Definition: khighscore.h:82
QWidget
KScoreDialog::setConfigGroup
void KDE_DEPRECATED setConfigGroup(const QString &group=QString())
The group name must be passed though I18N_NOOP() in order for the group name to be translated...
Definition: kscoredialog.cpp:151
KScoreDialog::setComment
void setComment(const QString &comment)
Definition: kscoredialog.cpp:217
KScoreDialog::addLocalizedConfigGroupNames
void addLocalizedConfigGroupNames(const QMap< QByteArray, QString > &groups)
You must add the translations of all group names to the dialog.
Definition: kscoredialog.cpp:173
QGridLayout::addWidget
void addWidget(QWidget *widget, int row, int column, QFlags< Qt::AlignmentFlag > alignment)
QByteArray
QByteArray::at
char at(int i) const
KScoreDialog::Score
Definition: kscoredialog.h:107
KExtHighscore::show
void show(QWidget *parent, int rank)
Definition: kexthighscore.cpp:59
QFont
QMap
KScoreDialog
A simple high score implementation.
Definition: kscoredialog.h:96
QList::removeAt
void removeAt(int i)
QByteArray::isEmpty
bool isEmpty() const
KScoreDialog::setConfigGroupWeights
void 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 n...
Definition: kscoredialog.cpp:205
KScoreDialog::Name
Definition: kscoredialog.h:103
QGridLayout
KDialog
KScoreDialog::addScore
int addScore(const FieldInfo &newInfo=FieldInfo(), const AddScoreFlags &flags=0)
Adds a new score to the list.
Definition: kscoredialog.cpp:515
KScoreDialog::AskName
Promt the player for their name.
Definition: kscoredialog.h:121
KScoreDialog::Level
Definition: kscoredialog.h:104
QGridLayout::setSpacing
void setSpacing(int spacing)
QList::indexOf
int indexOf(const T &value, int from) const
QFont::setBold
void setBold(bool enable)
KScoreDialog::show
virtual void show()
Display the dialog as non-modal.
Definition: kscoredialog.cpp:601
QString::number
QString number(int n, int base)
QEvent::ignore
void ignore()
QStackedWidget::setCurrentWidget
void setCurrentWidget(QWidget *widget)
KScoreDialog::highScore
int highScore()
Definition: kscoredialog.cpp:663
khighscore.h
KScoreDialog::Date
Definition: kscoredialog.h:105
KScoreDialog::addLocalizedConfigGroupName
void addLocalizedConfigGroupName(const QPair< QByteArray, QString > &group)
You must add the translations of all group names to the dialog.
Definition: kscoredialog.cpp:164
QString::isEmpty
bool isEmpty() const
QMap::const_iterator
KScoreDialog::initFromDifficulty
void initFromDifficulty(const KgDifficulty *difficulty, bool setConfigGroup=true)
Assume that config groups (incl.
Definition: kscoredialog.cpp:182
QStackedWidget
QLabel::setText
void setText(const QString &)
QString
QList
QMap::end
iterator end()
KScoreDialog::KScoreDialog
KScoreDialog(int fields=Name, QWidget *parent=0)
Definition: kscoredialog.cpp:101
QLayout::setMargin
void setMargin(int margin)
QMap::begin
iterator begin()
QPair< QByteArray, int >
QKeyEvent::key
int key() const
QSize
QWidget::setFont
void setFont(const QFont &)
QList::contains
bool contains(const T &value) const
kscoredialog.h
QMap::key
const Key key(const T &value) const
KScoreDialog::hideField
void hideField(int field)
Hide a field so that it is not shown on the table (but is still stored in the configuration file)...
Definition: kscoredialog.cpp:229
QKeyEvent
QLatin1String
KScoreDialog::FieldInfo
QMap< int, QString > FieldInfo
Definition: kscoredialog.h:126
QString::setNum
QString & setNum(short n, int base)
QGridLayout::addItem
void addItem(QLayoutItem *item, int row, int column, int rowSpan, int columnSpan, QFlags< Qt::AlignmentFlag > alignment)
QString::at
const QChar at(int position) const
KScoreDialog::addField
void addField(int field, const QString &header, const QString &key)
Define an extra FieldInfo entry.
Definition: kscoredialog.cpp:222
KScoreDialog::exec
virtual void exec()
Display the dialog as modal.
Definition: kscoredialog.cpp:607
DEFAULT_GROUP_NAME
#define DEFAULT_GROUP_NAME
Definition: kscoredialog.cpp:49
QMap::insert
iterator insert(const Key &key, const T &value)
KScoreDialog::Time
Definition: kscoredialog.h:106
GroupScores
QList< KScoreDialog::FieldInfo > GroupScores
The list of scores in a group.
Definition: kscoredialog.cpp:51
KScoreDialog::LessIsMore
A lower numerical score means higher placing on the table.
Definition: kscoredialog.h:122
QStackedWidget::addWidget
int addWidget(QWidget *widget)
QLabel
QByteArray::remove
QByteArray & remove(int pos, int len)
KScoreDialog::~KScoreDialog
~KScoreDialog()
Definition: kscoredialog.cpp:144
KScoreDialog::setHiddenConfigGroups
void setHiddenConfigGroups(const QList< QByteArray > &hiddenGroups)
Hide some config groups so that they are not shown on the dialog (but are still stored in the configu...
Definition: kscoredialog.cpp:200
QMap::value
const T value(const Key &key) const
QTimer::singleShot
singleShot
QString::toUtf8
QByteArray toUtf8() const
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