3 * Copyright 1995-2002 the LyX Team
4 * Read the file COPYING
6 * \author John Levon <moz@compsoc.man.ac.uk>
12 #pragma implementation
17 #include "QWorkArea.h"
18 #include "QLyXKeySym.h"
19 #include "funcrequest.h"
28 /// return the LyX key state from Qt's
29 key_modifier::state q_key_state(Qt::ButtonState state)
31 key_modifier::state k = key_modifier::none;
32 if (state & Qt::ControlButton)
33 k |= key_modifier::ctrl;
34 if (state & Qt::ShiftButton)
35 k |= key_modifier::shift;
36 if (state & Qt::AltButton)
37 k |= key_modifier::alt;
41 /// return the LyX mouse button state from Qt's
42 mouse_button::state q_button_state(Qt::ButtonState button)
44 mouse_button::state b = mouse_button::none;
47 b = mouse_button::button1;
50 b = mouse_button::button2;
53 b = mouse_button::button3;
62 /// return the LyX mouse button state from Qt's
63 mouse_button::state q_motion_state(Qt::ButtonState state)
65 mouse_button::state b = mouse_button::none;
66 if (state & Qt::LeftButton)
67 b |= mouse_button::button1;
68 if (state & Qt::MidButton)
69 b |= mouse_button::button2;
70 if (state & Qt::RightButton)
71 b |= mouse_button::button3;
78 QContentPane::QContentPane(QWorkArea * parent)
79 : QWidget(parent, "content_pane", WRepaintNoErase),
82 setFocusPolicy(QWidget::WheelFocus);
85 // stupid moc strikes again
86 connect(wa_->scrollbar_, SIGNAL(valueChanged(int)),
87 this, SLOT(scrollBarChanged(int)));
92 void QContentPane::scrollBarChanged(int val)
94 wa_->scrollDocView(val);
98 void QContentPane::mousePressEvent(QMouseEvent * e)
101 (LFUN_MOUSE_PRESS, e->x(), e->y(), q_button_state(e->button()));
106 void QContentPane::mouseReleaseEvent(QMouseEvent * e)
109 (LFUN_MOUSE_RELEASE, e->x(), e->y(), q_button_state(e->button()));
114 void QContentPane::mouseMoveEvent(QMouseEvent * e)
117 (LFUN_MOUSE_RELEASE, e->x(), e->y(), q_motion_state(e->button()));
122 void QContentPane::keyPressEvent(QKeyEvent * e)
124 lyxerr[Debug::KEY] << "Press key " << e->key()
125 << " text \"" << (e->text().isEmpty() ? "none" : e->text().latin1())
126 << "\", ascii \"" << e->ascii() << "\"" << endl;
127 QLyXKeySym * sym = new QLyXKeySym();
129 wa_->workAreaKeyPress(LyXKeySymPtr(sym), q_key_state(e->state()));
133 void QContentPane::mouseDoubleClickEvent(QMouseEvent * e)
136 (LFUN_MOUSE_DOUBLE, e->x(), e->y(), q_button_state(e->button()));
138 // FIXME: triple click
142 void QContentPane::resizeEvent(QResizeEvent *)
144 if (!pixmap_.get()) {
145 pixmap_.reset(new QPixmap(width(), height()));
148 pixmap_->resize(width(), height());
149 wa_->workAreaResize();
153 void QContentPane::paintEvent(QPaintEvent * e)
155 if (!pixmap_.get()) {
156 pixmap_.reset(new QPixmap(width(), height()));
157 wa_->workAreaResize();
163 lyxerr[Debug::GUI] << "repainting " << r.x()
164 << "," << r.y() << " " << r.width()
165 << "," << r.height() << endl;
167 q.drawPixmap(QPoint(r.x(), r.y()),