KDEGames

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

KDE's Doxygen guidelines are available online.