]> git.lyx.org Git - lyx.git/blob - src/frontends/qt3/QContentPane.h
Extracted from r14281
[lyx.git] / src / frontends / qt3 / QContentPane.h
1 // -*- C++ -*-
2 /**
3  * \file QContentPane.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author John Levon
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #ifndef QCONTENTPANE_H
13 #define QCONTENTPANE_H
14
15 #include "funcrequest.h"
16 #ifdef emit
17 #undef emit
18 #include "frontends/Timeout.h"
19 #define emit
20 #else
21 #include "frontends/Timeout.h"
22 #endif
23
24 #include <qwidget.h>
25 #include <qpixmap.h>
26 #include <qtimer.h>
27
28 #include <boost/scoped_ptr.hpp>
29
30 #include <queue>
31
32 #if (defined(Q_WS_X11) && QT_VERSION >= 0x030200)
33 #define USE_INPUT_METHODS 1
34 #endif
35
36
37 /// for emulating triple click
38 class double_click {
39 public:
40         int x;
41         int y;
42         Qt::ButtonState state;
43         bool active;
44
45         bool operator==(QMouseEvent const & e) {
46                 return x == e.x() && y == e.y()
47                         && state == e.button();
48         }
49
50         double_click()
51                 : x(0), y(0), state(Qt::NoButton), active(false) {}
52
53         double_click(QMouseEvent * e)
54                 : x(e->x()), y(e->y()),
55                 state(e->button()), active(true) {}
56 };
57
58
59 namespace lyx {
60 namespace frontend {
61
62 class QWorkArea;
63
64 /** Qt only emits mouse events when the mouse is being moved, but
65  *  we want to generate 'pseudo' mouse events when the mouse button is
66  *  pressed and the mouse cursor is below the bottom, or above the top
67  *  of the work area. In this way, we'll be able to continue scrolling
68  *  (and selecting) the text.
69  *
70  *  This class stores all the parameters needed to make this happen.
71  */
72 class SyntheticMouseEvent
73 {
74 public:
75         SyntheticMouseEvent();
76
77         FuncRequest cmd;
78         Timeout timeout;
79         bool restart_timeout;
80         int x_old;
81         int y_old;
82         double scrollbar_value_old;
83 };
84
85
86 /**
87  * Widget for actually drawing the document on
88  */
89 class QContentPane : public QWidget {
90         Q_OBJECT
91 public:
92         QContentPane(QWorkArea * parent);
93
94         /// return the backing pixmap
95         QPixmap * pixmap() const { return pixmap_.get(); }
96         /// track scrollbar signals?
97         void trackScrollbar(bool track_on);
98
99 protected:
100         /// repaint part of the widget
101         void paintEvent(QPaintEvent * e);
102         /// widget has been resized
103         void resizeEvent(QResizeEvent * e);
104
105         /// mouse button press
106         void mousePressEvent(QMouseEvent * e);
107         /// mouse button release
108         void mouseReleaseEvent(QMouseEvent * e);
109         /// mouse double click of button
110         void mouseDoubleClickEvent(QMouseEvent * e);
111         /// mouse motion
112         void mouseMoveEvent(QMouseEvent * e);
113         /// wheel event
114         void wheelEvent(QWheelEvent * e);
115         /// key press
116         void keyPressEvent(QKeyEvent * e);
117 #if USE_INPUT_METHODS
118         /// IM events
119         void imStartEvent(QIMEvent *);
120         void imComposeEvent(QIMEvent *);
121         void imEndEvent(QIMEvent *);
122 #endif
123 public slots:
124         void doubleClickTimeout();
125
126         void scrollBarChanged(int);
127         void keyeventTimeout();
128
129 private:
130         /// The slot connected to SyntheticMouseEvent::timeout.
131         void generateSyntheticMouseEvent();
132         SyntheticMouseEvent synthetic_mouse_event_;
133
134         ///
135         bool track_scrollbar_;
136         /// owning widget
137         QWorkArea * wa_;
138
139         QTimer step_timer_;
140         std::queue<boost::shared_ptr<QKeyEvent> > keyeventQueue_;
141
142         /// the double buffered pixmap
143         boost::scoped_ptr<QPixmap> pixmap_;
144
145         double_click dc_event_;
146 };
147
148 } // namespace frontend
149 } // namespace lyx
150
151 #endif // QCONTENTPANE_H