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"
26 /// return the LyX key state from Qt's
27 key_modifier::state q_key_state(Qt::ButtonState state)
29 key_modifier::state k = key_modifier::none;
30 if (state & Qt::ControlButton)
31 k |= key_modifier::ctrl;
32 if (state & Qt::ShiftButton)
33 k |= key_modifier::shift;
34 if (state & Qt::AltButton)
35 k |= key_modifier::alt;
39 /// return the LyX mouse button state from Qt's
40 mouse_button::state q_button_state(Qt::ButtonState button)
42 mouse_button::state b = mouse_button::none;
45 b = mouse_button::button1;
48 b = mouse_button::button2;
51 b = mouse_button::button3;
60 /// return the LyX mouse button state from Qt's
61 mouse_button::state q_motion_state(Qt::ButtonState state)
63 mouse_button::state b = mouse_button::none;
64 if (state & Qt::LeftButton)
65 b |= mouse_button::button1;
66 if (state & Qt::MidButton)
67 b |= mouse_button::button2;
68 if (state & Qt::RightButton)
69 b |= mouse_button::button3;
76 QContentPane::QContentPane(QWorkArea * parent)
77 : QWidget(parent, "content_pane", WRepaintNoErase),
80 setFocusPolicy(QWidget::WheelFocus);
83 // stupid moc strikes again
84 connect(wa_->scrollbar_, SIGNAL(valueChanged(int)),
85 this, SLOT(scrollBarChanged(int)));
90 void QContentPane::scrollBarChanged(int val)
92 wa_->scrollDocView(val);
96 void QContentPane::mousePressEvent(QMouseEvent * e)
98 wa_->workAreaButtonPress(e->x(), e->y(), q_button_state(e->button()));
102 void QContentPane::mouseReleaseEvent(QMouseEvent * e)
104 wa_->workAreaButtonRelease(e->x(), e->y(), q_button_state(e->button()));
108 void QContentPane::mouseMoveEvent(QMouseEvent * e)
110 wa_->workAreaMotionNotify(e->x(), e->y(), q_motion_state(e->state()));
114 void QContentPane::keyPressEvent(QKeyEvent * e)
116 char const * tmp = e->text().latin1();
117 string const text = tmp ? tmp : "";
118 lyxerr[Debug::GUI] << "key text " << text << endl;
119 QLyXKeySym * sym = new QLyXKeySym();
120 sym->set(e->key(), e->text());
121 wa_->workAreaKeyPress(LyXKeySymPtr(sym), q_key_state(e->state()));
125 void QContentPane::mouseDoubleClickEvent(QMouseEvent * e)
127 wa_->workAreaDoubleClick(e->x(), e->y(), q_button_state(e->state()));
128 // FIXME: triple click
132 void QContentPane::resizeEvent(QResizeEvent *)
134 if (!pixmap_.get()) {
135 pixmap_.reset(new QPixmap(width(), height()));
138 pixmap_->resize(width(), height());
139 wa_->workAreaResize();
143 void QContentPane::paintEvent(QPaintEvent * e)
145 if (!pixmap_.get()) {
146 pixmap_.reset(new QPixmap(width(), height()));
147 wa_->workAreaResize();
153 lyxerr[Debug::GUI] << "repainting " << r.x()
154 << "," << r.y() << " " << r.width()
155 << "," << r.height() << endl;
157 q.drawPixmap(QPoint(r.x(), r.y()),