/**
* \file QContentPane.C
- * Copyright 1995-2002 the LyX Team
- * Read the file COPYING
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
*
- * \author John Levon <moz@compsoc.man.ac.uk>
+ * \author John Levon
+ *
+ * Full author contact details are available in file CREDITS
*/
#include <config.h>
#include "QWorkArea.h"
#include "QLyXKeySym.h"
+#include "funcrequest.h"
#include <qevent.h>
#include <qpainter.h>
-
-
+#include <qtimer.h>
+#include <qapplication.h>
+
+using std::endl;
+
namespace {
-
+
/// return the LyX key state from Qt's
key_modifier::state q_key_state(Qt::ButtonState state)
{
return k;
}
+
/// return the LyX mouse button state from Qt's
mouse_button::state q_button_state(Qt::ButtonState button)
{
}
return b;
}
-
-
+
+
/// return the LyX mouse button state from Qt's
mouse_button::state q_motion_state(Qt::ButtonState state)
{
}
} // namespace anon
-
+
QContentPane::QContentPane(QWorkArea * parent)
- : QWidget(parent, "content_pane", WRepaintNoErase),
+ : QWidget(parent, "content_pane", WRepaintNoErase),
wa_(parent)
{
setFocusPolicy(QWidget::WheelFocus);
setFocus();
// stupid moc strikes again
- connect(wa_->scrollbar_, SIGNAL(valueChanged(int)),
+ connect(wa_->scrollbar_, SIGNAL(valueChanged(int)),
this, SLOT(scrollBarChanged(int)));
-
+
}
void QContentPane::scrollBarChanged(int val)
{
- wa_->scrollDocView(val);
+ wa_->scrollDocView(val);
}
-
-
+
+
void QContentPane::mousePressEvent(QMouseEvent * e)
{
- wa_->workAreaButtonPress(e->x(), e->y(), q_button_state(e->button()));
+ if (dc_event_.active && dc_event_ == *e) {
+ dc_event_.active = false;
+ FuncRequest cmd(LFUN_MOUSE_TRIPLE,
+ dc_event_.x, dc_event_.y,
+ q_button_state(dc_event_.state));
+ wa_->dispatch(cmd);
+ return;
+ }
+
+ FuncRequest cmd(LFUN_MOUSE_PRESS, e->x(), e->y(),
+ q_button_state(e->button()));
+ wa_->dispatch(cmd);
}
void QContentPane::mouseReleaseEvent(QMouseEvent * e)
{
- wa_->workAreaButtonRelease(e->x(), e->y(), q_button_state(e->button()));
+ FuncRequest cmd(LFUN_MOUSE_RELEASE, e->x(), e->y(),
+ q_button_state(e->button()));
+ wa_->dispatch(cmd);
}
-
+
void QContentPane::mouseMoveEvent(QMouseEvent * e)
{
- wa_->workAreaMotionNotify(e->x(), e->y(), q_motion_state(e->state()));
+ FuncRequest cmd
+ (LFUN_MOUSE_MOTION, e->x(), e->y(), q_motion_state(e->state()));
+ wa_->dispatch(cmd);
+}
+
+
+void QContentPane::wheelEvent(QWheelEvent * e)
+{
+ wa_->scrollbar_->setValue(wa_->scrollbar_->value() - e->delta());
}
void QContentPane::keyPressEvent(QKeyEvent * e)
{
- char const * tmp = e->text().latin1();
- string const text = tmp ? tmp : "";
- lyxerr[Debug::GUI] << "key text " << text << endl;
+ lyxerr[Debug::KEY] << "Press key " << e->key()
+ << " text \"" << (e->text().isEmpty() ? "none" : e->text().latin1())
+ << "\", ascii \"" << e->ascii() << "\"" << endl;
QLyXKeySym * sym = new QLyXKeySym();
- sym->set(e->key(), e->text());
+ sym->set(e);
wa_->workAreaKeyPress(LyXKeySymPtr(sym), q_key_state(e->state()));
}
-
+
+void QContentPane::doubleClickTimeout()
+{
+ if (!dc_event_.active)
+ return;
+
+ dc_event_.active = false;
+
+ FuncRequest cmd(LFUN_MOUSE_DOUBLE,
+ dc_event_.x, dc_event_.y,
+ q_button_state(dc_event_.state));
+ wa_->dispatch(cmd);
+}
+
+
void QContentPane::mouseDoubleClickEvent(QMouseEvent * e)
{
- wa_->workAreaDoubleClick(e->x(), e->y(), q_button_state(e->state()));
- // FIXME: triple click
+ dc_event_ = double_click(e);
+
+ // doubleClickInterval() is just too long.
+ QTimer::singleShot(int(QApplication::doubleClickInterval() / 1.5),
+ this, SLOT(doubleClickTimeout()));
}
-
-
+
+
void QContentPane::resizeEvent(QResizeEvent *)
{
if (!pixmap_.get()) {
}
pixmap_->resize(width(), height());
- // FIXME wa_->workAreaResize();
+ wa_->workAreaResize();
}
-
+
void QContentPane::paintEvent(QPaintEvent * e)
{
if (!pixmap_.get()) {
pixmap_.reset(new QPixmap(width(), height()));
- // FIXME: hmm. We do this to get an /initial/
- // painting. So it's wrong.
- // FIXME wa_->workAreaResize();
+ wa_->workAreaResize();
return;
}
QRect r(e->rect());
-
- lyxerr[Debug::GUI] << "repainting " << r.x()
- << "," << r.y() << " " << r.width()
+
+ lyxerr[Debug::GUI] << "repainting " << r.x()
+ << "," << r.y() << " " << r.width()
<< "," << r.height() << endl;
QPainter q(this);
q.drawPixmap(QPoint(r.x(), r.y()),
- *pixmap_.get(), r);
+ *pixmap_.get(), r);
}