Qt5: 'int QFontMetrics::width' is deprecated since Qt 5.11: Use QFontMetrics::horizontalAdvance [-Wdeprecated-declarations]
This commit is contained in:
@@ -70,6 +70,7 @@
|
||||
#include "SceneInspector.h"
|
||||
#include "DemoMode.h"
|
||||
#include "TextureMapping.h"
|
||||
#include "Tools.h"
|
||||
#include "Utilities.h"
|
||||
#include "NavigationStyle.h"
|
||||
|
||||
@@ -1862,14 +1863,15 @@ void StdViewScreenShot::activated(int iMsg)
|
||||
QFont font = painter.font();
|
||||
font.setPointSize(20);
|
||||
|
||||
int n = QFontMetrics(font).width(name);
|
||||
QFontMetrics fm(font);
|
||||
int n = QtTools::horizontalAdvance(fm, name);
|
||||
int h = pixmap.height();
|
||||
|
||||
painter.setFont(font);
|
||||
painter.drawText(8+appicon.width(), h-24, name);
|
||||
|
||||
font.setPointSize(12);
|
||||
int u = QFontMetrics(font).width(url);
|
||||
int u = QtTools::horizontalAdvance(fm, url);
|
||||
painter.setFont(font);
|
||||
painter.drawText(8+appicon.width()+n-u, h-9, url);
|
||||
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
#include "DlgExpressionInput.h"
|
||||
#include "ui_DlgExpressionInput.h"
|
||||
#include "ExpressionCompleter.h"
|
||||
#include "Tools.h"
|
||||
#include <Base/Tools.h>
|
||||
#include <Base/Console.h>
|
||||
#include <App/Application.h>
|
||||
@@ -124,7 +125,7 @@ void DlgExpressionInput::textChanged(const QString &text)
|
||||
try {
|
||||
//resize the input field according to text size
|
||||
QFontMetrics fm(ui->expression->font());
|
||||
int width = fm.width(text) + 15;
|
||||
int width = QtTools::horizontalAdvance(fm, text) + 15;
|
||||
if (width < minimumWidth)
|
||||
ui->expression->setMinimumWidth(minimumWidth);
|
||||
else
|
||||
|
||||
@@ -53,6 +53,7 @@
|
||||
#include "MainWindow.h"
|
||||
#include "FileDialog.h"
|
||||
#include "ui_DlgAuthorization.h"
|
||||
#include "Tools.h"
|
||||
|
||||
using namespace Gui::Dialog;
|
||||
|
||||
@@ -100,7 +101,7 @@ SqueezeLabel::SqueezeLabel(QWidget *parent) : QLabel(parent)
|
||||
void SqueezeLabel::paintEvent(QPaintEvent *event)
|
||||
{
|
||||
QFontMetrics fm = fontMetrics();
|
||||
if (fm.width(text()) > contentsRect().width()) {
|
||||
if (Gui::QtTools::horizontalAdvance(fm, text()) > contentsRect().width()) {
|
||||
QString elided = fm.elidedText(text(), Qt::ElideMiddle, width());
|
||||
QString oldText = text();
|
||||
setText(elided);
|
||||
|
||||
@@ -45,6 +45,7 @@
|
||||
#include "FileDialog.h"
|
||||
#include "MainWindow.h"
|
||||
#include "BitmapFactory.h"
|
||||
#include "Tools.h"
|
||||
|
||||
using namespace Gui;
|
||||
|
||||
@@ -779,8 +780,8 @@ void FileChooser::setFilter ( const QString& filter )
|
||||
void FileChooser::setButtonText( const QString& txt )
|
||||
{
|
||||
button->setText( txt );
|
||||
int w1 = 2*button->fontMetrics().width(txt);
|
||||
int w2 = 2*button->fontMetrics().width(QLatin1String(" ... "));
|
||||
int w1 = 2 * QtTools::horizontalAdvance(button->fontMetrics(), txt);
|
||||
int w2 = 2 * QtTools::horizontalAdvance(button->fontMetrics(), QLatin1String(" ... "));
|
||||
button->setFixedWidth( (w1 > w2 ? w1 : w2) );
|
||||
}
|
||||
|
||||
|
||||
@@ -116,6 +116,7 @@
|
||||
#include "View3DInventor.h"
|
||||
#include "View3DInventorViewer.h"
|
||||
#include "DlgObjectSelection.h"
|
||||
#include "Tools.h"
|
||||
|
||||
FC_LOG_LEVEL_INIT("MainWindow",false,true,true)
|
||||
|
||||
@@ -1547,14 +1548,14 @@ QPixmap MainWindow::splashImage() const
|
||||
QFont fontExe = painter.font();
|
||||
fontExe.setPointSize(20);
|
||||
QFontMetrics metricExe(fontExe);
|
||||
int l = metricExe.width(title);
|
||||
int l = QtTools::horizontalAdvance(metricExe, title);
|
||||
int w = splash_image.width();
|
||||
int h = splash_image.height();
|
||||
|
||||
QFont fontVer = painter.font();
|
||||
fontVer.setPointSize(12);
|
||||
QFontMetrics metricVer(fontVer);
|
||||
int v = metricVer.width(version);
|
||||
int v = QtTools::horizontalAdvance(metricVer, version);
|
||||
|
||||
int x = -1, y = -1;
|
||||
QRegExp rx(QLatin1String("(\\d+).(\\d+)"));
|
||||
|
||||
@@ -67,6 +67,7 @@
|
||||
#include "ManualAlignment.h"
|
||||
#include "BitmapFactory.h"
|
||||
#include "SoAxisCrossKit.h"
|
||||
#include "Tools.h"
|
||||
|
||||
|
||||
using namespace Gui;
|
||||
@@ -472,7 +473,7 @@ public:
|
||||
QColor front;
|
||||
front.setRgbF(0.8f, 0.8f, 0.8f);
|
||||
|
||||
int w = fm.width(text);
|
||||
int w = QtTools::horizontalAdvance(fm, text);
|
||||
int h = fm.height();
|
||||
|
||||
QImage image(w,h,QImage::Format_ARGB32_Premultiplied);
|
||||
|
||||
@@ -49,6 +49,7 @@
|
||||
#include "DlgEditorImp.h"
|
||||
#include "FileDialog.h"
|
||||
#include "MainWindow.h"
|
||||
#include "Tools.h"
|
||||
|
||||
#include <Base/Interpreter.h>
|
||||
#include <Base/Exception.h>
|
||||
@@ -524,7 +525,7 @@ void PythonConsole::OnChange( Base::Subject<const char*> &rCaller,const char* sR
|
||||
QFont font(fontFamily, fontSize);
|
||||
setFont(font);
|
||||
QFontMetrics metric(font);
|
||||
int width = metric.width(QLatin1String("0000"));
|
||||
int width = QtTools::horizontalAdvance(metric, QLatin1String("0000"));
|
||||
setTabStopWidth(width);
|
||||
} else {
|
||||
QMap<QString, QColor>::ConstIterator it = d->colormap.find(QString::fromLatin1(sReason));
|
||||
|
||||
@@ -41,6 +41,7 @@
|
||||
#include "DlgExpressionInput.h"
|
||||
#include "propertyeditor/PropertyItem.h"
|
||||
#include "BitmapFactory.h"
|
||||
#include "Tools.h"
|
||||
#include "Command.h"
|
||||
#include <Base/Tools.h>
|
||||
#include <Base/Exception.h>
|
||||
@@ -830,7 +831,7 @@ QSize QuantitySpinBox::sizeHint() const
|
||||
s = textFromValue(q);
|
||||
s.truncate(18);
|
||||
s += fixedContent;
|
||||
w = qMax(w, fm.width(s));
|
||||
w = qMax(w, QtTools::horizontalAdvance(fm, s));
|
||||
|
||||
w += 2; // cursor blinking space
|
||||
w += iconHeight;
|
||||
@@ -860,7 +861,7 @@ QSize QuantitySpinBox::minimumSizeHint() const
|
||||
s = textFromValue(q);
|
||||
s.truncate(18);
|
||||
s += fixedContent;
|
||||
w = qMax(w, fm.width(s));
|
||||
w = qMax(w, QtTools::horizontalAdvance(fm, s));
|
||||
|
||||
w += 2; // cursor blinking space
|
||||
w += iconHeight;
|
||||
|
||||
@@ -41,6 +41,7 @@
|
||||
#include "BitmapFactory.h"
|
||||
#include "MainWindow.h"
|
||||
#include "Application.h"
|
||||
#include "Tools.h"
|
||||
|
||||
using namespace Gui;
|
||||
using namespace Gui::DockWnd;
|
||||
@@ -653,7 +654,7 @@ void ReportOutput::OnChange(Base::Subject<const char*> &rCaller, const char * sR
|
||||
QFont font(fontFamily, fontSize);
|
||||
setFont(font);
|
||||
QFontMetrics metric(font);
|
||||
int width = metric.width(QLatin1String("0000"));
|
||||
int width = QtTools::horizontalAdvance(metric, QLatin1String("0000"));
|
||||
setTabStopWidth(width);
|
||||
}
|
||||
else if (strcmp(sReason, "RedirectPythonOutput") == 0) {
|
||||
|
||||
@@ -65,6 +65,7 @@
|
||||
#include "SoTextLabel.h"
|
||||
#include "SoFCInteractiveElement.h"
|
||||
#include "BitmapFactory.h"
|
||||
#include "Tools.h"
|
||||
|
||||
using namespace Gui;
|
||||
|
||||
@@ -452,7 +453,7 @@ void SoFrameLabel::drawImage()
|
||||
QStringList lines;
|
||||
for (int i=0; i<num; i++) {
|
||||
QString line = QString::fromUtf8(s[i].getString());
|
||||
w = std::max<int>(w, fm.width(line));
|
||||
w = std::max<int>(w, QtTools::horizontalAdvance(fm, line));
|
||||
lines << line;
|
||||
}
|
||||
|
||||
|
||||
@@ -32,6 +32,7 @@
|
||||
|
||||
#include "TextEdit.h"
|
||||
#include "SyntaxHighlighter.h"
|
||||
#include "Tools.h"
|
||||
|
||||
using namespace Gui;
|
||||
|
||||
@@ -239,7 +240,7 @@ TextEditor::~TextEditor()
|
||||
|
||||
int TextEditor::lineNumberAreaWidth()
|
||||
{
|
||||
return fontMetrics().width(QLatin1String("0000"))+10;
|
||||
return QtTools::horizontalAdvance(fontMetrics(), QLatin1String("0000")) + 10;
|
||||
}
|
||||
|
||||
void TextEditor::updateLineNumberAreaWidth(int /* newBlockCount */)
|
||||
@@ -449,7 +450,7 @@ void TextEditor::OnChange(Base::Subject<const char*> &rCaller,const char* sReaso
|
||||
if (strcmp(sReason, "TabSize") == 0 || strcmp(sReason, "FontSize") == 0) {
|
||||
int tabWidth = hPrefGrp->GetInt("TabSize", 4);
|
||||
QFontMetrics metric(font());
|
||||
int fontSize = metric.width(QLatin1String("0"));
|
||||
int fontSize = QtTools::horizontalAdvance(metric, QLatin1Char('0'));
|
||||
setTabStopWidth(tabWidth * fontSize);
|
||||
}
|
||||
|
||||
|
||||
54
src/Gui/Tools.h
Normal file
54
src/Gui/Tools.h
Normal file
@@ -0,0 +1,54 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2020 Werner Mayer <wmayer[at]users.sourceforge.net> *
|
||||
* *
|
||||
* This file is part of the FreeCAD CAx development system. *
|
||||
* *
|
||||
* This library is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU Library General Public *
|
||||
* License as published by the Free Software Foundation; either *
|
||||
* version 2 of the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This library is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU Library General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Library General Public *
|
||||
* License along with this library; see the file COPYING.LIB. If not, *
|
||||
* write to the Free Software Foundation, Inc., 59 Temple Place, *
|
||||
* Suite 330, Boston, MA 02111-1307, USA *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
#ifndef GUI_TOOLS_H
|
||||
#define GUI_TOOLS_H
|
||||
|
||||
#include <QFontMetrics>
|
||||
|
||||
namespace Gui {
|
||||
|
||||
/*!
|
||||
* \brief The QtTools class
|
||||
* Helper class to reduce adding a lot of extra QT_VERSION checks to client code.
|
||||
*/
|
||||
class GuiExport QtTools {
|
||||
public:
|
||||
static int horizontalAdvance(const QFontMetrics& fm, QChar ch) {
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)
|
||||
return fm.horizontalAdvance(ch);
|
||||
#else
|
||||
return fm.width(ch);
|
||||
#endif
|
||||
}
|
||||
static int horizontalAdvance(const QFontMetrics& fm, const QString& text, int len = -1) {
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)
|
||||
return fm.horizontalAdvance(text, len);
|
||||
#else
|
||||
return fm.width(text, len);
|
||||
#endif
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace Gui
|
||||
|
||||
#endif // GUI_TOOLS_H
|
||||
@@ -58,6 +58,7 @@
|
||||
#include "Application.h"
|
||||
#include "Document.h"
|
||||
#include "Window.h"
|
||||
#include "Tools.h"
|
||||
|
||||
using namespace Gui;
|
||||
|
||||
@@ -493,7 +494,7 @@ void ViewProviderAnnotationLabel::drawImage(const std::vector<std::string>& s)
|
||||
QStringList lines;
|
||||
for (std::vector<std::string>::const_iterator it = s.begin(); it != s.end(); ++it) {
|
||||
QString line = QString::fromUtf8(it->c_str());
|
||||
w = std::max<int>(w, fm.width(line));
|
||||
w = std::max<int>(w, QtTools::horizontalAdvance(fm, line));
|
||||
lines << line;
|
||||
}
|
||||
|
||||
|
||||
@@ -54,6 +54,7 @@
|
||||
#include "BitmapFactory.h"
|
||||
#include "DlgExpressionInput.h"
|
||||
#include "QuantitySpinBox_p.h"
|
||||
#include "Tools.h"
|
||||
|
||||
using namespace Gui;
|
||||
using namespace App;
|
||||
@@ -1191,7 +1192,7 @@ int PropertyListEditor::lineNumberAreaWidth()
|
||||
++digits;
|
||||
}
|
||||
|
||||
int space = 3 + fontMetrics().width(QLatin1Char('9')) * digits;
|
||||
int space = 3 + QtTools::horizontalAdvance(fontMetrics(), QLatin1Char('9')) * digits;
|
||||
|
||||
return space;
|
||||
}
|
||||
@@ -1398,8 +1399,8 @@ void LabelEditor::validateText(const QString& text)
|
||||
void LabelEditor::setButtonText(const QString& txt)
|
||||
{
|
||||
button->setText(txt);
|
||||
int w1 = 2*button->fontMetrics().width(txt);
|
||||
int w2 = 2*button->fontMetrics().width(QLatin1String(" ... "));
|
||||
int w1 = 2 * QtTools::horizontalAdvance(button->fontMetrics(), txt);
|
||||
int w2 = 2 * QtTools::horizontalAdvance(button->fontMetrics(), QLatin1String(" ... "));
|
||||
button->setFixedWidth((w1 > w2 ? w1 : w2));
|
||||
}
|
||||
|
||||
|
||||
@@ -74,7 +74,11 @@ QSize iisIconLabel::minimumSizeHint() const
|
||||
int w = 8 + px.width();
|
||||
if (!myText.isEmpty()) {
|
||||
QFontMetrics fm(myFont);
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)
|
||||
w += fm.horizontalAdvance(myText);
|
||||
#else
|
||||
w += fm.width(myText);
|
||||
#endif
|
||||
h = qMax(h, 4+fm.height());
|
||||
}
|
||||
|
||||
|
||||
@@ -61,6 +61,7 @@
|
||||
#include <Gui/Utilities.h>
|
||||
#include <Gui/View3DInventor.h>
|
||||
#include <Gui/View3DInventorViewer.h>
|
||||
#include <Gui/Tools.h>
|
||||
|
||||
#include <App/Document.h>
|
||||
#include <App/DocumentObject.h>
|
||||
@@ -408,7 +409,7 @@ void FaceColors::updatePanel()
|
||||
|
||||
int maxWidth = d->ui->labelElement->width();
|
||||
QFontMetrics fm(d->ui->labelElement->font());
|
||||
if (fm.width(faces) > maxWidth) {
|
||||
if (Gui::QtTools::horizontalAdvance(fm, faces) > maxWidth) {
|
||||
faces = fm.elidedText(faces, Qt::ElideMiddle, maxWidth);
|
||||
}
|
||||
|
||||
|
||||
@@ -44,6 +44,7 @@
|
||||
#include <Base/UnitsApi.h>
|
||||
#include <Gui/Selection.h>
|
||||
#include <Gui/Command.h>
|
||||
#include <Gui/Tools.h>
|
||||
#include <Mod/PartDesign/App/FeatureChamfer.h>
|
||||
#include <Mod/PartDesign/App/Body.h>
|
||||
#include <Mod/Sketcher/App/SketchObject.h>
|
||||
@@ -131,10 +132,10 @@ void TaskChamferParameters::setUpUI(PartDesign::Chamfer* pcChamfer)
|
||||
ui->stackedWidget->setFixedHeight(ui->chamferSize2->sizeHint().height());
|
||||
|
||||
QFontMetrics fm(ui->typeLabel->font());
|
||||
int minWidth = fm.width(ui->typeLabel->text());
|
||||
minWidth = std::max<int>(minWidth, fm.width(ui->sizeLabel->text()));
|
||||
minWidth = std::max<int>(minWidth, fm.width(ui->size2Label->text()));
|
||||
minWidth = std::max<int>(minWidth, fm.width(ui->angleLabel->text()));
|
||||
int minWidth = Gui::QtTools::horizontalAdvance(fm, ui->typeLabel->text());
|
||||
minWidth = std::max<int>(minWidth, Gui::QtTools::horizontalAdvance(fm, ui->sizeLabel->text()));
|
||||
minWidth = std::max<int>(minWidth, Gui::QtTools::horizontalAdvance(fm, ui->size2Label->text()));
|
||||
minWidth = std::max<int>(minWidth, Gui::QtTools::horizontalAdvance(fm, ui->angleLabel->text()));
|
||||
minWidth = minWidth + 5; //spacing
|
||||
ui->typeLabel->setMinimumWidth(minWidth);
|
||||
ui->sizeLabel->setMinimumWidth(minWidth);
|
||||
|
||||
@@ -56,6 +56,7 @@
|
||||
|
||||
#include "SoDatumLabel.h"
|
||||
#include <Gui/BitmapFactory.h>
|
||||
#include <Gui/Tools.h>
|
||||
|
||||
#define ZCONSTR 0.006f
|
||||
|
||||
@@ -116,7 +117,7 @@ void SoDatumLabel::drawImage()
|
||||
QFontMetrics fm(font);
|
||||
QString str = QString::fromUtf8(s[0].getString());
|
||||
|
||||
int w = fm.width(str);
|
||||
int w = Gui::QtTools::horizontalAdvance(fm, str);
|
||||
int h = fm.height();
|
||||
|
||||
// No Valid text
|
||||
|
||||
@@ -94,6 +94,7 @@
|
||||
#include <Gui/CommandT.h>
|
||||
#include <Gui/Control.h>
|
||||
#include <Gui/Selection.h>
|
||||
#include <Gui/Tools.h>
|
||||
#include <Gui/Utilities.h>
|
||||
#include <Gui/MainWindow.h>
|
||||
#include <Gui/MenuManager.h>
|
||||
@@ -3471,7 +3472,7 @@ QImage ViewProviderSketch::renderConstrIcon(const QString &type,
|
||||
boundingBoxes->push_back(labelBB);
|
||||
}
|
||||
|
||||
cursorOffset += qfm.width(labelStr);
|
||||
cursorOffset += Gui::QtTools::horizontalAdvance(qfm, labelStr);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -46,6 +46,7 @@
|
||||
#include <Gui/Command.h>
|
||||
#include <Gui/Application.h>
|
||||
#include <Gui/Document.h>
|
||||
#include <Gui/Tools.h>
|
||||
#include <Gui/ViewProvider.h>
|
||||
|
||||
#include "Rez.h"
|
||||
@@ -719,7 +720,7 @@ int QGIView::calculateFontPixelSize(double sizeInMillimetres)
|
||||
int QGIView::calculateFontPixelWidth(const QFont &font)
|
||||
{
|
||||
// Return the width of digit 0, most likely the most wide digit
|
||||
return QFontMetrics(font).width(QChar::fromLatin1('0'));
|
||||
return Gui::QtTools::horizontalAdvance(QFontMetrics(font), QChar::fromLatin1('0'));
|
||||
}
|
||||
|
||||
const double QGIView::DefaultFontSizeInMM = 5.0;
|
||||
|
||||
@@ -48,6 +48,7 @@
|
||||
#include <Base/Parameter.h>
|
||||
#include <Gui/Command.h>
|
||||
#include <Gui/Control.h>
|
||||
#include <Gui/Tools.h>
|
||||
#include <string>
|
||||
|
||||
#include <Mod/TechDraw/App/DrawPage.h>
|
||||
@@ -444,7 +445,7 @@ void QGIViewBalloon::updateBalloon(bool obtuse)
|
||||
int pos = labelText.indexOf(QString::fromUtf8("|"));
|
||||
labelText.replace(pos, 1, QString::fromUtf8(" "));
|
||||
QFontMetrics fm(balloonLabel->getFont());
|
||||
balloonLabel->seps.push_back(fm.width((labelText.left(pos + 2))));
|
||||
balloonLabel->seps.push_back(Gui::QtTools::horizontalAdvance(fm, labelText.left(pos + 2)));
|
||||
balloonLabel->verticalSep = true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user