Source Code (Use browser search to find items of interest.)
Class Index
ksirtet'HighScores (./kdegames/ksirtet/dialogs.h:26)
class HighScores : public DialogBase
{
Q_OBJECT
public:
HighScores(const GameOverItem *, QWidget *parent, const char *name = 0);
private slots:
void reject();
void writeName();
private:
uint k;
QLineEdit *qle;
};
//-----------------------------------------------------------------------------
ksirtet'HighScores::HighScores() (./kdegames/ksirtet/dialogs.cpp:44)
HighScores::HighScores(const GameOverItem *goi, QWidget *parent,
const char *name)
: DialogBase(i18n("Hall of Fame"), Close, Close, parent, name), qle(0)
{
KConfig *conf = kapp->config();
conf->setGroup(HS_GRP);
// find the number of score entries and the position of
// the new score (if set)
// (we assume they are ordered and valid ...)
k = NB_HS;
uint s, i;
for (i=0; i<NB_HS; i++) {
s = conf->readNumEntry(HSScore(i), 0);
if ( s==0 ) { // end of entries
if ( k==NB_HS ) k = i;
break;
}
if ( goi && s<goi->score && k==NB_HS ) k = i;
}
if (goi) {
if ( k==NB_HS ) return; // not a better score
// insert the new score
i++;
for (uint j=i-1; j>k; j--) {
conf->writeEntry(HSScore(j), conf->readEntry(HSScore(j-1)));
conf->writeEntry(HSName(j), conf->readEntry(HSName(j-1)));
conf->writeEntry(HSLevel(j), conf->readEntry(HSLevel(j-1)));
}
conf->writeEntry(HSScore(k), (uint)goi->score);
conf->writeEntry(HSName(k), i18n("Anonymous")); // default name
conf->writeEntry(HSLevel(k), (uint)goi->level);
}
/* layout */
QLabel *lab;
QGridLayout *gl;
QFont f( font() );
f.setBold(TRUE);
if ( i==0 ) {
lab = new QLabel(i18n("no score entry"), plainPage());
lab->setMinimumSize( lab->sizeHint() );
lab->setFont(f);
top->addWidget(lab);
} else {
gl = new QGridLayout(top, 4, i+1, 2*spacingHint());
lab = new QLabel(i18n("Rank"), plainPage());
lab->setMinimumSize( lab->sizeHint() );
gl->addWidget(lab, 0, 0);
lab = new QLabel(i18n("Player Name"), plainPage());
lab->setMinimumSize( lab->sizeHint() );
gl->addWidget(lab, 0, 1);
lab = new QLabel(i18n("Level"), plainPage());
lab->setMinimumSize( lab->sizeHint() );
lab->setAlignment(AlignCenter);
gl->addWidget(lab, 0, 2);
lab = new QLabel(i18n("Score"), plainPage());
lab->setMinimumSize( lab->sizeHint() );
lab->setAlignment(AlignRight);
gl->addWidget(lab, 0, 3);
}
for (uint j=0; j<i; j++) {
/* rank */
QString str;
str.sprintf("%i", j+1);
lab = new QLabel(str, plainPage());
lab->setMinimumSize( lab->sizeHint() );
gl->addWidget(lab, j+1, 0);
/* name */
if ( !goi || (k!=j) ) {
QString name = conf->readEntry(HSName(j));
lab = new QLabel(plainPage());
lab->setFont(f);
lab->setText(name);
lab->setMinimumSize( lab->sizeHint() );
gl->addWidget(lab, j+1, 1);
} else {
qle = new QLineEdit(plainPage());
qle->setMaxLength(10);
qle->setFont(f);
qle->setMinimumSize(qle->fontMetrics().maxWidth()*10,
qle->sizeHint().height());
qle->setFocus();
connect(qle, SIGNAL(returnPressed()), SLOT(writeName()));
gl->addWidget(qle, j+1, 1);
}
/* level */
lab = new QLabel(conf->readEntry(HSLevel(j)), plainPage());
lab->setMinimumSize( lab->sizeHint() );
lab->setAlignment(AlignCenter);
gl->addWidget(lab, j+1, 2);
/* score */
lab = new QLabel(conf->readEntry(HSScore(j)), plainPage());
lab->setMinimumSize( lab->sizeHint() );
lab->setFont(f);
lab->setAlignment(AlignRight);
gl->addWidget(lab ,j+1, 3);
}
/* button */
enableButtonSeparator(TRUE);
if (goi) enableButton(Close, FALSE);
}
ksirtet'HighScores::writeName() (./kdegames/ksirtet/dialogs.cpp:160)
void HighScores::writeName()
{
KConfig *conf = kapp->config();
conf->setGroup(HS_GRP);
QString str = qle->text();
if ( str.length() ) conf->writeEntry(HSName(k), str);
conf->sync();
str = conf->readEntry(HSName(k));
qle->setText(str);
enableButton(Close, TRUE);
}
ksirtet'HighScores::reject() (./kdegames/ksirtet/dialogs.cpp:172)
void HighScores::reject()
{
if ( qle && qle->isEnabled() ) {
qle->setEnabled(FALSE);
focusNextPrevChild(TRUE); // sort of hack (wonder why its call in
// setEnabled(FALSE) does nothing ...)
} else KDialogBase::reject();
}
//-----------------------------------------------------------------------------