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"
24 #include <qapplication.h>
30 /// return the LyX key state from Qt's
31 key_modifier::state q_key_state(Qt::ButtonState state)
33 key_modifier::state k = key_modifier::none;
34 if (state & Qt::ControlButton)
35 k |= key_modifier::ctrl;
36 if (state & Qt::ShiftButton)
37 k |= key_modifier::shift;
38 if (state & Qt::AltButton)
39 k |= key_modifier::alt;
43 /// return the LyX mouse button state from Qt's
44 mouse_button::state q_button_state(Qt::ButtonState button)
46 mouse_button::state b = mouse_button::none;
49 b = mouse_button::button1;
52 b = mouse_button::button2;
55 b = mouse_button::button3;
64 /// return the LyX mouse button state from Qt's
65 mouse_button::state q_motion_state(Qt::ButtonState state)
67 mouse_button::state b = mouse_button::none;
68 if (state & Qt::LeftButton)
69 b |= mouse_button::button1;
70 if (state & Qt::MidButton)
71 b |= mouse_button::button2;
72 if (state & Qt::RightButton)
73 b |= mouse_button::button3;
80 QContentPane::QContentPane(QWorkArea * parent)
81 : QWidget(parent, "content_pane", WRepaintNoErase),
84 setFocusPolicy(QWidget::WheelFocus);
87 // stupid moc strikes again
88 connect(wa_->scrollbar_, SIGNAL(valueChanged(int)),
89 this, SLOT(scrollBarChanged(int)));
94 void QContentPane::scrollBarChanged(int val)
96 wa_->scrollDocView(val);
100 void QContentPane::mousePressEvent(QMouseEvent * e)
102 if (dc_event_.active && dc_event_ == *e) {
103 dc_event_.active = false;
104 FuncRequest cmd(LFUN_MOUSE_TRIPLE,
105 dc_event_.x, dc_event_.y,
106 q_button_state(dc_event_.state));
112 (LFUN_MOUSE_PRESS, e->x(), e->y(), q_button_state(e->button()));
117 void QContentPane::mouseReleaseEvent(QMouseEvent * e)
120 (LFUN_MOUSE_RELEASE, e->x(), e->y(), q_button_state(e->button()));
125 void QContentPane::mouseMoveEvent(QMouseEvent * e)
128 (LFUN_MOUSE_MOTION, e->x(), e->y(), q_motion_state(e->state()));
133 void QContentPane::keyPressEvent(QKeyEvent * e)
135 lyxerr[Debug::KEY] << "Press key " << e->key()
136 << " text \"" << (e->text().isEmpty() ? "none" : e->text().latin1())
137 << "\", ascii \"" << e->ascii() << "\"" << endl;
138 QLyXKeySym * sym = new QLyXKeySym();
140 wa_->workAreaKeyPress(LyXKeySymPtr(sym), q_key_state(e->state()));
144 void QContentPane::doubleClickTimeout()
146 if (!dc_event_.active)
149 dc_event_.active = false;
151 FuncRequest cmd(LFUN_MOUSE_DOUBLE,
152 dc_event_.x, dc_event_.y,
153 q_button_state(dc_event_.state));
158 void QContentPane::mouseDoubleClickEvent(QMouseEvent * e)
160 dc_event_ = double_click(e);
162 // doubleClickInterval() is just too long.
163 QTimer::singleShot(QApplication::doubleClickInterval() / 1.5,
164 this, SLOT(doubleClickTimeout()));
168 void QContentPane::resizeEvent(QResizeEvent *)
170 if (!pixmap_.get()) {
171 pixmap_.reset(new QPixmap(width(), height()));
174 pixmap_->resize(width(), height());
175 wa_->workAreaResize();
179 void QContentPane::paintEvent(QPaintEvent * e)
181 if (!pixmap_.get()) {
182 pixmap_.reset(new QPixmap(width(), height()));
183 wa_->workAreaResize();
189 lyxerr[Debug::GUI] << "repainting " << r.x()
190 << "," << r.y() << " " << r.width()
191 << "," << r.height() << endl;
193 q.drawPixmap(QPoint(r.x(), r.y()),