Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added ability to change zoom using Ctrl + Scroll in Document Viewer #10964

Merged
merged 7 commits into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>.
cardionaut marked this conversation as resolved.
Show resolved Hide resolved
koppor marked this conversation as resolved.
Show resolved Hide resolved

### 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
Loading