Mostly the warnings were about QString::sprintf and QFontMetrics::width.
sprintf replacement is asprintf, which annoyingly behaves differently
from sprintf - it seems to append to the string.
Not thoroughly tested, but seems to work.
splash->repaint();
lsplash->repaint();
capt->repaint();
- qApp->flush();
+ qApp->processEvents();
} else {
splash = 0;
seteuid(getuid());
#endif
- QApplication::setColorSpec(ManyColor);
instance=new NetHackQtBind(*argc,argv);
#ifdef UNIX
}
if (complain) {
- QString message;
- message.sprintf("File not found: %s\n",filename);
+ QString message = QString::asprintf("File not found: %s\n",filename);
QMessageBox::warning(NULL, "File Error", message, QMessageBox::Ignore);
}
}
tile_file = PIXMAPDIR "/x11tiles";
if (!img.load(tile_file)) {
- QString msg;
- msg.sprintf("Cannot load 'nhtiles.bmp' or 'x11tiles'.");
+ QString msg = QString::asprintf("Cannot load 'nhtiles.bmp' or 'x11tiles'.");
QMessageBox::warning(0, "IO Error", msg);
iflags.wc_ascii_map = 1;
iflags.wc_tiled_map = 0;
if (v==NoNum) {
buf = "";
} else {
- buf.sprintf("%ld", v);
+ buf = QString::asprintf("%ld", v);
}
setLabel(t + buf + tail, cv < prev_value);
prev_value=cv;
Qt::KeyboardModifiers NetHackQtKeyBuffer::GetState()
{
- if ( Empty() ) return 0;
+ if ( Empty() ) return Qt::NoModifier;
Qt::KeyboardModifiers r=TopState();
out=(out+1)%maxkey;
return r;
Qt::KeyboardModifiers NetHackQtKeyBuffer::TopState() const
{
- if ( Empty() ) return 0;
+ if ( Empty() ) return Qt::NoModifier;
return state[out];
}
*p = '\0';
/* it's also long; break it into two pieces */
(void) strsubst(vbuf, " - ", "\n- ");
- QString msg;
- msg.sprintf(
+ QString msg = QString::asprintf(
// format
"NetHack-Qt is a version of NetHack built using" // no newline
#ifdef KDE
// nethack's #quit command itself) but this routine is unconditional
// in case someone wants to change that
#ifdef MACOS
- QString info;
- info.sprintf("This will end your NetHack session.%s",
+ QString info = QString::asprintf("This will end your NetHack session.%s",
!g.program_state.something_worth_saving ? ""
: "\n(Cancel quitting and use the Save command"
"\nto save your current game.)");
QFont f(fontfamily, pts, maybebold);
painter.setFont(QFont(fontfamily, pts));
QFontMetrics fm = painter.fontMetrics();
- if (fm.width("M") > qt_settings->glyphs().width())
+ if (fm.horizontalAdvance("M") > qt_settings->glyphs().width())
break;
if (fm.height() > qt_settings->glyphs().height())
break;
QPoint pos(0,ok->height());
move(pos);
- prompt.setParent(this,0);
+ prompt.setParent(this);
prompt.move(pos);
grid->addWidget(ok, 0, 0);
QFontMetrics fm(table->font());
QString col0width_str = "";
if (biggestcount > 0L)
- col0width_str.sprintf("%*ld", std::max(countdigits, 1), biggestcount);
- int col0width_int = (int) fm.width(col0width_str) + MENU_WIDTH_SLOP;
+ col0width_str = QString::asprintf("%*ld", std::max(countdigits, 1), biggestcount);
+ int col0width_int = (int) fm.horizontalAdvance(col0width_str) + MENU_WIDTH_SLOP;
if (col0width_int > table->columnWidth(0))
WidenColumn(0, col0width_int);
QStringList columns = itemlist[row].str.split("\t");
for (int fld = 0; fld < (int) columns.size(); ++fld) {
bool lastcol = (fld == (int) columns.size() - 1);
- int w = fm.width(columns[fld] + (lastcol ? "" : " "));
+ int w = fm.horizontalAdvance(columns[fld] + (lastcol ? "" : " "));
if (fld >= (int) col_widths.size()) {
col_widths.push_back(w); // add another element
} else if (col_widths[fld] < w) {
QString Amt = "";
long amt = count(row); // fetch item(row,0) as a number
if (amt > 0L)
- Amt.sprintf("%*ld", countdigits, amt);
+ Amt = QString::asprintf("%*ld", countdigits, amt);
cnt->setText(Amt);
}
for (int fld = 0; fld < (int) columns.size() - 1; ++fld) {
//columns[fld] += "\t"; /* (used to pad with tabs) */
int width = col_widths[fld];
- while (fm.width(columns[fld]) < width)
+ while (fm.horizontalAdvance(columns[fld]) < width)
columns[fld] += " "; //"\t";
}
text = columns.join("");
twi->setText(text);
}
// TODO? if description needs to wrap, increase the height of this row
- int wid = fm.width(text) + MENU_WIDTH_SLOP;
+ int wid = fm.horizontalAdvance(text) + MENU_WIDTH_SLOP;
if (wid > widest4)
widest4 = wid;
}
} else {
biggestcount = std::max(biggestcount, newcount);
QString num;
- num.sprintf("%*ld", std::max(countdigits, 1), biggestcount);
+ num = QString::asprintf("%*ld", std::max(countdigits, 1), biggestcount);
int numlen = (int) num.length();
if (numlen % 2)
++numlen;
table->setItem(row, 0, twi);
twi->setFlags(Qt::ItemIsEnabled);
#if 0 // active count field now widened as needed rather than preset
- WidenColumn(0, fm.width("999999") + MENU_WIDTH_SLOP);
+ WidenColumn(0, fm.horizontalAdvance("999999") + MENU_WIDTH_SLOP);
#else
WidenColumn(0, MENU_WIDTH_SLOP);
#endif
// for the normal case of "a - ", the trailing space hid the fact that
// the column wasn't wide enough for four characters; for the " #"
// and " *" cases, the last character was replaced by very tiny "..."
- int w = (int) fm.width(letter);
+ int w = (int) fm.horizontalAdvance(letter);
if (w)
w += MENU_WIDTH_SLOP / 2;
WidenColumn(3, w);
twi = new QTableWidgetItem(text);
table->setItem(row, 4, twi);
table->item(row, 4)->setFlags(Qt::ItemIsEnabled);
- WidenColumn(4, fm.width(text));
+ WidenColumn(4, fm.horizontalAdvance(text));
if ((int) mi.color != -1) {
twi->setForeground(colors[mi.color].q);
amt = count(row); // fetch item(row,0) as a number
QString Amt = "";
if (amt > 0L)
- Amt.sprintf("%*ld", countdigits, amt);
+ Amt = QString::asprintf("%*ld", countdigits, amt);
countfield->setText(Amt); // store right-justified value
}
ClearCount(); // blank out 'countstr' and reset 'counting'
int width = 0;
QFontMetrics fm(font());
for (int i = 0; i < count(); i++) {
- int lwidth = fm.width(item(i)->text());
+ int lwidth = fm.horizontalAdvance(item(i)->text());
width = std::max(width, lwidth);
}
return width;
{
if (!pm.load(fn)) {
QString msg;
- msg.sprintf("Cannot load \"%s\"", fn);
+ msg = QString::asprintf("Cannot load \"%s\"", fn);
QMessageBox::warning(NetHackQtBind::mainWidget(), "IO Error", msg);
}
}
geoH.setRight(std::min(lox + pxl_health - 1, hix));
hpbar_health.setGeometry(geoH);
w = geoH.right() - geoH.left() + 1; // might yield 0 (ie, if dead)
- styleH.sprintf(styleformat, barcolors[colorindx][0], w, w);
+ styleH = QString::asprintf(styleformat, barcolors[colorindx][0], w, w);
hpbar_health.setStyleSheet(styleH);
// when healing, having the old injury-side shown while the new
// health-side expands pushes the injury farther right and it's
geoI.setRight(hix);
hpbar_injury.setGeometry(geoI);
w = geoI.right() - geoI.left() + 1;
- styleI.sprintf(styleformat, barcolors[colorindx][1], w, w);
+ styleI = QString::asprintf(styleformat, barcolors[colorindx][1], w, w);
hpbar_injury.setStyleSheet(styleI);
if (geoI.left() != oldleft)
hpbar_injury.move(geoI.left(), geoI.top());
geoH.setRight(hix);
hpbar_health.setGeometry(geoH);
w = geoH.right() - geoH.left() + 1;
- styleH.sprintf(styleformat, barcolors[colorindx][0], w, w);
+ styleH = QString::asprintf(styleformat, barcolors[colorindx][0], w, w);
hpbar_health.setStyleSheet(styleH);
hpbar_health.show();
int st = ACURR(A_STR);
if (st > STR18(100)) {
- buf.sprintf("Str:%d", st - 100); // 19..25
+ buf = QString::asprintf("Str:%d", st - 100); // 19..25
} else if (st == STR18(100)) {
- buf.sprintf("Str:18/**"); // 18/100
+ buf = QString::asprintf("Str:18/**"); // 18/100
} else if (st > 18) {
- buf.sprintf("Str:18/%02d", st - 18); // 18/01..18/99
+ buf = QString::asprintf("Str:18/%02d", st - 18); // 18/01..18/99
} else {
- buf.sprintf("Str:%d", st); // 3..18
+ buf = QString::asprintf("Str:%d", st); // 3..18
}
str.setLabel(buf, NetHackQtLabelledIcon::NoNum, (long) st);
dex.setLabel("Dex:", (long) ACURR(A_DEX));
}
QString buf2;
char buf3[BUFSZ];
- buf2.sprintf("%s the %s", upstart(strcpy(buf3, g.plname)),
+ buf2 = QString::asprintf("%s the %s", upstart(strcpy(buf3, g.plname)),
buf.toLatin1().constData());
name.setLabel(buf2, NetHackQtLabelledIcon::NoNum, u.ulevel);
level.setCompareMode(NeitherIsBetter);
if (Upolyd) {
// You're a monster!
- buf.sprintf("/%d", u.mhmax);
+ buf = QString::asprintf("/%d", u.mhmax);
hp.setLabel("HP:", std::max((long) u.mh, 0L), buf);
level.setLabel("HD:", (long) mons[u.umonnum].mlevel); // hit dice
// Exp points are not shown when HD is displayed instead of Xp level
} else {
// You're normal.
- buf.sprintf("/%d", u.uhpmax);
+ buf = QString::asprintf("/%d", u.uhpmax);
hp.setLabel("HP:", std::max((long) u.uhp, 0L), buf);
// if Exp points are to be displayed, append them to Xp level;
// up/down highlighting becomes tricky--don't try very hard;
for (int i = ::flags.showexp ? 0 : 3; i < 4; ++i) {
// passes 0,1,2 are with Exp, 3 is without Exp and always fits
if (i < 3) {
- buf.sprintf("%s%ld/%ld", lvllbl[i], (long) u.ulevel, u.uexp);
+ buf = QString::asprintf("%s%ld/%ld", lvllbl[i], (long) u.ulevel, u.uexp);
} else {
- buf.sprintf("%s%ld", lvllbl[i - 3], (long) u.ulevel);
+ buf = QString::asprintf("%s%ld", lvllbl[i - 3], (long) u.ulevel);
}
// +2: allow a couple of pixels at either end to be clipped off
if (fm.size(0, buf).width() <= (2 + level.label->width() + 2))
was_polyd = Upolyd ? true : false;
had_exp = (::flags.showexp && !was_polyd) ? true : false;
- buf.sprintf("/%d", u.uenmax);
+ buf = QString::asprintf("/%d", u.uenmax);
power.setLabel("Pow:", (long) u.uen, buf);
ac.setLabel("AC:", (long) u.uac);
// gold prefix used to be "Au:", tty uses "$:"; never too wide to fit;
static const char *const scrlbl[3] = { "Score:", "Scr:", "S:" };
QFontMetrics fm(score.label->font());
for (int i = 0; i < 3; ++i) {
- buf.sprintf("%s%ld", scrlbl[i], pts);
+ buf = QString::asprintf("%s%ld", scrlbl[i], pts);
// +2: allow couple of pixels at either end to be clipped off
if (fm.size(0, buf).width() <= (2 + score.width() + 2))
break;
input.setMaxLength(maxchar - 1);
const QString &txt = prompt.text();
- int pw = fontMetrics().width(txt),
- ww = minchar * input.fontMetrics().width(QChar('X'));
+ int pw = fontMetrics().horizontalAdvance(txt),
+ ww = minchar * input.fontMetrics().horizontalAdvance(QChar('X'));
int heightfactor = ((txt.size() > 16) ? 3 : 2) * 2; // 2 or 3 lines high
int widthfudge = (((txt.size() > 16) ? 1 : 2) * 5) * 2; // 5: margn, guttr
resize(pw + ww + widthfudge, fontMetrics().height() * heightfactor);
for (i = 0; extcmdlist[i].ef_txt; ++i) {
if (interesting_command(i, set)) {
++ncmds;
- butw = std::max(butw, 30 + fm.width(extcmdlist[i].ef_txt));
+ butw = std::max(butw, 30 + fm.horizontalAdvance(extcmdlist[i].ef_txt));
}
}
// if any of the choice buttons were bigger than the control buttons,
q->setMargin(4);
vb->addWidget(q);
}
- QGroupBox *group = new QGroupBox(bigq ? QString::null : qlabel, this);
+ QGroupBox *group = new QGroupBox(bigq ? QString() : qlabel, this);
vb->addWidget(group);
QHBoxLayout *groupbox = new QHBoxLayout();
group->setLayout(groupbox);
QPushButton cancel("Dismiss",this);
label.setFrameStyle(QFrame::Box|QFrame::Sunken);
label.setAlignment(Qt::AlignCenter);
- label.resize(fontMetrics().width(qlabel)+60,30+fontMetrics().height());
+ label.resize(fontMetrics().horizontalAdvance(qlabel)+60,30+fontMetrics().height());
cancel.move(width()/2-cancel.width()/2,label.geometry().bottom()+8);
connect(&cancel,SIGNAL(clicked()),this,SLOT(reject()));
centerOnMain(this);