]> granicus.if.org Git - nethack/commitdiff
Qt: deprecation warnings, again
authorPasi Kallinen <paxed@alt.org>
Sun, 15 Aug 2021 07:58:39 +0000 (10:58 +0300)
committerPasi Kallinen <paxed@alt.org>
Sun, 15 Aug 2021 07:58:42 +0000 (10:58 +0300)
Check Qt version for the QFontMetrics::width vs horizontalAdvance.
Of course can't just #define horizontalAdvance to width, that would
be too easy ...

win/Qt/qt_map.cpp
win/Qt/qt_menu.cpp
win/Qt/qt_menu.h
win/Qt/qt_pre.h
win/Qt/qt_streq.cpp
win/Qt/qt_xcmd.cpp
win/Qt/qt_yndlg.cpp

index 344899425e4d39a12f8deed1141c64911ccfc755..7ab314bd75b82d1c276cd60b0ebeca97c2f98675 100644 (file)
@@ -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;
index 860ac764cd665f0842f5dc015131be7cd9dc9cc1..682a911cf0f7386321823858173a053ab16277e0 100644 (file)
@@ -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);
index 77dd080f9921b364f9766812c51eac8556899e7e..9528186e8f6fe346983a0d5eba1e314a553bca01 100644 (file)
@@ -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;
index 70f30a8fccf9298ff9c41683287dc0ec04acaaa5..53f7e4718a53695861824eaaafc86b4f596b9cfd 100644 (file)
 #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*/
 
index cd1de46e59ee538f0bc4fecaafdba139f5316862..dc6712a4dd8c4b0b5172f4cf7e33ddc05efbd691 100644 (file)
@@ -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);
index 0d1ad986c212fb16cc0de3afa2e2621dff6a70c3..f5ddabeb816698449172871aabf4f15a465c0927 100644 (file)
@@ -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,
index c6a0ac3d123ef642ad5cfb7884c470e47d8e0713..0e607a0b640e7545dd57904617ead7184c0c2755 100644 (file)
@@ -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);