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