diff options
author | Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> | 2020-08-09 17:55:34 +0300 |
---|---|---|
committer | Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> | 2020-08-26 20:17:52 +0300 |
commit | fa5749c805878304c107bcae0ae5ffa401dc7c4d (patch) | |
tree | 00567d46ca9289dcad996d00ab2312432ca12bdb /src | |
parent | b02264cb5dfcef50eec8a6346471cbaa25370e00 (diff) | |
download | bitcoin-fa5749c805878304c107bcae0ae5ffa401dc7c4d.tar.xz |
qt, refactor: Fix 'pixmap is deprecated' warnings
Diffstat (limited to 'src')
-rw-r--r-- | src/qt/bitcoingui.cpp | 2 | ||||
-rw-r--r-- | src/qt/guiutil.cpp | 22 | ||||
-rw-r--r-- | src/qt/guiutil.h | 8 | ||||
-rw-r--r-- | src/qt/qrimagewidget.cpp | 13 |
4 files changed, 36 insertions, 9 deletions
diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp index 8935ff19bf..07254fdbea 100644 --- a/src/qt/bitcoingui.cpp +++ b/src/qt/bitcoingui.cpp @@ -1305,7 +1305,7 @@ void BitcoinGUI::updateProxyIcon() bool proxy_enabled = clientModel->getProxyInfo(ip_port); if (proxy_enabled) { - if (labelProxyIcon->pixmap() == nullptr) { + if (!GUIUtil::HasPixmap(labelProxyIcon)) { QString ip_port_q = QString::fromStdString(ip_port); labelProxyIcon->setPixmap(platformStyle->SingleColorIcon(":/icons/proxy").pixmap(STATUSBAR_ICONSIZE, STATUSBAR_ICONSIZE)); labelProxyIcon->setToolTip(tr("Proxy is <b>enabled</b>: %1").arg(ip_port_q)); diff --git a/src/qt/guiutil.cpp b/src/qt/guiutil.cpp index 72bc4fcddd..70e76f765b 100644 --- a/src/qt/guiutil.cpp +++ b/src/qt/guiutil.cpp @@ -929,4 +929,26 @@ QDateTime StartOfDay(const QDate& date) #endif } +bool HasPixmap(const QLabel* label) +{ +#if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)) + return !label->pixmap(Qt::ReturnByValue).isNull(); +#else + return label->pixmap() != nullptr; +#endif +} + +QImage GetImage(const QLabel* label) +{ + if (!HasPixmap(label)) { + return QImage(); + } + +#if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)) + return label->pixmap(Qt::ReturnByValue).toImage(); +#else + return label->pixmap()->toImage(); +#endif +} + } // namespace GUIUtil diff --git a/src/qt/guiutil.h b/src/qt/guiutil.h index 9ce5275e10..47145d6f85 100644 --- a/src/qt/guiutil.h +++ b/src/qt/guiutil.h @@ -312,6 +312,14 @@ namespace GUIUtil */ QDateTime StartOfDay(const QDate& date); + /** + * Returns true if pixmap has been set. + * + * QPixmap* QLabel::pixmap() is deprecated since Qt 5.15. + */ + bool HasPixmap(const QLabel* label); + QImage GetImage(const QLabel* label); + } // namespace GUIUtil #endif // BITCOIN_QT_GUIUTIL_H diff --git a/src/qt/qrimagewidget.cpp b/src/qt/qrimagewidget.cpp index c816e1f8ed..5dc4d58f86 100644 --- a/src/qt/qrimagewidget.cpp +++ b/src/qt/qrimagewidget.cpp @@ -95,15 +95,12 @@ bool QRImageWidget::setQR(const QString& data, const QString& text) QImage QRImageWidget::exportImage() { - if(!pixmap()) - return QImage(); - return pixmap()->toImage(); + return GUIUtil::GetImage(this); } void QRImageWidget::mousePressEvent(QMouseEvent *event) { - if(event->button() == Qt::LeftButton && pixmap()) - { + if (event->button() == Qt::LeftButton && GUIUtil::HasPixmap(this)) { event->accept(); QMimeData *mimeData = new QMimeData; mimeData->setImageData(exportImage()); @@ -118,7 +115,7 @@ void QRImageWidget::mousePressEvent(QMouseEvent *event) void QRImageWidget::saveImage() { - if(!pixmap()) + if (!GUIUtil::HasPixmap(this)) return; QString fn = GUIUtil::getSaveFileName(this, tr("Save QR Code"), QString(), tr("PNG Image (*.png)"), nullptr); if (!fn.isEmpty()) @@ -129,14 +126,14 @@ void QRImageWidget::saveImage() void QRImageWidget::copyImage() { - if(!pixmap()) + if (!GUIUtil::HasPixmap(this)) return; QApplication::clipboard()->setImage(exportImage()); } void QRImageWidget::contextMenuEvent(QContextMenuEvent *event) { - if(!pixmap()) + if (!GUIUtil::HasPixmap(this)) return; contextMenu->exec(event->globalPos()); } |