17#if defined(HAVE_CONFIG_H)
18#include <config/bitcoin-config.h>
26 : QLabel(parent), contextMenu(nullptr) {
28 QAction *saveImageAction =
new QAction(tr(
"&Save Image..."),
this);
29 connect(saveImageAction, &QAction::triggered,
this,
32 QAction *copyImageAction =
new QAction(tr(
"&Copy Image"),
this);
33 connect(copyImageAction, &QAction::triggered,
this,
39#if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0))
40 return !pixmap(Qt::ReturnByValue).isNull();
42 return pixmap() !=
nullptr;
49 if (qrData.isEmpty()) {
55 setText(tr(
"Resulting URI too long, try to reduce the text for label / "
60 QRcode *code = QRcode_encodeString(qrData.toUtf8().constData(), 0,
61 QR_ECLEVEL_L, QR_MODE_8, 1);
64 setText(tr(
"Error encoding URI into QR Code."));
69 QImage(code->width + 8, code->width + 8, QImage::Format_RGB32);
70 qrImage.fill(0xffffff);
71 uint8_t *p = code->data;
72 for (
int y = 0; y < code->width; ++y) {
73 for (
int x = 0; x < code->width; ++x) {
74 qrImage.setPixel(x + 4, y + 4, ((*p & 1) ? 0x0 : 0xffffff));
82 QImage::Format_RGB32);
83 qrAddrImage.fill(0xffffff);
84 QPainter painter(&qrAddrImage);
87 if (!text.isEmpty()) {
89 QRect paddedRect = qrAddrImage.rect();
93 paddedRect.width() - 20, text, font);
94 font.setPointSizeF(font_size);
96 painter.setFont(font);
98 painter.drawText(paddedRect, Qt::AlignBottom | Qt::AlignCenter, text);
102 setPixmap(QPixmap::fromImage(qrAddrImage));
106 setText(tr(
"QR code support not available."));
112#if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0))
113 return pixmap(Qt::ReturnByValue).toImage();
115 return hasPixmap() ? pixmap()->toImage() : QImage();
120 if (event->button() == Qt::LeftButton &&
hasPixmap()) {
122 QMimeData *mimeData =
new QMimeData;
125 QDrag *drag =
new QDrag(
this);
126 drag->setMimeData(mimeData);
129 QLabel::mousePressEvent(event);
138 tr(
"PNG Image (*.png)"),
nullptr);
148 QApplication::clipboard()->setImage(
exportImage());
QString getSaveFileName(QWidget *parent, const QString &caption, const QString &dir, const QString &filter, QString *selectedSuffixOut)
Get save filename, mimics QFileDialog::getSaveFileName, except that it appends a default suffix when ...
qreal calculateIdealFontSize(int width, const QString &text, QFont font, qreal minPointSize, qreal font_size)