mirror of
https://invent.kde.org/network/falkon.git
synced 2024-12-24 12:46:35 +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 <QStyleOptionButton>
|
||||||
#include <QDrag>
|
#include <QDrag>
|
||||||
#include <QMimeData>
|
#include <QMimeData>
|
||||||
|
#include <QtGuiVersion>
|
||||||
|
|
||||||
#define MAX_WIDTH 150
|
#define MAX_WIDTH 150
|
||||||
#define SEPARATOR_WIDTH 8
|
#define SEPARATOR_WIDTH 8
|
||||||
@ -92,7 +93,11 @@ QSize BookmarksToolbarButton::sizeHint() const
|
|||||||
width = SEPARATOR_WIDTH;
|
width = SEPARATOR_WIDTH;
|
||||||
}
|
}
|
||||||
else if (!m_showOnlyIcon) {
|
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());
|
width += PADDING * 2 + fontMetrics().width(m_bookmark->title());
|
||||||
|
#endif
|
||||||
|
|
||||||
if (menu()) {
|
if (menu()) {
|
||||||
width += PADDING + 8;
|
width += PADDING + 8;
|
||||||
|
@ -29,6 +29,7 @@
|
|||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QMouseEvent>
|
#include <QMouseEvent>
|
||||||
#include <QTextLayout>
|
#include <QTextLayout>
|
||||||
|
#include <QtGuiVersion>
|
||||||
|
|
||||||
LocationCompleterDelegate::LocationCompleterDelegate(QObject *parent)
|
LocationCompleterDelegate::LocationCompleterDelegate(QObject *parent)
|
||||||
: QStyledItemDelegate(parent)
|
: QStyledItemDelegate(parent)
|
||||||
@ -141,7 +142,11 @@ void LocationCompleterDelegate::paint(QPainter* painter, const QStyleOptionViewI
|
|||||||
leftPosition += m_padding * 2;
|
leftPosition += m_padding * 2;
|
||||||
|
|
||||||
// Trim link to maximum number of characters that can be visible, otherwise there may be perf issue with huge URLs
|
// 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'));
|
const int maxChars = (opt.rect.width() - leftPosition) / opt.fontMetrics.width(QL1C('i'));
|
||||||
|
#endif
|
||||||
QString link;
|
QString link;
|
||||||
const QByteArray linkArray = index.data(Qt::DisplayRole).toByteArray();
|
const QByteArray linkArray = index.data(Qt::DisplayRole).toByteArray();
|
||||||
if (!linkArray.startsWith("data") && !linkArray.startsWith("javascript")) {
|
if (!linkArray.startsWith("data") && !linkArray.startsWith("javascript")) {
|
||||||
@ -171,7 +176,11 @@ void LocationCompleterDelegate::paint(QPainter* painter, const QStyleOptionViewI
|
|||||||
// Draw separator
|
// Draw separator
|
||||||
if (!link.isEmpty()) {
|
if (!link.isEmpty()) {
|
||||||
QChar separator = QL1C('-');
|
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());
|
QRect separatorRect(leftPosition, center - linkMetrics.height() / 2, linkMetrics.width(separator), linkMetrics.height());
|
||||||
|
#endif
|
||||||
style->drawItemText(painter, separatorRect, Qt::AlignCenter, textPalette, true, separator, colorRole);
|
style->drawItemText(painter, separatorRect, Qt::AlignCenter, textPalette, true, separator, colorRole);
|
||||||
leftPosition += separatorRect.width() + m_padding * 2;
|
leftPosition += separatorRect.width() + m_padding * 2;
|
||||||
}
|
}
|
||||||
|
@ -36,6 +36,7 @@
|
|||||||
#include <QMouseEvent>
|
#include <QMouseEvent>
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QToolTip>
|
#include <QToolTip>
|
||||||
|
#include <QtGuiVersion>
|
||||||
|
|
||||||
class QMovableTabWidget : public QWidget
|
class QMovableTabWidget : public QWidget
|
||||||
{
|
{
|
||||||
@ -1085,7 +1086,11 @@ QPixmap TabBarHelper::tabPixmap(int index) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (closeButton) {
|
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();
|
const int width = tab.fontMetrics.width(tab.text) + closeButton->width();
|
||||||
|
#endif
|
||||||
tab.text = tab.fontMetrics.elidedText(tabText(index), Qt::ElideRight, width);
|
tab.text = tab.fontMetrics.elidedText(tabText(index), Qt::ElideRight, width);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
|
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
|
#include <QtGuiVersion>
|
||||||
|
|
||||||
ListItemDelegate::ListItemDelegate(int iconSize, QWidget* parent)
|
ListItemDelegate::ListItemDelegate(int iconSize, QWidget* parent)
|
||||||
: QStyledItemDelegate(parent)
|
: QStyledItemDelegate(parent)
|
||||||
@ -114,8 +115,11 @@ QSize ListItemDelegate::sizeHint(const QStyleOptionViewItem &option, const QMode
|
|||||||
p->setFixedHeight(m_itemHeight + 2 * frameWidth);
|
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());
|
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;
|
width = width > (m_iconSize + 2 * m_padding) ? width : m_iconSize + 2 * m_padding;
|
||||||
|
|
||||||
if (m_uniformItemSizes) {
|
if (m_uniformItemSizes) {
|
||||||
|
@ -41,6 +41,7 @@
|
|||||||
#include <QProcess>
|
#include <QProcess>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <QUrlQuery>
|
#include <QUrlQuery>
|
||||||
|
#include <QtGuiVersion>
|
||||||
|
|
||||||
#ifdef QZ_WS_X11
|
#ifdef QZ_WS_X11
|
||||||
#include <QX11Info>
|
#include <QX11Info>
|
||||||
@ -395,7 +396,11 @@ QPixmap QzTools::createPixmapForSite(const QIcon &icon, const QString &title, co
|
|||||||
{
|
{
|
||||||
const QFontMetrics fontMetrics = QApplication::fontMetrics();
|
const QFontMetrics fontMetrics = QApplication::fontMetrics();
|
||||||
const int padding = 4;
|
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;
|
const int maxWidth = fontMetrics.width(title.length() > url.length() ? title : url) + 3 * padding + 16;
|
||||||
|
#endif
|
||||||
const int width = qMin(maxWidth, 150);
|
const int width = qMin(maxWidth, 150);
|
||||||
const int height = fontMetrics.height() * 2 + fontMetrics.leading() + 2 * padding;
|
const int height = fontMetrics.height() * 2 + fontMetrics.leading() + 2 * padding;
|
||||||
|
|
||||||
|
@ -23,6 +23,7 @@
|
|||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <QListWidget>
|
#include <QListWidget>
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
|
#include <QtGuiVersion>
|
||||||
|
|
||||||
GM_SettingsListDelegate::GM_SettingsListDelegate(QObject* parent)
|
GM_SettingsListDelegate::GM_SettingsListDelegate(QObject* parent)
|
||||||
: QStyledItemDelegate(parent)
|
: QStyledItemDelegate(parent)
|
||||||
@ -110,7 +111,11 @@ void GM_SettingsListDelegate::paint(QPainter* painter, const QStyleOptionViewIte
|
|||||||
const QString name = index.data(Qt::DisplayRole).toString();
|
const QString name = index.data(Qt::DisplayRole).toString();
|
||||||
const int leftTitleEdge = leftPosition + 2;
|
const int leftTitleEdge = leftPosition + 2;
|
||||||
const int rightTitleEdge = rightPosition - m_padding;
|
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;
|
const int leftPosForVersion = titleMetrics.width(name) + m_padding;
|
||||||
|
#endif
|
||||||
QRect nameRect(leftTitleEdge, opt.rect.top() + m_padding, rightTitleEdge - leftTitleEdge, titleMetrics.height());
|
QRect nameRect(leftTitleEdge, opt.rect.top() + m_padding, rightTitleEdge - leftTitleEdge, titleMetrics.height());
|
||||||
painter->setFont(titleFont);
|
painter->setFont(titleFont);
|
||||||
style->drawItemText(painter, nameRect, Qt::AlignLeft, textPalette, true, name, colorRole);
|
style->drawItemText(painter, nameRect, Qt::AlignLeft, textPalette, true, name, colorRole);
|
||||||
|
Loading…
Reference in New Issue
Block a user