Restore compatibility with Qt 4
The test system is Slackware 14.2, which uses Qt 4.8.7. * WANT_WIN_QT4 is defined, and has the expected meaning. Qt 5 is still the default. * The QT_NO_SOUND macro now excludes all headers and declarations relating to sound; the multimedia package is not needed to build (on any Qt 4, 5 or 6). * A new function, nh_qsprintf, replaces QString::asprintf, for Qt older than 5.5. These versions do not have QString::asprintf. * DYNAMIC_STATUSLINES is disabled for Qt older than 5.9. These versions do not have QSplitter::replaceWidget.
This commit is contained in:
@@ -106,6 +106,11 @@ ifndef WANT_WIN_QT
|
|||||||
ifdef WANT_WIN_ALL
|
ifdef WANT_WIN_ALL
|
||||||
WANT_WIN_QT=1
|
WANT_WIN_QT=1
|
||||||
endif
|
endif
|
||||||
|
ifdef WANT_WIN_QT4
|
||||||
|
ifndef WANT_WIN_QT
|
||||||
|
WANT_WIN_QT=1
|
||||||
|
endif # not WANT_WIN_QT
|
||||||
|
endif # WANT_WIN_QT4
|
||||||
ifdef WANT_WIN_QT5
|
ifdef WANT_WIN_QT5
|
||||||
ifndef WANT_WIN_QT
|
ifndef WANT_WIN_QT
|
||||||
WANT_WIN_QT=1
|
WANT_WIN_QT=1
|
||||||
@@ -120,11 +125,19 @@ endif # not def WANT_WIN_QT
|
|||||||
|
|
||||||
ifdef WANT_WIN_QT
|
ifdef WANT_WIN_QT
|
||||||
# WANT_WIN_QT5 is the default
|
# WANT_WIN_QT5 is the default
|
||||||
|
ifndef WANT_WIN_QT4
|
||||||
ifndef WANT_WIN_QT5
|
ifndef WANT_WIN_QT5
|
||||||
ifndef WANT_WIN_QT6
|
ifndef WANT_WIN_QT6
|
||||||
WANT_WIN_QT5=1
|
WANT_WIN_QT5=1
|
||||||
endif # not WANT_WIN_QT6
|
endif # not WANT_WIN_QT6
|
||||||
endif # not WANT_WIN_QT5
|
endif # not WANT_WIN_QT5
|
||||||
|
endif # not WANT_WIN_QT4
|
||||||
|
ifdef WANT_WIN_QT4
|
||||||
|
#Slackware 14.2 puts Qt4 here
|
||||||
|
#if your Qt4 is elsewhere, change this to match
|
||||||
|
QT4DIR=/usr/lib64/qt
|
||||||
|
QTDIR=$(QT4DIR)
|
||||||
|
endif # WANT_WIN_QT4
|
||||||
endif # WANT_WIN_QT
|
endif # WANT_WIN_QT
|
||||||
|
|
||||||
ifdef WANT_WIN_QT
|
ifdef WANT_WIN_QT
|
||||||
|
|||||||
@@ -154,6 +154,10 @@ endif # WANT_WIN_X11
|
|||||||
|
|
||||||
ifdef WANT_WIN_QT
|
ifdef WANT_WIN_QT
|
||||||
LINK = $(CXX)
|
LINK = $(CXX)
|
||||||
|
ifdef WANT_WIN_QT4
|
||||||
|
QTCXXFLAGS += $(sort $(shell PKG_CONFIG_PATH=$(QTDIR)/lib/pkgconfig pkg-config QtGui --cflags)) -DQT_NO_SOUND=1
|
||||||
|
WINLIB += $(shell PKG_CONFIG_PATH=$(QTDIR)/lib/pkgconfig pkg-config QtGui --libs)
|
||||||
|
endif # WANT_WIN_QT4
|
||||||
ifdef WANT_WIN_QT5
|
ifdef WANT_WIN_QT5
|
||||||
QTCXXFLAGS += $(sort $(shell PKG_CONFIG_PATH=$(QTDIR)/lib/pkgconfig pkg-config Qt5Gui Qt5Widgets Qt5Multimedia --cflags))
|
QTCXXFLAGS += $(sort $(shell PKG_CONFIG_PATH=$(QTDIR)/lib/pkgconfig pkg-config Qt5Gui Qt5Widgets Qt5Multimedia --cflags))
|
||||||
WINLIB += $(shell PKG_CONFIG_PATH=$(QTDIR)/lib/pkgconfig pkg-config Qt5Gui Qt5Widgets Qt5Multimedia --libs)
|
WINLIB += $(shell PKG_CONFIG_PATH=$(QTDIR)/lib/pkgconfig pkg-config Qt5Gui Qt5Widgets Qt5Multimedia --libs)
|
||||||
|
|||||||
+5
-1
@@ -11,6 +11,7 @@ extern "C" {
|
|||||||
#include "qt_pre.h"
|
#include "qt_pre.h"
|
||||||
#include <QtGui/QtGui>
|
#include <QtGui/QtGui>
|
||||||
#include <QtCore/QStringList>
|
#include <QtCore/QStringList>
|
||||||
|
#if defined(USER_SOUNDS) && !defined(QT_NO_SOUND)
|
||||||
#if QT_VERSION < 0x050000
|
#if QT_VERSION < 0x050000
|
||||||
#include <QtGui/QSoundEffect>
|
#include <QtGui/QSoundEffect>
|
||||||
#elif QT_VERSION < 0x060000
|
#elif QT_VERSION < 0x060000
|
||||||
@@ -21,6 +22,7 @@ extern "C" {
|
|||||||
#include <QtWidgets/QtWidgets>
|
#include <QtWidgets/QtWidgets>
|
||||||
#include <QSoundEffect>
|
#include <QSoundEffect>
|
||||||
#endif /* QT_VERSION */
|
#endif /* QT_VERSION */
|
||||||
|
#endif /* USER_SOUNDS && !QT_NO_SOUND */
|
||||||
#include "qt_post.h"
|
#include "qt_post.h"
|
||||||
#include "qt_bind.h"
|
#include "qt_bind.h"
|
||||||
#include "qt_click.h"
|
#include "qt_click.h"
|
||||||
@@ -446,7 +448,7 @@ void NetHackQtBind::qt_display_file(const char *filename, boolean must_exist)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (complain) {
|
if (complain) {
|
||||||
QString message = QString::asprintf("File not found: %s\n",filename);
|
QString message = nh_qsprintf("File not found: %s\n",filename);
|
||||||
QMessageBox::warning(NULL, "File Error", message, QMessageBox::Ignore);
|
QMessageBox::warning(NULL, "File Error", message, QMessageBox::Ignore);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1118,7 +1120,9 @@ struct window_procs Qt_procs = {
|
|||||||
#ifndef WIN32
|
#ifndef WIN32
|
||||||
extern "C" void play_usersound(const char *, int);
|
extern "C" void play_usersound(const char *, int);
|
||||||
|
|
||||||
|
#if defined(USER_SOUNDS) && !defined(QT_NO_SOUND)
|
||||||
QSoundEffect *effect = NULL;
|
QSoundEffect *effect = NULL;
|
||||||
|
#endif
|
||||||
|
|
||||||
/* called from core, sounds.c */
|
/* called from core, sounds.c */
|
||||||
void
|
void
|
||||||
|
|||||||
+4
-4
@@ -63,10 +63,10 @@ NetHackQtGlyphs::NetHackQtGlyphs()
|
|||||||
|
|
||||||
if (!tile_file) {
|
if (!tile_file) {
|
||||||
tilesok = FALSE;
|
tilesok = FALSE;
|
||||||
QString msg = QString::asprintf("Cannot load '%s'.",
|
QString msg = nh_qsprintf("Cannot load '%s'.",
|
||||||
user_tiles ? tile_list[0]
|
user_tiles ? tile_list[0]
|
||||||
// mismatched quotes match format
|
// mismatched quotes match format
|
||||||
: "nhtiles.bmp' or 'x11tiles");
|
: "nhtiles.bmp' or 'x11tiles");
|
||||||
QMessageBox::warning(0, "IO Error", msg);
|
QMessageBox::warning(0, "IO Error", msg);
|
||||||
} else {
|
} else {
|
||||||
if (img.width() % tiles_per_row) {
|
if (img.width() % tiles_per_row) {
|
||||||
|
|||||||
+2
-1
@@ -35,6 +35,7 @@ extern "C" {
|
|||||||
#endif
|
#endif
|
||||||
#include "qt_post.h"
|
#include "qt_post.h"
|
||||||
#include "qt_icon.h"
|
#include "qt_icon.h"
|
||||||
|
#include "qt_str.h"
|
||||||
|
|
||||||
namespace nethack_qt_ {
|
namespace nethack_qt_ {
|
||||||
|
|
||||||
@@ -106,7 +107,7 @@ void NetHackQtLabelledIcon::setLabel(const QString& t, long v, long cv,
|
|||||||
if (v==NoNum) {
|
if (v==NoNum) {
|
||||||
buf = "";
|
buf = "";
|
||||||
} else {
|
} else {
|
||||||
buf = QString::asprintf("%ld", v);
|
buf = nh_qsprintf("%ld", v);
|
||||||
}
|
}
|
||||||
setLabel(t + buf + tail, cv < prev_value);
|
setLabel(t + buf + tail, cv < prev_value);
|
||||||
prev_value=cv;
|
prev_value=cv;
|
||||||
|
|||||||
+3
-3
@@ -13,7 +13,7 @@ extern "C" {
|
|||||||
#include <QtGui/QtGui>
|
#include <QtGui/QtGui>
|
||||||
#if QT_VERSION >= 0x060000
|
#if QT_VERSION >= 0x060000
|
||||||
#include <QtGui/QShortcut>
|
#include <QtGui/QShortcut>
|
||||||
#else
|
#elif QT_VERSION >= 0x050000
|
||||||
#include <QtWidgets/QShortcut>
|
#include <QtWidgets/QShortcut>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -463,7 +463,7 @@ aboutMsg()
|
|||||||
*p = '\0';
|
*p = '\0';
|
||||||
/* it's also long; break it into two pieces */
|
/* it's also long; break it into two pieces */
|
||||||
(void) strsubst(vbuf, " - ", "\n- ");
|
(void) strsubst(vbuf, " - ", "\n- ");
|
||||||
QString msg = QString::asprintf(
|
QString msg = nh_qsprintf(
|
||||||
// format
|
// format
|
||||||
"NetHack-Qt is a version of NetHack built using" // no newline
|
"NetHack-Qt is a version of NetHack built using" // no newline
|
||||||
#ifdef KDE
|
#ifdef KDE
|
||||||
@@ -1034,7 +1034,7 @@ void NetHackQtMainWindow::doQuit(bool)
|
|||||||
// nethack's #quit command itself) but this routine is unconditional
|
// nethack's #quit command itself) but this routine is unconditional
|
||||||
// in case someone wants to change that
|
// in case someone wants to change that
|
||||||
#ifdef MACOS
|
#ifdef MACOS
|
||||||
QString info = QString::asprintf("This will end your NetHack session.%s",
|
QString info = nh_qsprintf("This will end your NetHack session.%s",
|
||||||
!g.program_state.something_worth_saving ? ""
|
!g.program_state.something_worth_saving ? ""
|
||||||
: "\n(Cancel quitting and use the Save command"
|
: "\n(Cancel quitting and use the Save command"
|
||||||
"\nto save your current game.)");
|
"\nto save your current game.)");
|
||||||
|
|||||||
@@ -17,7 +17,9 @@
|
|||||||
// Allow changing 'statuslines:2' to 'statuslines:3' or vice versa
|
// Allow changing 'statuslines:2' to 'statuslines:3' or vice versa
|
||||||
// while the game is running; deletes and re-creates the status window.
|
// while the game is running; deletes and re-creates the status window.
|
||||||
// [Used in qt_bind.cpp and qt_main.cpp, but not referenced in qt_stat.cpp.]
|
// [Used in qt_bind.cpp and qt_main.cpp, but not referenced in qt_stat.cpp.]
|
||||||
|
#if QT_VERSION >= QT_VERSION_CHECK(5, 9, 0)
|
||||||
#define DYNAMIC_STATUSLINES
|
#define DYNAMIC_STATUSLINES
|
||||||
|
#endif
|
||||||
|
|
||||||
// NetHackQtBind::notify() doesn't see ^V on OSX
|
// NetHackQtBind::notify() doesn't see ^V on OSX
|
||||||
#ifdef MACOS
|
#ifdef MACOS
|
||||||
|
|||||||
+5
-6
@@ -383,8 +383,8 @@ void NetHackQtMenuWindow::PadMenuColumns(bool split_descr)
|
|||||||
QFontMetrics fm(table->font());
|
QFontMetrics fm(table->font());
|
||||||
QString col0width_str = "";
|
QString col0width_str = "";
|
||||||
if (biggestcount > 0L)
|
if (biggestcount > 0L)
|
||||||
col0width_str = QString::asprintf("%*ld", std::max(countdigits, 1),
|
col0width_str = nh_qsprintf("%*ld", std::max(countdigits, 1),
|
||||||
biggestcount);
|
biggestcount);
|
||||||
int col0width_int = (int) fm.QFM_WIDTH(col0width_str) + MENU_WIDTH_SLOP;
|
int col0width_int = (int) fm.QFM_WIDTH(col0width_str) + MENU_WIDTH_SLOP;
|
||||||
if (col0width_int > table->columnWidth(0))
|
if (col0width_int > table->columnWidth(0))
|
||||||
WidenColumn(0, col0width_int);
|
WidenColumn(0, col0width_int);
|
||||||
@@ -427,7 +427,7 @@ void NetHackQtMenuWindow::PadMenuColumns(bool split_descr)
|
|||||||
QString Amt = "";
|
QString Amt = "";
|
||||||
long amt = count(row); // fetch item(row,0) as a number
|
long amt = count(row); // fetch item(row,0) as a number
|
||||||
if (amt > 0L)
|
if (amt > 0L)
|
||||||
Amt = QString::asprintf("%*ld", countdigits, amt);
|
Amt = nh_qsprintf("%*ld", countdigits, amt);
|
||||||
cnt->setText(Amt);
|
cnt->setText(Amt);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -470,8 +470,7 @@ void NetHackQtMenuWindow::UpdateCountColumn(long newcount)
|
|||||||
} else {
|
} else {
|
||||||
biggestcount = std::max(biggestcount, newcount);
|
biggestcount = std::max(biggestcount, newcount);
|
||||||
QString num;
|
QString num;
|
||||||
num = QString::asprintf("%*ld", std::max(countdigits, 1),
|
num = nh_qsprintf("%*ld", std::max(countdigits, 1), biggestcount);
|
||||||
biggestcount);
|
|
||||||
int numlen = (int) num.length();
|
int numlen = (int) num.length();
|
||||||
if (numlen % 2)
|
if (numlen % 2)
|
||||||
++numlen;
|
++numlen;
|
||||||
@@ -903,7 +902,7 @@ void NetHackQtMenuWindow::ToggleSelect(int row, bool already_toggled)
|
|||||||
amt = count(row); // fetch item(row,0) as a number
|
amt = count(row); // fetch item(row,0) as a number
|
||||||
QString Amt = "";
|
QString Amt = "";
|
||||||
if (amt > 0L)
|
if (amt > 0L)
|
||||||
Amt = QString::asprintf("%*ld", countdigits, amt);
|
Amt = nh_qsprintf("%*ld", countdigits, amt);
|
||||||
countfield->setText(Amt); // store right-justified value
|
countfield->setText(Amt); // store right-justified value
|
||||||
}
|
}
|
||||||
ClearCount(); // blank out 'countstr' and reset 'counting'
|
ClearCount(); // blank out 'countstr' and reset 'counting'
|
||||||
|
|||||||
+1
-1
@@ -36,7 +36,7 @@ tryload(QPixmap& pm, const char* fn)
|
|||||||
{
|
{
|
||||||
if (!pm.load(fn)) {
|
if (!pm.load(fn)) {
|
||||||
QString msg;
|
QString msg;
|
||||||
msg = QString::asprintf("Cannot load \"%s\"", fn);
|
msg = nh_qsprintf("Cannot load \"%s\"", fn);
|
||||||
QMessageBox::warning(NetHackQtBind::mainWidget(), "IO Error", msg);
|
QMessageBox::warning(NetHackQtBind::mainWidget(), "IO Error", msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+17
-21
@@ -643,8 +643,7 @@ void NetHackQtStatusWindow::HitpointBar()
|
|||||||
geoH.setRight(std::min(lox + pxl_health - 1, hix));
|
geoH.setRight(std::min(lox + pxl_health - 1, hix));
|
||||||
hpbar_health.setGeometry(geoH);
|
hpbar_health.setGeometry(geoH);
|
||||||
w = geoH.right() - geoH.left() + 1; // might yield 0 (ie, if dead)
|
w = geoH.right() - geoH.left() + 1; // might yield 0 (ie, if dead)
|
||||||
styleH = QString::asprintf(styleformat, barcolors[colorindx][0],
|
styleH = nh_qsprintf(styleformat, barcolors[colorindx][0], w, w);
|
||||||
w, w);
|
|
||||||
hpbar_health.setStyleSheet(styleH);
|
hpbar_health.setStyleSheet(styleH);
|
||||||
// when healing, having the old injury-side shown while the new
|
// when healing, having the old injury-side shown while the new
|
||||||
// health-side expands pushes the injury farther right and it's
|
// health-side expands pushes the injury farther right and it's
|
||||||
@@ -657,8 +656,7 @@ void NetHackQtStatusWindow::HitpointBar()
|
|||||||
geoI.setRight(hix);
|
geoI.setRight(hix);
|
||||||
hpbar_injury.setGeometry(geoI);
|
hpbar_injury.setGeometry(geoI);
|
||||||
w = geoI.right() - geoI.left() + 1;
|
w = geoI.right() - geoI.left() + 1;
|
||||||
styleI = QString::asprintf(styleformat, barcolors[colorindx][1],
|
styleI = nh_qsprintf(styleformat, barcolors[colorindx][1], w, w);
|
||||||
w, w);
|
|
||||||
hpbar_injury.setStyleSheet(styleI);
|
hpbar_injury.setStyleSheet(styleI);
|
||||||
if (geoI.left() != oldleft)
|
if (geoI.left() != oldleft)
|
||||||
hpbar_injury.move(geoI.left(), geoI.top());
|
hpbar_injury.move(geoI.left(), geoI.top());
|
||||||
@@ -676,8 +674,7 @@ void NetHackQtStatusWindow::HitpointBar()
|
|||||||
geoH.setRight(hix);
|
geoH.setRight(hix);
|
||||||
hpbar_health.setGeometry(geoH);
|
hpbar_health.setGeometry(geoH);
|
||||||
w = geoH.right() - geoH.left() + 1;
|
w = geoH.right() - geoH.left() + 1;
|
||||||
styleH = QString::asprintf(styleformat, barcolors[colorindx][0],
|
styleH = nh_qsprintf(styleformat, barcolors[colorindx][0], w, w);
|
||||||
w, w);
|
|
||||||
hpbar_health.setStyleSheet(styleH);
|
hpbar_health.setStyleSheet(styleH);
|
||||||
hpbar_health.show();
|
hpbar_health.show();
|
||||||
|
|
||||||
@@ -728,13 +725,13 @@ void NetHackQtStatusWindow::updateStats()
|
|||||||
|
|
||||||
int st = ACURR(A_STR);
|
int st = ACURR(A_STR);
|
||||||
if (st > STR18(100)) {
|
if (st > STR18(100)) {
|
||||||
buf = QString::asprintf("Str:%d", st - 100); // 19..25
|
buf = nh_qsprintf("Str:%d", st - 100); // 19..25
|
||||||
} else if (st == STR18(100)) {
|
} else if (st == STR18(100)) {
|
||||||
buf = QString::asprintf("Str:18/**"); // 18/100
|
buf = nh_qsprintf("Str:18/**"); // 18/100
|
||||||
} else if (st > 18) {
|
} else if (st > 18) {
|
||||||
buf = QString::asprintf("Str:18/%02d", st - 18); // 18/01..18/99
|
buf = nh_qsprintf("Str:18/%02d", st - 18); // 18/01..18/99
|
||||||
} else {
|
} else {
|
||||||
buf = QString::asprintf("Str:%d", st); // 3..18
|
buf = nh_qsprintf("Str:%d", st); // 3..18
|
||||||
}
|
}
|
||||||
str.setLabel(buf, NetHackQtLabelledIcon::NoNum, (long) st);
|
str.setLabel(buf, NetHackQtLabelledIcon::NoNum, (long) st);
|
||||||
dex.setLabel("Dex:", (long) ACURR(A_DEX));
|
dex.setLabel("Dex:", (long) ACURR(A_DEX));
|
||||||
@@ -824,8 +821,8 @@ void NetHackQtStatusWindow::updateStats()
|
|||||||
}
|
}
|
||||||
QString buf2;
|
QString buf2;
|
||||||
char buf3[BUFSZ];
|
char buf3[BUFSZ];
|
||||||
buf2 = QString::asprintf("%s the %s", upstart(strcpy(buf3, g.plname)),
|
buf2 = nh_qsprintf("%s the %s", upstart(strcpy(buf3, g.plname)),
|
||||||
buf.toLatin1().constData());
|
buf.toLatin1().constData());
|
||||||
name.setLabel(buf2, NetHackQtLabelledIcon::NoNum, u.ulevel);
|
name.setLabel(buf2, NetHackQtLabelledIcon::NoNum, u.ulevel);
|
||||||
|
|
||||||
if (!describe_level(buf3, 0)) {
|
if (!describe_level(buf3, 0)) {
|
||||||
@@ -843,13 +840,13 @@ void NetHackQtStatusWindow::updateStats()
|
|||||||
level.setCompareMode(NeitherIsBetter);
|
level.setCompareMode(NeitherIsBetter);
|
||||||
if (Upolyd) {
|
if (Upolyd) {
|
||||||
// You're a monster!
|
// You're a monster!
|
||||||
buf = QString::asprintf("/%d", u.mhmax);
|
buf = nh_qsprintf("/%d", u.mhmax);
|
||||||
hp.setLabel("HP:", std::max((long) u.mh, 0L), buf);
|
hp.setLabel("HP:", std::max((long) u.mh, 0L), buf);
|
||||||
level.setLabel("HD:", (long) mons[u.umonnum].mlevel); // hit dice
|
level.setLabel("HD:", (long) mons[u.umonnum].mlevel); // hit dice
|
||||||
// Exp points are not shown when HD is displayed instead of Xp level
|
// Exp points are not shown when HD is displayed instead of Xp level
|
||||||
} else {
|
} else {
|
||||||
// You're normal.
|
// You're normal.
|
||||||
buf = QString::asprintf("/%d", u.uhpmax);
|
buf = nh_qsprintf("/%d", u.uhpmax);
|
||||||
hp.setLabel("HP:", std::max((long) u.uhp, 0L), buf);
|
hp.setLabel("HP:", std::max((long) u.uhp, 0L), buf);
|
||||||
// if Exp points are to be displayed, append them to Xp level;
|
// if Exp points are to be displayed, append them to Xp level;
|
||||||
// up/down highlighting becomes tricky--don't try very hard;
|
// up/down highlighting becomes tricky--don't try very hard;
|
||||||
@@ -860,11 +857,10 @@ void NetHackQtStatusWindow::updateStats()
|
|||||||
for (int i = ::flags.showexp ? 0 : 3; i < 4; ++i) {
|
for (int i = ::flags.showexp ? 0 : 3; i < 4; ++i) {
|
||||||
// passes 0,1,2 are with Exp, 3 is without Exp and always fits
|
// passes 0,1,2 are with Exp, 3 is without Exp and always fits
|
||||||
if (i < 3) {
|
if (i < 3) {
|
||||||
buf = QString::asprintf("%s%ld/%ld", lvllbl[i],
|
buf = nh_qsprintf("%s%ld/%ld", lvllbl[i], (long) u.ulevel,
|
||||||
(long) u.ulevel, u.uexp);
|
u.uexp);
|
||||||
} else {
|
} else {
|
||||||
buf = QString::asprintf("%s%ld", lvllbl[i - 3],
|
buf = nh_qsprintf("%s%ld", lvllbl[i - 3], (long) u.ulevel);
|
||||||
(long) u.ulevel);
|
|
||||||
}
|
}
|
||||||
// +2: allow a couple of pixels at either end to be clipped off
|
// +2: allow a couple of pixels at either end to be clipped off
|
||||||
if (fm.size(0, buf).width() <= (2 + level.label->width() + 2))
|
if (fm.size(0, buf).width() <= (2 + level.label->width() + 2))
|
||||||
@@ -884,7 +880,7 @@ void NetHackQtStatusWindow::updateStats()
|
|||||||
was_polyd = Upolyd ? true : false;
|
was_polyd = Upolyd ? true : false;
|
||||||
had_exp = (::flags.showexp && !was_polyd) ? true : false;
|
had_exp = (::flags.showexp && !was_polyd) ? true : false;
|
||||||
|
|
||||||
buf = QString::asprintf("/%d", u.uenmax);
|
buf = nh_qsprintf("/%d", u.uenmax);
|
||||||
power.setLabel("Pow:", (long) u.uen, buf);
|
power.setLabel("Pow:", (long) u.uen, buf);
|
||||||
ac.setLabel("AC:", (long) u.uac);
|
ac.setLabel("AC:", (long) u.uac);
|
||||||
// gold prefix used to be "Au:", tty uses "$:"; never too wide to fit;
|
// gold prefix used to be "Au:", tty uses "$:"; never too wide to fit;
|
||||||
@@ -910,7 +906,7 @@ void NetHackQtStatusWindow::updateStats()
|
|||||||
: (u.ualign.type == A_NONE) ? "unaligned"
|
: (u.ualign.type == A_NONE) ? "unaligned"
|
||||||
: "other?";
|
: "other?";
|
||||||
}
|
}
|
||||||
qtext = QString::asprintf("%sly aligned", text);
|
qtext = nh_qsprintf("%sly aligned", text);
|
||||||
align.setIcon(*pxmp, qtext.toLower());
|
align.setIcon(*pxmp, qtext.toLower());
|
||||||
align.setLabel(QString(text));
|
align.setLabel(QString(text));
|
||||||
// without this, the ankh pixmap shifts from centered to left
|
// without this, the ankh pixmap shifts from centered to left
|
||||||
@@ -948,7 +944,7 @@ void NetHackQtStatusWindow::updateStats()
|
|||||||
static const char *const scrlbl[3] = { "Score:", "Scr:", "S:" };
|
static const char *const scrlbl[3] = { "Score:", "Scr:", "S:" };
|
||||||
QFontMetrics fm(score.label->font());
|
QFontMetrics fm(score.label->font());
|
||||||
for (int i = 0; i < 3; ++i) {
|
for (int i = 0; i < 3; ++i) {
|
||||||
buf = QString::asprintf("%s%ld", scrlbl[i], pts);
|
buf = nh_qsprintf("%s%ld", scrlbl[i], pts);
|
||||||
// +2: allow couple of pixels at either end to be clipped off
|
// +2: allow couple of pixels at either end to be clipped off
|
||||||
if (fm.size(0, buf).width() <= (2 + score.width() + 2))
|
if (fm.size(0, buf).width() <= (2 + score.width() + 2))
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
|
|
||||||
#include <QtCore/QString>
|
#include <QtCore/QString>
|
||||||
#include <QtCore/QStringList>
|
#include <QtCore/QStringList>
|
||||||
|
#include <cstdarg>
|
||||||
#include "qt_str.h"
|
#include "qt_str.h"
|
||||||
|
|
||||||
namespace nethack_qt_ {
|
namespace nethack_qt_ {
|
||||||
@@ -80,4 +81,20 @@ int cp437(int ch)
|
|||||||
return cp437table[(unsigned char)ch];
|
return cp437table[(unsigned char)ch];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString
|
||||||
|
nh_qsprintf(const char *format, ...)
|
||||||
|
{
|
||||||
|
QString msg;
|
||||||
|
std::va_list args;
|
||||||
|
|
||||||
|
va_start(args, format);
|
||||||
|
#if QT_VERSION >= QT_VERSION_CHECK(5, 5, 0)
|
||||||
|
msg = QString::vasprintf(format, args);
|
||||||
|
#else
|
||||||
|
msg.vsprintf(format, args);
|
||||||
|
#endif
|
||||||
|
va_end(args);
|
||||||
|
return msg;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace nethack_qt_
|
} // namespace nethack_qt_
|
||||||
|
|||||||
@@ -19,6 +19,13 @@ extern QString nh_capitalize_words(const QString& str);
|
|||||||
// Map symbol conversion
|
// Map symbol conversion
|
||||||
extern int cp437(int ch);
|
extern int cp437(int ch);
|
||||||
|
|
||||||
|
// sprintf
|
||||||
|
extern QString nh_qsprintf(const char *format, ...)
|
||||||
|
#if defined(__GNUC__) && (__GNUC__ >= 2)
|
||||||
|
__attribute__((format(printf, 1, 2)))
|
||||||
|
#endif
|
||||||
|
;
|
||||||
|
|
||||||
} // namespace nethack_qt_
|
} // namespace nethack_qt_
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+1
-1
@@ -294,7 +294,7 @@ NetHackQtExtCmdRequestor::NetHackQtExtCmdRequestor(QWidget *parent) :
|
|||||||
QString btn_lbl = extcmdlist[i].ef_txt;
|
QString btn_lbl = extcmdlist[i].ef_txt;
|
||||||
if (btn_lbl == "wait")
|
if (btn_lbl == "wait")
|
||||||
btn_lbl += " (rest)";
|
btn_lbl += " (rest)";
|
||||||
QString btn_tip = QString::asprintf(" %s ", extcmdlist[i].ef_desc);
|
QString btn_tip = nh_qsprintf(" %s ", extcmdlist[i].ef_desc);
|
||||||
QPushButton *pb = new QPushButton(btn_lbl, grid);
|
QPushButton *pb = new QPushButton(btn_lbl, grid);
|
||||||
pb->setMinimumSize(butw, pb->sizeHint().height());
|
pb->setMinimumSize(butw, pb->sizeHint().height());
|
||||||
// force the button to have fixed width or it can move around a
|
// force the button to have fixed width or it can move around a
|
||||||
|
|||||||
Reference in New Issue
Block a user