3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
8 * Full author contact details are available in file CREDITS
14 #pragma implementation
19 #include "QWorkArea.h"
20 #include "QLyXKeySym.h"
21 #include "funcrequest.h"
26 #include <qapplication.h>
32 /// return the LyX key state from Qt's
33 key_modifier::state q_key_state(Qt::ButtonState state)
35 key_modifier::state k = key_modifier::none;
36 if (state & Qt::ControlButton)
37 k |= key_modifier::ctrl;
38 if (state & Qt::ShiftButton)
39 k |= key_modifier::shift;
40 if (state & Qt::AltButton)
41 k |= key_modifier::alt;
46 /// return the LyX mouse button state from Qt's
47 mouse_button::state q_button_state(Qt::ButtonState button)
49 mouse_button::state b = mouse_button::none;
52 b = mouse_button::button1;
55 b = mouse_button::button2;
58 b = mouse_button::button3;
67 /// return the LyX mouse button state from Qt's
68 mouse_button::state q_motion_state(Qt::ButtonState state)
70 mouse_button::state b = mouse_button::none;
71 if (state & Qt::LeftButton)
72 b |= mouse_button::button1;
73 if (state & Qt::MidButton)
74 b |= mouse_button::button2;
75 if (state & Qt::RightButton)
76 b |= mouse_button::button3;
83 QContentPane::QContentPane(QWorkArea * parent)
84 : QWidget(parent, "content_pane", WRepaintNoErase),
87 setFocusPolicy(QWidget::WheelFocus);
90 // stupid moc strikes again
91 connect(wa_->scrollbar_, SIGNAL(valueChanged(int)),
92 this, SLOT(scrollBarChanged(int)));
97 void QContentPane::scrollBarChanged(int val)
99 wa_->scrollDocView(val);
103 void QContentPane::mousePressEvent(QMouseEvent * e)
105 if (dc_event_.active && dc_event_ == *e) {
106 dc_event_.active = false;
107 FuncRequest cmd(LFUN_MOUSE_TRIPLE,
108 dc_event_.x, dc_event_.y,
109 q_button_state(dc_event_.state));
114 FuncRequest cmd(LFUN_MOUSE_PRESS, e->x(), e->y(),
115 q_button_state(e->button()));
120 void QContentPane::mouseReleaseEvent(QMouseEvent * e)
122 FuncRequest cmd(LFUN_MOUSE_RELEASE, e->x(), e->y(),
123 q_button_state(e->button()));
128 void QContentPane::mouseMoveEvent(QMouseEvent * e)
131 (LFUN_MOUSE_MOTION, e->x(), e->y(), q_motion_state(e->state()));
136 void QContentPane::keyPressEvent(QKeyEvent * e)
138 lyxerr[Debug::KEY] << "Press key " << e->key()
139 << " text \"" << (e->text().isEmpty() ? "none" : e->text().latin1())
140 << "\", ascii \"" << e->ascii() << "\"" << endl;
141 QLyXKeySym * sym = new QLyXKeySym();
143 wa_->workAreaKeyPress(LyXKeySymPtr(sym), q_key_state(e->state()));
147 void QContentPane::doubleClickTimeout()
149 if (!dc_event_.active)
152 dc_event_.active = false;
154 FuncRequest cmd(LFUN_MOUSE_DOUBLE,
155 dc_event_.x, dc_event_.y,
156 q_button_state(dc_event_.state));
161 void QContentPane::mouseDoubleClickEvent(QMouseEvent * e)
163 dc_event_ = double_click(e);
165 // doubleClickInterval() is just too long.
166 QTimer::singleShot(int(QApplication::doubleClickInterval() / 1.5),
167 this, SLOT(doubleClickTimeout()));
171 void QContentPane::resizeEvent(QResizeEvent *)
173 if (!pixmap_.get()) {
174 pixmap_.reset(new QPixmap(width(), height()));
177 pixmap_->resize(width(), height());
178 wa_->workAreaResize();
182 void QContentPane::paintEvent(QPaintEvent * e)
184 if (!pixmap_.get()) {
185 pixmap_.reset(new QPixmap(width(), height()));
186 wa_->workAreaResize();
192 lyxerr[Debug::GUI] << "repainting " << r.x()
193 << "," << r.y() << " " << r.width()
194 << "," << r.height() << endl;
196 q.drawPixmap(QPoint(r.x(), r.y()),