9 #include <QApplication>
12 #include <QFontDatabase>
15 #include <QMouseEvent>
18 #if defined(HAVE_CONFIG_H)
38 if (data.isEmpty())
return false;
42 setText(tr(
"Resulting URI too long, try to reduce the text for label / message."));
46 QRcode *code = QRcode_encodeString(data.toUtf8().constData(), 0, QR_ECLEVEL_L, QR_MODE_8, 1);
49 setText(tr(
"Error encoding URI into QR Code."));
53 QImage qrImage = QImage(code->width + 8, code->width + 8, QImage::Format_RGB32);
54 qrImage.fill(0xffffff);
55 unsigned char *p = code->data;
56 for (
int y = 0; y < code->width; ++y) {
57 for (
int x = 0; x < code->width; ++x) {
58 qrImage.setPixel(x + 4, y + 4, ((*p & 1) ? 0x0 : 0xffffff));
65 QImage qrAddrImage(qr_image_size, qr_image_size, QImage::Format_RGB32);
66 qrAddrImage.fill(0xffffff);
68 QPainter painter(&qrAddrImage);
71 if (!text.isEmpty()) {
72 QRect paddedRect = qrAddrImage.rect();
76 font.setStretch(QFont::SemiCondensed);
77 font.setLetterSpacing(QFont::AbsoluteSpacing, 1);
79 font.setPointSizeF(font_size);
81 painter.setFont(font);
82 painter.drawText(paddedRect, Qt::AlignBottom | Qt::AlignCenter, text);
86 setPixmap(QPixmap::fromImage(qrAddrImage));
90 setText(tr(
"QR code support not available."));
104 QMimeData *mimeData =
new QMimeData;
107 QDrag *drag =
new QDrag(
this);
108 drag->setMimeData(mimeData);
111 QLabel::mousePressEvent(event);
120 this, tr(
"Save QR Code"), QString(),
123 tr(
"PNG Image") + QLatin1String(
" (*.png)"),
nullptr);
134 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)