1 /* 2 * Xournal++ 3 * 4 * Base class for prviews in the sidebar 5 * 6 * @author Xournal++ Team 7 * https://github.com/xournalpp/xournalpp 8 * 9 * @license GNU GPLv2 or later 10 */ 11 12 #pragma once 13 14 #include <string> 15 #include <vector> 16 17 #include <gtk/gtk.h> 18 19 #include "gui/GladeGui.h" 20 #include "gui/sidebar/AbstractSidebarPage.h" 21 22 #include "XournalType.h" 23 24 class PdfCache; 25 class SidebarLayout; 26 class SidebarPreviewBaseEntry; 27 class SidebarToolbar; 28 29 class SidebarPreviewBase: public AbstractSidebarPage { 30 public: 31 SidebarPreviewBase(Control* control, GladeGui* gui, SidebarToolbar* toolbar); 32 virtual ~SidebarPreviewBase(); 33 34 public: 35 virtual void enableSidebar(); 36 virtual void disableSidebar(); 37 38 /** 39 * Layout the pages to the current size of the sidebar 40 */ 41 void layout(); 42 43 /** 44 * Update the preview images 45 */ 46 virtual void updatePreviews() = 0; 47 48 /** 49 * @overwrite 50 */ 51 virtual bool hasData(); 52 53 /** 54 * @overwrite 55 */ 56 virtual GtkWidget* getWidget(); 57 58 /** 59 * Gets the zoom factor for the previews 60 */ 61 double getZoom() const; 62 63 /** 64 * Gets the PDF cache for preview rendering 65 */ 66 PdfCache* getCache(); 67 68 public: 69 // DocumentListener interface (only the part handled by SidebarPreviewBase) 70 virtual void documentChanged(DocumentChangeType type); 71 virtual void pageInserted(size_t page); 72 virtual void pageDeleted(size_t page); 73 74 protected: 75 /** 76 * Timeout callback to scroll to a page 77 */ 78 static bool scrollToPreview(SidebarPreviewBase* sidebar); 79 80 /** 81 * The size of the sidebar has chnaged 82 */ 83 static void sizeChanged(GtkWidget* widget, GtkAllocation* allocation, SidebarPreviewBase* sidebar); 84 85 private: 86 /** 87 * The scrollbar with the icons 88 */ 89 GtkWidget* scrollPreview = nullptr; 90 91 /** 92 * The Zoom of the previews 93 */ 94 double zoom = 0.15; 95 96 /** 97 * For preview rendering 98 */ 99 PdfCache* cache = nullptr; 100 101 /** 102 * The layouting class for the prviews 103 */ 104 SidebarLayout* layoutmanager = nullptr; 105 106 107 // Members also used by subclasses 108 protected: 109 /** 110 * The currently selected entry in the sidebar, starting from 0 111 * -1 means no valid selection 112 */ 113 size_t selectedEntry = -1; 114 115 /** 116 * The widget within the scrollarea with the page icons 117 */ 118 GtkWidget* iconViewPreview = nullptr; 119 120 /** 121 * The previews 122 */ 123 vector<SidebarPreviewBaseEntry*> previews; 124 125 /** 126 * The sidebar is enabled 127 */ 128 bool enabled = false; 129 130 friend class SidebarLayout; 131 }; 132