28 #if defined(Q_OS_WIN32) || defined(Q_OS_HAIKU)
31 #include <sys/errno.h>
48 image =
new QImage(
size, QImage::Format_RGB32);
75 return image->save(path,
nullptr, 75);
81 QPainter painter(
image);
87 const std::string dataString =
data.toStdString();
88 QRcode* qr = QRcode_encodeString(dataString.c_str(), 1, QR_ECLEVEL_M, QR_MODE_8, 1);
94 painter.setPen(Qt::NoPen);
95 painter.drawRect(0, 0,
size.width(),
size.height());
97 painter.scale(0.96, 0.96);
98 painter.translate(
size.width() * 0.02,
size.height() * 0.02);
99 const int s = qr->width > 0 ? qr->width : 1;
100 const double w = width();
101 const double h = height();
102 const double aspect = w / h;
103 const double scale = ((aspect > 1.0) ? h : w) / s;
105 for (
int y = 0; y < s; ++y) {
106 const int yy = y * s;
107 for (
int x = 0; x < s; ++x) {
108 const int xx = yy + x;
109 const unsigned char b = qr->data[xx];
111 const double rx1 = x * scale, ry1 = y * scale;
112 QRectF r(rx1, ry1, scale, scale);
113 painter.drawRects(&r, 1);
120 painter.setBrush(error);
121 painter.drawRect(0, 0, width(), height());
122 qDebug() <<
"QR FAIL: " << strerror(errno);