]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiWorkArea_Private.h
Amend f441590c
[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 #include "LyXRC.h"
17
18 #include "support/Timeout.h"
19
20 #include <QMouseEvent>
21 #include <QImage>
22 #include <QPixmap>
23 #include <QTimer>
24
25 class QContextMenuEvent;
26 class QDragEnterEvent;
27 class QDropEvent;
28 class QKeyEvent;
29 class QPaintEvent;
30 class QResizeEvent;
31 class QToolButton;
32 class QWheelEvent;
33 class QWidget;
34
35 #ifdef CursorShape
36 #undef CursorShape
37 #endif
38
39 namespace lyx {
40
41 class Buffer;
42
43 namespace frontend {
44
45 class GuiCompleter;
46 class GuiView;
47 class GuiWorkArea;
48
49 /// for emulating triple click
50 class DoubleClick {
51 public:
52         ///
53         DoubleClick() : state(Qt::NoButton), active(false) {}
54         ///
55         DoubleClick(QMouseEvent * e) : state(e->button()), active(true) {}
56         ///
57         bool operator==(QMouseEvent const & e) { return state == e.button(); }
58         ///
59 public:
60         ///
61         Qt::MouseButton state;
62         ///
63         bool active;
64 };
65
66 /** Qt only emits mouse events when the mouse is being moved, but
67  *  we want to generate 'pseudo' mouse events when the mouse button is
68  *  pressed and the mouse cursor is below the bottom, or above the top
69  *  of the work area. In this way, we'll be able to continue scrolling
70  *  (and selecting) the text.
71  *
72  *  This class stores all the parameters needed to make this happen.
73  */
74 class SyntheticMouseEvent
75 {
76 public:
77         SyntheticMouseEvent();
78
79         FuncRequest cmd;
80         Timeout timeout;
81         bool restart_timeout;
82 };
83
84
85 /**
86  * Implementation of the work area (buffer view GUI)
87 */
88 class CursorWidget;
89
90 struct GuiWorkArea::Private
91 {
92         Private(GuiWorkArea *);
93
94         /// update the passed area.
95         void update(int x, int y, int w, int h);
96         ///
97         void updateScreen();
98         ///
99         void resizeBufferView();
100
101         /// paint the cursor and store the background
102         void showCursor(int x, int y, int h,
103                 bool l_shape, bool rtl, bool completable);
104
105         /// hide the cursor
106         void removeCursor();
107         ///
108         void dispatch(FuncRequest const & cmd0, KeyModifier = NoModifier);
109         /// hide the visible cursor, if it is visible
110         void hideCursor();
111         /// show the cursor if it is not visible
112         void showCursor();
113         ///
114         void updateScrollbar();
115         /// Change the cursor when the mouse hovers over a clickable inset
116         void updateCursorShape();
117         ///
118         void setCursorShape(Qt::CursorShape shape);
119
120         bool needResize() const {
121                 return need_resize_ || p->pixelRatio() != pixel_ratio_;
122         }
123
124         void resetScreen()
125         {
126                 delete screen_;
127                 pixel_ratio_ = p->pixelRatio();
128                 if (lyxrc.use_qimage) {
129                         QImage *x = 
130                                 new QImage(static_cast<int>(pixel_ratio_ * p->viewport()->width()),
131                                                    static_cast<int>(pixel_ratio_ * p->viewport()->height()),
132                                                    QImage::Format_ARGB32_Premultiplied);
133 #if QT_VERSION >= 0x050000
134                         x->setDevicePixelRatio(pixel_ratio_);
135 #endif
136                         screen_ = x;
137                 } else {
138                         QPixmap *x = 
139                                 new QPixmap(static_cast<int>(pixel_ratio_ * p->viewport()->width()),
140                                                         static_cast<int>(pixel_ratio_ * p->viewport()->height()));
141 #if QT_VERSION >= 0x050000
142                         x->setDevicePixelRatio(pixel_ratio_);
143 #endif
144                         screen_ = x;
145                 }
146         }
147         ///
148         GuiWorkArea * p;
149         ///
150         QPaintDevice * screen_;
151         ///
152         BufferView * buffer_view_;
153         /// Read only Buffer status cache.
154         bool read_only_;
155         ///
156         GuiView * lyx_view_;
157         /// is the cursor currently displayed
158         bool cursor_visible_;
159
160         ///
161         QTimer cursor_timeout_;
162         ///
163         SyntheticMouseEvent synthetic_mouse_event_;
164         ///
165         DoubleClick dc_event_;
166
167         ///
168         CursorWidget * cursor_;
169         ///
170         bool need_resize_;
171         ///
172         bool schedule_redraw_;
173         ///
174         int preedit_lines_;
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 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 }; // GuiWorkArea
191
192 } // namespace frontend
193 } // namespace lyx
194
195 #endif // WORKAREA_H