]> git.lyx.org Git - features.git/blob - src/frontends/qt4/GuiWorkArea_Private.h
0915b64d4c2d87b0c2bb456bacb65269225275f6
[features.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 = new QImage(pixel_ratio_ * p->viewport()->width(),
130                                 pixel_ratio_ * p->viewport()->height(), QImage::Format_ARGB32_Premultiplied);
131 #if QT_VERSION > 0x050000
132                         x->setDevicePixelRatio(pixel_ratio_);
133 #endif
134                         screen_ = x;
135                 } else {
136                         QPixmap *x = new QPixmap(pixel_ratio_ * p->viewport()->width(),
137                                 pixel_ratio_ * p->viewport()->height());
138 #if QT_VERSION > 0x050000
139                         x->setDevicePixelRatio(pixel_ratio_);
140 #endif
141                         screen_ = x;
142                 }
143         }
144         ///
145         GuiWorkArea * p;
146         ///
147         QPaintDevice * screen_;
148         ///
149         BufferView * buffer_view_;
150         /// Read only Buffer status cache.
151         bool read_only_;
152         ///
153         GuiView * lyx_view_;
154         /// is the cursor currently displayed
155         bool cursor_visible_;
156
157         ///
158         QTimer cursor_timeout_;
159         ///
160         SyntheticMouseEvent synthetic_mouse_event_;
161         ///
162         DoubleClick dc_event_;
163
164         ///
165         CursorWidget * cursor_;
166         ///
167         bool need_resize_;
168         ///
169         bool schedule_redraw_;
170         ///
171         int preedit_lines_;
172         /// Ratio between physical pixels and device-independent pixels
173         /// We save the last used value to detect changes of the
174         /// current pixel_ratio of the viewport.
175         double pixel_ratio_;
176         ///
177         GuiCompleter * completer_;
178
179         /// Special mode in which Esc and Enter (with or without Shift)
180         /// are ignored
181         bool dialog_mode_;
182         /// store the name of the context menu when the mouse is
183         /// pressed. This is used to get the correct context menu 
184         /// when the menu is actually shown (after releasing on Windows)
185         /// and after the DEPM has done its job.
186         std::string context_menu_name_;
187 }; // GuiWorkArea
188
189 } // namespace frontend
190 } // namespace lyx
191
192 #endif // WORKAREA_H