Skip to content

Commit

Permalink
fix(core,ui): fix Qt 5.11 deprecation warnings (#1137)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gianluca Recchia authored and trollixx committed Sep 29, 2019
1 parent 7fc27d3 commit 99d2cee
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
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));
}

// 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

0 comments on commit 99d2cee

Please sign in to comment.