|
9 | 9 | #include <QApplication> |
10 | 10 | #include <QClipboard> |
11 | 11 | #include <QDrag> |
| 12 | +#include <QFontDatabase> |
12 | 13 | #include <QMenu> |
13 | 14 | #include <QMimeData> |
14 | 15 | #include <QMouseEvent> |
@@ -64,26 +65,28 @@ bool QRImageWidget::setQR(const QString& data, const QString& text) |
64 | 65 | } |
65 | 66 | QRcode_free(code); |
66 | 67 |
|
67 | | - QImage qrAddrImage = QImage(QR_IMAGE_SIZE, QR_IMAGE_SIZE + (text.isEmpty() ? 0 : 20), QImage::Format_RGB32); |
| 68 | + const int qr_image_size = QR_IMAGE_SIZE + (text.isEmpty() ? 0 : 2 * QR_IMAGE_MARGIN); |
| 69 | + QImage qrAddrImage(qr_image_size, qr_image_size, QImage::Format_RGB32); |
68 | 70 | qrAddrImage.fill(0xffffff); |
69 | | - QPainter painter(&qrAddrImage); |
70 | | - painter.drawImage(0, 0, qrImage.scaled(QR_IMAGE_SIZE, QR_IMAGE_SIZE)); |
| 71 | + { |
| 72 | + QPainter painter(&qrAddrImage); |
| 73 | + painter.drawImage(QR_IMAGE_MARGIN, 0, qrImage.scaled(QR_IMAGE_SIZE, QR_IMAGE_SIZE)); |
71 | 74 |
|
72 | | - if (!text.isEmpty()) { |
73 | | - QFont font = GUIUtil::fixedPitchFont(); |
74 | | - font.setStyleStrategy(QFont::NoAntialias); |
75 | | - QRect paddedRect = qrAddrImage.rect(); |
| 75 | + if (!text.isEmpty()) { |
| 76 | + QRect paddedRect = qrAddrImage.rect(); |
| 77 | + paddedRect.setHeight(QR_IMAGE_SIZE + QR_IMAGE_TEXT_MARGIN); |
76 | 78 |
|
77 | | - // calculate ideal font size |
78 | | - qreal font_size = GUIUtil::calculateIdealFontSize(paddedRect.width() - 20, text, font); |
79 | | - font.setPointSizeF(font_size); |
| 79 | + QFont font = GUIUtil::fixedPitchFont(); |
| 80 | + font.setStretch(QFont::SemiCondensed); |
| 81 | + font.setLetterSpacing(QFont::AbsoluteSpacing, 1); |
| 82 | + const qreal font_size = GUIUtil::calculateIdealFontSize(paddedRect.width() - 2 * QR_IMAGE_TEXT_MARGIN, text, font); |
| 83 | + font.setPointSizeF(font_size); |
80 | 84 |
|
81 | | - painter.setFont(font); |
82 | | - paddedRect.setHeight(QR_IMAGE_SIZE+12); |
83 | | - painter.drawText(paddedRect, Qt::AlignBottom|Qt::AlignCenter, text); |
| 85 | + painter.setFont(font); |
| 86 | + painter.drawText(paddedRect, Qt::AlignBottom | Qt::AlignCenter, text); |
| 87 | + } |
84 | 88 | } |
85 | 89 |
|
86 | | - painter.end(); |
87 | 90 | setPixmap(QPixmap::fromImage(qrAddrImage)); |
88 | 91 |
|
89 | 92 | return true; |
|
0 commit comments