From de200c77c43d7888c14947e80ea7c721719b0138 Mon Sep 17 00:00:00 2001 From: Juraj Oravec Date: Tue, 31 Dec 2019 15:38:48 +0100 Subject: [PATCH] Port from deprecated QFontMetrics::width() > QFontMetrics::horizontalAdvance() Signed-off-by: Juraj Oravec --- src/lib/bookmarks/bookmarkstoolbarbutton.cpp | 5 +++++ .../navigation/completer/locationcompleterdelegate.cpp | 9 +++++++++ src/lib/tabwidget/combotabbar.cpp | 5 +++++ src/lib/tools/listitemdelegate.cpp | 6 +++++- src/lib/tools/qztools.cpp | 5 +++++ .../GreaseMonkey/settings/gm_settingslistdelegate.cpp | 5 +++++ 6 files changed, 34 insertions(+), 1 deletion(-) diff --git a/src/lib/bookmarks/bookmarkstoolbarbutton.cpp b/src/lib/bookmarks/bookmarkstoolbarbutton.cpp index 4dc078c80..bfd125322 100644 --- a/src/lib/bookmarks/bookmarkstoolbarbutton.cpp +++ b/src/lib/bookmarks/bookmarkstoolbarbutton.cpp @@ -29,6 +29,7 @@ #include #include #include +#include #define MAX_WIDTH 150 #define SEPARATOR_WIDTH 8 @@ -92,7 +93,11 @@ QSize BookmarksToolbarButton::sizeHint() const width = SEPARATOR_WIDTH; } else if (!m_showOnlyIcon) { +#if QTGUI_VERSION >= QT_VERSION_CHECK(5, 11, 0) + width += PADDING * 2 + fontMetrics().horizontalAdvance(m_bookmark->title()); +#else width += PADDING * 2 + fontMetrics().width(m_bookmark->title()); +#endif if (menu()) { width += PADDING + 8; diff --git a/src/lib/navigation/completer/locationcompleterdelegate.cpp b/src/lib/navigation/completer/locationcompleterdelegate.cpp index 9d2499f9a..79d80f33a 100644 --- a/src/lib/navigation/completer/locationcompleterdelegate.cpp +++ b/src/lib/navigation/completer/locationcompleterdelegate.cpp @@ -29,6 +29,7 @@ #include #include #include +#include LocationCompleterDelegate::LocationCompleterDelegate(QObject *parent) : QStyledItemDelegate(parent) @@ -141,7 +142,11 @@ void LocationCompleterDelegate::paint(QPainter* painter, const QStyleOptionViewI leftPosition += m_padding * 2; // Trim link to maximum number of characters that can be visible, otherwise there may be perf issue with huge URLs +#if QTGUI_VERSION >= QT_VERSION_CHECK(5, 11, 0) + const int maxChars = (opt.rect.width() - leftPosition) / opt.fontMetrics.horizontalAdvance(QL1C('i')); +#else const int maxChars = (opt.rect.width() - leftPosition) / opt.fontMetrics.width(QL1C('i')); +#endif QString link; const QByteArray linkArray = index.data(Qt::DisplayRole).toByteArray(); if (!linkArray.startsWith("data") && !linkArray.startsWith("javascript")) { @@ -171,7 +176,11 @@ void LocationCompleterDelegate::paint(QPainter* painter, const QStyleOptionViewI // Draw separator if (!link.isEmpty()) { QChar separator = QL1C('-'); +#if QTGUI_VERSION >= QT_VERSION_CHECK(5, 11, 0) + QRect separatorRect(leftPosition, center - linkMetrics.height() / 2, linkMetrics.horizontalAdvance(separator), linkMetrics.height()); +#else QRect separatorRect(leftPosition, center - linkMetrics.height() / 2, linkMetrics.width(separator), linkMetrics.height()); +#endif style->drawItemText(painter, separatorRect, Qt::AlignCenter, textPalette, true, separator, colorRole); leftPosition += separatorRect.width() + m_padding * 2; } diff --git a/src/lib/tabwidget/combotabbar.cpp b/src/lib/tabwidget/combotabbar.cpp index 8a309072d..155773d36 100644 --- a/src/lib/tabwidget/combotabbar.cpp +++ b/src/lib/tabwidget/combotabbar.cpp @@ -36,6 +36,7 @@ #include #include #include +#include class QMovableTabWidget : public QWidget { @@ -1085,7 +1086,11 @@ QPixmap TabBarHelper::tabPixmap(int index) const } if (closeButton) { +#if QTGUI_VERSION >= QT_VERSION_CHECK(5, 11, 0) + const int width = tab.fontMetrics.horizontalAdvance(tab.text) + closeButton->width(); +#else const int width = tab.fontMetrics.width(tab.text) + closeButton->width(); +#endif tab.text = tab.fontMetrics.elidedText(tabText(index), Qt::ElideRight, width); } diff --git a/src/lib/tools/listitemdelegate.cpp b/src/lib/tools/listitemdelegate.cpp index 94dbd6f43..234b5fa83 100644 --- a/src/lib/tools/listitemdelegate.cpp +++ b/src/lib/tools/listitemdelegate.cpp @@ -21,6 +21,7 @@ #include #include +#include ListItemDelegate::ListItemDelegate(int iconSize, QWidget* parent) : QStyledItemDelegate(parent) @@ -114,8 +115,11 @@ QSize ListItemDelegate::sizeHint(const QStyleOptionViewItem &option, const QMode p->setFixedHeight(m_itemHeight + 2 * frameWidth); } } - +#if QTGUI_VERSION >= QT_VERSION_CHECK(5, 11, 0) + int width = 2 * m_padding + option.fontMetrics.horizontalAdvance(index.data(Qt::DisplayRole).toString()); +#else int width = 2 * m_padding + option.fontMetrics.width(index.data(Qt::DisplayRole).toString()); +#endif width = width > (m_iconSize + 2 * m_padding) ? width : m_iconSize + 2 * m_padding; if (m_uniformItemSizes) { diff --git a/src/lib/tools/qztools.cpp b/src/lib/tools/qztools.cpp index a24f07741..4f05084a1 100644 --- a/src/lib/tools/qztools.cpp +++ b/src/lib/tools/qztools.cpp @@ -41,6 +41,7 @@ #include #include #include +#include #ifdef QZ_WS_X11 #include @@ -395,7 +396,11 @@ QPixmap QzTools::createPixmapForSite(const QIcon &icon, const QString &title, co { const QFontMetrics fontMetrics = QApplication::fontMetrics(); const int padding = 4; +#if QTGUI_VERSION >= QT_VERSION_CHECK(5, 11, 0) + const int maxWidth = fontMetrics.horizontalAdvance(title.length() > url.length() ? title : url) + 3 * padding + 16; +#else const int maxWidth = fontMetrics.width(title.length() > url.length() ? title : url) + 3 * padding + 16; +#endif const int width = qMin(maxWidth, 150); const int height = fontMetrics.height() * 2 + fontMetrics.leading() + 2 * padding; diff --git a/src/plugins/GreaseMonkey/settings/gm_settingslistdelegate.cpp b/src/plugins/GreaseMonkey/settings/gm_settingslistdelegate.cpp index a7decfda3..bbe564570 100644 --- a/src/plugins/GreaseMonkey/settings/gm_settingslistdelegate.cpp +++ b/src/plugins/GreaseMonkey/settings/gm_settingslistdelegate.cpp @@ -23,6 +23,7 @@ #include #include #include +#include GM_SettingsListDelegate::GM_SettingsListDelegate(QObject* parent) : QStyledItemDelegate(parent) @@ -110,7 +111,11 @@ void GM_SettingsListDelegate::paint(QPainter* painter, const QStyleOptionViewIte const QString name = index.data(Qt::DisplayRole).toString(); const int leftTitleEdge = leftPosition + 2; const int rightTitleEdge = rightPosition - m_padding; +#if QTGUI_VERSION >= QT_VERSION_CHECK(5, 11, 0) + const int leftPosForVersion = titleMetrics.horizontalAdvance(name) + m_padding; +#else const int leftPosForVersion = titleMetrics.width(name) + m_padding; +#endif QRect nameRect(leftTitleEdge, opt.rect.top() + m_padding, rightTitleEdge - leftTitleEdge, titleMetrics.height()); painter->setFont(titleFont); style->drawItemText(painter, nameRect, Qt::AlignLeft, textPalette, true, name, colorRole);