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.
ifdef WANT_WIN_ALL
WANT_WIN_QT=1
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
ifndef WANT_WIN_QT
WANT_WIN_QT=1
ifdef WANT_WIN_QT
# WANT_WIN_QT5 is the default
+ifndef WANT_WIN_QT4
ifndef WANT_WIN_QT5
ifndef WANT_WIN_QT6
WANT_WIN_QT5=1
endif # not WANT_WIN_QT6
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
ifdef WANT_WIN_QT
ifdef WANT_WIN_QT
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
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)
#include "qt_pre.h"
#include <QtGui/QtGui>
#include <QtCore/QStringList>
+#if defined(USER_SOUNDS) && !defined(QT_NO_SOUND)
#if QT_VERSION < 0x050000
#include <QtGui/QSoundEffect>
#elif QT_VERSION < 0x060000
#include <QtWidgets/QtWidgets>
#include <QSoundEffect>
#endif /* QT_VERSION */
+#endif /* USER_SOUNDS && !QT_NO_SOUND */
#include "qt_post.h"
#include "qt_bind.h"
#include "qt_click.h"
}
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);
}
}
#ifndef WIN32
extern "C" void play_usersound(const char *, int);
+#if defined(USER_SOUNDS) && !defined(QT_NO_SOUND)
QSoundEffect *effect = NULL;
+#endif
/* called from core, sounds.c */
void
if (!tile_file) {
tilesok = FALSE;
- QString msg = QString::asprintf("Cannot load '%s'.",
- user_tiles ? tile_list[0]
- // mismatched quotes match format
- : "nhtiles.bmp' or 'x11tiles");
+ QString msg = nh_qsprintf("Cannot load '%s'.",
+ user_tiles ? tile_list[0]
+ // mismatched quotes match format
+ : "nhtiles.bmp' or 'x11tiles");
QMessageBox::warning(0, "IO Error", msg);
} else {
if (img.width() % tiles_per_row) {
#endif
#include "qt_post.h"
#include "qt_icon.h"
+#include "qt_str.h"
namespace nethack_qt_ {
if (v==NoNum) {
buf = "";
} else {
- buf = QString::asprintf("%ld", v);
+ buf = nh_qsprintf("%ld", v);
}
setLabel(t + buf + tail, cv < prev_value);
prev_value=cv;
#include <QtGui/QtGui>
#if QT_VERSION >= 0x060000
#include <QtGui/QShortcut>
-#else
+#elif QT_VERSION >= 0x050000
#include <QtWidgets/QShortcut>
#endif
*p = '\0';
/* it's also long; break it into two pieces */
(void) strsubst(vbuf, " - ", "\n- ");
- QString msg = QString::asprintf(
+ QString msg = nh_qsprintf(
// 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 = 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 ? ""
: "\n(Cancel quitting and use the Save command"
"\nto save your current game.)");
// Allow changing 'statuslines:2' to 'statuslines:3' or vice versa
// 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.]
+#if QT_VERSION >= QT_VERSION_CHECK(5, 9, 0)
#define DYNAMIC_STATUSLINES
+#endif
// NetHackQtBind::notify() doesn't see ^V on OSX
#ifdef MACOS
QFontMetrics fm(table->font());
QString col0width_str = "";
if (biggestcount > 0L)
- col0width_str = QString::asprintf("%*ld", std::max(countdigits, 1),
- biggestcount);
+ col0width_str = nh_qsprintf("%*ld", std::max(countdigits, 1),
+ biggestcount);
int col0width_int = (int) fm.QFM_WIDTH(col0width_str) + MENU_WIDTH_SLOP;
if (col0width_int > table->columnWidth(0))
WidenColumn(0, col0width_int);
QString Amt = "";
long amt = count(row); // fetch item(row,0) as a number
if (amt > 0L)
- Amt = QString::asprintf("%*ld", countdigits, amt);
+ Amt = nh_qsprintf("%*ld", countdigits, amt);
cnt->setText(Amt);
}
} else {
biggestcount = std::max(biggestcount, newcount);
QString num;
- num = QString::asprintf("%*ld", std::max(countdigits, 1),
- biggestcount);
+ num = nh_qsprintf("%*ld", std::max(countdigits, 1), biggestcount);
int numlen = (int) num.length();
if (numlen % 2)
++numlen;
amt = count(row); // fetch item(row,0) as a number
QString Amt = "";
if (amt > 0L)
- Amt = QString::asprintf("%*ld", countdigits, amt);
+ Amt = nh_qsprintf("%*ld", countdigits, amt);
countfield->setText(Amt); // store right-justified value
}
ClearCount(); // blank out 'countstr' and reset 'counting'
{
if (!pm.load(fn)) {
QString msg;
- msg = QString::asprintf("Cannot load \"%s\"", fn);
+ msg = nh_qsprintf("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 = QString::asprintf(styleformat, barcolors[colorindx][0],
- w, w);
+ styleH = nh_qsprintf(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 = QString::asprintf(styleformat, barcolors[colorindx][1],
- w, w);
+ styleI = nh_qsprintf(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 = QString::asprintf(styleformat, barcolors[colorindx][0],
- w, w);
+ styleH = nh_qsprintf(styleformat, barcolors[colorindx][0], w, w);
hpbar_health.setStyleSheet(styleH);
hpbar_health.show();
int st = ACURR(A_STR);
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)) {
- buf = QString::asprintf("Str:18/**"); // 18/100
+ buf = nh_qsprintf("Str:18/**"); // 18/100
} 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 {
- buf = QString::asprintf("Str:%d", st); // 3..18
+ buf = nh_qsprintf("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 = QString::asprintf("%s the %s", upstart(strcpy(buf3, g.plname)),
- buf.toLatin1().constData());
+ buf2 = nh_qsprintf("%s the %s", upstart(strcpy(buf3, g.plname)),
+ buf.toLatin1().constData());
name.setLabel(buf2, NetHackQtLabelledIcon::NoNum, u.ulevel);
if (!describe_level(buf3, 0)) {
level.setCompareMode(NeitherIsBetter);
if (Upolyd) {
// 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);
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 = QString::asprintf("/%d", u.uhpmax);
+ buf = nh_qsprintf("/%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 = QString::asprintf("%s%ld/%ld", lvllbl[i],
- (long) u.ulevel, u.uexp);
+ buf = nh_qsprintf("%s%ld/%ld", lvllbl[i], (long) u.ulevel,
+ u.uexp);
} else {
- buf = QString::asprintf("%s%ld", lvllbl[i - 3],
- (long) u.ulevel);
+ buf = nh_qsprintf("%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 = QString::asprintf("/%d", u.uenmax);
+ buf = nh_qsprintf("/%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;
: (u.ualign.type == A_NONE) ? "unaligned"
: "other?";
}
- qtext = QString::asprintf("%sly aligned", text);
+ qtext = nh_qsprintf("%sly aligned", text);
align.setIcon(*pxmp, qtext.toLower());
align.setLabel(QString(text));
// without this, the ankh pixmap shifts from centered to left
static const char *const scrlbl[3] = { "Score:", "Scr:", "S:" };
QFontMetrics fm(score.label->font());
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
if (fm.size(0, buf).width() <= (2 + score.width() + 2))
break;
#include <QtCore/QString>
#include <QtCore/QStringList>
+#include <cstdarg>
#include "qt_str.h"
namespace nethack_qt_ {
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_
// Map symbol conversion
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_
#endif
QString btn_lbl = extcmdlist[i].ef_txt;
if (btn_lbl == "wait")
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);
pb->setMinimumSize(butw, pb->sizeHint().height());
// force the button to have fixed width or it can move around a