QR code changes
This commit is contained in:
@@ -12,7 +12,7 @@ QRCodeLabel::QRCodeLabel(QWidget *parent) :
|
||||
QSize QRCodeLabel::sizeHint() const
|
||||
{
|
||||
int w = this->width();
|
||||
return QSize(w, w); // 1:1
|
||||
return QSize(w, w); // 1:1
|
||||
}
|
||||
|
||||
void QRCodeLabel::resizeEvent(QResizeEvent*)
|
||||
@@ -25,8 +25,8 @@ QPixmap QRCodeLabel::scaledPixmap() const {
|
||||
QPixmap pm(size());
|
||||
pm.fill(Qt::white);
|
||||
QPainter painter(&pm);
|
||||
|
||||
qrcodegen::QrCode qr = qrcodegen::QrCode::encodeText(str.toUtf8().constData(), qrcodegen::QrCode::Ecc::LOW);
|
||||
|
||||
qrcodegen::QrCode qr = qrcodegen::QrCode::encodeText(str.toUtf8().constData(), qrcodegen::QrCode::Ecc::HIGH);
|
||||
const int s = qr.getSize()>0?qr.getSize():1;
|
||||
const double w = pm.width();
|
||||
const double h = pm.height();
|
||||
@@ -35,8 +35,8 @@ QPixmap QRCodeLabel::scaledPixmap() const {
|
||||
const double scale = size/(s+2);
|
||||
const double woff = (w - size) > 0 ? (w - size) / 2 : 0;
|
||||
const double hoff = (h - size) > 0 ? (h - size) / 2 : 0;
|
||||
|
||||
// NOTE: For performance reasons my implementation only draws the foreground parts
|
||||
|
||||
// NOTE: For performance reasons my implementation only draws the foreground parts
|
||||
painter.setPen(Qt::NoPen);
|
||||
painter.setBrush(QColor(Qt::black));
|
||||
for(int y=0; y<s; y++) {
|
||||
@@ -49,7 +49,11 @@ QPixmap QRCodeLabel::scaledPixmap() const {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// TODO: Maybe add logo if it doesn't break QR code - requires setting Ecc to HIGH
|
||||
painter.drawPixmap((w/2)-50, (h/2)-50, 100, 100, QPixmap(":/img/logobig.gif"));
|
||||
painter.end();
|
||||
|
||||
return pm;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user