mirror of
https://invent.kde.org/network/falkon.git
synced 2024-12-20 02:36:34 +01:00
Port from deprecated QFontMetrics::width() > QFontMetrics::horizontalAdvance()
Signed-off-by: Juraj Oravec <sgd.orava@gmail.com>
This commit is contained in:
parent
168f61c602
commit
de200c77c4
@ -29,6 +29,7 @@
|
||||
#include <QStyleOptionButton>
|
||||
#include <QDrag>
|
||||
#include <QMimeData>
|
||||
#include <QtGuiVersion>
|
||||
|
||||
#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;
|
||||
|
@ -29,6 +29,7 @@
|
||||
#include <QApplication>
|
||||
#include <QMouseEvent>
|
||||
#include <QTextLayout>
|
||||
#include <QtGuiVersion>
|
||||
|
||||
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;
|
||||
}
|
||||
|
@ -36,6 +36,7 @@
|
||||
#include <QMouseEvent>
|
||||
#include <QApplication>
|
||||
#include <QToolTip>
|
||||
#include <QtGuiVersion>
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -21,6 +21,7 @@
|
||||
|
||||
#include <QApplication>
|
||||
#include <QPainter>
|
||||
#include <QtGuiVersion>
|
||||
|
||||
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) {
|
||||
|
@ -41,6 +41,7 @@
|
||||
#include <QProcess>
|
||||
#include <QMessageBox>
|
||||
#include <QUrlQuery>
|
||||
#include <QtGuiVersion>
|
||||
|
||||
#ifdef QZ_WS_X11
|
||||
#include <QX11Info>
|
||||
@ -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;
|
||||
|
||||
|
@ -23,6 +23,7 @@
|
||||
#include <QPainter>
|
||||
#include <QListWidget>
|
||||
#include <QApplication>
|
||||
#include <QtGuiVersion>
|
||||
|
||||
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);
|
||||
|
Loading…
Reference in New Issue
Block a user