From 4a4351b73df5592621c49e3afaa5bbf866faea80 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Wed, 24 Jul 2019 13:42:22 +0300 Subject: [PATCH] Fix error: 'width' is deprecated: Use QFontMetrics::horizontalAdvance. --HG-- branch : develop --- src/libs/vlayout/vlayoutpiece.cpp | 12 ++++++++++++ src/libs/vlayout/vtextmanager.cpp | 8 ++++++++ src/libs/vwidgets/fancytabbar/fancytabbar.cpp | 11 ++++++++++- src/libs/vwidgets/vtextgraphicsitem.cpp | 4 ++++ 4 files changed, 34 insertions(+), 1 deletion(-) diff --git a/src/libs/vlayout/vlayoutpiece.cpp b/src/libs/vlayout/vlayoutpiece.cpp index 01b4e2075..088b7e8c5 100644 --- a/src/libs/vlayout/vlayoutpiece.cpp +++ b/src/libs/vlayout/vlayoutpiece.cpp @@ -1180,7 +1180,11 @@ void VLayoutPiece::CreateLabelStrings(QGraphicsItem *parent, const QVector= QT_VERSION_CHECK(5, 11, 0) + if (fm.horizontalAdvance(qsText) > dW) +#else if (fm.width(qsText) > dW) +#endif { qsText = fm.elidedText(qsText, Qt::ElideMiddle, static_cast(dW)); } @@ -1190,11 +1194,19 @@ void VLayoutPiece::CreateLabelStrings(QGraphicsItem *parent, const QVector 0) { +#if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0) + dX = (dW - fm.horizontalAdvance(qsText))/2; +#else dX = (dW - fm.width(qsText))/2; +#endif } else { +#if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0) + dX = dW - fm.horizontalAdvance(qsText); +#else dX = dW - fm.width(qsText); +#endif } // set up the rotation around top-left corner matrix diff --git a/src/libs/vlayout/vtextmanager.cpp b/src/libs/vlayout/vtextmanager.cpp index 2ef084ef8..e9ef99ae7 100644 --- a/src/libs/vlayout/vtextmanager.cpp +++ b/src/libs/vlayout/vtextmanager.cpp @@ -431,7 +431,11 @@ void VTextManager::FitFontSize(qreal fW, qreal fH) fnt.setBold(tl.m_bold); fnt.setItalic(tl.m_italic); QFontMetrics fm(fnt); +#if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0) + const int iTW = fm.horizontalAdvance(tl.m_qsText); +#else const int iTW = fm.width(tl.m_qsText); +#endif if (iTW > iMaxLen) { iMaxLen = iTW; @@ -450,7 +454,11 @@ void VTextManager::FitFontSize(qreal fW, qreal fH) --iFS; fnt.setPixelSize(iFS + maxLine.m_iFontSize); QFontMetrics fm(fnt); +#if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0) + lineLength = fm.horizontalAdvance(maxLine.m_qsText); +#else lineLength = fm.width(maxLine.m_qsText); +#endif } while (lineLength > fW && iFS > MIN_FONT_SIZE); } diff --git a/src/libs/vwidgets/fancytabbar/fancytabbar.cpp b/src/libs/vwidgets/fancytabbar/fancytabbar.cpp index de76c60ad..a5352a0c2 100644 --- a/src/libs/vwidgets/fancytabbar/fancytabbar.cpp +++ b/src/libs/vwidgets/fancytabbar/fancytabbar.cpp @@ -78,7 +78,7 @@ QSize FancyTabBar::TabSizeHint(bool minimum) const boldFont.setBold(true); QFontMetrics fm(boldFont); int spacing = 8; - int width = 60 + spacing + 2; + int maxLabelwidth = 0; for (int tab=0 ; tab= QT_VERSION_CHECK(5, 11, 0) + const int width = fm.horizontalAdvance(sentence); +#else const int width = fm.width(sentence); +#endif if (maxLabelwidth < width) { maxLabelwidth = width; @@ -102,7 +106,11 @@ QSize FancyTabBar::TabSizeHint(bool minimum) const } else { +#if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0) + const int width = fm.horizontalAdvance(tabText); +#else const int width = fm.width(tabText); +#endif if (width > maxLabelwidth) { maxLabelwidth = width; @@ -110,6 +118,7 @@ QSize FancyTabBar::TabSizeHint(bool minimum) const } } + int width = 60 + spacing + 2; int iconHeight = minimum ? 0 : 32; return QSize(qMax(width, maxLabelwidth + 4), iconHeight + spacing + fm.height()); diff --git a/src/libs/vwidgets/vtextgraphicsitem.cpp b/src/libs/vwidgets/vtextgraphicsitem.cpp index 9deb7c707..d2c6c2599 100644 --- a/src/libs/vwidgets/vtextgraphicsitem.cpp +++ b/src/libs/vwidgets/vtextgraphicsitem.cpp @@ -176,7 +176,11 @@ void VTextGraphicsItem::paint(QPainter *painter, const QStyleOptionGraphicsItem break; } +#if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0) + if (fm.horizontalAdvance(qsText) > iW) +#else if (fm.width(qsText) > iW) +#endif { qsText = fm.elidedText(qsText, Qt::ElideMiddle, iW); }