KDEGames

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

KDE's Doxygen guidelines are available online.