mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 09:42:45 +00:00 
			
		
		
		
	PDFViewer: Add zoom in/out/reset menu actions
Make PDFViewer::zoom_in() & ::zoom_out() public and add menu and toolbar actions. Also add an action for zoom reset.
This commit is contained in:
		
							parent
							
								
									45085122ee
								
							
						
					
					
						commit
						3af71c406d
					
				
					 4 changed files with 50 additions and 8 deletions
				
			
		|  | @ -109,9 +109,8 @@ void PDFViewer::mousewheel_event(GUI::MouseEvent& event) | |||
|                 scrollbar.decrease_slider_by(20); | ||||
|             } | ||||
|         } | ||||
|         update(); | ||||
|     } | ||||
| 
 | ||||
|     update(); | ||||
| } | ||||
| 
 | ||||
| void PDFViewer::timer_event(Core::TimerEvent&) | ||||
|  | @ -125,14 +124,24 @@ void PDFViewer::timer_event(Core::TimerEvent&) | |||
| 
 | ||||
| void PDFViewer::zoom_in() | ||||
| { | ||||
|     if (m_zoom_level < number_of_zoom_levels - 1) | ||||
|     if (m_zoom_level < number_of_zoom_levels - 1) { | ||||
|         m_zoom_level++; | ||||
|         update(); | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| void PDFViewer::zoom_out() | ||||
| { | ||||
|     if (m_zoom_level > 0) | ||||
|     if (m_zoom_level > 0) { | ||||
|         m_zoom_level--; | ||||
|         update(); | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| void PDFViewer::reset_zoom() | ||||
| { | ||||
|     m_zoom_level = initial_zoom_level; | ||||
|     update(); | ||||
| } | ||||
| 
 | ||||
| RefPtr<Gfx::Bitmap> PDFViewer::render_page(const PDF::Page& page) | ||||
|  |  | |||
|  | @ -49,6 +49,10 @@ public: | |||
| 
 | ||||
|     Function<void(u32 new_page)> on_page_change; | ||||
| 
 | ||||
|     void zoom_in(); | ||||
|     void zoom_out(); | ||||
|     void reset_zoom(); | ||||
| 
 | ||||
| protected: | ||||
|     PDFViewer(); | ||||
| 
 | ||||
|  | @ -60,9 +64,6 @@ private: | |||
|     RefPtr<Gfx::Bitmap> get_rendered_page(u32 index); | ||||
|     RefPtr<Gfx::Bitmap> render_page(const PDF::Page&); | ||||
| 
 | ||||
|     void zoom_in(); | ||||
|     void zoom_out(); | ||||
| 
 | ||||
|     RefPtr<PDF::Document> m_document; | ||||
|     u32 m_current_page_index { 0 }; | ||||
|     Vector<HashMap<u32, RefPtr<Gfx::Bitmap>>> m_rendered_page_list; | ||||
|  |  | |||
|  | @ -58,6 +58,10 @@ void PDFViewerWidget::initialize_menubar(GUI::Window& window) | |||
| 
 | ||||
|     auto& view_menu = window.add_menu("&View"); | ||||
|     view_menu.add_action(*m_toggle_sidebar_action); | ||||
|     view_menu.add_separator(); | ||||
|     view_menu.add_action(*m_zoom_in_action); | ||||
|     view_menu.add_action(*m_zoom_out_action); | ||||
|     view_menu.add_action(*m_reset_zoom_action); | ||||
| 
 | ||||
|     auto& help_menu = window.add_menu("&Help"); | ||||
|     help_menu.add_action(GUI::CommonActions::make_about_action("PDF Viewer", GUI::Icon::default_icon("app-pdf-viewer"), &window)); | ||||
|  | @ -111,6 +115,28 @@ void PDFViewerWidget::create_toolbar() | |||
|     }; | ||||
| 
 | ||||
|     m_total_page_label = toolbar.add<GUI::Label>(); | ||||
|     m_total_page_label->set_fixed_width(30); | ||||
|     toolbar.add_separator(); | ||||
| 
 | ||||
|     m_zoom_in_action = GUI::CommonActions::make_zoom_in_action([&](auto&) { | ||||
|         m_viewer->zoom_in(); | ||||
|     }); | ||||
| 
 | ||||
|     m_zoom_out_action = GUI::CommonActions::make_zoom_out_action([&](auto&) { | ||||
|         m_viewer->zoom_out(); | ||||
|     }); | ||||
| 
 | ||||
|     m_reset_zoom_action = GUI::CommonActions::make_reset_zoom_action([&](auto&) { | ||||
|         m_viewer->reset_zoom(); | ||||
|     }); | ||||
| 
 | ||||
|     m_zoom_in_action->set_enabled(false); | ||||
|     m_zoom_out_action->set_enabled(false); | ||||
|     m_reset_zoom_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); | ||||
| } | ||||
| 
 | ||||
| void PDFViewerWidget::open_file(int fd, String const& path) | ||||
|  | @ -131,7 +157,6 @@ void PDFViewerWidget::open_file(int fd, String const& path) | |||
| 
 | ||||
|     m_viewer->set_document(document); | ||||
|     m_total_page_label->set_text(String::formatted("of {}", document->get_page_count())); | ||||
|     m_total_page_label->set_fixed_width(30); | ||||
| 
 | ||||
|     m_page_text_box->set_enabled(true); | ||||
|     m_page_text_box->set_current_number(1, false); | ||||
|  | @ -139,6 +164,9 @@ void PDFViewerWidget::open_file(int fd, String const& path) | |||
|     m_go_to_prev_page_action->set_enabled(false); | ||||
|     m_go_to_next_page_action->set_enabled(document->get_page_count() > 1); | ||||
|     m_toggle_sidebar_action->set_enabled(true); | ||||
|     m_zoom_in_action->set_enabled(true); | ||||
|     m_zoom_out_action->set_enabled(true); | ||||
|     m_reset_zoom_action->set_enabled(true); | ||||
| 
 | ||||
|     if (document->outline()) { | ||||
|         auto outline = document->outline(); | ||||
|  |  | |||
|  | @ -35,6 +35,10 @@ private: | |||
|     RefPtr<GUI::Action> m_go_to_prev_page_action; | ||||
|     RefPtr<GUI::Action> m_go_to_next_page_action; | ||||
|     RefPtr<GUI::Action> m_toggle_sidebar_action; | ||||
|     RefPtr<GUI::Action> m_zoom_in_action; | ||||
|     RefPtr<GUI::Action> m_zoom_out_action; | ||||
|     RefPtr<GUI::Action> m_reset_zoom_action; | ||||
| 
 | ||||
|     bool m_sidebar_open { false }; | ||||
|     ByteBuffer m_buffer; | ||||
| }; | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Marcus Nilsson
						Marcus Nilsson