1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 13:07:46 +00:00

PDFViewer: Add actions to rotate the displayed PDF

This implements the rotate cw/ccw actions in PDFViewer.
Since the rendered pages are stored in a HashMap for caching,
the bitmap is wrapped in a struct with the current rotation.
This way the caching works as expected while zooming, and a new bitmap
is rendered when the page is rotated.
This commit is contained in:
Marcus Nilsson 2022-01-03 00:24:11 +01:00 committed by Andreas Kling
parent cecbed467b
commit eb97617ff0
4 changed files with 36 additions and 7 deletions

View file

@ -130,13 +130,25 @@ void PDFViewerWidget::create_toolbar()
m_viewer->reset_zoom();
});
m_rotate_counterclockwise_action = GUI::CommonActions::make_rotate_counterclockwise_action([&](auto&) {
m_viewer->rotate(-90);
});
m_rotate_clockwise_action = GUI::CommonActions::make_rotate_clockwise_action([&](auto&) {
m_viewer->rotate(90);
});
m_zoom_in_action->set_enabled(false);
m_zoom_out_action->set_enabled(false);
m_reset_zoom_action->set_enabled(false);
m_rotate_counterclockwise_action->set_enabled(false);
m_rotate_clockwise_action->set_enabled(false);
toolbar.add_action(*m_zoom_in_action);
toolbar.add_action(*m_zoom_out_action);
toolbar.add_action(*m_reset_zoom_action);
toolbar.add_action(*m_rotate_counterclockwise_action);
toolbar.add_action(*m_rotate_clockwise_action);
}
void PDFViewerWidget::open_file(int fd, String const& path)
@ -167,6 +179,8 @@ void PDFViewerWidget::open_file(int fd, String const& path)
m_zoom_in_action->set_enabled(true);
m_zoom_out_action->set_enabled(true);
m_reset_zoom_action->set_enabled(true);
m_rotate_counterclockwise_action->set_enabled(true);
m_rotate_clockwise_action->set_enabled(true);
if (document->outline()) {
auto outline = document->outline();