2002-06-19 03:38:44 +00:00
|
|
|
/**
|
|
|
|
* \file QContentPane.C
|
2002-09-24 13:57:09 +00:00
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
2002-06-19 03:38:44 +00:00
|
|
|
*
|
2002-10-20 01:48:28 +00:00
|
|
|
* \author John Levon
|
2002-09-24 13:57:09 +00:00
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS
|
2002-06-19 03:38:44 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
|
|
|
|
#include "debug.h"
|
|
|
|
|
|
|
|
#include "QWorkArea.h"
|
|
|
|
#include "QLyXKeySym.h"
|
2002-08-28 08:30:27 +00:00
|
|
|
#include "funcrequest.h"
|
2002-12-17 20:37:13 +00:00
|
|
|
#include "qt_helpers.h"
|
2002-06-19 03:38:44 +00:00
|
|
|
|
|
|
|
#include <qevent.h>
|
|
|
|
#include <qpainter.h>
|
2002-08-29 01:25:41 +00:00
|
|
|
#include <qtimer.h>
|
|
|
|
#include <qapplication.h>
|
2002-12-05 13:50:13 +00:00
|
|
|
#include <qcursor.h>
|
2002-10-20 01:48:28 +00:00
|
|
|
|
2002-06-21 16:40:54 +00:00
|
|
|
using std::endl;
|
|
|
|
|
2002-06-19 03:38:44 +00:00
|
|
|
namespace {
|
2002-10-20 01:48:28 +00:00
|
|
|
|
2002-06-19 03:38:44 +00:00
|
|
|
/// return the LyX key state from Qt's
|
|
|
|
key_modifier::state q_key_state(Qt::ButtonState state)
|
|
|
|
{
|
|
|
|
key_modifier::state k = key_modifier::none;
|
|
|
|
if (state & Qt::ControlButton)
|
|
|
|
k |= key_modifier::ctrl;
|
|
|
|
if (state & Qt::ShiftButton)
|
|
|
|
k |= key_modifier::shift;
|
|
|
|
if (state & Qt::AltButton)
|
|
|
|
k |= key_modifier::alt;
|
|
|
|
return k;
|
|
|
|
}
|
|
|
|
|
2002-10-20 01:48:28 +00:00
|
|
|
|
2002-06-19 03:38:44 +00:00
|
|
|
/// return the LyX mouse button state from Qt's
|
|
|
|
mouse_button::state q_button_state(Qt::ButtonState button)
|
|
|
|
{
|
|
|
|
mouse_button::state b = mouse_button::none;
|
|
|
|
switch (button) {
|
|
|
|
case Qt::LeftButton:
|
|
|
|
b = mouse_button::button1;
|
|
|
|
break;
|
|
|
|
case Qt::MidButton:
|
|
|
|
b = mouse_button::button2;
|
|
|
|
break;
|
|
|
|
case Qt::RightButton:
|
|
|
|
b = mouse_button::button3;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return b;
|
|
|
|
}
|
2002-10-20 01:48:28 +00:00
|
|
|
|
|
|
|
|
2002-06-19 03:38:44 +00:00
|
|
|
/// return the LyX mouse button state from Qt's
|
|
|
|
mouse_button::state q_motion_state(Qt::ButtonState state)
|
|
|
|
{
|
|
|
|
mouse_button::state b = mouse_button::none;
|
|
|
|
if (state & Qt::LeftButton)
|
|
|
|
b |= mouse_button::button1;
|
|
|
|
if (state & Qt::MidButton)
|
|
|
|
b |= mouse_button::button2;
|
|
|
|
if (state & Qt::RightButton)
|
|
|
|
b |= mouse_button::button3;
|
|
|
|
return b;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace anon
|
2002-10-20 01:48:28 +00:00
|
|
|
|
2002-06-19 03:38:44 +00:00
|
|
|
|
|
|
|
QContentPane::QContentPane(QWorkArea * parent)
|
2002-10-20 01:48:28 +00:00
|
|
|
: QWidget(parent, "content_pane", WRepaintNoErase),
|
2002-06-19 03:38:44 +00:00
|
|
|
wa_(parent)
|
|
|
|
{
|
|
|
|
setFocusPolicy(QWidget::WheelFocus);
|
|
|
|
setFocus();
|
2002-12-05 13:50:13 +00:00
|
|
|
setCursor(ibeamCursor);
|
2002-06-19 03:38:44 +00:00
|
|
|
|
|
|
|
// stupid moc strikes again
|
2002-10-20 01:48:28 +00:00
|
|
|
connect(wa_->scrollbar_, SIGNAL(valueChanged(int)),
|
2002-06-19 03:38:44 +00:00
|
|
|
this, SLOT(scrollBarChanged(int)));
|
2002-10-20 01:48:28 +00:00
|
|
|
|
2002-06-19 03:38:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void QContentPane::scrollBarChanged(int val)
|
|
|
|
{
|
2002-10-20 01:48:28 +00:00
|
|
|
wa_->scrollDocView(val);
|
2002-06-19 03:38:44 +00:00
|
|
|
}
|
2002-10-20 01:48:28 +00:00
|
|
|
|
|
|
|
|
2002-06-19 03:38:44 +00:00
|
|
|
void QContentPane::mousePressEvent(QMouseEvent * e)
|
|
|
|
{
|
2002-08-29 01:25:41 +00:00
|
|
|
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;
|
|
|
|
}
|
2002-10-20 01:48:28 +00:00
|
|
|
|
|
|
|
FuncRequest cmd(LFUN_MOUSE_PRESS, e->x(), e->y(),
|
|
|
|
q_button_state(e->button()));
|
2002-08-28 08:30:27 +00:00
|
|
|
wa_->dispatch(cmd);
|
2002-06-19 03:38:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void QContentPane::mouseReleaseEvent(QMouseEvent * e)
|
|
|
|
{
|
2002-10-20 01:48:28 +00:00
|
|
|
FuncRequest cmd(LFUN_MOUSE_RELEASE, e->x(), e->y(),
|
|
|
|
q_button_state(e->button()));
|
2002-08-28 08:30:27 +00:00
|
|
|
wa_->dispatch(cmd);
|
2002-06-19 03:38:44 +00:00
|
|
|
}
|
|
|
|
|
2002-10-20 01:48:28 +00:00
|
|
|
|
2002-06-19 03:38:44 +00:00
|
|
|
void QContentPane::mouseMoveEvent(QMouseEvent * e)
|
|
|
|
{
|
2002-08-28 08:30:27 +00:00
|
|
|
FuncRequest cmd
|
2002-08-28 22:18:03 +00:00
|
|
|
(LFUN_MOUSE_MOTION, e->x(), e->y(), q_motion_state(e->state()));
|
2002-08-28 08:30:27 +00:00
|
|
|
wa_->dispatch(cmd);
|
2002-06-19 03:38:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-10-21 04:46:26 +00:00
|
|
|
void QContentPane::wheelEvent(QWheelEvent * e)
|
|
|
|
{
|
|
|
|
wa_->scrollbar_->setValue(wa_->scrollbar_->value() - e->delta());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-06-19 03:38:44 +00:00
|
|
|
void QContentPane::keyPressEvent(QKeyEvent * e)
|
|
|
|
{
|
2002-06-19 05:20:29 +00:00
|
|
|
QLyXKeySym * sym = new QLyXKeySym();
|
2002-08-25 05:41:42 +00:00
|
|
|
sym->set(e);
|
2002-06-19 05:20:29 +00:00
|
|
|
wa_->workAreaKeyPress(LyXKeySymPtr(sym), q_key_state(e->state()));
|
2002-06-19 03:38:44 +00:00
|
|
|
}
|
|
|
|
|
2002-10-20 01:48:28 +00:00
|
|
|
|
2002-08-29 01:25:41 +00:00
|
|
|
void QContentPane::doubleClickTimeout()
|
2002-06-19 03:38:44 +00:00
|
|
|
{
|
2002-08-29 01:25:41 +00:00
|
|
|
if (!dc_event_.active)
|
|
|
|
return;
|
|
|
|
|
|
|
|
dc_event_.active = false;
|
2002-10-20 01:48:28 +00:00
|
|
|
|
2002-08-29 01:25:41 +00:00
|
|
|
FuncRequest cmd(LFUN_MOUSE_DOUBLE,
|
|
|
|
dc_event_.x, dc_event_.y,
|
|
|
|
q_button_state(dc_event_.state));
|
2002-08-28 08:30:27 +00:00
|
|
|
wa_->dispatch(cmd);
|
2002-08-29 01:25:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void QContentPane::mouseDoubleClickEvent(QMouseEvent * e)
|
|
|
|
{
|
|
|
|
dc_event_ = double_click(e);
|
|
|
|
|
|
|
|
// doubleClickInterval() is just too long.
|
2002-09-11 15:56:07 +00:00
|
|
|
QTimer::singleShot(int(QApplication::doubleClickInterval() / 1.5),
|
2002-08-29 01:25:41 +00:00
|
|
|
this, SLOT(doubleClickTimeout()));
|
2002-06-19 03:38:44 +00:00
|
|
|
}
|
2002-10-20 01:48:28 +00:00
|
|
|
|
|
|
|
|
2002-06-19 03:38:44 +00:00
|
|
|
void QContentPane::resizeEvent(QResizeEvent *)
|
|
|
|
{
|
|
|
|
if (!pixmap_.get()) {
|
|
|
|
pixmap_.reset(new QPixmap(width(), height()));
|
|
|
|
}
|
|
|
|
|
|
|
|
pixmap_->resize(width(), height());
|
2002-06-21 02:58:54 +00:00
|
|
|
wa_->workAreaResize();
|
2002-06-19 03:38:44 +00:00
|
|
|
}
|
|
|
|
|
2002-10-20 01:48:28 +00:00
|
|
|
|
2002-06-19 03:38:44 +00:00
|
|
|
void QContentPane::paintEvent(QPaintEvent * e)
|
|
|
|
{
|
|
|
|
if (!pixmap_.get()) {
|
|
|
|
pixmap_.reset(new QPixmap(width(), height()));
|
2002-06-21 02:58:54 +00:00
|
|
|
wa_->workAreaResize();
|
2002-06-19 03:38:44 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QRect r(e->rect());
|
2002-10-20 01:48:28 +00:00
|
|
|
|
2002-06-19 03:38:44 +00:00
|
|
|
QPainter q(this);
|
|
|
|
q.drawPixmap(QPoint(r.x(), r.y()),
|
2002-10-20 01:48:28 +00:00
|
|
|
*pixmap_.get(), r);
|
2002-06-19 03:38:44 +00:00
|
|
|
}
|