mirror of
https://github.com/monero-project/monero-gui.git
synced 2025-01-21 10:14:35 +00:00
Merge pull request #1649
f17c407
Add border to generated QR codes (glv2)
This commit is contained in:
commit
7fa55b49fe
2 changed files with 15 additions and 6 deletions
|
@ -473,7 +473,7 @@ Rectangle {
|
||||||
Image {
|
Image {
|
||||||
id: qrCode
|
id: qrCode
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
anchors.margins: 6
|
anchors.margins: 1
|
||||||
|
|
||||||
smooth: false
|
smooth: false
|
||||||
fillMode: Image.PreserveAspectFit
|
fillMode: Image.PreserveAspectFit
|
||||||
|
|
|
@ -7,12 +7,21 @@ QImage QRCodeImageProvider::genQrImage(const QString &id, QSize *size)
|
||||||
using namespace qrcodegen;
|
using namespace qrcodegen;
|
||||||
|
|
||||||
QrCode qrcode = QrCode::encodeText(id.toStdString().c_str(), QrCode::Ecc::MEDIUM);
|
QrCode qrcode = QrCode::encodeText(id.toStdString().c_str(), QrCode::Ecc::MEDIUM);
|
||||||
QImage img = QImage(qrcode.size, qrcode.size, QImage::Format_Mono);
|
unsigned int black = 0;
|
||||||
for (int y = 0; y < qrcode.size; ++y)
|
unsigned int white = 1;
|
||||||
for (int x = 0; x < qrcode.size; ++x)
|
unsigned int borderSize = 4;
|
||||||
img.setPixel(x, y, !qrcode.getModule(x, y)); // 1 is black, not "255/white"
|
unsigned int imageSize = qrcode.size + (2 * borderSize);
|
||||||
|
QImage img = QImage(imageSize, imageSize, QImage::Format_Mono);
|
||||||
|
|
||||||
|
for (unsigned int y = 0; y < imageSize; ++y)
|
||||||
|
for (unsigned int x = 0; x < imageSize; ++x)
|
||||||
|
if ((x < borderSize) || (x >= imageSize - borderSize) || (y < borderSize) || (y >= imageSize - borderSize))
|
||||||
|
img.setPixel(x, y, white);
|
||||||
|
else
|
||||||
|
img.setPixel(x, y, qrcode.getModule(x - borderSize, y - borderSize) ? black : white);
|
||||||
if (size)
|
if (size)
|
||||||
*size = QSize(qrcode.size, qrcode.size);
|
*size = QSize(imageSize, imageSize);
|
||||||
|
|
||||||
return img;
|
return img;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue