]> git.lyx.org Git - lyx.git/blob - src/frontends/qt2/QContentPane.h
some tabular fixes for the problems reported by Helge
[lyx.git] / src / frontends / qt2 / 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 #ifdef emit
16 #undef emit
17 #endif
18
19 #include "funcrequest.h"
20 #include "frontends/Timeout.h"
21
22 #include <qwidget.h>
23 #include <qpixmap.h>
24
25 #include <boost/scoped_ptr.hpp>
26
27 class QWorkArea;
28
29 /// for emulating triple click
30 class double_click {
31 public:
32         int x;
33         int y;
34         Qt::ButtonState state;
35         bool active;
36
37         bool operator==(QMouseEvent const & e) {
38                 return x == e.x() && y == e.y()
39                         && state == e.button();
40         }
41
42         double_click()
43                 : x(0), y(0), state(Qt::NoButton), active(false) {}
44
45         double_click(QMouseEvent * e)
46                 : x(e->x()), y(e->y()),
47                 state(e->button()), active(true) {}
48 };
49
50
51 /** Qt only emits mouse events when the mouse is being moved, but
52  *  we want to generate 'pseudo' mouse events when the mouse button is
53  *  pressed and the mouse cursor is below the bottom, or above the top
54  *  of the work area. In this way, we'll be able to continue scrolling
55  *  (and selecting) the text.
56  *
57  *  This class stores all the parameters needed to make this happen.
58  */
59 class SyntheticMouseEvent
60 {
61 public:
62         SyntheticMouseEvent();
63
64         FuncRequest cmd;
65         Timeout timeout;
66         bool restart_timeout;
67         int x_old;
68         int y_old;
69         double scrollbar_value_old;
70 };
71
72
73 /**
74  * Widget for actually drawing the document on
75  */
76 class QContentPane : public QWidget {
77         Q_OBJECT
78 public:
79         QContentPane(QWorkArea * parent);
80
81         /// return the backing pixmap
82         QPixmap * pixmap() const { return pixmap_.get(); }
83         /// track scrollbar signals?
84         void trackScrollbar(bool track_on);
85
86 protected:
87         /// repaint part of the widget
88         void paintEvent(QPaintEvent * e);
89         /// widget has been resized
90         void resizeEvent(QResizeEvent * e);
91
92         /// mouse button press
93         void mousePressEvent(QMouseEvent * e);
94         /// mouse button release
95         void mouseReleaseEvent(QMouseEvent * e);
96         /// mouse double click of button
97         void mouseDoubleClickEvent(QMouseEvent * e);
98         /// mouse motion
99         void mouseMoveEvent(QMouseEvent * e);
100         /// wheel event
101         void wheelEvent(QWheelEvent * e);
102         /// key press
103         void keyPressEvent(QKeyEvent * e);
104 public slots:
105         void doubleClickTimeout();
106
107         void scrollBarChanged(int);
108 private:
109         /// The slot connected to SyntheticMouseEvent::timeout.
110         void generateSyntheticMouseEvent();
111         SyntheticMouseEvent synthetic_mouse_event_;
112
113         ///
114         bool track_scrollbar_;
115         /// owning widget
116         QWorkArea * wa_;
117
118         /// the double buffered pixmap
119         boost::scoped_ptr<QPixmap> pixmap_;
120
121         double_click dc_event_;
122 };
123
124 #endif // QCONTENTPANE_H