support changing the frame rate of animated qrs with mouse scroll on the qr image

This commit is contained in:
Craig Raw 2024-04-18 11:45:10 +02:00
parent 72adbe44a7
commit 8baa8e2e96

View file

@ -42,7 +42,7 @@ public class QRDisplayDialog extends Dialog<ButtonType> {
private static final int MIN_FRAGMENT_LENGTH = 10; private static final int MIN_FRAGMENT_LENGTH = 10;
private static final int ANIMATION_PERIOD_MILLIS = 200; private static final double ANIMATION_PERIOD_MILLIS = 200d;
private static final int DEFAULT_QR_SIZE = 580; private static final int DEFAULT_QR_SIZE = 580;
private static final int REDUCED_QR_SIZE = 520; private static final int REDUCED_QR_SIZE = 520;
@ -100,6 +100,16 @@ public class QRDisplayDialog extends Dialog<ButtonType> {
qrImageView = new ImageView(); qrImageView = new ImageView();
stackPane.getChildren().add(qrImageView); stackPane.getChildren().add(qrImageView);
qrImageView.setOnScroll(scrollEvent -> {
if(animateQRService != null && animateQRService.isRunning()) {
Duration duration = animateQRService.getPeriod();
Duration newDuration = scrollEvent.getDeltaY() > 0 ? duration.multiply(1.1) : duration.multiply(0.9);
if(newDuration.lessThan(Duration.millis(ANIMATION_PERIOD_MILLIS*10)) && newDuration.greaterThan(Duration.millis(ANIMATION_PERIOD_MILLIS/2))) {
animateQRService.setPeriod(newDuration);
}
}
});
dialogPane.setContent(Borders.wrap(stackPane).lineBorder().buildAll()); dialogPane.setContent(Borders.wrap(stackPane).lineBorder().buildAll());
nextPart(); nextPart();