mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-09 10:43:19 -05:00
qt, refactor: Fix 'pixmap is deprecated' warnings
This commit is contained in:
parent
b02264cb5d
commit
fa5749c805
4 changed files with 36 additions and 9 deletions
|
@ -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));
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue