Merge #16701: qt: Replace functions deprecated in Qt 5.13
c6dd32da69
qt: Replace obsolete functions of QDesktopWidget (Hennadii Stepanov)1260ecd812
qt: Add TextWidth() wrapper (Hennadii Stepanov) Pull request description: The following functions are obsolete in Qt 5.13: - [`QFontMetrics::width()`](https://doc.qt.io/qt-5/qfontmetrics-obsolete.html#width) - [`QDesktopWidget::availableGeometry()`](https://doc.qt.io/qt-5/qdesktopwidget-obsolete.html#availableGeometry) - [`QDesktopWidget::screenGeometry()`](https://doc.qt.io/qt-5/qdesktopwidget-obsolete.html#screenGeometry) This PR replaces them and does not change behavior. Here are some excerpts from the master build log: ``` qt/bitcoingui.cpp: In constructor ‘BitcoinGUI::BitcoinGUI(interfaces::Node&, const PlatformStyle*, const NetworkStyle*, QWidget*)’: qt/bitcoingui.cpp:84:57: warning: ‘const QRect QDesktopWidget::availableGeometry(int) const’ is deprecated: Use QGuiApplication::screens() [-Wdeprecated-declarations] move(QApplication::desktop()->availableGeometry().center() - frameGeometry().center()); ^ In file included from /home/hebasto/Qt/5.13.0/gcc_64/include/QtWidgets/QDesktopWidget:1:0, from qt/bitcoingui.cpp:43: /home/hebasto/Qt/5.13.0/gcc_64/include/QtWidgets/qdesktopwidget.h:88:67: note: declared here QT_DEPRECATED_X("Use QGuiApplication::screens()") const QRect availableGeometry(int screen = -1) const; ^~~~~~~~~~~~~~~~~ ``` ``` qt/bitcoingui.cpp:1410:74: warning: ‘int QFontMetrics::width(const QString&, int) const’ is deprecated: Use QFontMetrics::horizontalAdvance [-Wdeprecated-declarations] max_width = qMax(max_width, fm.width(BitcoinUnits::longName(unit))); ^ In file included from /home/hebasto/Qt/5.13.0/gcc_64/include/QtWidgets/qwidget.h:50:0, from /home/hebasto/Qt/5.13.0/gcc_64/include/QtWidgets/qdialog.h:44, from /home/hebasto/Qt/5.13.0/gcc_64/include/QtWidgets/QDialog:1, from ./qt/optionsdialog.h:8, from ./qt/bitcoingui.h:12, from qt/bitcoingui.cpp:5: /home/hebasto/Qt/5.13.0/gcc_64/include/QtGui/qfontmetrics.h:108:9: note: declared here int width(const QString &, int len = -1) const; ^~~~~ ``` ``` qt/splashscreen.cpp: In constructor ‘SplashScreen::SplashScreen(interfaces::Node&, Qt::WindowFlags, const NetworkStyle*)’: qt/splashscreen.cpp:127:50: warning: ‘const QRect QDesktopWidget::screenGeometry(int) const’ is deprecated: Use QGuiApplication::screens() [-Wdeprecated-declarations] move(QApplication::desktop()->screenGeometry().center() - r.center()); ^ In file included from /home/hebasto/Qt/5.13.0/gcc_64/include/QtWidgets/QDesktopWidget:1:0, from qt/splashscreen.cpp:24: /home/hebasto/Qt/5.13.0/gcc_64/include/QtWidgets/qdesktopwidget.h:79:67: note: declared here QT_DEPRECATED_X("Use QGuiApplication::screens()") const QRect screenGeometry(int screen = -1) const; ^~~~~~~~~~~~~~ ``` ACKs for top commit: jonasschnelli: utACKc6dd32da69
Tree-SHA512: deb7bcbf86e1dcc6508bd91288772c2fe8811db79fa2011de37d0469cdd094fbf7fd8c4512c607bed0bd08dc2968e893c0bbc190732c43c69ed1085259df766c
This commit is contained in:
commit
d20d171f26
7 changed files with 34 additions and 17 deletions
|
@ -6,6 +6,7 @@
|
||||||
|
|
||||||
#include <qt/bitcoinunits.h>
|
#include <qt/bitcoinunits.h>
|
||||||
#include <qt/guiconstants.h>
|
#include <qt/guiconstants.h>
|
||||||
|
#include <qt/guiutil.h>
|
||||||
#include <qt/qvaluecombobox.h>
|
#include <qt/qvaluecombobox.h>
|
||||||
|
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
|
@ -121,7 +122,7 @@ public:
|
||||||
|
|
||||||
const QFontMetrics fm(fontMetrics());
|
const QFontMetrics fm(fontMetrics());
|
||||||
int h = lineEdit()->minimumSizeHint().height();
|
int h = lineEdit()->minimumSizeHint().height();
|
||||||
int w = fm.width(BitcoinUnits::format(BitcoinUnits::BTC, BitcoinUnits::maxMoney(), false, BitcoinUnits::separatorAlways));
|
int w = GUIUtil::TextWidth(fm, BitcoinUnits::format(BitcoinUnits::BTC, BitcoinUnits::maxMoney(), false, BitcoinUnits::separatorAlways));
|
||||||
w += 2; // cursor blinking space
|
w += 2; // cursor blinking space
|
||||||
|
|
||||||
QStyleOptionSpinBox opt;
|
QStyleOptionSpinBox opt;
|
||||||
|
|
|
@ -40,7 +40,6 @@
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QComboBox>
|
#include <QComboBox>
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
#include <QDesktopWidget>
|
|
||||||
#include <QDragEnterEvent>
|
#include <QDragEnterEvent>
|
||||||
#include <QListWidget>
|
#include <QListWidget>
|
||||||
#include <QMenu>
|
#include <QMenu>
|
||||||
|
@ -48,6 +47,7 @@
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <QMimeData>
|
#include <QMimeData>
|
||||||
#include <QProgressDialog>
|
#include <QProgressDialog>
|
||||||
|
#include <QScreen>
|
||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
#include <QShortcut>
|
#include <QShortcut>
|
||||||
#include <QStackedWidget>
|
#include <QStackedWidget>
|
||||||
|
@ -81,7 +81,7 @@ BitcoinGUI::BitcoinGUI(interfaces::Node& node, const PlatformStyle *_platformSty
|
||||||
QSettings settings;
|
QSettings settings;
|
||||||
if (!restoreGeometry(settings.value("MainWindowGeometry").toByteArray())) {
|
if (!restoreGeometry(settings.value("MainWindowGeometry").toByteArray())) {
|
||||||
// Restore failed (perhaps missing setting), center the window
|
// Restore failed (perhaps missing setting), center the window
|
||||||
move(QApplication::desktop()->availableGeometry().center() - frameGeometry().center());
|
move(QGuiApplication::primaryScreen()->availableGeometry().center() - frameGeometry().center());
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef ENABLE_WALLET
|
#ifdef ENABLE_WALLET
|
||||||
|
@ -1407,7 +1407,7 @@ UnitDisplayStatusBarControl::UnitDisplayStatusBarControl(const PlatformStyle *pl
|
||||||
const QFontMetrics fm(font());
|
const QFontMetrics fm(font());
|
||||||
for (const BitcoinUnits::Unit unit : units)
|
for (const BitcoinUnits::Unit unit : units)
|
||||||
{
|
{
|
||||||
max_width = qMax(max_width, fm.width(BitcoinUnits::longName(unit)));
|
max_width = qMax(max_width, GUIUtil::TextWidth(fm, BitcoinUnits::longName(unit)));
|
||||||
}
|
}
|
||||||
setMinimumSize(max_width, 0);
|
setMinimumSize(max_width, 0);
|
||||||
setAlignment(Qt::AlignRight | Qt::AlignVCenter);
|
setAlignment(Qt::AlignRight | Qt::AlignVCenter);
|
||||||
|
|
|
@ -39,7 +39,6 @@
|
||||||
#include <QClipboard>
|
#include <QClipboard>
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
#include <QDesktopServices>
|
#include <QDesktopServices>
|
||||||
#include <QDesktopWidget>
|
|
||||||
#include <QDoubleValidator>
|
#include <QDoubleValidator>
|
||||||
#include <QFileDialog>
|
#include <QFileDialog>
|
||||||
#include <QFont>
|
#include <QFont>
|
||||||
|
@ -916,7 +915,7 @@ qreal calculateIdealFontSize(int width, const QString& text, QFont font, qreal m
|
||||||
while(font_size >= minPointSize) {
|
while(font_size >= minPointSize) {
|
||||||
font.setPointSizeF(font_size);
|
font.setPointSizeF(font_size);
|
||||||
QFontMetrics fm(font);
|
QFontMetrics fm(font);
|
||||||
if (fm.width(text) < width) {
|
if (TextWidth(fm, text) < width) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
font_size -= 0.5;
|
font_size -= 0.5;
|
||||||
|
@ -956,4 +955,13 @@ void PolishProgressDialog(QProgressDialog* dialog)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int TextWidth(const QFontMetrics& fm, const QString& text)
|
||||||
|
{
|
||||||
|
#if (QT_VERSION >= QT_VERSION_CHECK(5, 11, 0))
|
||||||
|
return fm.horizontalAdvance(text);
|
||||||
|
#else
|
||||||
|
return fm.width(text);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace GUIUtil
|
} // namespace GUIUtil
|
||||||
|
|
|
@ -257,6 +257,14 @@ namespace GUIUtil
|
||||||
|
|
||||||
// Fix known bugs in QProgressDialog class.
|
// Fix known bugs in QProgressDialog class.
|
||||||
void PolishProgressDialog(QProgressDialog* dialog);
|
void PolishProgressDialog(QProgressDialog* dialog);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the distance in pixels appropriate for drawing a subsequent character after text.
|
||||||
|
*
|
||||||
|
* In Qt 5.12 and before the QFontMetrics::width() is used and it is deprecated since Qt 13.0.
|
||||||
|
* In Qt 5.11 the QFontMetrics::horizontalAdvance() was introduced.
|
||||||
|
*/
|
||||||
|
int TextWidth(const QFontMetrics& fm, const QString& text);
|
||||||
} // namespace GUIUtil
|
} // namespace GUIUtil
|
||||||
|
|
||||||
#endif // BITCOIN_QT_GUIUTIL_H
|
#endif // BITCOIN_QT_GUIUTIL_H
|
||||||
|
|
|
@ -28,11 +28,11 @@
|
||||||
#include <wallet/wallet.h>
|
#include <wallet/wallet.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <QDesktopWidget>
|
|
||||||
#include <QKeyEvent>
|
#include <QKeyEvent>
|
||||||
#include <QMenu>
|
#include <QMenu>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <QScrollBar>
|
#include <QScrollBar>
|
||||||
|
#include <QScreen>
|
||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
#include <QSignalMapper>
|
#include <QSignalMapper>
|
||||||
#include <QTime>
|
#include <QTime>
|
||||||
|
@ -451,7 +451,7 @@ RPCConsole::RPCConsole(interfaces::Node& node, const PlatformStyle *_platformSty
|
||||||
QSettings settings;
|
QSettings settings;
|
||||||
if (!restoreGeometry(settings.value("RPCConsoleWindowGeometry").toByteArray())) {
|
if (!restoreGeometry(settings.value("RPCConsoleWindowGeometry").toByteArray())) {
|
||||||
// Restore failed (perhaps missing setting), center the window
|
// Restore failed (perhaps missing setting), center the window
|
||||||
move(QApplication::desktop()->availableGeometry().center() - frameGeometry().center());
|
move(QGuiApplication::primaryScreen()->availableGeometry().center() - frameGeometry().center());
|
||||||
}
|
}
|
||||||
|
|
||||||
QChar nonbreaking_hyphen(8209);
|
QChar nonbreaking_hyphen(8209);
|
||||||
|
|
|
@ -704,7 +704,7 @@ void SendCoinsDialog::updateSmartFeeLabel()
|
||||||
int lightness = ui->fallbackFeeWarningLabel->palette().color(QPalette::WindowText).lightness();
|
int lightness = ui->fallbackFeeWarningLabel->palette().color(QPalette::WindowText).lightness();
|
||||||
QColor warning_colour(255 - (lightness / 5), 176 - (lightness / 3), 48 - (lightness / 14));
|
QColor warning_colour(255 - (lightness / 5), 176 - (lightness / 3), 48 - (lightness / 14));
|
||||||
ui->fallbackFeeWarningLabel->setStyleSheet("QLabel { color: " + warning_colour.name() + "; }");
|
ui->fallbackFeeWarningLabel->setStyleSheet("QLabel { color: " + warning_colour.name() + "; }");
|
||||||
ui->fallbackFeeWarningLabel->setIndent(QFontMetrics(ui->fallbackFeeWarningLabel->font()).width("x"));
|
ui->fallbackFeeWarningLabel->setIndent(GUIUtil::TextWidth(QFontMetrics(ui->fallbackFeeWarningLabel->font()), "x"));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -8,12 +8,12 @@
|
||||||
|
|
||||||
#include <qt/splashscreen.h>
|
#include <qt/splashscreen.h>
|
||||||
|
|
||||||
#include <qt/networkstyle.h>
|
|
||||||
|
|
||||||
#include <clientversion.h>
|
#include <clientversion.h>
|
||||||
#include <interfaces/handler.h>
|
#include <interfaces/handler.h>
|
||||||
#include <interfaces/node.h>
|
#include <interfaces/node.h>
|
||||||
#include <interfaces/wallet.h>
|
#include <interfaces/wallet.h>
|
||||||
|
#include <qt/guiutil.h>
|
||||||
|
#include <qt/networkstyle.h>
|
||||||
#include <ui_interface.h>
|
#include <ui_interface.h>
|
||||||
#include <util/system.h>
|
#include <util/system.h>
|
||||||
#include <util/translation.h>
|
#include <util/translation.h>
|
||||||
|
@ -21,9 +21,9 @@
|
||||||
|
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QCloseEvent>
|
#include <QCloseEvent>
|
||||||
#include <QDesktopWidget>
|
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <QRadialGradient>
|
#include <QRadialGradient>
|
||||||
|
#include <QScreen>
|
||||||
|
|
||||||
|
|
||||||
SplashScreen::SplashScreen(interfaces::Node& node, Qt::WindowFlags f, const NetworkStyle *networkStyle) :
|
SplashScreen::SplashScreen(interfaces::Node& node, Qt::WindowFlags f, const NetworkStyle *networkStyle) :
|
||||||
|
@ -75,21 +75,21 @@ SplashScreen::SplashScreen(interfaces::Node& node, Qt::WindowFlags f, const Netw
|
||||||
// check font size and drawing with
|
// check font size and drawing with
|
||||||
pixPaint.setFont(QFont(font, 33*fontFactor));
|
pixPaint.setFont(QFont(font, 33*fontFactor));
|
||||||
QFontMetrics fm = pixPaint.fontMetrics();
|
QFontMetrics fm = pixPaint.fontMetrics();
|
||||||
int titleTextWidth = fm.width(titleText);
|
int titleTextWidth = GUIUtil::TextWidth(fm, titleText);
|
||||||
if (titleTextWidth > 176) {
|
if (titleTextWidth > 176) {
|
||||||
fontFactor = fontFactor * 176 / titleTextWidth;
|
fontFactor = fontFactor * 176 / titleTextWidth;
|
||||||
}
|
}
|
||||||
|
|
||||||
pixPaint.setFont(QFont(font, 33*fontFactor));
|
pixPaint.setFont(QFont(font, 33*fontFactor));
|
||||||
fm = pixPaint.fontMetrics();
|
fm = pixPaint.fontMetrics();
|
||||||
titleTextWidth = fm.width(titleText);
|
titleTextWidth = GUIUtil::TextWidth(fm, titleText);
|
||||||
pixPaint.drawText(pixmap.width()/devicePixelRatio-titleTextWidth-paddingRight,paddingTop,titleText);
|
pixPaint.drawText(pixmap.width()/devicePixelRatio-titleTextWidth-paddingRight,paddingTop,titleText);
|
||||||
|
|
||||||
pixPaint.setFont(QFont(font, 15*fontFactor));
|
pixPaint.setFont(QFont(font, 15*fontFactor));
|
||||||
|
|
||||||
// if the version string is too long, reduce size
|
// if the version string is too long, reduce size
|
||||||
fm = pixPaint.fontMetrics();
|
fm = pixPaint.fontMetrics();
|
||||||
int versionTextWidth = fm.width(versionText);
|
int versionTextWidth = GUIUtil::TextWidth(fm, versionText);
|
||||||
if(versionTextWidth > titleTextWidth+paddingRight-10) {
|
if(versionTextWidth > titleTextWidth+paddingRight-10) {
|
||||||
pixPaint.setFont(QFont(font, 10*fontFactor));
|
pixPaint.setFont(QFont(font, 10*fontFactor));
|
||||||
titleVersionVSpace -= 5;
|
titleVersionVSpace -= 5;
|
||||||
|
@ -111,7 +111,7 @@ SplashScreen::SplashScreen(interfaces::Node& node, Qt::WindowFlags f, const Netw
|
||||||
boldFont.setWeight(QFont::Bold);
|
boldFont.setWeight(QFont::Bold);
|
||||||
pixPaint.setFont(boldFont);
|
pixPaint.setFont(boldFont);
|
||||||
fm = pixPaint.fontMetrics();
|
fm = pixPaint.fontMetrics();
|
||||||
int titleAddTextWidth = fm.width(titleAddText);
|
int titleAddTextWidth = GUIUtil::TextWidth(fm, titleAddText);
|
||||||
pixPaint.drawText(pixmap.width()/devicePixelRatio-titleAddTextWidth-10,15,titleAddText);
|
pixPaint.drawText(pixmap.width()/devicePixelRatio-titleAddTextWidth-10,15,titleAddText);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -124,7 +124,7 @@ SplashScreen::SplashScreen(interfaces::Node& node, Qt::WindowFlags f, const Netw
|
||||||
QRect r(QPoint(), QSize(pixmap.size().width()/devicePixelRatio,pixmap.size().height()/devicePixelRatio));
|
QRect r(QPoint(), QSize(pixmap.size().width()/devicePixelRatio,pixmap.size().height()/devicePixelRatio));
|
||||||
resize(r.size());
|
resize(r.size());
|
||||||
setFixedSize(r.size());
|
setFixedSize(r.size());
|
||||||
move(QApplication::desktop()->screenGeometry().center() - r.center());
|
move(QGuiApplication::primaryScreen()->geometry().center() - r.center());
|
||||||
|
|
||||||
subscribeToCoreSignals();
|
subscribeToCoreSignals();
|
||||||
installEventFilter(this);
|
installEventFilter(this);
|
||||||
|
|
Loading…
Reference in a new issue