From 517cad7044e5861220f1b6da88fa93ad06153ce4 Mon Sep 17 00:00:00 2001 From: Jakob Heher Date: Mon, 8 Aug 2022 11:08:59 +0200 Subject: scale QR code to fit, cf. #115 --- .../pdfover/gui/composites/MobileBKUQRComposite.java | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'pdf-over-gui') diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/MobileBKUQRComposite.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/MobileBKUQRComposite.java index ad9cb530..2525d3ba 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/MobileBKUQRComposite.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/MobileBKUQRComposite.java @@ -27,6 +27,7 @@ import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.graphics.Image; import org.eclipse.swt.graphics.ImageData; +import org.eclipse.swt.graphics.Point; import org.eclipse.swt.graphics.Rectangle; import org.eclipse.swt.layout.FormLayout; import org.eclipse.swt.program.Program; @@ -100,6 +101,8 @@ public class MobileBKUQRComposite extends StateComposite { private String refVal; + private ImageData currentQRImage; + private String signatureData; /** @@ -202,7 +205,19 @@ public class MobileBKUQRComposite extends StateComposite { } else { this.lblRefVal.setText(""); } + } + private void updateQRImage() { + if (this.currentQRImage == null) + return; + + Point availableSize = this.lblQR.getSize(); + int targetSize = Math.min(availableSize.x, availableSize.y); + log.info("target size {}", targetSize); + if (targetSize <= 0) + return; + + this.lblQR.setImage(new Image(this.lblQR.getDisplay(), this.currentQRImage.scaledTo(targetSize, targetSize))); } /** @@ -214,8 +229,8 @@ public class MobileBKUQRComposite extends StateComposite { setErrorMessage(Messages.getString("error.FailedToLoadQRCode")); return; } - Image qr = new Image(Display.getCurrent(), qrcode); - this.lblQR.setImage(qr); + this.currentQRImage = new ImageData(qrcode); + updateQRImage(); } /** @@ -293,6 +308,7 @@ public class MobileBKUQRComposite extends StateComposite { this.lblQRLabel.setAlignment(SWT.RIGHT); this.lblQR = new Label(containerComposite, SWT.NATIVE); + this.lblQR.addListener(SWT.Resize, (e) -> { updateQRImage(); }); this.lnk_sig_data = new Link(containerComposite, SWT.NATIVE | SWT.RESIZE); SWTUtils.anchor(lnk_sig_data).right(100, -20).top(0, 20).set(); -- cgit v1.2.3