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.
7 * \author Abdelrazak Younes
9 * Full author contact details are available in file CREDITS.
12 #ifndef WORKAREA_PRIVATE_H
13 #define WORKAREA_PRIVATE_H
15 #include "FuncRequest.h"
17 #include "support/FileName.h"
18 #include "support/Timeout.h"
20 #include <QMouseEvent>
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
42 /// for emulating triple click
46 DoubleClick() : state(Qt::NoButton), active(false) {}
48 DoubleClick(QMouseEvent * e) : state(e->button()), active(true) {}
50 bool operator==(QMouseEvent const & e) { return state == e.button(); }
54 Qt::MouseButton state;
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.
65 * This class stores all the parameters needed to make this happen.
67 class SyntheticMouseEvent
70 SyntheticMouseEvent();
79 * Implementation of the work area (buffer view GUI)
83 struct GuiWorkArea::Private
86 Private(GuiWorkArea *);
92 void resizeBufferView();
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
100 /// hide the caret if it is visible
102 /// Set the range and value of the scrollbar and connect to its valueChanged
104 void updateScrollbar();
105 /// Change the cursor when the mouse hovers over a clickable inset
106 void updateCursorShape();
108 void paintPreeditText(GuiPainter & pain);
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);
122 QPaintDevice * screenDevice() {
123 #ifdef LYX_BACKINGSTORE
126 return p->viewport();
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);
139 void updateScreen(QRectF const & ) {}
145 BufferView * buffer_view_;
149 #ifdef LYX_BACKINGSTORE
154 CaretWidget * caret_;
155 /// is the caret currently displayed
158 QTimer caret_timeout_;
161 SyntheticMouseEvent synthetic_mouse_event_;
163 DoubleClick dc_event_;
168 /// the current preedit text of the input method
169 docstring preedit_string_;
170 /// Number of lines used by preedit text
172 /// the attributes of the preedit text
173 QList<QInputMethodEvent::Attribute> preedit_attr_;
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_;
180 GuiCompleter * completer_;
182 /// Special mode in which Esc and Enter (with or without Shift)
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_;
191 /// stuff related to window title
193 support::FileName file_name_;
199 docstring vc_status_;
203 bool externally_modified_;
207 } // namespace frontend