]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiWorkArea_Private.h
Use <cstdint> instead of <boost/cstdint.hpp>
[lyx.git] / src / frontends / qt4 / 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 #ifdef Q_OS_MAC
24 /* Qt on macOS does not respect the Qt::WA_OpaquePaintEvent attribute
25  * and resets the widget backing store at each update. Therefore, we
26  * use our own backing store in this case */
27 #define LYX_BACKINGSTORE 1
28 #include <QPainter>
29 #endif
30
31 namespace lyx {
32
33 class Buffer;
34
35 namespace frontend {
36
37 class GuiCompleter;
38 class GuiPainter;
39 class GuiView;
40 class GuiWorkArea;
41
42 /// for emulating triple click
43 class DoubleClick {
44 public:
45         ///
46         DoubleClick() : state(Qt::NoButton), active(false) {}
47         ///
48         DoubleClick(QMouseEvent * e) : state(e->button()), active(true) {}
49         ///
50         bool operator==(QMouseEvent const & e) { return state == e.button(); }
51         ///
52 public:
53         ///
54         Qt::MouseButton state;
55         ///
56         bool active;
57 };
58
59 /** Qt only emits mouse events when the mouse is being moved, but
60  *  we want to generate 'pseudo' mouse events when the mouse button is
61  *  pressed and the mouse cursor is below the bottom, or above the top
62  *  of the work area. In this way, we'll be able to continue scrolling
63  *  (and selecting) the text.
64  *
65  *  This class stores all the parameters needed to make this happen.
66  */
67 class SyntheticMouseEvent
68 {
69 public:
70         SyntheticMouseEvent();
71
72         FuncRequest cmd;
73         Timeout timeout;
74         bool restart_timeout;
75 };
76
77
78 /**
79  * Implementation of the work area (buffer view GUI)
80 */
81 class CaretWidget;
82
83 struct GuiWorkArea::Private
84 {
85         ///
86         Private(GuiWorkArea *);
87
88         ///
89         ~Private();
90
91         ///
92         void resizeBufferView();
93
94         ///
95         void dispatch(FuncRequest const & cmd0);
96         /// recompute the shape and position of the caret
97         void updateCaretGeometry();
98         /// show the caret if it is not visible
99         void showCaret();
100         /// hide the caret if it is visible
101         void hideCaret();
102         /// Set the range and value of the scrollbar and connect to its valueChanged
103         /// signal.
104         void updateScrollbar();
105         /// Change the cursor when the mouse hovers over a clickable inset
106         void updateCursorShape();
107
108         void paintPreeditText(GuiPainter & pain);
109
110         void resetScreen() {
111 #ifdef LYX_BACKINGSTORE
112                 int const pr = p->pixelRatio();
113                 screen_ = QImage(static_cast<int>(pr * p->viewport()->width()),
114                                  static_cast<int>(pr * p->viewport()->height()),
115                                  QImage::Format_ARGB32_Premultiplied);
116 #  if QT_VERSION >= 0x050000
117                 screen_.setDevicePixelRatio(pr);
118 #  endif
119 #endif
120         }
121
122         QPaintDevice * screenDevice() {
123 #ifdef LYX_BACKINGSTORE
124                 return &screen_;
125 #else
126                 return p->viewport();
127 #endif
128         }
129
130 #ifdef LYX_BACKINGSTORE
131         void updateScreen(QRectF const & rc) {
132                 QPainter qpain(p->viewport());
133                 double const pr = p->pixelRatio();
134                 QRectF const rcs = QRectF(rc.x() * pr, rc.y() * pr,
135                                           rc.width() * pr, rc.height() * pr);
136                 qpain.drawImage(rc, screen_, rcs);
137         }
138 #else
139         void updateScreen(QRectF const & ) {}
140 #endif
141
142         ///
143         GuiWorkArea * p;
144         ///
145         BufferView * buffer_view_;
146         ///
147         GuiView * lyx_view_;
148
149 #ifdef LYX_BACKINGSTORE
150         ///
151         QImage screen_;
152 #endif
153         ///
154         CaretWidget * caret_;
155         /// is the caret currently displayed
156         bool caret_visible_;
157         ///
158         QTimer caret_timeout_;
159
160         ///
161         SyntheticMouseEvent synthetic_mouse_event_;
162         ///
163         DoubleClick dc_event_;
164
165         ///
166         bool need_resize_;
167
168         /// the current preedit text of the input method
169         docstring preedit_string_;
170         /// Number of lines used by preedit text
171         int preedit_lines_;
172         /// the attributes of the preedit text
173         QList<QInputMethodEvent::Attribute> preedit_attr_;
174
175         /// Ratio between physical pixels and device-independent pixels
176         /// We save the last used value to detect changes of the
177         /// current pixel_ratio of the viewport.
178         double last_pixel_ratio_;
179         ///
180         GuiCompleter * completer_;
181
182         /// Special mode in which Esc and Enter (with or without Shift)
183         /// are ignored
184         bool dialog_mode_;
185         /// store the name of the context menu when the mouse is
186         /// pressed. This is used to get the correct context menu
187         /// when the menu is actually shown (after releasing on Windows)
188         /// and after the DEPM has done its job.
189         std::string context_menu_name_;
190
191         /// stuff related to window title
192         ///
193         support::FileName file_name_;
194         ///
195         bool shell_escape_;
196         ///
197         bool read_only_;
198         ///
199         docstring vc_status_;
200         ///
201         bool clean_;
202         ///
203         bool externally_modified_;
204
205 }; // GuiWorkArea
206
207 } // namespace frontend
208 } // namespace lyx
209
210 #endif // WORKAREA_H