Schim
sheetview.h
Go to the documentation of this file.
1 #ifndef SHEETVIEW_H
3 #define SHEETVIEW_H
4 
5 #include "model/sheet.h"
6 #include "sheetscene.h"
7 #include "ui/widgets/insertcompleter.h"
8 
9 #include <QGraphicsView>
10 
11 class MainWindow;
12 
16 class SheetView : public QGraphicsView
17 {
18  Q_OBJECT
19 public:
20  // CONSTRUCTORS
27  SheetView() = default;
31  explicit SheetView(Sheet *sheet, QWidget *parent = nullptr);
32  ~SheetView();
33 
34  // GETTERS
35  SheetScene *scene();
36 
37  // USER ACTIONS
38  void setZoom(float zoom);
39  void resetZoom();
40  void zoomIn(float step = 1.2);
41  void zoomOut(float step = 1.2);
42  void scrollUp(Vim::N n = 0);
43  void scrollDown(Vim::N n = 0);
44  void scrollLeft(Vim::N n = 0);
45  void scrollRight(Vim::N n = 0);
46  void showContextMenu();
47 public slots:
48  void insertPopup();
49 
50  // EVENTS
51  void mousePressEvent(QMouseEvent *event) override;
52  void mouseMoveEvent(QMouseEvent *event) override;
53  void mouseReleaseEvent(QMouseEvent *event) override;
54  void keyPressEvent(QKeyEvent *event) override;
55  void dropEvent(QDropEvent *event) override;
56  void leaveEvent(QEvent *event) override;
57  void enterEvent(QEvent *event) override;
58  void resizeEvent(QResizeEvent *event) override;
59  void wheelEvent(QWheelEvent *event) override;
60 
61 private slots:
62  // SLOTS
63  void onCursorMoved();
69  void onInsertionRequested(const Object &obj);
70 
71 private:
72  // OVERRIDDE QGraphicsView
73  void drawForeground(QPainter *painter, const QRectF &rect) override;
74 
75  // HELPERS
76  void init();
77  void recalculateBaseZoom();
78  void processRubberBandDrag(QMouseEvent *event);
79  float zoom() const;
80  void updateBackground();
81  void updateCursorGuides();
82  bool processVimAction(const Vim::Action &action);
83 
84 private:
85  // ATTRIBUTES
87  float baselineZoom = 1, userZoom = 1;
89  InsertCompleter *insertCompleter{};
91  QPoint _panStartPos, _selectStartPos;
93  bool _selectionTypeDetermined = false, _rubberBandDragging = false;
94 };
95 
96 #endif // SHEETVIEW_H
The abstract base class for all objects in a sheet.
Definition: object.h:21
Definition: insertcompleter.h:14
Count n()
The vim-count from the current key sequence.
A specialized QGraphicsScene containing a sheet of paper.
Definition: sheetscene.h:27
An action in vim-mode.
Definition: vim.h:81
SheetView()=default
This constructor is only used so that the MainWindow ui can be generated properly.
This class models a sheet of paper.
Definition: sheet.h:16
A specialized QGraphicsView that displays a sheet of paper.
Definition: sheetview.h:16
The main application window.
Definition: mainwindow.h:24
Representation of a vim-count.
Definition: vim.h:48