mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-23 07:15:29 +01:00
qt: Fix visual quality of text in QR image
This commit is contained in:
parent
8071c75d45
commit
6954156b40
2 changed files with 13 additions and 9 deletions
|
@ -9,6 +9,7 @@
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QClipboard>
|
#include <QClipboard>
|
||||||
#include <QDrag>
|
#include <QDrag>
|
||||||
|
#include <QFontDatabase>
|
||||||
#include <QMenu>
|
#include <QMenu>
|
||||||
#include <QMimeData>
|
#include <QMimeData>
|
||||||
#include <QMouseEvent>
|
#include <QMouseEvent>
|
||||||
|
@ -64,23 +65,24 @@ bool QRImageWidget::setQR(const QString& data, const QString& text)
|
||||||
}
|
}
|
||||||
QRcode_free(code);
|
QRcode_free(code);
|
||||||
|
|
||||||
QImage qrAddrImage = QImage(QR_IMAGE_SIZE, QR_IMAGE_SIZE + (text.isEmpty() ? 0 : 20), QImage::Format_RGB32);
|
const int qr_image_size = QR_IMAGE_SIZE + (text.isEmpty() ? 0 : 2 * QR_IMAGE_MARGIN);
|
||||||
|
QImage qrAddrImage(qr_image_size, qr_image_size, QImage::Format_RGB32);
|
||||||
qrAddrImage.fill(0xffffff);
|
qrAddrImage.fill(0xffffff);
|
||||||
{
|
{
|
||||||
QPainter painter(&qrAddrImage);
|
QPainter painter(&qrAddrImage);
|
||||||
painter.drawImage(0, 0, qrImage.scaled(QR_IMAGE_SIZE, QR_IMAGE_SIZE));
|
painter.drawImage(QR_IMAGE_MARGIN, 0, qrImage.scaled(QR_IMAGE_SIZE, QR_IMAGE_SIZE));
|
||||||
|
|
||||||
if (!text.isEmpty()) {
|
if (!text.isEmpty()) {
|
||||||
QFont font = GUIUtil::fixedPitchFont();
|
|
||||||
font.setStyleStrategy(QFont::NoAntialias);
|
|
||||||
QRect paddedRect = qrAddrImage.rect();
|
QRect paddedRect = qrAddrImage.rect();
|
||||||
|
paddedRect.setHeight(QR_IMAGE_SIZE + QR_IMAGE_TEXT_MARGIN);
|
||||||
|
|
||||||
// calculate ideal font size
|
QFont font = GUIUtil::fixedPitchFont();
|
||||||
qreal font_size = GUIUtil::calculateIdealFontSize(paddedRect.width() - 20, text, font);
|
font.setStretch(QFont::SemiCondensed);
|
||||||
|
font.setLetterSpacing(QFont::AbsoluteSpacing, 1);
|
||||||
|
const qreal font_size = GUIUtil::calculateIdealFontSize(paddedRect.width() - 2 * QR_IMAGE_TEXT_MARGIN, text, font);
|
||||||
font.setPointSizeF(font_size);
|
font.setPointSizeF(font_size);
|
||||||
|
|
||||||
painter.setFont(font);
|
painter.setFont(font);
|
||||||
paddedRect.setHeight(QR_IMAGE_SIZE+12);
|
|
||||||
painter.drawText(paddedRect, Qt::AlignBottom | Qt::AlignCenter, text);
|
painter.drawText(paddedRect, Qt::AlignBottom | Qt::AlignCenter, text);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,9 @@
|
||||||
static const int MAX_URI_LENGTH = 255;
|
static const int MAX_URI_LENGTH = 255;
|
||||||
|
|
||||||
/* Size of exported QR Code image */
|
/* Size of exported QR Code image */
|
||||||
static const int QR_IMAGE_SIZE = 300;
|
static constexpr int QR_IMAGE_SIZE = 300;
|
||||||
|
static constexpr int QR_IMAGE_TEXT_MARGIN = 10;
|
||||||
|
static constexpr int QR_IMAGE_MARGIN = 2 * QR_IMAGE_TEXT_MARGIN;
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
class QMenu;
|
class QMenu;
|
||||||
|
|
Loading…
Add table
Reference in a new issue