mirror of
https://github.com/ElementsProject/elements.git
synced 2026-08-13 12:33:42 +02:00
GUI: Receive: Split up long addresses across multiple lines, in QR code image
This commit is contained in:
parent
25600f90dd
commit
273aa76f85
1 changed files with 13 additions and 4 deletions
|
|
@ -178,20 +178,29 @@ void ReceiveRequestDialog::update()
|
|||
}
|
||||
QRcode_free(code);
|
||||
|
||||
QImage qrAddrImage = QImage(QR_IMAGE_SIZE, QR_IMAGE_SIZE+20, QImage::Format_RGB32);
|
||||
QFont font = GUIUtil::fixedPitchFont();
|
||||
font.setPixelSize(12);
|
||||
QFontMetrics fm(font);
|
||||
const int lines = (fm.width(info.address) / QR_IMAGE_SIZE) + 1;
|
||||
QString split_address = info.address;
|
||||
const int chars_per_line = (info.address.length() + lines - 1) / lines;
|
||||
for (int i = 0; i < lines; ++i) {
|
||||
split_address.insert((chars_per_line * i) + i, '\n');
|
||||
}
|
||||
|
||||
QImage qrAddrImage = QImage(QR_IMAGE_SIZE, QR_IMAGE_SIZE + 16 + fm.height(), QImage::Format_RGB32);
|
||||
qrAddrImage.fill(0xffffff);
|
||||
QPainter painter(&qrAddrImage);
|
||||
painter.drawImage(0, 0, qrImage.scaled(QR_IMAGE_SIZE, QR_IMAGE_SIZE));
|
||||
QFont font = GUIUtil::fixedPitchFont();
|
||||
QRect paddedRect = qrAddrImage.rect();
|
||||
paddedRect.setHeight(QR_IMAGE_SIZE + 8 + fm.height());
|
||||
painter.drawText(paddedRect, Qt::AlignBottom | Qt::AlignCenter | Qt::TextWordWrap, split_address);
|
||||
|
||||
// calculate ideal font size
|
||||
qreal font_size = GUIUtil::calculateIdealFontSize(paddedRect.width() - 20, info.address, font);
|
||||
font.setPointSizeF(font_size);
|
||||
|
||||
painter.setFont(font);
|
||||
paddedRect.setHeight(QR_IMAGE_SIZE+12);
|
||||
painter.drawText(paddedRect, Qt::AlignBottom|Qt::AlignCenter, info.address);
|
||||
painter.end();
|
||||
|
||||
ui->lblQRCode->setPixmap(QPixmap::fromImage(qrAddrImage));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue