Skip to content

Commit

Permalink
Added ability to change zoom using Ctrl + Scroll in Document Viewer (#…
Browse files Browse the repository at this point in the history
…10964)

* Add ability to zoom using Ctrl + Scroll in PDF Viewer

* Limit zoom-out to ~1 page

Observed problems with infinite zoom-out:
- Occasional display errors (e.g. no text displayed for certain pages)
- No content can be seen if zoomed out too far, might be unclear to user what happened and that zooming in will fix problem

* Updated CHANGELOG

* Remove catch newline from formatter

* Update CHANGELOG.md

---------

Co-authored-by: Oliver Kopp <kopp.dev@gmail.com>
  • Loading branch information
cardionaut and koppor committed Mar 4, 2024
1 parent 3c632e3 commit 84463e7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv
- We added the possibility to redownload files that had been present but are no longer in the specified location. [#10848](https://github.com/JabRef/jabref/issues/10848)
- We added the citation key pattern `[camelN]`. Equivalent to the first N words of the `[camel]` pattern.
- We added ability to export in CFF (Citation File Format) [#10661](https://github.com/JabRef/jabref/issues/10661).
- We added the ability to zoom in and out in the document viewer using <kbd>Ctrl</kbd> + <kbd>Scroll</kbd>. [#10964](https://github.com/JabRef/jabref/pull/10964)

### Changed

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import javafx.scene.control.ProgressIndicator;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.input.ScrollEvent;
import javafx.scene.layout.StackPane;
import javafx.scene.shape.Rectangle;
import javafx.util.Duration;
Expand Down Expand Up @@ -76,6 +77,16 @@ public void show(DocumentViewModel document) {
flow.estimatedScrollYProperty().addListener((observable, oldValue, newValue) -> scrollY.setValue(newValue));
scrollY.addListener((observable, oldValue, newValue) -> flow.estimatedScrollYProperty().setValue((double) newValue));
flow.totalLengthEstimateProperty().addListener((observable, oldValue, newValue) -> scrollYMax.setValue(newValue));
flow.addEventFilter(ScrollEvent.SCROLL, (ScrollEvent event) -> {
if (event.isControlDown()) {
event.consume();
if (event.getDeltaY() > 0) {
changePageWidth(100);
} else {
changePageWidth(-100);
}
}
});
}

private void updateCurrentPage(ObservableList<DocumentViewerPage> visiblePages) {
Expand Down Expand Up @@ -128,7 +139,16 @@ private void updateSizeOfDisplayedPages() {

public void changePageWidth(int delta) {
// Assuming the current page is A4 (or has same aspect ratio)
setPageWidth(desiredPageDimension.getWidth(Math.sqrt(2)) + delta);
int newWidth = desiredPageDimension.getWidth(Math.sqrt(2)) + delta;
// Limit zoom out to ~1 page due to occasional display errors when zooming out further
int minWidth = (int) (flow.getHeight() / 2 * Math.sqrt(2));
if (newWidth < minWidth) {
if (newWidth - delta == minWidth) { // Attempting to zoom out when already at minWidth
return;
}
newWidth = minWidth;
}
setPageWidth(newWidth);
}

/**
Expand Down

0 comments on commit 84463e7

Please sign in to comment.