2006-03-05 17:24:44 +00:00
|
|
|
/**
|
2006-06-20 08:39:16 +00:00
|
|
|
* \file GuiWorkArea.C
|
2006-03-05 17:24:44 +00:00
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
|
|
|
* \author John Levon
|
|
|
|
* \author Abdelrazak Younes
|
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
2006-06-20 08:39:16 +00:00
|
|
|
#include "GuiWorkArea.h"
|
2006-07-13 16:37:55 +00:00
|
|
|
|
2006-09-22 09:47:39 +00:00
|
|
|
#include "GuiApplication.h"
|
2006-03-05 17:24:44 +00:00
|
|
|
#include "QLPainter.h"
|
|
|
|
#include "QLyXKeySym.h"
|
|
|
|
#include "qt_helpers.h"
|
2006-08-17 17:15:17 +00:00
|
|
|
|
2006-08-21 09:14:18 +00:00
|
|
|
#include "LyXView.h"
|
|
|
|
|
2006-04-13 20:39:42 +00:00
|
|
|
#include "BufferView.h"
|
2006-10-23 08:46:09 +00:00
|
|
|
#include "rowpainter.h"
|
2006-03-05 17:24:44 +00:00
|
|
|
#include "debug.h"
|
|
|
|
#include "funcrequest.h"
|
|
|
|
#include "LColor.h"
|
2006-10-23 08:46:09 +00:00
|
|
|
#include "version.h"
|
|
|
|
#include "lyxrc.h"
|
2006-08-17 17:15:17 +00:00
|
|
|
|
2006-10-23 08:46:09 +00:00
|
|
|
#include "support/filetools.h" // LibFileSearch
|
2006-03-05 17:24:44 +00:00
|
|
|
#include "support/os.h"
|
|
|
|
|
2006-10-23 08:46:09 +00:00
|
|
|
#include "graphics/GraphicsImage.h"
|
|
|
|
#include "graphics/GraphicsLoader.h"
|
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
#include <QLayout>
|
|
|
|
#include <QMainWindow>
|
2006-05-07 10:20:43 +00:00
|
|
|
#include <QMimeData>
|
|
|
|
#include <QUrl>
|
2006-03-05 17:24:44 +00:00
|
|
|
#include <QDragEnterEvent>
|
|
|
|
#include <QPixmap>
|
|
|
|
#include <QPainter>
|
|
|
|
#include <QScrollBar>
|
|
|
|
|
|
|
|
#include <boost/bind.hpp>
|
2006-07-13 16:37:55 +00:00
|
|
|
#include <boost/current_function.hpp>
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2006-06-26 16:55:35 +00:00
|
|
|
// Abdel (26/06/2006):
|
|
|
|
// On windows-XP the UserGuide PageDown scroll test is faster without event pruning (16 s)
|
|
|
|
// than with it (23 s).
|
|
|
|
#ifdef Q_WS_WIN
|
|
|
|
#define USE_EVENT_PRUNING 0
|
|
|
|
#else
|
|
|
|
#define USE_EVENT_PRUNING 0
|
|
|
|
#endif
|
2006-03-12 17:29:34 +00:00
|
|
|
|
2006-10-23 11:19:17 +00:00
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
using std::endl;
|
|
|
|
using std::string;
|
|
|
|
|
|
|
|
namespace os = lyx::support::os;
|
|
|
|
|
2006-10-23 08:46:09 +00:00
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
namespace lyx {
|
2006-03-12 17:29:34 +00:00
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
/// return the LyX key state from Qt's
|
2006-10-21 00:16:43 +00:00
|
|
|
static key_modifier::state q_key_state(Qt::KeyboardModifiers state)
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
|
|
|
key_modifier::state k = key_modifier::none;
|
|
|
|
if (state & Qt::ControlModifier)
|
|
|
|
k |= key_modifier::ctrl;
|
|
|
|
if (state & Qt::ShiftModifier)
|
|
|
|
k |= key_modifier::shift;
|
2006-07-09 17:30:21 +00:00
|
|
|
if (state & Qt::AltModifier || state & Qt::MetaModifier)
|
2006-03-05 17:24:44 +00:00
|
|
|
k |= key_modifier::alt;
|
|
|
|
return k;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// return the LyX mouse button state from Qt's
|
2006-10-21 00:16:43 +00:00
|
|
|
static mouse_button::state q_button_state(Qt::MouseButton button)
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-10-23 11:19:17 +00:00
|
|
|
/// return the LyX mouse button state from Qt's
|
2006-08-13 15:55:03 +00:00
|
|
|
mouse_button::state q_motion_state(Qt::MouseButton state)
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-06-20 08:39:16 +00:00
|
|
|
namespace frontend {
|
|
|
|
|
2006-10-23 11:19:17 +00:00
|
|
|
class CursorWidget : public QWidget {
|
|
|
|
public:
|
|
|
|
CursorWidget(QWidget * parent)
|
|
|
|
: QWidget(parent)
|
|
|
|
{
|
|
|
|
resize(2, 20);
|
|
|
|
}
|
|
|
|
|
|
|
|
void paintEvent(QPaintEvent *)
|
|
|
|
{
|
|
|
|
QColor const & col = guiApp->colorCache().get(LColor::cursor);
|
|
|
|
|
|
|
|
/*
|
|
|
|
int cursor_w_;
|
|
|
|
int cursor_h_;
|
|
|
|
|
|
|
|
switch (cursor_shape_) {
|
|
|
|
case BAR_SHAPE:
|
|
|
|
// FIXME the cursor width shouldn't be hard-coded!
|
|
|
|
cursor_w_ = 2;
|
|
|
|
lshape_cursor_ = false;
|
|
|
|
break;
|
|
|
|
case L_SHAPE:
|
|
|
|
cursor_w_ = cursor_h_ / 3;
|
|
|
|
lshape_cursor_ = true;
|
|
|
|
break;
|
|
|
|
case REVERSED_L_SHAPE:
|
|
|
|
cursor_w_ = cursor_h_ / 3;
|
|
|
|
//cursor_x_ -= cursor_w_ - 1;
|
|
|
|
lshape_cursor_ = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
|
|
// We cache two pixmaps:
|
|
|
|
// 1 the vertical line of the cursor.
|
|
|
|
// 2 the horizontal line of the L-shaped cursor (if necessary).
|
|
|
|
|
|
|
|
// Draw the new (vertical) cursor.
|
|
|
|
QPainter pain(this);
|
|
|
|
pain.fillRect(rect(), col);
|
|
|
|
/*
|
|
|
|
// Draw the new (horizontal) cursor if necessary.
|
|
|
|
if (lshape_cursor_) {
|
|
|
|
hcursor_ = QPixmap(cursor_w_, 1);
|
|
|
|
hcursor_.fill(col);
|
|
|
|
show_hcursor_ = true;
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
/// shown?
|
|
|
|
bool on_;
|
|
|
|
///
|
|
|
|
CursorShape shape_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
// This is a 'heartbeat' generating synthetic mouse move events when the
|
|
|
|
// cursor is at the top or bottom edge of the viewport. One scroll per 0.2 s
|
|
|
|
SyntheticMouseEvent::SyntheticMouseEvent()
|
|
|
|
: timeout(200), restart_timeout(true),
|
|
|
|
x_old(-1), y_old(-1), scrollbar_value_old(-1.0)
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
2006-10-23 16:29:24 +00:00
|
|
|
GuiWorkArea::GuiWorkArea(int w, int h, int id, LyXView & lyx_view)
|
|
|
|
: WorkArea(id, lyx_view)
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
2006-10-23 11:19:17 +00:00
|
|
|
cursor_ = new frontend::CursorWidget(this);
|
2006-10-23 11:34:43 +00:00
|
|
|
cursor_->hide();
|
2006-10-23 11:19:17 +00:00
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
|
|
|
|
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
|
|
|
setAcceptDrops(true);
|
|
|
|
setMinimumSize(100, 70);
|
|
|
|
|
2006-10-23 08:46:09 +00:00
|
|
|
//viewport()->setAutoFillBackground(false);
|
|
|
|
//viewport()->setAttribute(Qt::WA_OpaquePaintEvent);
|
2006-03-05 17:24:44 +00:00
|
|
|
setFocusPolicy(Qt::WheelFocus);
|
2006-03-12 17:29:34 +00:00
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
viewport()->setCursor(Qt::IBeamCursor);
|
|
|
|
|
|
|
|
resize(w, h);
|
|
|
|
|
|
|
|
synthetic_mouse_event_.timeout.timeout.connect(
|
2006-06-20 08:39:16 +00:00
|
|
|
boost::bind(&GuiWorkArea::generateSyntheticMouseEvent,
|
2006-03-05 17:24:44 +00:00
|
|
|
this));
|
2006-04-05 23:56:29 +00:00
|
|
|
|
2006-03-12 17:29:34 +00:00
|
|
|
// Initialize the vertical Scroll Bar
|
|
|
|
QObject::connect(verticalScrollBar(), SIGNAL(actionTriggered(int)),
|
|
|
|
this, SLOT(adjustViewWithScrollBar(int)));
|
|
|
|
|
|
|
|
// PageStep only depends on the viewport height.
|
2006-08-17 17:15:17 +00:00
|
|
|
verticalScrollBar()->setPageStep(viewport()->height());
|
2006-03-12 17:29:34 +00:00
|
|
|
|
|
|
|
lyxerr[Debug::GUI] << BOOST_CURRENT_FUNCTION
|
|
|
|
<< "\n Area width\t" << width()
|
|
|
|
<< "\n Area height\t" << height()
|
|
|
|
<< "\n viewport width\t" << viewport()->width()
|
|
|
|
<< "\n viewport height\t" << viewport()->height()
|
|
|
|
<< endl;
|
|
|
|
|
2006-06-26 16:55:35 +00:00
|
|
|
if (USE_EVENT_PRUNING) {
|
2006-06-20 08:39:16 +00:00
|
|
|
// This is the keyboard buffering stuff...
|
|
|
|
// I don't see any need for this under windows. The keyboard is reactive
|
|
|
|
// enough...
|
2006-03-12 17:29:34 +00:00
|
|
|
|
2006-06-20 08:39:16 +00:00
|
|
|
if ( !QObject::connect(&step_timer_, SIGNAL(timeout()),
|
|
|
|
this, SLOT(keyeventTimeout())) )
|
2006-03-05 17:24:44 +00:00
|
|
|
lyxerr[Debug::GUI] << "ERROR: keyeventTimeout cannot connect!" << endl;
|
2006-03-12 17:29:34 +00:00
|
|
|
|
2006-06-20 08:39:16 +00:00
|
|
|
// Start the timer, one-shot.
|
2006-08-13 15:55:03 +00:00
|
|
|
step_timer_.setSingleShot(true);
|
|
|
|
step_timer_.start(50);
|
2006-06-20 08:39:16 +00:00
|
|
|
}
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2006-06-26 16:55:35 +00:00
|
|
|
// Enables input methods for asian languages.
|
|
|
|
// Must be set when creating custom text editing widgets.
|
|
|
|
setAttribute(Qt::WA_InputMethodEnabled, true);
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
2006-08-17 17:15:17 +00:00
|
|
|
|
2006-06-20 08:39:16 +00:00
|
|
|
void GuiWorkArea::setScrollbarParams(int h, int scroll_pos, int scroll_line_step)
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
2006-08-16 15:24:38 +00:00
|
|
|
verticalScrollBar()->setTracking(false);
|
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
// do what cursor movement does (some grey)
|
|
|
|
h += height() / 4;
|
|
|
|
int scroll_max_ = std::max(0, h - height());
|
|
|
|
|
2006-11-01 17:51:56 +00:00
|
|
|
setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
|
2006-03-05 17:24:44 +00:00
|
|
|
verticalScrollBar()->setRange(0, scroll_max_);
|
2006-03-12 17:29:34 +00:00
|
|
|
verticalScrollBar()->setSliderPosition(scroll_pos);
|
2006-08-13 15:55:03 +00:00
|
|
|
verticalScrollBar()->setSingleStep(scroll_line_step);
|
2006-10-22 12:36:31 +00:00
|
|
|
verticalScrollBar()->setValue(scroll_pos);
|
2006-08-16 15:24:38 +00:00
|
|
|
|
|
|
|
verticalScrollBar()->setTracking(true);
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
2006-06-26 16:55:35 +00:00
|
|
|
|
2006-06-20 08:39:16 +00:00
|
|
|
void GuiWorkArea::adjustViewWithScrollBar(int)
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
2006-08-15 21:57:23 +00:00
|
|
|
scrollBufferView(verticalScrollBar()->sliderPosition());
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-06-20 08:39:16 +00:00
|
|
|
void GuiWorkArea::dragEnterEvent(QDragEnterEvent * event)
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
2006-05-07 10:20:43 +00:00
|
|
|
if (event->mimeData()->hasUrls())
|
|
|
|
event->accept();
|
2006-03-05 17:24:44 +00:00
|
|
|
/// \todo Ask lyx-devel is this is enough:
|
|
|
|
/// if (event->mimeData()->hasFormat("text/plain"))
|
2006-04-05 23:56:29 +00:00
|
|
|
/// event->acceptProposedAction();
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-06-20 08:39:16 +00:00
|
|
|
void GuiWorkArea::dropEvent(QDropEvent* event)
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
2006-05-07 10:20:43 +00:00
|
|
|
QList<QUrl> files = event->mimeData()->urls();
|
|
|
|
if (files.isEmpty())
|
|
|
|
return;
|
|
|
|
|
2006-06-20 08:39:16 +00:00
|
|
|
lyxerr[Debug::GUI] << "GuiWorkArea::dropEvent: got URIs!" << endl;
|
2006-05-07 10:20:43 +00:00
|
|
|
for (int i = 0; i!=files.size(); ++i) {
|
2006-08-27 16:10:41 +00:00
|
|
|
string const file = os::internal_path(fromqstr(files.at(i).toLocalFile()));
|
2006-05-07 10:20:43 +00:00
|
|
|
if (!file.empty())
|
2006-07-13 16:37:55 +00:00
|
|
|
dispatch(FuncRequest(LFUN_FILE_OPEN, file));
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-10-27 23:26:52 +00:00
|
|
|
void GuiWorkArea::focusInEvent(QFocusEvent * /*event*/)
|
|
|
|
{
|
2006-11-01 22:57:32 +00:00
|
|
|
// FIXME: it would be better to send a signal "newBuffer()"
|
|
|
|
// in BufferList that could be connected to the different tabbar.
|
|
|
|
lyx_view_.updateTab();
|
2006-10-27 23:26:52 +00:00
|
|
|
startBlinkingCursor();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GuiWorkArea::focusOutEvent(QFocusEvent * /*event*/)
|
|
|
|
{
|
|
|
|
stopBlinkingCursor();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-06-20 08:39:16 +00:00
|
|
|
void GuiWorkArea::mousePressEvent(QMouseEvent * e)
|
2006-03-05 17:24:44 +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));
|
2006-07-13 16:37:55 +00:00
|
|
|
dispatch(cmd);
|
2006-03-05 17:24:44 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
FuncRequest const cmd(LFUN_MOUSE_PRESS, e->x(), e->y(),
|
|
|
|
q_button_state(e->button()));
|
2006-07-13 16:37:55 +00:00
|
|
|
dispatch(cmd);
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-06-20 08:39:16 +00:00
|
|
|
void GuiWorkArea::mouseReleaseEvent(QMouseEvent * e)
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
|
|
|
if (synthetic_mouse_event_.timeout.running())
|
|
|
|
synthetic_mouse_event_.timeout.stop();
|
|
|
|
|
|
|
|
FuncRequest const cmd(LFUN_MOUSE_RELEASE, e->x(), e->y(),
|
|
|
|
q_button_state(e->button()));
|
2006-07-13 16:37:55 +00:00
|
|
|
dispatch(cmd);
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-06-20 08:39:16 +00:00
|
|
|
void GuiWorkArea::mouseMoveEvent(QMouseEvent * e)
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
|
|
|
FuncRequest cmd(LFUN_MOUSE_MOTION, e->x(), e->y(),
|
2006-08-13 15:55:03 +00:00
|
|
|
q_motion_state(e->button()));
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
// If we're above or below the work area...
|
2006-03-12 17:29:34 +00:00
|
|
|
if (e->y() <= 20 || e->y() >= viewport()->height() - 20) {
|
2006-03-05 17:24:44 +00:00
|
|
|
// Make sure only a synthetic event can cause a page scroll,
|
|
|
|
// so they come at a steady rate:
|
|
|
|
if (e->y() <= 20)
|
|
|
|
// _Force_ a scroll up:
|
|
|
|
cmd.y = -40;
|
|
|
|
else
|
2006-03-12 17:29:34 +00:00
|
|
|
cmd.y = viewport()->height();
|
2006-03-05 17:24:44 +00:00
|
|
|
// Store the event, to be handled when the timeout expires.
|
|
|
|
synthetic_mouse_event_.cmd = cmd;
|
|
|
|
|
|
|
|
if (synthetic_mouse_event_.timeout.running())
|
|
|
|
// Discard the event. Note that it _may_ be handled
|
|
|
|
// when the timeout expires if
|
|
|
|
// synthetic_mouse_event_.cmd has not been overwritten.
|
|
|
|
// Ie, when the timeout expires, we handle the
|
|
|
|
// most recent event but discard all others that
|
|
|
|
// occurred after the one used to start the timeout
|
|
|
|
// in the first place.
|
|
|
|
return;
|
|
|
|
else {
|
|
|
|
synthetic_mouse_event_.restart_timeout = true;
|
|
|
|
synthetic_mouse_event_.timeout.start();
|
|
|
|
// Fall through to handle this event...
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if (synthetic_mouse_event_.timeout.running()) {
|
|
|
|
// Store the event, to be possibly handled when the timeout
|
|
|
|
// expires.
|
|
|
|
// Once the timeout has expired, normal control is returned
|
|
|
|
// to mouseMoveEvent (restart_timeout = false).
|
|
|
|
// This results in a much smoother 'feel' when moving the
|
|
|
|
// mouse back into the work area.
|
|
|
|
synthetic_mouse_event_.cmd = cmd;
|
|
|
|
synthetic_mouse_event_.restart_timeout = false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Has anything changed on-screen since the last QMouseEvent
|
|
|
|
// was received?
|
|
|
|
double const scrollbar_value = verticalScrollBar()->value();
|
|
|
|
if (e->x() != synthetic_mouse_event_.x_old ||
|
|
|
|
e->y() != synthetic_mouse_event_.y_old ||
|
|
|
|
scrollbar_value != synthetic_mouse_event_.scrollbar_value_old) {
|
|
|
|
// Yes it has. Store the params used to check this.
|
|
|
|
synthetic_mouse_event_.x_old = e->x();
|
|
|
|
synthetic_mouse_event_.y_old = e->y();
|
|
|
|
synthetic_mouse_event_.scrollbar_value_old = scrollbar_value;
|
|
|
|
|
|
|
|
// ... and dispatch the event to the LyX core.
|
2006-07-13 16:37:55 +00:00
|
|
|
dispatch(cmd);
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-06-20 08:39:16 +00:00
|
|
|
void GuiWorkArea::wheelEvent(QWheelEvent * e)
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
2006-03-16 20:34:20 +00:00
|
|
|
// Wheel rotation by one notch results in a delta() of 120 (see
|
|
|
|
// documentation of QWheelEvent)
|
2006-06-20 08:39:16 +00:00
|
|
|
int const lines = qApp->wheelScrollLines() * e->delta() / 120;
|
2006-03-16 20:34:20 +00:00
|
|
|
verticalScrollBar()->setValue(verticalScrollBar()->value() -
|
2006-08-13 15:55:03 +00:00
|
|
|
lines * verticalScrollBar()->singleStep());
|
2006-03-16 20:34:20 +00:00
|
|
|
adjustViewWithScrollBar();
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
2006-03-16 20:34:20 +00:00
|
|
|
|
2006-06-20 08:39:16 +00:00
|
|
|
void GuiWorkArea::generateSyntheticMouseEvent()
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
2006-08-13 22:54:59 +00:00
|
|
|
// Set things off to generate the _next_ 'pseudo' event.
|
2006-03-05 17:24:44 +00:00
|
|
|
if (synthetic_mouse_event_.restart_timeout)
|
|
|
|
synthetic_mouse_event_.timeout.start();
|
|
|
|
|
|
|
|
// Has anything changed on-screen since the last timeout signal
|
|
|
|
// was received?
|
|
|
|
double const scrollbar_value = verticalScrollBar()->value();
|
|
|
|
if (scrollbar_value != synthetic_mouse_event_.scrollbar_value_old) {
|
|
|
|
// Yes it has. Store the params used to check this.
|
|
|
|
synthetic_mouse_event_.scrollbar_value_old = scrollbar_value;
|
|
|
|
|
|
|
|
// ... and dispatch the event to the LyX core.
|
2006-07-13 16:37:55 +00:00
|
|
|
dispatch(synthetic_mouse_event_.cmd);
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-06-20 08:39:16 +00:00
|
|
|
|
|
|
|
void GuiWorkArea::keyPressEvent(QKeyEvent * e)
|
2006-03-12 17:29:34 +00:00
|
|
|
{
|
|
|
|
lyxerr[Debug::KEY] << BOOST_CURRENT_FUNCTION
|
|
|
|
<< " count=" << e->count()
|
2006-08-13 15:55:03 +00:00
|
|
|
<< " text=" << fromqstr(e->text())
|
2006-03-12 17:29:34 +00:00
|
|
|
<< " isAutoRepeat=" << e->isAutoRepeat()
|
|
|
|
<< " key=" << e->key()
|
|
|
|
<< endl;
|
|
|
|
|
2006-06-26 16:55:35 +00:00
|
|
|
if (USE_EVENT_PRUNING) {
|
2006-06-20 08:39:16 +00:00
|
|
|
keyeventQueue_.push(boost::shared_ptr<QKeyEvent>(new QKeyEvent(*e)));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
boost::shared_ptr<QLyXKeySym> sym(new QLyXKeySym);
|
|
|
|
sym->set(e);
|
2006-08-13 15:55:03 +00:00
|
|
|
processKeySym(sym, q_key_state(e->modifiers()));
|
2006-06-20 08:39:16 +00:00
|
|
|
}
|
2006-03-12 17:29:34 +00:00
|
|
|
}
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2006-06-26 16:55:35 +00:00
|
|
|
|
|
|
|
// This is used only if USE_EVENT_PRUNING is defined...
|
2006-06-20 08:39:16 +00:00
|
|
|
void GuiWorkArea::keyeventTimeout()
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
|
|
|
bool handle_autos = true;
|
|
|
|
|
|
|
|
while (!keyeventQueue_.empty()) {
|
|
|
|
boost::shared_ptr<QKeyEvent> ev = keyeventQueue_.front();
|
|
|
|
|
|
|
|
// We never handle more than one auto repeated
|
|
|
|
// char in a list of queued up events.
|
|
|
|
if (!handle_autos && ev->isAutoRepeat()) {
|
|
|
|
keyeventQueue_.pop();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2006-06-26 16:55:35 +00:00
|
|
|
boost::shared_ptr<QLyXKeySym> sym(new QLyXKeySym);
|
2006-03-05 17:24:44 +00:00
|
|
|
sym->set(ev.get());
|
|
|
|
|
2006-06-26 16:55:35 +00:00
|
|
|
lyxerr[Debug::GUI] << BOOST_CURRENT_FUNCTION
|
|
|
|
<< " count=" << ev->count()
|
2006-08-13 15:55:03 +00:00
|
|
|
<< " text=" << fromqstr(ev->text())
|
2006-06-26 16:55:35 +00:00
|
|
|
<< " isAutoRepeat=" << ev->isAutoRepeat()
|
|
|
|
<< " key=" << ev->key()
|
|
|
|
<< endl;
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2006-08-13 15:55:03 +00:00
|
|
|
processKeySym(sym, q_key_state(ev->modifiers()));
|
2006-03-05 17:24:44 +00:00
|
|
|
keyeventQueue_.pop();
|
|
|
|
|
|
|
|
handle_autos = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Restart the timer.
|
2006-08-13 15:55:03 +00:00
|
|
|
step_timer_.setSingleShot(true);
|
|
|
|
step_timer_.start(25);
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-06-20 08:39:16 +00:00
|
|
|
void GuiWorkArea::mouseDoubleClickEvent(QMouseEvent * e)
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
|
|
|
dc_event_ = double_click(e);
|
|
|
|
|
|
|
|
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));
|
2006-07-13 16:37:55 +00:00
|
|
|
dispatch(cmd);
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-10-23 08:46:09 +00:00
|
|
|
void GuiWorkArea::resizeEvent(QResizeEvent * ev)
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
2006-10-23 11:34:43 +00:00
|
|
|
cursor_->hide();
|
2006-03-12 17:29:34 +00:00
|
|
|
verticalScrollBar()->setPageStep(viewport()->height());
|
2006-10-23 08:46:09 +00:00
|
|
|
QAbstractScrollArea::resizeEvent(ev);
|
2006-07-13 16:37:55 +00:00
|
|
|
resizeBufferView();
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
2006-06-20 08:39:16 +00:00
|
|
|
|
|
|
|
void GuiWorkArea::update(int x, int y, int w, int h)
|
2006-03-20 17:25:02 +00:00
|
|
|
{
|
2006-10-22 18:49:18 +00:00
|
|
|
viewport()->update(x, y, w, h);
|
2006-03-20 17:25:02 +00:00
|
|
|
}
|
|
|
|
|
2006-06-20 08:39:16 +00:00
|
|
|
|
2006-10-23 08:46:09 +00:00
|
|
|
void GuiWorkArea::doGreyOut(QLPainter & pain)
|
2006-03-20 17:25:02 +00:00
|
|
|
{
|
2006-10-23 08:46:09 +00:00
|
|
|
greyed_out_ = true;
|
|
|
|
pain.fillRectangle(0, 0, width(), height(),
|
|
|
|
LColor::bottomarea);
|
|
|
|
|
|
|
|
//if (!lyxrc.show_banner)
|
|
|
|
// return;
|
|
|
|
lyxerr << "show banner: " << lyxrc.show_banner << endl;
|
|
|
|
/// The text to be written on top of the pixmap
|
|
|
|
string const text = lyx_version ? lyx_version : "unknown";
|
|
|
|
string const file = support::libFileSearch("images", "banner", "ppm");
|
|
|
|
if (file.empty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
QPixmap pm(toqstr(file));
|
|
|
|
if (!pm) {
|
|
|
|
lyxerr << "could not load splash screen: '" << file << "'" << endl;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QFont font;
|
|
|
|
// The font used to display the version info
|
|
|
|
font.setStyleHint(QFont::SansSerif);
|
|
|
|
font.setWeight(QFont::Bold);
|
|
|
|
font.setPointSize(LyXFont::SIZE_NORMAL);
|
|
|
|
|
|
|
|
int const w = pm.width();
|
|
|
|
int const h = pm.height();
|
|
|
|
|
|
|
|
int x = (width() - w) / 2;
|
|
|
|
int y = (height() - h) / 2;
|
|
|
|
|
|
|
|
pain.drawPixmap(x, y, pm);
|
|
|
|
|
|
|
|
x += 260;
|
|
|
|
y += 265;
|
|
|
|
|
|
|
|
pain.setPen(QColor(255, 255, 0));
|
|
|
|
pain.setFont(font);
|
|
|
|
pain.drawText(x, y, toqstr(text));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GuiWorkArea::paintEvent(QPaintEvent * ev)
|
|
|
|
{
|
2006-10-23 11:19:17 +00:00
|
|
|
/*
|
|
|
|
lyxerr[Debug::GUI] << BOOST_CURRENT_FUNCTION
|
|
|
|
<< "\n QWidget width\t" << this->width()
|
|
|
|
<< "\n QWidget height\t" << this->height()
|
|
|
|
<< "\n viewport width\t" << viewport()->width()
|
|
|
|
<< "\n viewport height\t" << viewport()->height()
|
|
|
|
<< "\n QPaintEvent x\t" << e->rect().x()
|
|
|
|
<< "\n QPaintEvent y\t" << e->rect().y()
|
|
|
|
<< "\n QPaintEvent w\t" << e->rect().width()
|
|
|
|
<< "\n QPaintEvent h\t" << e->rect().height()
|
|
|
|
<< endl;
|
|
|
|
*/
|
|
|
|
|
2006-10-23 08:46:09 +00:00
|
|
|
QRect const rc = ev->rect();
|
2006-10-23 11:19:17 +00:00
|
|
|
//lyxerr << "paintEvent begin: x: " << rc.x()
|
|
|
|
// << " y: " << rc.y()
|
|
|
|
// << " w: " << rc.width()
|
|
|
|
// << " h: " << rc.height() << endl;
|
2006-10-23 08:46:09 +00:00
|
|
|
|
|
|
|
if (!buffer_view_) {
|
|
|
|
lyxerr << "no bufferview" << endl;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2006-10-30 13:49:41 +00:00
|
|
|
QLPainter pain(viewport());
|
2006-10-23 08:46:09 +00:00
|
|
|
|
|
|
|
if (rc.width() == 3) { // FIXME HACK
|
|
|
|
// Assume splash screen drawing is requested when
|
2006-10-23 11:19:17 +00:00
|
|
|
// width == 3
|
|
|
|
lyxerr << "splash screen requested" << endl;
|
2006-10-23 08:46:09 +00:00
|
|
|
doGreyOut(pain);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!buffer_view_->buffer()) {
|
|
|
|
lyxerr << "no buffer: " << endl;
|
|
|
|
doGreyOut(pain);
|
|
|
|
updateScrollbar();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2006-10-23 11:19:17 +00:00
|
|
|
//lyxerr << "real drawing" << endl;
|
2006-10-28 09:59:43 +00:00
|
|
|
paintText(*buffer_view_, pain);
|
2006-03-12 17:29:34 +00:00
|
|
|
}
|
2006-03-20 17:25:02 +00:00
|
|
|
|
* frontends/WorkArea.h(workAreaResize, scrollDocView, workAreaKeyPress,
dispatch, selectionReuqested, selectionLost): remove signals
* BufferView.[Ch] (selectionRequested, selectionLost, workAreaResize,
workAreaKeyPress, workAreaDispatch): add forwarding functions to the pimpl
* BufferView_pimpl.C (Pimpl): Remove the setup of the now deleted signals,
also remove corresponding connection objects.
* frontends/xforms/XWorkArea.h:
* frontends/qt2/QWorkArea.h:
* frontends/qt4/QWorkArea.h:
* frontends/gtk/GWorkArea.h: add LyXView as class variable view_ (qt
classes also get view() medthod)
* frontends/qt2/QWorkArea.C:
* frontends/qt2/QContentPane.C:
* frontends/qt4/QWorkArea.C:
* frontends/xforms/XWorkArea.C:
* frontends/gtk/GWorkArea.C: Change from calling signals to call
the functions directly through view_.view()
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@13671 a592a061-630c-0410-9148-cb99ea01b6c8
2006-04-13 18:58:48 +00:00
|
|
|
|
2006-10-23 11:19:17 +00:00
|
|
|
|
2006-06-20 08:39:16 +00:00
|
|
|
void GuiWorkArea::expose(int x, int y, int w, int h)
|
2006-06-02 12:01:28 +00:00
|
|
|
{
|
|
|
|
update(x, y, w, h);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-06-26 16:55:35 +00:00
|
|
|
void GuiWorkArea::showCursor(int x, int y, int h, CursorShape shape)
|
2006-06-02 12:01:28 +00:00
|
|
|
{
|
2006-10-26 11:01:34 +00:00
|
|
|
cursor_->setGeometry(x, y, 2, h);
|
2006-10-23 11:19:17 +00:00
|
|
|
cursor_->shape_ = shape;
|
|
|
|
cursor_->on_ = true;
|
|
|
|
cursor_->show();
|
2006-06-02 12:01:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-06-20 08:39:16 +00:00
|
|
|
void GuiWorkArea::removeCursor()
|
2006-06-02 12:01:28 +00:00
|
|
|
{
|
2006-10-23 11:34:43 +00:00
|
|
|
if (!qApp->focusWidget())
|
|
|
|
return;
|
2006-10-23 11:19:17 +00:00
|
|
|
cursor_->hide();
|
2006-06-02 12:01:28 +00:00
|
|
|
}
|
2006-03-12 17:29:34 +00:00
|
|
|
|
|
|
|
|
2006-06-20 08:39:16 +00:00
|
|
|
void GuiWorkArea::inputMethodEvent(QInputMethodEvent * e)
|
2006-03-12 17:29:34 +00:00
|
|
|
{
|
2006-06-26 16:55:35 +00:00
|
|
|
QString const & text = e->commitString();
|
2006-03-12 17:29:34 +00:00
|
|
|
if (!text.isEmpty()) {
|
2006-06-26 16:55:35 +00:00
|
|
|
|
|
|
|
lyxerr[Debug::KEY] << BOOST_CURRENT_FUNCTION
|
2006-08-13 15:55:03 +00:00
|
|
|
<< " preeditString =" << fromqstr(e->preeditString())
|
|
|
|
<< " commitString =" << fromqstr(e->commitString())
|
2006-06-26 16:55:35 +00:00
|
|
|
<< endl;
|
|
|
|
|
2006-03-12 17:29:34 +00:00
|
|
|
int key = 0;
|
|
|
|
// needed to make math superscript work on some systems
|
|
|
|
// ideally, such special coding should not be necessary
|
|
|
|
if (text == "^")
|
|
|
|
key = Qt::Key_AsciiCircum;
|
2006-08-18 09:25:45 +00:00
|
|
|
// FIXME: Needs for investigation, this key is not really used,
|
|
|
|
// the ctor below just check if key is different from 0.
|
2006-10-23 08:46:09 +00:00
|
|
|
QKeyEvent ev(QEvent::KeyPress, key, Qt::NoModifier, text);
|
2006-03-12 17:29:34 +00:00
|
|
|
keyPressEvent(&ev);
|
|
|
|
}
|
|
|
|
e->accept();
|
|
|
|
}
|
2006-06-26 16:55:35 +00:00
|
|
|
|
2006-06-20 08:39:16 +00:00
|
|
|
} // namespace frontend
|
|
|
|
} // namespace lyx
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2006-06-20 08:39:16 +00:00
|
|
|
#include "GuiWorkArea_moc.cpp"
|