Commit 836a6834 authored by Friedrich W. H. Kossebau's avatar Friedrich W. H. Kossebau
Browse files

Port deprecated QFontMetrics::width() -> QFontMetrics::horizontalAdvance()

parent f372629c
......@@ -64,7 +64,11 @@ StatusbarProgressWidget::StatusbarProgressWidget( ProgressDialog* progressDialog
mDelayTimer( nullptr ), mCleanTimer( nullptr )
{
m_bShowButton = button;
#if (QT_VERSION >= QT_VERSION_CHECK(5, 11, 0))
int w = fontMetrics().horizontalAdvance(QStringLiteral(" 999.9 kB/s 00:00:01 ")) + 8;
#else
int w = fontMetrics().width( QStringLiteral(" 999.9 kB/s 00:00:01 ") ) + 8;
#endif
box = new QHBoxLayout( this );
box->setMargin(0);
box->setSpacing(0);
......
......@@ -64,8 +64,11 @@ QSize IdealToolButton::sizeHint() const
QFontMetrics fm = fontMetrics();
#if (QT_VERSION >= QT_VERSION_CHECK(5, 11, 0))
const int charWidth = fm.horizontalAdvance(QLatin1Char('x'));
#else
const int charWidth = fm.width(QLatin1Char('x'));
#endif
QSize textSize;
// Use text size only if we request text
if (toolButtonStyle() != Qt::ToolButtonIconOnly || opt.icon.isNull()) {
......
......@@ -48,7 +48,11 @@ QSize KExpandableLineEdit::sizeHint() const
{
auto idealSize = QLineEdit::sizeHint();
#if (QT_VERSION >= QT_VERSION_CHECK(5, 11, 0))
int idealWidth = fontMetrics().horizontalAdvance(text());
#else
int idealWidth = fontMetrics().width(text());
#endif
if (isClearButtonEnabled()) {
idealWidth += 2 * idealSize.height();
}
......
......@@ -282,11 +282,19 @@ void VcsAnnotationItemDelegate::paint(QPainter* painter, const KTextEditor::Styl
if (date.isValid()) {
ageText = ageOfDate(date.date());
ageRect = QRect(QPoint(0, 0),
#if (QT_VERSION >= QT_VERSION_CHECK(5, 11, 0))
QSize(option.fontMetrics.horizontalAdvance(ageText), option.rect.height()));
#else
QSize(option.fontMetrics.width(ageText), option.rect.height()));
#endif
}
const auto messageText = annotationLine.commitMessage();
auto messageRect = QRect(QPoint(0, 0),
#if (QT_VERSION >= QT_VERSION_CHECK(5, 11, 0))
QSize(option.fontMetrics.horizontalAdvance(messageText), option.rect.height()));
#else
QSize(option.fontMetrics.width(messageText), option.rect.height()));
#endif
doMessageLineLayout(option, &messageRect, &ageRect);
......@@ -296,7 +304,11 @@ void VcsAnnotationItemDelegate::paint(QPainter* painter, const KTextEditor::Styl
if (!author.isEmpty()) {
const auto authorText = i18nc("By: commit author", "By: %1", author);
auto authorRect = QRect(QPoint(0, 0),
#if (QT_VERSION >= QT_VERSION_CHECK(5, 11, 0))
QSize(option.fontMetrics.horizontalAdvance(authorText), option.rect.height()));
#else
QSize(option.fontMetrics.width(authorText), option.rect.height()));
#endif
doAuthorLineLayout(option, &authorRect);
......
......@@ -173,18 +173,30 @@ QSize GrepOutputDelegate::sizeHint(const QStyleOptionViewItem& option, const QMo
for (int i = 0; i < item->rowCount(); ++i) {
bWidth += static_cast<GrepOutputItem*>(item->child(i))->change()->m_range.columnWidth();
}
#if (QT_VERSION >= QT_VERSION_CHECK(5, 11, 0))
int width = option.fontMetrics.horizontalAdvance(i18n("Line %1: ",item->lineNumber())) +
metrics.horizontalAdvance(item->text().length() - bWidth) + bMetrics.horizontalAdvance(bWidth) +
std::max(option.decorationSize.width(), 0);
#else
int width = option.fontMetrics.width(i18n("Line %1: ",item->lineNumber())) +
metrics.width(item->text().length() - bWidth) + bMetrics.width(bWidth) +
std::max(option.decorationSize.width(), 0);
#endif
ret.setWidth(width);
} else {
const KTextEditor::Range rng = item->change()->m_range;
#if (QT_VERSION >= QT_VERSION_CHECK(5, 11, 0))
int width = metrics.horizontalAdvance(item->text().left(rng.start().column())) +
metrics.horizontalAdvance(item->text().mid(rng.end().column())) +
bMetrics.horizontalAdvance(item->text().mid(rng.start().column(), rng.end().column() - rng.start().column())) +
std::max(option.decorationSize.width(), 0);
#else
int width = metrics.width(item->text().left(rng.start().column())) +
metrics.width(item->text().mid(rng.end().column())) +
bMetrics.width(item->text().mid(rng.start().column(), rng.end().column() - rng.start().column())) +
std::max(option.decorationSize.width(), 0);
#endif
ret.setWidth(width);
}
}else{
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment