12#include <QFontDatabase>
18#include <bitcoin-build-config.h>
36 if (
data.isEmpty())
return false;
40 setText(tr(
"Resulting URI too long, try to reduce the text for label / message."));
44 QRcode *code = QRcode_encodeString(
data.toUtf8().constData(), 0, QR_ECLEVEL_L, QR_MODE_8, 1);
47 setText(tr(
"Error encoding URI into QR Code."));
51 QImage qrImage = QImage(code->width + 8, code->width + 8, QImage::Format_RGB32);
52 qrImage.fill(0xffffff);
53 unsigned char *p = code->data;
54 for (
int y = 0; y < code->width; ++y) {
55 for (
int x = 0; x < code->width; ++x) {
56 qrImage.setPixel(x + 4, y + 4, ((*p & 1) ? 0x0 : 0xffffff));
63 QImage qrAddrImage(qr_image_size, qr_image_size, QImage::Format_RGB32);
64 qrAddrImage.fill(0xffffff);
66 QPainter painter(&qrAddrImage);
69 if (!text.isEmpty()) {
70 QRect paddedRect = qrAddrImage.rect();
74 font.setStretch(QFont::SemiCondensed);
75 font.setLetterSpacing(QFont::AbsoluteSpacing, 1);
77 font.setPointSizeF(font_size);
79 painter.setFont(font);
80 painter.drawText(paddedRect, Qt::AlignBottom | Qt::AlignCenter, text);
84 setPixmap(QPixmap::fromImage(qrAddrImage));
88 setText(tr(
"QR code support not available."));
102 QMimeData *mimeData =
new QMimeData;
105 QDrag *drag =
new QDrag(
this);
106 drag->setMimeData(mimeData);
109 QLabel::mousePressEvent(event);
118 this, tr(
"Save QR Code"), QString(),
121 tr(
"PNG Image") + QLatin1String(
" (*.png)"),
nullptr);
132 QApplication::clipboard()->setImage(
exportImage());
QImage GetImage(const QLabel *label)
QFont fixedPitchFont(bool use_embedded_font)
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 ...
bool HasPixmap(const QLabel *label)
Returns true if pixmap has been set.
qreal calculateIdealFontSize(int width, const QString &text, QFont font, qreal minPointSize, qreal font_size)