]> git.lyx.org Git - lyx.git/blob - src/frontends/qt2/QContentPane.h
implement triple click
[lyx.git] / src / frontends / qt2 / QContentPane.h
1 // -*- C++ -*-
2 /**
3  * \file QContentPane.h
4  * Copyright 1995-2002 the LyX Team
5  * Read the file COPYING
6  *
7  * \author John Levon <moz@compsoc.man.ac.uk>
8  */
9
10 #ifndef QCONTENTPANE_H
11 #define QCONTENTPANE_H
12
13 #ifdef __GNUG__
14 #pragma interface
15 #endif
16
17 #include <config.h>
18 #include <utility>
19 #include <boost/smart_ptr.hpp>
20
21 #include <qwidget.h>
22 #include <qscrollbar.h>
23 #include <qpixmap.h>
24 #include <qevent.h>
25
26 class QWorkArea; 
27  
28 /// for emulating triple click
29 struct double_click {
30         int x;
31         int y;
32         Qt::ButtonState state;
33         bool active;
34
35         bool operator==(QMouseEvent const & e) {
36                 return x == e.x() && y == e.y()
37                         && state == e.button();
38         }
39
40         double_click()
41                 : x(0), y(0), state(Qt::NoButton), active(false) {}
42  
43         double_click(QMouseEvent * e)
44                 : x(e->x()), y(e->y()),
45                 state(e->button()), active(true) {}
46 };
47
48 /**
49  * Widget for actually drawing the document on
50  */
51 class QContentPane : public QWidget {
52         Q_OBJECT
53  
54 public:
55         QContentPane(QWorkArea * parent);
56          
57         /// return the backing pixmap
58         QPixmap * pixmap() const { return pixmap_.get(); } 
59  
60 protected:
61         /// repaint part of the widget
62         void paintEvent(QPaintEvent * e);
63         /// widget has been resized
64         void resizeEvent(QResizeEvent * e);
65  
66         /// mouse button press
67         void mousePressEvent(QMouseEvent * e);
68         /// mouse button release 
69         void mouseReleaseEvent(QMouseEvent * e);
70         /// mouse double click of button 
71         void mouseDoubleClickEvent(QMouseEvent * e);
72         /// mouse motion
73         void mouseMoveEvent(QMouseEvent * e);
74  
75         /// key press
76         void keyPressEvent(QKeyEvent * e);
77  
78 public slots:
79         void doubleClickTimeout();
80  
81         void scrollBarChanged(int);
82  
83 private:
84         /// owning widget
85         QWorkArea * wa_;
86  
87         /// the double buffered pixmap
88         boost::scoped_ptr<QPixmap> pixmap_;
89
90         double_click dc_event_;
91 };
92
93 #endif // QCONTENTPANE_H