fix(core,ui): fix Qt 5.11 deprecation warnings (#1137)

This commit is contained in:
Gianluca Recchia 2019-09-29 17:55:52 +02:00 committed by Oleg Shparber
parent 7fc27d3d44
commit 99d2ceef5f
3 changed files with 22 additions and 6 deletions

View File

@ -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'

View File

@ -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);
@ -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;
}

View File

@ -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);