1 #ifndef CANVAS_H 2 #define CANVAS_H 3 4 #include <QWidget> 5 #include <QPaintEvent> 6 #include <QMouseEvent> 7 #include <QWheelEvent> 8 #include <QResizeEvent> 9 #include <QList> 10 #include <QTimer> 11 #include <sys/socket.h> 12 13 14 class Viewer; 15 class Layout; 16 class SingleLayout; 17 class GridLayout; 18 class PresenterLayout; 19 class GotoLine; 20 class QLabel; 21 22 23 class Canvas : public QWidget { 24 Q_OBJECT 25 26 public: 27 Canvas(Viewer *v, QWidget *parent = 0); 28 ~Canvas(); 29 30 bool is_valid() const; 31 void reload(bool clamp); 32 33 void set_search_visible(bool visible); 34 35 Layout *get_layout() const; 36 37 void update_page_overlay(); 38 39 protected: 40 // QT event handling 41 void paintEvent(QPaintEvent *event); 42 void mousePressEvent(QMouseEvent *event); 43 void mouseReleaseEvent(QMouseEvent *event); 44 void mouseMoveEvent(QMouseEvent *event); 45 void wheelEvent(QWheelEvent *event); 46 void mouseDoubleClickEvent(QMouseEvent * event); 47 void resizeEvent(QResizeEvent *event); 48 49 signals: 50 /** 51 * Emitted when the user requests to see the source code of a 52 * particular point on a particular page. 53 */ 54 void synchronize_editor(int page, int x, int y); 55 56 private slots: 57 void page_rendered(int page); 58 void goto_page(); 59 60 // primitive actions 61 void set_single_layout(); 62 void set_grid_layout(); 63 void set_presenter_layout(); 64 65 void toggle_overlay(); 66 void focus_goto(); 67 68 void disable_triple_click(); 69 void hide_mouse_pointer(); 70 71 void swap_selection_and_panning_buttons(); 72 73 private: 74 void setup_keys(QWidget *base); 75 76 Viewer *viewer; 77 Layout *cur_layout; 78 SingleLayout *single_layout; 79 GridLayout *grid_layout; 80 PresenterLayout *presenter_layout; 81 82 GotoLine *goto_line; 83 QLabel *page_overlay; 84 85 int mx, my; 86 int mx_down, my_down; 87 bool triple_click_possible; 88 89 int hide_mouse_timeout; 90 QTimer hide_mouse_timer; 91 Qt::CursorShape last_cursor; 92 93 bool valid; 94 95 // config options 96 QColor background; 97 QColor background_fullscreen; 98 int mouse_wheel_factor; 99 100 Qt::MouseButton click_link_button; 101 Qt::MouseButton drag_view_button; 102 Qt::MouseButton select_text_button; 103 }; 104 105 #endif 106 107