Qt: deprecation warnings, again
Check Qt version for the QFontMetrics::width vs horizontalAdvance. Of course can't just #define horizontalAdvance to width, that would be too easy ...
This commit is contained in:
@@ -145,7 +145,7 @@ void NetHackQtMapViewport::SetupTextmapFont(QPainter &painter)
|
||||
QFont f(fontfamily, pts, maybebold);
|
||||
painter.setFont(QFont(fontfamily, pts));
|
||||
QFontMetrics fm = painter.fontMetrics();
|
||||
if (fm.horizontalAdvance("M") > qt_settings->glyphs().width())
|
||||
if (fm.QFM_WIDTH("M") > qt_settings->glyphs().width())
|
||||
break;
|
||||
if (fm.height() > qt_settings->glyphs().height())
|
||||
break;
|
||||
|
||||
@@ -379,7 +379,7 @@ void NetHackQtMenuWindow::PadMenuColumns(bool split_descr)
|
||||
QString col0width_str = "";
|
||||
if (biggestcount > 0L)
|
||||
col0width_str = QString::asprintf("%*ld", std::max(countdigits, 1), biggestcount);
|
||||
int col0width_int = (int) fm.horizontalAdvance(col0width_str) + MENU_WIDTH_SLOP;
|
||||
int col0width_int = (int) fm.QFM_WIDTH(col0width_str) + MENU_WIDTH_SLOP;
|
||||
if (col0width_int > table->columnWidth(0))
|
||||
WidenColumn(0, col0width_int);
|
||||
|
||||
@@ -401,7 +401,7 @@ void NetHackQtMenuWindow::PadMenuColumns(bool split_descr)
|
||||
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.horizontalAdvance(columns[fld] + (lastcol ? "" : " "));
|
||||
int w = fm.QFM_WIDTH(columns[fld] + (lastcol ? "" : " "));
|
||||
if (fld >= (int) col_widths.size()) {
|
||||
col_widths.push_back(w); // add another element
|
||||
} else if (col_widths[fld] < w) {
|
||||
@@ -435,14 +435,14 @@ void NetHackQtMenuWindow::PadMenuColumns(bool split_descr)
|
||||
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.horizontalAdvance(columns[fld]) < width)
|
||||
while (fm.QFM_WIDTH(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.horizontalAdvance(text) + MENU_WIDTH_SLOP;
|
||||
int wid = fm.QFM_WIDTH(text) + MENU_WIDTH_SLOP;
|
||||
if (wid > widest4)
|
||||
widest4 = wid;
|
||||
}
|
||||
@@ -552,7 +552,7 @@ void NetHackQtMenuWindow::AddRow(int row, const MenuItem& mi)
|
||||
table->setItem(row, 0, twi);
|
||||
twi->setFlags(Qt::ItemIsEnabled);
|
||||
#if 0 // active count field now widened as needed rather than preset
|
||||
WidenColumn(0, fm.horizontalAdvance("999999") + MENU_WIDTH_SLOP);
|
||||
WidenColumn(0, fm.QFM_WIDTH("999999") + MENU_WIDTH_SLOP);
|
||||
#else
|
||||
WidenColumn(0, MENU_WIDTH_SLOP);
|
||||
#endif
|
||||
@@ -600,7 +600,7 @@ void NetHackQtMenuWindow::AddRow(int row, const MenuItem& mi)
|
||||
// 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.horizontalAdvance(letter);
|
||||
int w = (int) fm.QFM_WIDTH(letter);
|
||||
if (w)
|
||||
w += MENU_WIDTH_SLOP / 2;
|
||||
WidenColumn(3, w);
|
||||
@@ -608,7 +608,7 @@ void NetHackQtMenuWindow::AddRow(int row, const MenuItem& mi)
|
||||
twi = new QTableWidgetItem(text);
|
||||
table->setItem(row, 4, twi);
|
||||
table->item(row, 4)->setFlags(Qt::ItemIsEnabled);
|
||||
WidenColumn(4, fm.horizontalAdvance(text));
|
||||
WidenColumn(4, fm.QFM_WIDTH(text));
|
||||
|
||||
if ((int) mi.color != -1) {
|
||||
twi->setForeground(colors[mi.color].q);
|
||||
|
||||
@@ -24,7 +24,7 @@ public:
|
||||
int width = 0;
|
||||
QFontMetrics fm(font());
|
||||
for (int i = 0; i < count(); i++) {
|
||||
int lwidth = fm.horizontalAdvance(item(i)->text());
|
||||
int lwidth = fm.QFM_WIDTH(item(i)->text());
|
||||
width = std::max(width, lwidth);
|
||||
}
|
||||
return width;
|
||||
|
||||
@@ -27,5 +27,14 @@
|
||||
#pragma GCC diagnostic ignored "-Wshadow"
|
||||
#endif
|
||||
|
||||
#include <QtGlobal>
|
||||
|
||||
/* QFontMetrics::width was deprecated in Qt 5.11 */
|
||||
#if QT_VERSION < QT_VERSION_CHECK(5, 11, 0)
|
||||
#define QFM_WIDTH(foo) width(foo)
|
||||
#else
|
||||
#define QFM_WIDTH(foo) horizontalAdvance(foo)
|
||||
#endif
|
||||
|
||||
/*qt_pre.h*/
|
||||
|
||||
|
||||
@@ -80,8 +80,8 @@ bool NetHackQtStringRequestor::Get(char *buffer, int maxchar, int minchar)
|
||||
input.setMaxLength(maxchar - 1);
|
||||
|
||||
const QString &txt = prompt.text();
|
||||
int pw = fontMetrics().horizontalAdvance(txt),
|
||||
ww = minchar * input.fontMetrics().horizontalAdvance(QChar('X'));
|
||||
int pw = fontMetrics().QFM_WIDTH(txt),
|
||||
ww = minchar * input.fontMetrics().QFM_WIDTH(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);
|
||||
|
||||
@@ -244,7 +244,7 @@ NetHackQtExtCmdRequestor::NetHackQtExtCmdRequestor(QWidget *parent) :
|
||||
for (i = 0; extcmdlist[i].ef_txt; ++i) {
|
||||
if (interesting_command(i, set)) {
|
||||
++ncmds;
|
||||
butw = std::max(butw, 30 + fm.horizontalAdvance(extcmdlist[i].ef_txt));
|
||||
butw = std::max(butw, 30 + fm.QFM_WIDTH(extcmdlist[i].ef_txt));
|
||||
}
|
||||
}
|
||||
// if any of the choice buttons were bigger than the control buttons,
|
||||
|
||||
@@ -350,7 +350,7 @@ char NetHackQtYnDialog::Exec()
|
||||
QPushButton cancel("Dismiss",this);
|
||||
label.setFrameStyle(QFrame::Box|QFrame::Sunken);
|
||||
label.setAlignment(Qt::AlignCenter);
|
||||
label.resize(fontMetrics().horizontalAdvance(qlabel)+60,30+fontMetrics().height());
|
||||
label.resize(fontMetrics().QFM_WIDTH(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);
|
||||
|
||||
Reference in New Issue
Block a user