diff --git a/krusader/Dialogs/krsqueezedtextlabel.cpp b/krusader/Dialogs/krsqueezedtextlabel.cpp --- a/krusader/Dialogs/krsqueezedtextlabel.cpp +++ b/krusader/Dialogs/krsqueezedtextlabel.cpp @@ -31,6 +31,8 @@ #include #include +#include "../compat.h" + KrSqueezedTextLabel::KrSqueezedTextLabel(QWidget *parent): KSqueezedTextLabel(parent), _index(-1), _length(-1) { @@ -55,7 +57,7 @@ QString sqtext = fullText; QFontMetrics fm(fontMetrics()); int labelWidth = size().width(); - int textWidth = fm.width(sqtext); + int textWidth = fm.QFONTMETRICS_WIDTH(sqtext); if (textWidth > labelWidth) { int avgCharSize = textWidth / sqtext.length(); int numOfExtraChars = (textWidth - labelWidth) / avgCharSize; diff --git a/krusader/DiskUsage/diskusage.cpp b/krusader/DiskUsage/diskusage.cpp --- a/krusader/DiskUsage/diskusage.cpp +++ b/krusader/DiskUsage/diskusage.cpp @@ -63,6 +63,7 @@ #include "../defaults.h" #include "../krglobal.h" #include "../filelisticon.h" +#include "../compat.h" // these are the values that will exist in the menu #define DELETE_ID 90 @@ -146,7 +147,7 @@ searchedDirectory = new KSqueezedTextLabel(loaderBox); searchedDirectory->setFrameShape(QLabel::StyledPanel); searchedDirectory->setFrameShadow(QLabel::Sunken); - searchedDirectory->setMinimumWidth(width = QFontMetrics(searchedDirectory->font()).width("W") * 30); + searchedDirectory->setMinimumWidth(width = QFontMetrics(searchedDirectory->font()).QFONTMETRICS_WIDTH("W") * 30); searchedDirectory->setMaximumWidth(width); synchGrid->addWidget(searchedDirectory, 4, 0, 1, 2); diff --git a/krusader/DiskUsage/diskusagegui.cpp b/krusader/DiskUsage/diskusagegui.cpp --- a/krusader/DiskUsage/diskusagegui.cpp +++ b/krusader/DiskUsage/diskusagegui.cpp @@ -37,6 +37,7 @@ #include "../icon.h" #include "../FileSystem/filesystem.h" #include "../Dialogs/krdialogs.h" +#include "../compat.h" DiskUsageGUI::DiskUsageGUI(const QUrl &openDir) : QDialog(nullptr), exitAtFailure(true) @@ -134,7 +135,7 @@ diskUsage->setView(view); - sizeX = group.readEntry("Window Width", QFontMetrics(font()).width("W") * 70); + sizeX = group.readEntry("Window Width", QFontMetrics(font()).QFONTMETRICS_WIDTH("W") * 70); sizeY = group.readEntry("Window Height", QFontMetrics(font()).height() * 25); resize(sizeX, sizeY); diff --git a/krusader/DiskUsage/dulines.cpp b/krusader/DiskUsage/dulines.cpp --- a/krusader/DiskUsage/dulines.cpp +++ b/krusader/DiskUsage/dulines.cpp @@ -43,6 +43,7 @@ #include #include +#include "../compat.h" class DULinesItemDelegate : public QItemDelegate { @@ -88,7 +89,7 @@ QString renderedText = text; int textMargin = QApplication::style()->pixelMetric(QStyle::PM_FocusFrameHMargin); - int pos = 3 * textMargin + option.fontMetrics.width(display) + iconSize.width(); + int pos = 3 * textMargin + option.fontMetrics.QFONTMETRICS_WIDTH(display) + iconSize.width(); bool truncd = false; @@ -96,12 +97,12 @@ if (rct.width() > pos) { rct.setX(rct.x() + pos); - if (fm.width(renderedText) > rct.width()) { + if (fm.QFONTMETRICS_WIDTH(renderedText) > rct.width()) { truncd = true; - int points = fm.width("..."); + int points = fm.QFONTMETRICS_WIDTH("..."); - while (!renderedText.isEmpty() && (fm.width(renderedText) + points > rct.width())) + while (!renderedText.isEmpty() && (fm.QFONTMETRICS_WIDTH(renderedText) + points > rct.width())) renderedText.truncate(renderedText.length() - 1); renderedText += "..."; @@ -181,7 +182,7 @@ setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded); setIndentation(10); - int defaultSize = QFontMetrics(font()).width("W"); + int defaultSize = QFontMetrics(font()).QFONTMETRICS_WIDTH("W"); QStringList labels; labels << i18n("Line View"); diff --git a/krusader/DiskUsage/dulistview.cpp b/krusader/DiskUsage/dulistview.cpp --- a/krusader/DiskUsage/dulistview.cpp +++ b/krusader/DiskUsage/dulistview.cpp @@ -36,6 +36,8 @@ #include #include +#include "../compat.h" + DUListView::DUListView(DiskUsage *usage) : KrTreeWidget(usage), diskUsage(usage) { @@ -65,7 +67,7 @@ if (group.hasKey("D State")) header()->restoreState(group.readEntry("D State", QByteArray())); else { - int defaultSize = QFontMetrics(font()).width("W"); + int defaultSize = QFontMetrics(font()).QFONTMETRICS_WIDTH("W"); setColumnWidth(0, defaultSize * 20); setColumnWidth(1, defaultSize * 5); diff --git a/krusader/DiskUsage/radialMap/labels.cpp b/krusader/DiskUsage/radialMap/labels.cpp --- a/krusader/DiskUsage/radialMap/labels.cpp +++ b/krusader/DiskUsage/radialMap/labels.cpp @@ -32,6 +32,7 @@ #include "radialMap.h" #include "sincos.h" #include "widget.h" +#include "../compat.h" namespace RadialMap { @@ -292,7 +293,7 @@ qs = fm.elidedText((*it)->segment->file()->name(), Qt::ElideMiddle, width() - x2); - x3 = width() - fm.width(qs) + x3 = width() - fm.QFONTMETRICS_WIDTH(qs) - LABEL_HMARGIN //outer margin - LABEL_TEXT_HMARGIN //margin between strut and text //- ((*it)->lvl - startLevel) * LABEL_HMARGIN //indentation @@ -315,7 +316,7 @@ //**** needs a little tweaking: - tx = fm.width(qs) + LABEL_HMARGIN/* + ((*it)->lvl - startLevel) * LABEL_HMARGIN*/; + tx = fm.QFONTMETRICS_WIDTH(qs) + LABEL_HMARGIN/* + ((*it)->lvl - startLevel) * LABEL_HMARGIN*/; if (tx > x2) { //text is too long tx = LABEL_HMARGIN + x2 - tx; //some text will be lost from sight x3 = x2; //no text margin (right side of text here) diff --git a/krusader/DiskUsage/radialMap/segmentTip.cpp b/krusader/DiskUsage/radialMap/segmentTip.cpp --- a/krusader/DiskUsage/radialMap/segmentTip.cpp +++ b/krusader/DiskUsage/radialMap/segmentTip.cpp @@ -32,6 +32,7 @@ #include #include "fileTree.h" +#include "../compat.h" namespace RadialMap { @@ -131,15 +132,15 @@ if (pc > 0) s3 += QString(" (%1%)").arg(loc.toString(pc)); - maxw = fontMetrics().width(s3); + maxw = fontMetrics().QFONTMETRICS_WIDTH(s3); h += fontMetrics().height(); m_text += '\n'; m_text += s3; } uint - w = fontMetrics().width(s1); if (w > maxw) maxw = w; - w = fontMetrics().width(s2); if (w > maxw) maxw = w; + w = fontMetrics().QFONTMETRICS_WIDTH(s1); if (w > maxw) maxw = w; + w = fontMetrics().QFONTMETRICS_WIDTH(s2); if (w > maxw) maxw = w; resize(maxw + 2 * MARGIN, h); } diff --git a/krusader/GUI/kcmdline.cpp b/krusader/GUI/kcmdline.cpp --- a/krusader/GUI/kcmdline.cpp +++ b/krusader/GUI/kcmdline.cpp @@ -49,7 +49,7 @@ #include "../krservices.h" #include "../ActionMan/addplaceholderpopup.h" #include "kcmdmodebutton.h" - +#include "../compat.h" CmdLineCombo::CmdLineCombo(QWidget *parent) : KHistoryComboBox(parent), _handlingLineEditResize(false) { @@ -88,14 +88,14 @@ { QString pathNameLabel = _path; QFontMetrics fm(_pathLabel->fontMetrics()); - int textWidth = fm.width(_path); + int textWidth = fm.QFONTMETRICS_WIDTH(_path); int maxWidth = (width() + _pathLabel->width()) * 2 / 5; int letters = _path.length() / 2; while (letters && textWidth > maxWidth) { pathNameLabel = _path.left(letters) + "..." + _path.right(letters); letters--; - textWidth = fm.width(pathNameLabel); + textWidth = fm.QFONTMETRICS_WIDTH(pathNameLabel); } _pathLabel->setText(pathNameLabel + "> "); diff --git a/krusader/GUI/krtreewidget.cpp b/krusader/GUI/krtreewidget.cpp --- a/krusader/GUI/krtreewidget.cpp +++ b/krusader/GUI/krtreewidget.cpp @@ -20,6 +20,7 @@ #include "krtreewidget.h" #include "krstyleproxy.h" +#include "../compat.h" // QtGui #include @@ -162,7 +163,7 @@ QString tip = item->text(column); int textMargin = QApplication::style()->pixelMetric(QStyle::PM_FocusFrameHMargin) + 1; - int requiredWidth = QFontMetrics(font()).width(tip) + 2 * textMargin; + int requiredWidth = QFontMetrics(font()).QFONTMETRICS_WIDTH(tip) + 2 * textMargin; if (column == 0 && indentation()) { int level = 0; diff --git a/krusader/KViewer/lister.cpp b/krusader/KViewer/lister.cpp --- a/krusader/KViewer/lister.cpp +++ b/krusader/KViewer/lister.cpp @@ -64,6 +64,7 @@ #include "../icon.h" #include "../kractions.h" #include "../GUI/krremoteencodingmenu.h" +#include "../compat.h" #define SEARCH_CACHE_CHARS 100000 #define SEARCH_MAX_ROW_LEN 4000 @@ -127,7 +128,7 @@ // This is quite accurate (although not perfect) way of getting // a single character width along with its surrounding space. - const float fontWidth = (fm.width("WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW") - fm.width("W")) / 99.0; + const float fontWidth = (fm.QFONTMETRICS_WIDTH("WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW") - fm.QFONTMETRICS_WIDTH("W")) / 99.0; const int sizeY = contentRect.height() / fontHeight; _pageSize = sizeY; @@ -2017,7 +2018,7 @@ const QFontMetrics fmFixed(fixedFont); const int fixedFontHeight = std::max(fmFixed.height(), 1); - const int fixedFontWidth = std::max(fmFixed.width("W"), 1); + const int fixedFontWidth = std::max(fmFixed.QFONTMETRICS_WIDTH("W"), 1); const int effPageSize = drawingRect.height() - normalFontHeight - 1; const int rowsPerPage = std::max(effPageSize / fixedFontHeight, 1); diff --git a/krusader/Locate/locate.cpp b/krusader/Locate/locate.cpp --- a/krusader/Locate/locate.cpp +++ b/krusader/Locate/locate.cpp @@ -33,6 +33,7 @@ #include "../FileSystem/virtualfilesystem.h" #include "../KViewer/krviewer.h" #include "../panelmanager.h" +#include "../compat.h" // QtCore #include @@ -178,7 +179,7 @@ resultList->setColumnCount(1); resultList->setHeaderLabel(i18n("Results")); - resultList->setColumnWidth(0, QFontMetrics(resultList->font()).width("W") * 60); + resultList->setColumnWidth(0, QFontMetrics(resultList->font()).QFONTMETRICS_WIDTH("W") * 60); KConfigGroup gl(krConfig, "Look&Feel"); resultList->setFont(gl.readEntry("Filelist Font", _FilelistFont)); diff --git a/krusader/MountMan/kmountmangui.cpp b/krusader/MountMan/kmountmangui.cpp --- a/krusader/MountMan/kmountmangui.cpp +++ b/krusader/MountMan/kmountmangui.cpp @@ -26,6 +26,7 @@ #include "../Dialogs/krspecialwidgets.h" #include "../defaults.h" #include "../FileSystem/filesystem.h" +#include "../compat.h" // QtCore #include @@ -169,8 +170,8 @@ if (grp.hasKey("Last State")) mountList->header()->restoreState(grp.readEntry("Last State", QByteArray())); else { - int i = QFontMetrics(mountList->font()).width("W"); - int j = QFontMetrics(mountList->font()).width("0"); + int i = QFontMetrics(mountList->font()).QFONTMETRICS_WIDTH("W"); + int j = QFontMetrics(mountList->font()).QFONTMETRICS_WIDTH("0"); j = (i > j ? i : j); mountList->setColumnWidth(0, j*8); diff --git a/krusader/Panel/PanelView/krinterbriefview.cpp b/krusader/Panel/PanelView/krinterbriefview.cpp --- a/krusader/Panel/PanelView/krinterbriefview.cpp +++ b/krusader/Panel/PanelView/krinterbriefview.cpp @@ -48,6 +48,7 @@ #include "../FileSystem/krpermhandler.h" #include "../defaults.h" #include "../GUI/krstyleproxy.h" +#include "../compat.h" #define MAX_BRIEF_COLS 5 @@ -545,7 +546,7 @@ { QString text = index.data(Qt::DisplayRole).toString(); - int textWidth = QFontMetrics(_viewFont).width(text); + int textWidth = QFontMetrics(_viewFont).QFONTMETRICS_WIDTH(text); const int textMargin = QApplication::style()->pixelMetric(QStyle::PM_FocusFrameHMargin) + 1; textWidth += 2 * textMargin; diff --git a/krusader/Panel/PanelView/krinterdetailedview.cpp b/krusader/Panel/PanelView/krinterdetailedview.cpp --- a/krusader/Panel/PanelView/krinterdetailedview.cpp +++ b/krusader/Panel/PanelView/krinterdetailedview.cpp @@ -45,7 +45,7 @@ #include "krmousehandler.h" #include "../krcolorcache.h" #include "../GUI/krstyleproxy.h" - +#include "../compat.h" KrInterDetailedView::KrInterDetailedView(QWidget *parent, KrViewInstance &instance, KConfig *cfg): QTreeView(parent), @@ -117,14 +117,14 @@ hideColumn(KrViewProperties::Group); hideColumn(KrViewProperties::Changed); hideColumn(KrViewProperties::Accessed); - headerView->resizeSection(KrViewProperties::Ext, QFontMetrics(_viewFont).width("tar.bz2 ")); - headerView->resizeSection(KrViewProperties::KrPermissions, QFontMetrics(_viewFont).width("rwx ")); - headerView->resizeSection(KrViewProperties::Size, QFontMetrics(_viewFont).width("9") * 10); + headerView->resizeSection(KrViewProperties::Ext, QFontMetrics(_viewFont).QFONTMETRICS_WIDTH("tar.bz2 ")); + headerView->resizeSection(KrViewProperties::KrPermissions, QFontMetrics(_viewFont).QFONTMETRICS_WIDTH("rwx ")); + headerView->resizeSection(KrViewProperties::Size, QFontMetrics(_viewFont).QFONTMETRICS_WIDTH("9") * 10); QDateTime tmp(QDate(2099, 12, 29), QTime(23, 59)); QString desc = QLocale().toString(tmp, QLocale::ShortFormat) + " "; - headerView->resizeSection(KrViewProperties::Modified, QFontMetrics(_viewFont).width(desc)); + headerView->resizeSection(KrViewProperties::Modified, QFontMetrics(_viewFont).QFONTMETRICS_WIDTH(desc)); } else { headerView->restoreState(savedState); @@ -379,7 +379,7 @@ int width = header()->sectionSize(index.column()); QString text = index.data(Qt::DisplayRole).toString(); - int textWidth = QFontMetrics(_viewFont).width(text); + int textWidth = QFontMetrics(_viewFont).QFONTMETRICS_WIDTH(text); const int textMargin = QApplication::style()->pixelMetric(QStyle::PM_FocusFrameHMargin) + 1; textWidth += 2 * textMargin; diff --git a/krusader/Panel/krfiletreeview.cpp b/krusader/Panel/krfiletreeview.cpp --- a/krusader/Panel/krfiletreeview.cpp +++ b/krusader/Panel/krfiletreeview.cpp @@ -25,6 +25,7 @@ #include "../krglobal.h" #include "../icon.h" #include "../FileSystem/filesystemprovider.h" +#include "../compat.h" #include #include @@ -111,7 +112,7 @@ connect(mSourceModel, &KDirModel::expand, this, &KrFileTreeView::slotExpanded); QFontMetrics fontMetrics(viewport()->font()); - header()->resizeSection(KDirModel::Name, fontMetrics.width("WWWWWWWWWWWWWWW")); + header()->resizeSection(KDirModel::Name, fontMetrics.QFONTMETRICS_WIDTH("WWWWWWWWWWWWWWW")); header()->setContextMenuPolicy(Qt::CustomContextMenu); connect(header(), &QHeaderView::customContextMenuRequested, this, diff --git a/krusader/compat.h b/krusader/compat.h --- a/krusader/compat.h +++ b/krusader/compat.h @@ -28,4 +28,18 @@ #define UDS_ENTRY_INSERT(A, B) UDSEntry::insert((A), (B)); #endif +/** + * QFontMetrics::width(const QString&, int) was made obsoleted in QT 5.11 in + * favor of QFontMetrics::horizontalAdvance(const QString &, int) + * + * https://doc.qt.io/archives/qt-5.11/qfontmetrics-obsolete.html#width + * + * This can be removed when the qt minimum version required will be >= 5.11 + */ +#if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0) + #define QFONTMETRICS_WIDTH(A) horizontalAdvance(A) +#else + #define QFONTMETRICS_WIDTH(A) width(A) +#endif + #endif diff --git a/krusader/paneltabbar.cpp b/krusader/paneltabbar.cpp --- a/krusader/paneltabbar.cpp +++ b/krusader/paneltabbar.cpp @@ -29,6 +29,7 @@ #include "../icon.h" #include "Panel/listpanel.h" #include "Panel/panelfunc.h" +#include "compat.h" // QtCore #include @@ -197,23 +198,23 @@ // set the real max length QFontMetrics fm(fontMetrics()); - _maxTabLength = (dynamic_cast(parent())->width() - (6 * fm.width("W"))) / fm.width("W"); + _maxTabLength = (dynamic_cast(parent())->width() - (6 * fm.QFONTMETRICS_WIDTH("W"))) / fm.QFONTMETRICS_WIDTH("W"); // each tab gets a fair share of the max tab length const int effectiveTabLength = _maxTabLength / (count() == 0 ? 1 : count()); - const int labelWidth = fm.width("W") * effectiveTabLength; - const int textWidth = fm.width(text); + const int labelWidth = fm.QFONTMETRICS_WIDTH("W") * effectiveTabLength; + const int textWidth = fm.QFONTMETRICS_WIDTH(text); if (textWidth <= labelWidth) return text; // squeeze text - start with the dots only QString squeezedText = "..."; - int squeezedWidth = fm.width(squeezedText); + int squeezedWidth = fm.QFONTMETRICS_WIDTH(squeezedText); int letters = text.length() * (labelWidth - squeezedWidth) / textWidth / 2; if (labelWidth < squeezedWidth) letters = 1; squeezedText = text.left(letters) + "..." + text.right(letters); - squeezedWidth = fm.width(squeezedText); + squeezedWidth = fm.QFONTMETRICS_WIDTH(squeezedText); if (squeezedWidth < labelWidth) { // we estimated too short @@ -221,7 +222,7 @@ do { letters++; squeezedText = text.left(letters) + "..." + text.right(letters); - squeezedWidth = fm.width(squeezedText); + squeezedWidth = fm.QFONTMETRICS_WIDTH(squeezedText); } while (squeezedWidth < labelWidth); letters--; squeezedText = text.left(letters) + "..." + text.right(letters); @@ -231,7 +232,7 @@ do { letters--; squeezedText = text.left(letters) + "..." + text.right(letters); - squeezedWidth = fm.width(squeezedText); + squeezedWidth = fm.QFONTMETRICS_WIDTH(squeezedText); } while (letters && squeezedWidth > labelWidth); }