]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiWorkArea_Private.h
The View->Source pane resets the format every time you click into
[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 // Comment out to use QImage backend instead of QPixmap. This won't have any
16 // effect on Windows, MacOSX and most X11 environment when running locally.
17 // When running remotely on X11, this may have a big performance penalty.
18 //#define USE_QIMAGE
19
20 #include "FuncRequest.h"
21 #include "qt_helpers.h"
22
23 #include "support/docstring.h"
24 #include "support/Timeout.h"
25
26 #include <QAbstractScrollArea>
27 #include <QMouseEvent>
28 #ifdef USE_QIMAGE
29 #include <QImage>
30 #else
31 #include <QPixmap>
32 #endif
33 #include <QTimer>
34
35 class QContextMenuEvent;
36 class QDragEnterEvent;
37 class QDropEvent;
38 class QKeyEvent;
39 class QPaintEvent;
40 class QResizeEvent;
41 class QToolButton;
42 class QWheelEvent;
43 class QWidget;
44
45 #ifdef CursorShape
46 #undef CursorShape
47 #endif
48
49 namespace lyx {
50
51 class Buffer;
52
53 namespace frontend {
54
55 class GuiCompleter;
56 class GuiView;
57 class GuiWorkArea;
58
59 /// for emulating triple click
60 class DoubleClick {
61 public:
62         ///
63         DoubleClick() : state(Qt::NoButton), active(false) {}
64         ///
65         DoubleClick(QMouseEvent * e) : state(e->button()), active(true) {}
66         ///
67         bool operator==(QMouseEvent const & e) { return state == e.button(); }
68         ///
69 public:
70         ///
71         Qt::MouseButton state;
72         ///
73         bool active;
74 };
75
76 /** Qt only emits mouse events when the mouse is being moved, but
77  *  we want to generate 'pseudo' mouse events when the mouse button is
78  *  pressed and the mouse cursor is below the bottom, or above the top
79  *  of the work area. In this way, we'll be able to continue scrolling
80  *  (and selecting) the text.
81  *
82  *  This class stores all the parameters needed to make this happen.
83  */
84 class SyntheticMouseEvent
85 {
86 public:
87         SyntheticMouseEvent();
88
89         FuncRequest cmd;
90         Timeout timeout;
91         bool restart_timeout;
92 };
93
94
95 /**
96  * Implementation of the work area (buffer view GUI)
97 */
98 class CursorWidget;
99
100 struct GuiWorkArea::Private
101 {
102         Private(GuiWorkArea *);
103
104         /// update the passed area.
105         void update(int x, int y, int w, int h);
106         ///
107         void updateScreen();
108         ///
109         void resizeBufferView();
110
111         /// paint the cursor and store the background
112         virtual void showCursor(int x, int y, int h,
113                 bool l_shape, bool rtl, bool completable);
114
115         /// hide the cursor
116         virtual void removeCursor();
117         ///
118         void dispatch(FuncRequest const & cmd0, KeyModifier = NoModifier);
119         /// hide the visible cursor, if it is visible
120         void hideCursor();
121         /// show the cursor if it is not visible
122         void showCursor();
123         ///
124         void updateScrollbar();
125         /// Change the cursor when the mouse hovers over a clickable inset
126         void updateCursorShape();
127         ///
128         void setCursorShape(Qt::CursorShape shape);
129
130 #ifdef USE_QIMAGE
131         void resetScreen()
132         {
133                 screen_ = QImage(p->viewport()->width(), p->viewport()->height(),
134                         QImage::Format_ARGB32_Premultiplied);
135         }
136
137         QImage screen_;
138 #else
139         void resetScreen()
140         {
141                 screen_ = QPixmap(p->viewport()->width(), p->viewport()->height());
142         }
143
144         QPixmap screen_;
145 #endif
146         ///
147         GuiWorkArea * p;
148
149         ///
150         BufferView * buffer_view_;
151         /// Read only Buffer status cache.
152         bool read_only_;
153         ///
154         GuiView * lyx_view_;
155         /// is the cursor currently displayed
156         bool cursor_visible_;
157
158         ///
159         QTimer cursor_timeout_;
160         ///
161         SyntheticMouseEvent synthetic_mouse_event_;
162         ///
163         DoubleClick dc_event_;
164
165         ///
166         CursorWidget * cursor_;
167         ///
168         bool need_resize_;
169         ///
170         bool schedule_redraw_;
171         ///
172         int preedit_lines_;
173
174         ///
175         GuiCompleter * completer_;
176
177         /// Special mode in which Esc and Enter (with or without Shift)
178         /// are ignored
179         bool dialog_mode_;
180         /// store the name of the context menu when the mouse is
181         /// pressed. This is used to get the correct context menu 
182         /// when the menu is actually shown (after releasing on Windows)
183         /// and after the DEPM has done its job.
184         std::string context_menu_name_;
185 }; // GuiWorkArea
186
187 } // namespace frontend
188 } // namespace lyx
189
190 #endif // WORKAREA_H