]> git.lyx.org Git - lyx.git/blob - src/frontends/qt2/QContentPane.C
incomplete key mapping stuff. Introduces some breakage.
[lyx.git] / src / frontends / qt2 / QContentPane.C
1 /**
2  * \file QContentPane.C
3  * Copyright 1995-2002 the LyX Team
4  * Read the file COPYING
5  *
6  * \author John Levon <moz@compsoc.man.ac.uk>
7  */
8
9 #include <config.h>
10
11 #ifdef __GNUG__
12 #pragma implementation
13 #endif
14
15 #include "debug.h"
16
17 #include "QWorkArea.h"
18 #include "QLyXKeySym.h"
19
20 #include <qevent.h>
21 #include <qpainter.h>
22  
23 using std::endl;
24
25 namespace {
26  
27 /// return the LyX key state from Qt's
28 key_modifier::state q_key_state(Qt::ButtonState state)
29 {
30         key_modifier::state k = key_modifier::none;
31         if (state & Qt::ControlButton)
32                 k |= key_modifier::ctrl;
33         if (state & Qt::ShiftButton)
34                 k |= key_modifier::shift;
35         if (state & Qt::AltButton)
36                 k |= key_modifier::alt;
37         return k;
38 }
39
40 /// return the LyX mouse button state from Qt's
41 mouse_button::state q_button_state(Qt::ButtonState button)
42 {
43         mouse_button::state b = mouse_button::none;
44         switch (button) {
45                 case Qt::LeftButton:
46                         b = mouse_button::button1;
47                         break;
48                 case Qt::MidButton:
49                         b = mouse_button::button2;
50                         break;
51                 case Qt::RightButton:
52                         b = mouse_button::button3;
53                         break;
54                 default:
55                         break;
56         }
57         return b;
58 }
59  
60  
61 /// return the LyX mouse button state from Qt's
62 mouse_button::state q_motion_state(Qt::ButtonState state)
63 {
64         mouse_button::state b = mouse_button::none;
65         if (state & Qt::LeftButton)
66                 b |= mouse_button::button1;
67         if (state & Qt::MidButton)
68                 b |= mouse_button::button2;
69         if (state & Qt::RightButton)
70                 b |= mouse_button::button3;
71         return b;
72 }
73
74 } // namespace anon
75  
76
77 QContentPane::QContentPane(QWorkArea * parent)
78         : QWidget(parent, "content_pane", WRepaintNoErase), 
79         wa_(parent)
80 {
81         setFocusPolicy(QWidget::WheelFocus);
82         setFocus();
83
84         // stupid moc strikes again
85         connect(wa_->scrollbar_, SIGNAL(valueChanged(int)), 
86                 this, SLOT(scrollBarChanged(int)));
87  
88 }
89
90
91 void QContentPane::scrollBarChanged(int val)
92 {
93         wa_->scrollDocView(val); 
94 }
95  
96  
97 void QContentPane::mousePressEvent(QMouseEvent * e)
98 {
99         wa_->workAreaButtonPress(e->x(), e->y(), q_button_state(e->button()));
100 }
101
102
103 void QContentPane::mouseReleaseEvent(QMouseEvent * e)
104 {
105         wa_->workAreaButtonRelease(e->x(), e->y(), q_button_state(e->button()));
106 }
107
108  
109 void QContentPane::mouseMoveEvent(QMouseEvent * e)
110 {
111         wa_->workAreaMotionNotify(e->x(), e->y(), q_motion_state(e->state()));
112 }
113
114
115 void QContentPane::keyPressEvent(QKeyEvent * e)
116 {
117         QLyXKeySym * sym = new QLyXKeySym();
118         sym->set(e->key(), bool(e->state() & Qt::ShiftButton));
119         wa_->workAreaKeyPress(LyXKeySymPtr(sym), q_key_state(e->state()));
120 }
121
122  
123 void QContentPane::mouseDoubleClickEvent(QMouseEvent * e)
124 {
125         wa_->workAreaDoubleClick(e->x(), e->y(), q_button_state(e->state()));
126         // FIXME: triple click 
127 }
128  
129  
130 void QContentPane::resizeEvent(QResizeEvent *)
131 {
132         if (!pixmap_.get()) {
133                 pixmap_.reset(new QPixmap(width(), height()));
134         }
135
136         pixmap_->resize(width(), height());
137         wa_->workAreaResize();
138 }
139
140  
141 void QContentPane::paintEvent(QPaintEvent * e)
142 {
143         if (!pixmap_.get()) {
144                 pixmap_.reset(new QPixmap(width(), height()));
145                 wa_->workAreaResize();
146                 return;
147         }
148
149         QRect r(e->rect());
150  
151         lyxerr[Debug::GUI] << "repainting " << r.x() 
152                 << "," << r.y() << " " << r.width() 
153                 << "," << r.height() << endl;
154         QPainter q(this);
155         q.drawPixmap(QPoint(r.x(), r.y()),
156                 *pixmap_.get(), r); 
157 }