diff options
author | Jakob Heher <jakob.heher@iaik.tugraz.at> | 2022-08-08 11:08:59 +0200 |
---|---|---|
committer | Jakob Heher <jakob.heher@iaik.tugraz.at> | 2022-08-08 11:08:59 +0200 |
commit | 517cad7044e5861220f1b6da88fa93ad06153ce4 (patch) | |
tree | 17419f35994e4e76b13b99e76018970f41c2bb77 /pdf-over-gui/src/main/java/at/asit | |
parent | 6393885781ea38e05229892d01194d700988a45d (diff) | |
download | pdf-over-517cad7044e5861220f1b6da88fa93ad06153ce4.tar.gz pdf-over-517cad7044e5861220f1b6da88fa93ad06153ce4.tar.bz2 pdf-over-517cad7044e5861220f1b6da88fa93ad06153ce4.zip |
scale QR code to fit, cf. #115
Diffstat (limited to 'pdf-over-gui/src/main/java/at/asit')
-rw-r--r-- | pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/MobileBKUQRComposite.java | 20 |
1 files changed, 18 insertions, 2 deletions
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();
|