diff options
author | Jonas Schnelli <dev@jonasschnelli.ch> | 2020-10-23 11:54:19 +0200 |
---|---|---|
committer | Jonas Schnelli <dev@jonasschnelli.ch> | 2020-10-23 11:54:47 +0200 |
commit | 49984b44cfcd3fd0cef16c8ce97197973afc3c04 (patch) | |
tree | 42e26c33189d70b2c42db6c5d3e647447cd644dd /src | |
parent | 9af7c1993b3512a7230f723b1923abd496989c59 (diff) | |
parent | 6954156b4091bc1e561502f0eef0cece56c76eec (diff) | |
download | bitcoin-49984b44cfcd3fd0cef16c8ce97197973afc3c04.tar.xz |
Merge bitcoin-core/gui#71: Fix visual quality of text in QR image
6954156b4091bc1e561502f0eef0cece56c76eec qt: Fix visual quality of text in QR image (Hennadii Stepanov)
8071c75d45e12c2bca04b170c687bebd30ad19ac qt, refactor: Limit scope of QPainter object (Hennadii Stepanov)
Pull request description:
Master (197450f80868fe752c6107955e5da80704212b34):
![DeepinScreenshot_select-area_20200824001800](https://user-images.githubusercontent.com/32963518/90988962-96283680-e59f-11ea-8e20-42e9b23033f5.png)
This PR (6954156b4091bc1e561502f0eef0cece56c76eec):
- macOS 10.15.6
![Screenshot from 2020-09-07 15-40-30](https://user-images.githubusercontent.com/32963518/92390251-2c716600-f123-11ea-96f0-0e9d35810c76.png)
- Linux Mint 20
![Screenshot from 2020-09-07 15-48-13](https://user-images.githubusercontent.com/32963518/92390272-36936480-f123-11ea-8fee-4de23bb40ed9.png)
Fix #54
Fix https://github.com/bitcoin/bitcoin/issues/19103
---
The first commit is easy to review with [`git diff --word-diff`](https://github.com/bitcoin-core/gui/pull/71/commits/8071c75d45e12c2bca04b170c687bebd30ad19ac?w=1).
ACKs for top commit:
jonasschnelli:
Tested ACK 6954156b4091bc1e561502f0eef0cece56c76eec - tested on macOS 10.15. Fixes the problem.
Tree-SHA512: 6ecb3397d2a5094c5f00ee05fc09520751568404e000a8691b6de7e57f38c2d5da628694e5e45a2b4cc302a846bbc00014c40820233eb026d3ebd4f68c2c9913
Diffstat (limited to 'src')
-rw-r--r-- | src/qt/qrimagewidget.cpp | 31 | ||||
-rw-r--r-- | src/qt/qrimagewidget.h | 4 |
2 files changed, 20 insertions, 15 deletions
diff --git a/src/qt/qrimagewidget.cpp b/src/qt/qrimagewidget.cpp index c816e1f8ed..52f1e60957 100644 --- a/src/qt/qrimagewidget.cpp +++ b/src/qt/qrimagewidget.cpp @@ -9,6 +9,7 @@ #include <QApplication> #include <QClipboard> #include <QDrag> +#include <QFontDatabase> #include <QMenu> #include <QMimeData> #include <QMouseEvent> @@ -64,26 +65,28 @@ bool QRImageWidget::setQR(const QString& data, const QString& text) } 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); - QPainter painter(&qrAddrImage); - painter.drawImage(0, 0, qrImage.scaled(QR_IMAGE_SIZE, QR_IMAGE_SIZE)); + { + QPainter painter(&qrAddrImage); + painter.drawImage(QR_IMAGE_MARGIN, 0, qrImage.scaled(QR_IMAGE_SIZE, QR_IMAGE_SIZE)); - if (!text.isEmpty()) { - QFont font = GUIUtil::fixedPitchFont(); - font.setStyleStrategy(QFont::NoAntialias); - QRect paddedRect = qrAddrImage.rect(); + if (!text.isEmpty()) { + QRect paddedRect = qrAddrImage.rect(); + paddedRect.setHeight(QR_IMAGE_SIZE + QR_IMAGE_TEXT_MARGIN); - // calculate ideal font size - qreal font_size = GUIUtil::calculateIdealFontSize(paddedRect.width() - 20, text, font); - font.setPointSizeF(font_size); + QFont font = GUIUtil::fixedPitchFont(); + 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); - painter.setFont(font); - paddedRect.setHeight(QR_IMAGE_SIZE+12); - painter.drawText(paddedRect, Qt::AlignBottom|Qt::AlignCenter, text); + painter.setFont(font); + painter.drawText(paddedRect, Qt::AlignBottom | Qt::AlignCenter, text); + } } - painter.end(); setPixmap(QPixmap::fromImage(qrAddrImage)); return true; diff --git a/src/qt/qrimagewidget.h b/src/qt/qrimagewidget.h index cca598c2ce..a031bd7632 100644 --- a/src/qt/qrimagewidget.h +++ b/src/qt/qrimagewidget.h @@ -12,7 +12,9 @@ static const int MAX_URI_LENGTH = 255; /* 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 class QMenu; |