]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/QWorkArea.h
Added initial qt4 work by Abdelrazak Younes
[lyx.git] / src / frontends / qt4 / QWorkArea.h
1 // -*- C++ -*-
2 /**
3  * \file QWorkArea.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author unknown
8  * \author John Levon
9  * \author Abdelrazak Younes
10  *
11  * Full author contact details are available in file CREDITS.
12  */
13
14 #ifndef QWORKAREA_H
15 #define QWORKAREA_H
16
17 #if (defined(Q_WS_X11) && QT_VERSION >= 0x030200)
18 #define USE_INPUT_METHODS 1
19 #endif
20
21 #ifdef emit
22 #undef emit
23 #endif
24
25 #include "funcrequest.h"
26 #include "frontends/Timeout.h"
27
28 #include "WorkArea.h"
29 #include "QLPainter.h"
30 #include "LyXView.h"
31
32 #include <QAbstractScrollArea>
33 #include <QMouseEvent>
34 #include <QWheelEvent>
35 #include <QResizeEvent>
36 #include <QKeyEvent>
37 #include <QPaintEvent>
38 #include <QTimer>
39
40 #include <boost/scoped_ptr.hpp>
41
42 #include <queue>
43
44 class Painter;
45
46 class QWidget;
47 class QDragEnterEvent;
48 class QDropEvent;
49 class QMouseEvent;
50
51 /// for emulating triple click
52 class double_click {
53 public:
54         int x;
55         int y;
56         Qt::ButtonState state;
57         bool active;
58
59         bool operator==(QMouseEvent const & e) {
60                 return x == e.x() && y == e.y()
61                         && state == e.button();
62         }
63
64         double_click()
65                 : x(0), y(0), state(Qt::NoButton), active(false) {}
66
67         double_click(QMouseEvent * e)
68                 : x(e->x()), y(e->y()),
69                 state(e->button()), active(true) {}
70 };
71
72
73 /** Qt only emits mouse events when the mouse is being moved, but
74  *  we want to generate 'pseudo' mouse events when the mouse button is
75  *  pressed and the mouse cursor is below the bottom, or above the top
76  *  of the work area. In this way, we'll be able to continue scrolling
77  *  (and selecting) the text.
78  *
79  *  This class stores all the parameters needed to make this happen.
80  */
81 class SyntheticMouseEvent
82 {
83 public:
84         SyntheticMouseEvent();
85
86         FuncRequest cmd;
87         Timeout timeout;
88         bool restart_timeout;
89         int x_old;
90         int y_old;
91         double scrollbar_value_old;
92 };
93
94 /**
95  * Qt-specific implementation of the work area
96  * (buffer view GUI)
97  *
98  * It consists of a content pane widget, and a scrollbar.
99  * Hopefully soon we can just use QScrollView ...
100  */
101 class QWorkArea : public QAbstractScrollArea, public WorkArea {
102
103         Q_OBJECT
104
105 public:
106
107         QWorkArea(LyXView & owner, int w, int h);
108
109         virtual ~QWorkArea();
110         /// return the width of the content pane
111         virtual int workWidth() const { return viewport()->width(); }
112         /// return the height of the content pane
113         virtual int workHeight() const { return viewport()->height(); }
114         ///
115         virtual void setScrollbarParams(int height, int pos, int line_height);
116
117         /// a selection exists
118         virtual void haveSelection(bool) const;
119         ///
120         virtual std::string const getClipboard() const;
121         ///
122         virtual void putClipboard(std::string const &) const;
123         ///
124         virtual void dragEnterEvent(QDragEnterEvent * event);
125         ///
126         virtual void dropEvent(QDropEvent* event);
127         
128         /// return the widget's painter
129         virtual Painter & getPainter();
130
131         //virtual QPaintDevice & paintDevice() { return content_->pixmap(); }
132         /// return the backing pixmap
133         QPixmap * pixmap() const { return pixmap_.get(); }
134
135         /// return the widget's painter
136 //      virtual QLPainter & getQLPainter();
137
138         /// get the content pane widget
139         QWidget * getContent() const;
140
141
142
143 protected:
144         
145 //      void scrollContentsBy(int dx, int dy);
146
147         /// repaint part of the widget
148         void paintEvent(QPaintEvent * e);
149
150         /// widget has been resized
151         void resizeEvent(QResizeEvent * e);
152
153         /// mouse button press
154         void mousePressEvent(QMouseEvent * e);
155         /// mouse button release
156         void mouseReleaseEvent(QMouseEvent * e);
157         /// mouse double click of button
158         void mouseDoubleClickEvent(QMouseEvent * e);
159         /// mouse motion
160         void mouseMoveEvent(QMouseEvent * e);
161         /// wheel event
162         void wheelEvent(QWheelEvent * e);
163         /// key press
164         void keyPressEvent(QKeyEvent * e);
165
166 #if USE_INPUT_METHODS
167         /// IM events
168         void QWorkArea::inputMethodEvent(QInputMethodEvent * e) 
169 #endif
170
171 public slots:
172
173         void keyeventTimeout();
174         void adjustViewWithScrollBar(int action);
175
176 protected:
177
178
179 private:
180
181         /// our painter
182         QLPainter painter_;
183
184         /// The slot connected to SyntheticMouseEvent::timeout.
185         void generateSyntheticMouseEvent();
186
187         SyntheticMouseEvent synthetic_mouse_event_;
188
189         /// the double buffered pixmap
190         boost::scoped_ptr<QPixmap> pixmap_;
191
192         QTimer step_timer_;
193         std::queue<boost::shared_ptr<QKeyEvent> > keyeventQueue_;
194
195         double_click dc_event_;
196
197         bool scrolled_with_mouse_;
198         bool scrolled_with_keyboard_;
199 };
200
201 #endif // QWORKAREA_H