Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Qt 5.11 deprecation warning for QFontMetrics::width #1137

Merged
merged 1 commit into from
Sep 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/libs/core/extractor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ void Extractor::extract(const QString &sourceFile, const QString &destination, c

QDir destinationDir(destination);
if (!root.isEmpty()) {
destinationDir = destinationDir.filePath(root);
destinationDir.setPath(destinationDir.filePath(root));
trollixx marked this conversation as resolved.
Show resolved Hide resolved
}

// TODO: Do not strip root directory in archive if it equals to 'root'
Expand Down
18 changes: 13 additions & 5 deletions src/libs/ui/searchitemdelegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,16 @@ void SearchItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &op
const int matchIndex = opt.text.indexOf(m_highlight, i, Qt::CaseInsensitive);
if (matchIndex == -1 || matchIndex >= elidedText.length() - 1)
break;

QRect highlightRect
= textRect.adjusted(fm.width(elidedText.left(matchIndex)), 2, 0, -2);
#if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)
QRect highlightRect = textRect.adjusted(fm.horizontalAdvance(elidedText.left(matchIndex)), 2, 0, -2);
#else
QRect highlightRect = textRect.adjusted(fm.width(elidedText.left(matchIndex)), 2, 0, -2);
#endif
#if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)
highlightRect.setWidth(fm.horizontalAdvance(elidedText.mid(matchIndex, m_highlight.length())));
#else
highlightRect.setWidth(fm.width(elidedText.mid(matchIndex, m_highlight.length())));

#endif
QPainterPath path;
path.addRoundedRect(highlightRect, 2, 2);

Expand Down Expand Up @@ -202,8 +207,11 @@ QSize SearchItemDelegate::sizeHint(const QStyleOptionViewItem &option,
const int decorationWidth = std::min(opt.decorationSize.width(), actualSize.width());
size.rwidth() = (decorationWidth + margin) * roles.size() + margin;
}

#if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)
size.rwidth() += opt.fontMetrics.horizontalAdvance(index.data().toString()) + margin * 2;
#else
size.rwidth() += opt.fontMetrics.width(index.data().toString()) + margin * 2;
#endif
return size;
}

Expand Down
8 changes: 8 additions & 0 deletions src/libs/ui/widgets/searchedit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,13 +147,21 @@ void SearchEdit::showCompletions(const QString &newValue)
return;

const int frameWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth);
#if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)
const int textWidth = fontMetrics().horizontalAdvance(newValue);
#else
const int textWidth = fontMetrics().width(newValue);
#endif

if (m_prefixCompleter)
m_prefixCompleter->setCompletionPrefix(text());

const QString completed = currentCompletion(newValue).mid(newValue.size());
#if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)
const QSize labelSize(fontMetrics().horizontalAdvance(completed), size().height());
#else
const QSize labelSize(fontMetrics().width(completed), size().height());
#endif
const int shiftX = static_cast<int>(window()->devicePixelRatioF() * (frameWidth + 2)) + textWidth;

m_completionLabel->setMinimumSize(labelSize);
Expand Down