|
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>
|
@@ -67,26 +68,28 @@ bool QRImageWidget::setQR(const QString& data, const QString& text)
|
67 | 68 | // Elements: Hack to get QR address to print right
|
68 | 69 | const size_t MORE_WIDTH = 80;
|
69 | 70 | 
|
70 |
| - QImage qrAddrImage = QImage(QR_IMAGE_SIZE + MORE_WIDTH, QR_IMAGE_SIZE + 16 + fm.height(), QImage::Format_RGB32); |
| 71 | + const int qr_image_size = QR_IMAGE_SIZE + MORE_WIDTH + (text.isEmpty() ? 0 : 2 * QR_IMAGE_MARGIN); |
| 72 | + QImage qrAddrImage(qr_image_size, qr_image_size, QImage::Format_RGB32); |
71 | 73 | qrAddrImage.fill(0xffffff);
|
72 |
| - QPainter painter(&qrAddrImage); |
73 |
| - painter.drawImage(MORE_WIDTH/2, 0, qrImage.scaled(QR_IMAGE_SIZE, QR_IMAGE_SIZE)); |
| 74 | + { |
| 75 | + QPainter painter(&qrAddrImage); |
| 76 | + painter.drawImage(QR_IMAGE_MARGIN + MORE_WIDTH/2, 0, qrImage.scaled(QR_IMAGE_SIZE, QR_IMAGE_SIZE)); |
74 | 77 |
|
75 |
| - if (!text.isEmpty()) { |
76 |
| - QFont font = GUIUtil::fixedPitchFont(); |
77 |
| - font.setStyleStrategy(QFont::NoAntialias); |
78 |
| - QRect paddedRect = qrAddrImage.rect(); |
| 78 | + if (!text.isEmpty()) { |
| 79 | + QRect paddedRect = qrAddrImage.rect(); |
| 80 | + paddedRect.setHeight(QR_IMAGE_SIZE + QR_IMAGE_TEXT_MARGIN); |
79 | 81 |
|
80 |
| - // calculate ideal font size |
81 |
| - qreal font_size = GUIUtil::calculateIdealFontSize(paddedRect.width() - 20, text, font); |
82 |
| - font.setPointSizeF(font_size); |
| 82 | + QFont font = GUIUtil::fixedPitchFont(); |
| 83 | + font.setStretch(QFont::SemiCondensed); |
| 84 | + font.setLetterSpacing(QFont::AbsoluteSpacing, 1); |
| 85 | + const qreal font_size = GUIUtil::calculateIdealFontSize(paddedRect.width() - 2 * QR_IMAGE_TEXT_MARGIN, text, font); |
| 86 | + font.setPointSizeF(font_size); |
83 | 87 |
|
84 |
| - painter.setFont(font); |
85 |
| - paddedRect.setHeight(QR_IMAGE_SIZE+12); |
86 |
| - painter.drawText(paddedRect, Qt::AlignBottom|Qt::AlignCenter, text); |
| 88 | + painter.setFont(font); |
| 89 | + painter.drawText(paddedRect, Qt::AlignBottom | Qt::AlignCenter, text); |
| 90 | + } |
87 | 91 | }
|
88 | 92 |
|
89 |
| - painter.end(); |
90 | 93 | setPixmap(QPixmap::fromImage(qrAddrImage));
|
91 | 94 |
|
92 | 95 | return true;
|
|
0 commit comments