]> git.lyx.org Git - lyx.git/blob - src/frontends/qt/GuiWorkArea_Private.h
42dcef836c89a8871517053ec122d9b635b8d904
[lyx.git] / src / frontends / qt / GuiWorkArea_Private.h
1 // -*- C++ -*-
2 /**
3  * \file GuiWorkArea_Private.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Abdelrazak Younes
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #ifndef WORKAREA_PRIVATE_H
13 #define WORKAREA_PRIVATE_H
14
15 #include "FuncRequest.h"
16
17 #include "support/FileName.h"
18 #include "support/Timeout.h"
19
20 #include <QMouseEvent>
21 #include <QTimer>
22
23 namespace lyx {
24
25 namespace frontend {
26
27 class GuiCompleter;
28 class GuiPainter;
29 class GuiView;
30 class GuiWorkArea;
31
32 /// for emulating triple click
33 class DoubleClick {
34 public:
35         ///
36         DoubleClick() : state(Qt::NoButton), active(false) {}
37         ///
38         DoubleClick(QMouseEvent * e) : state(e->button()), active(true) {}
39         ///
40         bool operator==(QMouseEvent const & e) { return state == e.button(); }
41         ///
42 public:
43         ///
44         Qt::MouseButton state;
45         ///
46         bool active;
47 };
48
49 /** Qt only emits mouse events when the mouse is being moved, but
50  *  we want to generate 'pseudo' mouse events when the mouse button is
51  *  pressed and the mouse cursor is below the bottom, or above the top
52  *  of the work area. In this way, we'll be able to continue scrolling
53  *  (and selecting) the text.
54  *
55  *  This class stores all the parameters needed to make this happen.
56  */
57 class SyntheticMouseEvent
58 {
59 public:
60         SyntheticMouseEvent();
61
62         FuncRequest cmd;
63         Timeout timeout;
64         bool restart_timeout;
65 };
66
67
68 /**
69  * Implementation of the work area (buffer view GUI)
70 */
71
72 struct GuiWorkArea::Private
73 {
74         ///
75         Private(GuiWorkArea *);
76
77         ///
78         ~Private();
79
80         ///
81         void resizeBufferView();
82
83         ///
84         void dispatch(FuncRequest const & cmd0);
85         /// Make caret visible and signal that its geometry needs to be updated
86         void resetCaret();
87         /// recompute the shape and position of the caret
88         void updateCaretGeometry();
89         /// show the caret if it is not visible
90         void showCaret();
91         /// hide the caret if it is visible
92         void hideCaret();
93         /* Draw the caret. Parameter \c horiz_offset is not 0 when there
94          * has been horizontal scrolling in current row
95          */
96         void drawCaret(QPainter & painter, int horiz_offset) const;
97         /// Set the range and value of the scrollbar and connect to its valueChanged
98         /// signal.
99         void updateScrollbar();
100         /// Change the cursor when the mouse hovers over a clickable inset
101         void updateCursorShape();
102
103         /// Restore coordinate transformation information
104         void resetInputItemTransform();
105         /// Paint preedit text provided by the platform input method
106         void paintPreeditText(GuiPainter & pain);
107
108         /// Prepare screen for next painting
109         void resetScreen();
110         /// Where painting takes place
111         QPaintDevice * screenDevice();
112         /// Put backingstore to screen if necessary
113         void updateScreen(QRectF const & rc);
114
115         ///
116         GuiWorkArea * p = nullptr;
117         ///
118         BufferView * buffer_view_ = nullptr;
119         ///
120         GuiView * lyx_view_ = nullptr;
121
122         /// Do we need an intermediate image when painting (for now macOS and Wayland)
123         bool use_backingstore_ = false;
124         ///
125         QImage screen_;
126
127         /// is the caret currently displayed
128         bool caret_visible_ = false;
129         ///
130         bool needs_caret_geometry_update_ = true;
131         ///
132         QTimer caret_timeout_;
133
134         ///
135         SyntheticMouseEvent synthetic_mouse_event_;
136         ///
137         DoubleClick dc_event_;
138
139         ///
140         bool need_resize_ = false;
141
142         /// provides access to the platform input method
143         QInputMethod * im_ = QGuiApplication::inputMethod();
144         /// the current preedit text of the input method
145         docstring preedit_string_;
146         /// Number of lines used by preedit text
147         int preedit_lines_ = 1;
148         /// the attributes of the preedit text
149         QList<QInputMethodEvent::Attribute> preedit_attr_;
150         QRectF im_cursor_rect_;
151         QRectF im_anchor_rect_;
152         QTransform item_trans_;
153         bool item_trans_needs_reset_ = false;
154         /// for debug
155         QLocale::Language im_lang_;
156
157         /// Ratio between physical pixels and device-independent pixels
158         /// We save the last used value to detect changes of the
159         /// current pixel_ratio of the viewport.
160         double last_pixel_ratio_ = 1.0;
161         ///
162         GuiCompleter * completer_;
163
164         /// Special mode in which Esc and Enter (with or without Shift)
165         /// are ignored
166         bool dialog_mode_ = false;
167         /// store the name of the context menu when the mouse is
168         /// pressed. This is used to get the correct context menu
169         /// when the menu is actually shown (after releasing on Windows)
170         /// and after the DEPM has done its job.
171         std::string context_menu_name_;
172
173         /// stuff related to window title
174         ///
175         support::FileName file_name_;
176         ///
177         bool shell_escape_ = false;
178         ///
179         bool read_only_ = false;
180         ///
181         docstring vc_status_;
182         ///
183         bool clean_ = true;
184         ///
185         bool externally_modified_ = false;
186
187 }; // GuiWorkArea
188
189 } // namespace frontend
190 } // namespace lyx
191
192 #endif // WORKAREA_H