@@ -178,20 +178,29 @@ void ReceiveRequestDialog::update()
178178 }
179179 QRcode_free (code);
180180
181- QImage qrAddrImage = QImage (QR_IMAGE_SIZE, QR_IMAGE_SIZE+20 , QImage::Format_RGB32);
181+ QFont font = GUIUtil::fixedPitchFont ();
182+ font.setPixelSize (12 );
183+ QFontMetrics fm (font);
184+ const int lines = (fm.width (info.address ) / QR_IMAGE_SIZE) + 1 ;
185+ QString split_address = info.address ;
186+ const int chars_per_line = (info.address .length () + lines - 1 ) / lines;
187+ for (int i = 0 ; i < lines; ++i) {
188+ split_address.insert ((chars_per_line * i) + i, ' \n ' );
189+ }
190+
191+ QImage qrAddrImage = QImage (QR_IMAGE_SIZE, QR_IMAGE_SIZE + 16 + fm.height (), QImage::Format_RGB32);
182192 qrAddrImage.fill (0xffffff );
183193 QPainter painter (&qrAddrImage);
184194 painter.drawImage (0 , 0 , qrImage.scaled (QR_IMAGE_SIZE, QR_IMAGE_SIZE));
185- QFont font = GUIUtil::fixedPitchFont ();
186195 QRect paddedRect = qrAddrImage.rect ();
196+ paddedRect.setHeight (QR_IMAGE_SIZE + 8 + fm.height ());
197+ painter.drawText (paddedRect, Qt::AlignBottom | Qt::AlignCenter | Qt::TextWordWrap, split_address);
187198
188199 // calculate ideal font size
189200 qreal font_size = GUIUtil::calculateIdealFontSize (paddedRect.width () - 20 , info.address , font);
190201 font.setPointSizeF (font_size);
191202
192203 painter.setFont (font);
193- paddedRect.setHeight (QR_IMAGE_SIZE+12 );
194- painter.drawText (paddedRect, Qt::AlignBottom|Qt::AlignCenter, info.address );
195204 painter.end ();
196205
197206 ui->lblQRCode ->setPixmap (QPixmap::fromImage (qrAddrImage));
0 commit comments