Skip to content

Commit

Permalink
qt, refactor: Fix 'pixmap is deprecated' warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
hebasto committed Aug 26, 2020
1 parent b02264c commit fa5749c
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/qt/bitcoingui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
22 changes: 22 additions & 0 deletions src/qt/guiutil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 8 additions & 0 deletions src/qt/guiutil.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
13 changes: 5 additions & 8 deletions src/qt/qrimagewidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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())
Expand All @@ -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());
}

0 comments on commit fa5749c

Please sign in to comment.