2006-03-05 17:24:44 +00:00
|
|
|
/**
|
2007-04-26 03:53:02 +00:00
|
|
|
* \file GuiWorkArea.cpp
|
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
|
|
|
|
2007-10-06 15:48:58 +00:00
|
|
|
#include "Buffer.h"
|
2007-11-12 22:15:51 +00:00
|
|
|
#include "BufferParams.h"
|
2006-04-13 20:39:42 +00:00
|
|
|
#include "BufferView.h"
|
2007-11-12 22:15:51 +00:00
|
|
|
#include "CoordCache.h"
|
2007-10-11 09:59:01 +00:00
|
|
|
#include "Cursor.h"
|
2007-11-12 22:15:51 +00:00
|
|
|
#include "Font.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "FuncRequest.h"
|
2007-11-12 22:15:51 +00:00
|
|
|
#include "GuiApplication.h"
|
|
|
|
#include "GuiKeySymbol.h"
|
|
|
|
#include "GuiPainter.h"
|
2007-12-25 20:12:07 +00:00
|
|
|
#include "GuiPopupMenu.h"
|
2007-11-13 09:52:28 +00:00
|
|
|
#include "GuiView.h"
|
2007-11-12 22:15:51 +00:00
|
|
|
#include "KeySymbol.h"
|
|
|
|
#include "Language.h"
|
2007-10-06 15:48:58 +00:00
|
|
|
#include "LyXFunc.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "LyXRC.h"
|
2007-11-12 22:15:51 +00:00
|
|
|
#include "MetricsInfo.h"
|
|
|
|
#include "qt_helpers.h"
|
2007-08-14 13:14:47 +00:00
|
|
|
#include "version.h"
|
2006-08-17 17:15:17 +00:00
|
|
|
|
2006-10-23 08:46:09 +00:00
|
|
|
#include "graphics/GraphicsImage.h"
|
|
|
|
#include "graphics/GraphicsLoader.h"
|
|
|
|
|
2007-11-29 19:19:39 +00:00
|
|
|
#include "support/debug.h"
|
|
|
|
#include "support/gettext.h"
|
2007-11-12 22:15:51 +00:00
|
|
|
#include "support/FileName.h"
|
|
|
|
|
|
|
|
#include "frontends/Application.h"
|
|
|
|
#include "frontends/FontMetrics.h"
|
|
|
|
#include "frontends/WorkAreaManager.h"
|
|
|
|
|
2007-12-25 20:12:07 +00:00
|
|
|
#include <QContextMenuEvent>
|
2007-08-14 13:14:47 +00:00
|
|
|
#include <QInputContext>
|
2007-12-25 20:12:07 +00:00
|
|
|
#include <QHelpEvent>
|
2006-03-05 17:24:44 +00:00
|
|
|
#include <QLayout>
|
|
|
|
#include <QMainWindow>
|
|
|
|
#include <QPainter>
|
2007-10-11 19:00:18 +00:00
|
|
|
#include <QPalette>
|
2006-03-05 17:24:44 +00:00
|
|
|
#include <QScrollBar>
|
2007-10-06 15:48:58 +00:00
|
|
|
#include <QTabBar>
|
2007-03-27 17:26:11 +00:00
|
|
|
#include <QTimer>
|
2007-12-25 20:12:07 +00:00
|
|
|
#include <QToolButton>
|
2007-12-26 06:44:22 +00:00
|
|
|
#include <QToolTip>
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
#include <boost/bind.hpp>
|
|
|
|
|
2007-06-02 07:58:11 +00:00
|
|
|
#ifdef Q_WS_X11
|
|
|
|
#include <QX11Info>
|
|
|
|
extern "C" int XEventsQueued(Display *display, int mode);
|
|
|
|
#endif
|
|
|
|
|
2006-06-26 16:55:35 +00:00
|
|
|
#ifdef Q_WS_WIN
|
2006-11-02 22:53:10 +00:00
|
|
|
int const CursorWidth = 2;
|
2006-06-26 16:55:35 +00:00
|
|
|
#else
|
2006-11-02 22:53:10 +00:00
|
|
|
int const CursorWidth = 1;
|
2006-06-26 16:55:35 +00:00
|
|
|
#endif
|
2006-03-12 17:29:34 +00:00
|
|
|
|
2007-08-19 09:44:34 +00:00
|
|
|
#undef KeyPress
|
|
|
|
#undef NoModifier
|
2006-10-23 11:19:17 +00:00
|
|
|
|
2007-12-12 10:16:00 +00:00
|
|
|
using namespace std;
|
2007-12-12 18:57:56 +00:00
|
|
|
using namespace lyx::support;
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
namespace lyx {
|
2006-03-12 17:29:34 +00:00
|
|
|
|
2006-11-26 21:30:39 +00:00
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
/// 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-11-02 22:23:26 +00:00
|
|
|
mouse_button::state q_motion_state(Qt::MouseButtons 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-11-12 07:50:18 +00:00
|
|
|
class CursorWidget {
|
2006-10-23 11:19:17 +00:00
|
|
|
public:
|
2006-11-12 07:50:18 +00:00
|
|
|
CursorWidget() {}
|
|
|
|
|
|
|
|
void draw(QPainter & painter)
|
2006-10-23 11:19:17 +00:00
|
|
|
{
|
2007-06-04 06:21:33 +00:00
|
|
|
if (show_ && rect_.isValid()) {
|
|
|
|
switch (shape_) {
|
|
|
|
case L_SHAPE:
|
|
|
|
painter.fillRect(rect_.x(), rect_.y(), CursorWidth, rect_.height(), color_);
|
|
|
|
painter.setPen(color_);
|
|
|
|
painter.drawLine(rect_.bottomLeft().x() + CursorWidth, rect_.bottomLeft().y(),
|
|
|
|
rect_.bottomRight().x(), rect_.bottomLeft().y());
|
|
|
|
break;
|
|
|
|
|
|
|
|
case REVERSED_L_SHAPE:
|
|
|
|
painter.fillRect(rect_.x() + rect_.height() / 3, rect_.y(), CursorWidth, rect_.height(), color_);
|
|
|
|
painter.setPen(color_);
|
|
|
|
painter.drawLine(rect_.bottomRight().x() - CursorWidth, rect_.bottomLeft().y(),
|
|
|
|
rect_.bottomLeft().x(), rect_.bottomLeft().y());
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
painter.fillRect(rect_, color_);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2006-10-23 11:19:17 +00:00
|
|
|
}
|
|
|
|
|
2006-11-12 07:50:18 +00:00
|
|
|
void update(int x, int y, int h, CursorShape shape)
|
2006-10-23 11:19:17 +00:00
|
|
|
{
|
2007-10-25 12:41:02 +00:00
|
|
|
color_ = guiApp->colorCache().get(Color_cursor);
|
2006-11-12 07:50:18 +00:00
|
|
|
shape_ = shape;
|
2007-06-04 06:21:33 +00:00
|
|
|
switch (shape) {
|
|
|
|
case L_SHAPE:
|
|
|
|
rect_ = QRect(x, y, CursorWidth + h / 3, h);
|
|
|
|
break;
|
|
|
|
case REVERSED_L_SHAPE:
|
|
|
|
rect_ = QRect(x - h / 3, y, CursorWidth + h / 3, h);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
rect_ = QRect(x, y, CursorWidth, h);
|
|
|
|
break;
|
|
|
|
}
|
2006-11-12 07:50:18 +00:00
|
|
|
}
|
2006-10-23 11:19:17 +00:00
|
|
|
|
2006-11-12 08:29:05 +00:00
|
|
|
void show(bool set_show = true) { show_ = set_show; }
|
2006-11-12 07:50:18 +00:00
|
|
|
void hide() { show_ = false; }
|
2006-10-23 11:19:17 +00:00
|
|
|
|
2006-11-12 08:29:05 +00:00
|
|
|
QRect const & rect() { return rect_; }
|
|
|
|
|
2006-11-12 07:50:18 +00:00
|
|
|
private:
|
2006-10-23 11:19:17 +00:00
|
|
|
///
|
|
|
|
CursorShape shape_;
|
2006-11-02 22:53:10 +00:00
|
|
|
///
|
2006-11-12 07:50:18 +00:00
|
|
|
bool show_;
|
2006-11-02 22:53:10 +00:00
|
|
|
///
|
2006-11-12 07:50:18 +00:00
|
|
|
QColor color_;
|
2006-11-02 22:53:10 +00:00
|
|
|
///
|
2006-11-12 07:50:18 +00:00
|
|
|
QRect rect_;
|
2006-10-23 11:19:17 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
2007-11-12 22:15:51 +00:00
|
|
|
|
2007-11-13 09:52:28 +00:00
|
|
|
GuiWorkArea::GuiWorkArea(Buffer & buffer, GuiView & lv)
|
2007-11-12 22:15:51 +00:00
|
|
|
: buffer_view_(new BufferView(buffer)), lyx_view_(&lv),
|
2007-11-21 21:15:23 +00:00
|
|
|
cursor_visible_(false),
|
2007-11-12 22:15:51 +00:00
|
|
|
need_resize_(false), schedule_redraw_(false),
|
|
|
|
preedit_lines_(1)
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
2007-11-12 22:15:51 +00:00
|
|
|
buffer.workAreaManager().add(this);
|
|
|
|
// Setup the signals
|
2007-11-21 21:15:23 +00:00
|
|
|
connect(&cursor_timeout_, SIGNAL(timeout()),
|
|
|
|
this, SLOT(toggleCursor()));
|
2008-02-02 03:05:54 +00:00
|
|
|
|
|
|
|
int const time = QApplication::cursorFlashTime() / 2;
|
|
|
|
if (time > 0) {
|
|
|
|
cursor_timeout_.setInterval(time);
|
|
|
|
cursor_timeout_.start();
|
|
|
|
} else
|
|
|
|
// let's initialize this just to be safe
|
|
|
|
cursor_timeout_.setInterval(500);
|
|
|
|
|
2007-02-08 16:41:06 +00:00
|
|
|
screen_ = QPixmap(viewport()->width(), viewport()->height());
|
2006-11-12 07:50:18 +00:00
|
|
|
cursor_ = new frontend::CursorWidget();
|
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
|
|
|
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
|
|
|
setAcceptDrops(true);
|
2006-12-04 04:31:18 +00:00
|
|
|
setMouseTracking(true);
|
2006-03-05 17:24:44 +00:00
|
|
|
setMinimumSize(100, 70);
|
2007-11-11 22:30:21 +00:00
|
|
|
updateWindowTitle();
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2006-11-13 17:28:37 +00:00
|
|
|
viewport()->setAutoFillBackground(false);
|
2006-12-21 14:50:46 +00:00
|
|
|
// We don't need double-buffering nor SystemBackground on
|
|
|
|
// the viewport because we have our own backing pixmap.
|
|
|
|
viewport()->setAttribute(Qt::WA_NoSystemBackground);
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
synthetic_mouse_event_.timeout.timeout.connect(
|
2006-06-20 08:39:16 +00:00
|
|
|
boost::bind(&GuiWorkArea::generateSyntheticMouseEvent,
|
2007-11-12 22:15:51 +00:00
|
|
|
this));
|
2006-04-05 23:56:29 +00:00
|
|
|
|
2006-03-12 17:29:34 +00:00
|
|
|
// Initialize the vertical Scroll Bar
|
2008-01-29 12:54:23 +00:00
|
|
|
QObject::connect(verticalScrollBar(), SIGNAL(valueChanged(int)),
|
|
|
|
this, SLOT(scrollTo(int)));
|
2006-03-12 17:29:34 +00:00
|
|
|
|
2007-11-29 21:10:35 +00:00
|
|
|
LYXERR(Debug::GUI, "viewport width: " << viewport()->width()
|
|
|
|
<< " viewport height: " << viewport()->height());
|
2006-03-12 17:29:34 +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
|
|
|
|
2007-11-12 22:15:51 +00:00
|
|
|
|
|
|
|
GuiWorkArea::~GuiWorkArea()
|
|
|
|
{
|
|
|
|
buffer_view_->buffer().workAreaManager().remove(this);
|
|
|
|
delete buffer_view_;
|
2007-12-02 18:39:05 +00:00
|
|
|
delete cursor_;
|
2007-11-12 22:15:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GuiWorkArea::close()
|
|
|
|
{
|
|
|
|
lyx_view_->removeWorkArea(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
BufferView & GuiWorkArea::bufferView()
|
|
|
|
{
|
|
|
|
return *buffer_view_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
BufferView const & GuiWorkArea::bufferView() const
|
|
|
|
{
|
|
|
|
return *buffer_view_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GuiWorkArea::stopBlinkingCursor()
|
|
|
|
{
|
|
|
|
cursor_timeout_.stop();
|
|
|
|
hideCursor();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GuiWorkArea::startBlinkingCursor()
|
|
|
|
{
|
|
|
|
showCursor();
|
2008-02-02 03:05:54 +00:00
|
|
|
//we're not supposed to cache this value.
|
|
|
|
int const time = QApplication::cursorFlashTime() / 2;
|
|
|
|
if (time <= 0)
|
|
|
|
return;
|
|
|
|
cursor_timeout_.setInterval(time);
|
2007-11-21 21:15:23 +00:00
|
|
|
cursor_timeout_.start();
|
2007-11-12 22:15:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GuiWorkArea::redraw()
|
|
|
|
{
|
|
|
|
if (!isVisible())
|
|
|
|
// No need to redraw in this case.
|
|
|
|
return;
|
|
|
|
|
|
|
|
// No need to do anything if this is the current view. The BufferView
|
|
|
|
// metrics are already up to date.
|
2007-11-18 20:36:52 +00:00
|
|
|
if (lyx_view_ != guiApp->currentView()) {
|
2007-11-12 22:15:51 +00:00
|
|
|
// FIXME: it would be nice to optimize for the off-screen case.
|
|
|
|
buffer_view_->updateMetrics();
|
|
|
|
buffer_view_->cursor().fixIfBroken();
|
|
|
|
}
|
|
|
|
|
|
|
|
// update cursor position, because otherwise it has to wait until
|
|
|
|
// the blinking interval is over
|
|
|
|
if (cursor_visible_) {
|
|
|
|
hideCursor();
|
|
|
|
showCursor();
|
|
|
|
}
|
|
|
|
|
2007-11-15 20:04:51 +00:00
|
|
|
LYXERR(Debug::WORKAREA, "WorkArea::redraw screen");
|
2007-11-14 17:39:16 +00:00
|
|
|
updateScreen();
|
2007-11-17 11:27:03 +00:00
|
|
|
update(0, 0, viewport()->width(), viewport()->height());
|
2007-11-12 22:15:51 +00:00
|
|
|
|
2007-12-21 09:43:23 +00:00
|
|
|
/// \warning: scrollbar updating *must* be done after the BufferView is drawn
|
|
|
|
/// because \c BufferView::updateScrollbar() is called in \c BufferView::draw().
|
2007-12-21 08:28:18 +00:00
|
|
|
updateScrollbar();
|
2007-11-20 22:03:56 +00:00
|
|
|
lyx_view_->updateStatusBar();
|
|
|
|
|
2007-11-12 22:15:51 +00:00
|
|
|
if (lyxerr.debugging(Debug::WORKAREA))
|
|
|
|
buffer_view_->coordCache().dump();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GuiWorkArea::processKeySym(KeySymbol const & key, KeyModifier mod)
|
|
|
|
{
|
|
|
|
// In order to avoid bad surprise in the middle of an operation,
|
2008-02-05 00:37:30 +00:00
|
|
|
// we better stop the blinking cursor...
|
2008-02-05 13:10:42 +00:00
|
|
|
// the cursor gets restarted in GuiView::restartCursor()
|
2007-11-12 22:15:51 +00:00
|
|
|
stopBlinkingCursor();
|
|
|
|
|
|
|
|
theLyXFunc().setLyXView(lyx_view_);
|
|
|
|
theLyXFunc().processKeySym(key, mod);
|
2008-02-05 00:37:30 +00:00
|
|
|
|
2007-11-12 22:15:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GuiWorkArea::dispatch(FuncRequest const & cmd0, KeyModifier mod)
|
|
|
|
{
|
|
|
|
// Handle drag&drop
|
|
|
|
if (cmd0.action == LFUN_FILE_OPEN) {
|
|
|
|
lyx_view_->dispatch(cmd0);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
theLyXFunc().setLyXView(lyx_view_);
|
|
|
|
|
|
|
|
FuncRequest cmd;
|
|
|
|
|
|
|
|
if (cmd0.action == LFUN_MOUSE_PRESS) {
|
|
|
|
if (mod == ShiftModifier)
|
|
|
|
cmd = FuncRequest(cmd0, "region-select");
|
|
|
|
else if (mod == ControlModifier)
|
|
|
|
cmd = FuncRequest(cmd0, "paragraph-select");
|
|
|
|
else
|
|
|
|
cmd = cmd0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
cmd = cmd0;
|
|
|
|
|
2008-02-05 00:37:30 +00:00
|
|
|
bool const notJustMovingTheMouse =
|
|
|
|
cmd.action != LFUN_MOUSE_MOTION || cmd.button() != mouse_button::none;
|
|
|
|
|
2007-11-12 22:15:51 +00:00
|
|
|
// In order to avoid bad surprise in the middle of an operation, we better stop
|
2008-02-05 13:10:42 +00:00
|
|
|
// the blinking cursor.
|
|
|
|
if (notJustMovingTheMouse)
|
2007-11-12 22:15:51 +00:00
|
|
|
stopBlinkingCursor();
|
|
|
|
|
|
|
|
buffer_view_->mouseEventDispatch(cmd);
|
|
|
|
|
|
|
|
// Skip these when selecting
|
|
|
|
if (cmd.action != LFUN_MOUSE_MOTION) {
|
2007-11-20 22:03:56 +00:00
|
|
|
lyx_view_->updateLayoutList();
|
2007-11-12 22:15:51 +00:00
|
|
|
lyx_view_->updateToolbars();
|
|
|
|
}
|
|
|
|
|
|
|
|
// GUI tweaks except with mouse motion with no button pressed.
|
2008-02-05 00:37:30 +00:00
|
|
|
if (notJustMovingTheMouse) {
|
2007-11-12 22:15:51 +00:00
|
|
|
// Slight hack: this is only called currently when we
|
|
|
|
// clicked somewhere, so we force through the display
|
|
|
|
// of the new status here.
|
|
|
|
lyx_view_->clearMessage();
|
|
|
|
|
2008-02-05 00:37:30 +00:00
|
|
|
// Show the cursor immediately after any operation
|
2007-11-12 22:15:51 +00:00
|
|
|
startBlinkingCursor();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GuiWorkArea::resizeBufferView()
|
|
|
|
{
|
|
|
|
// WARNING: Please don't put any code that will trigger a repaint here!
|
|
|
|
// We are already inside a paint event.
|
|
|
|
lyx_view_->setBusy(true);
|
2007-11-14 14:34:55 +00:00
|
|
|
buffer_view_->resize(viewport()->width(), viewport()->height());
|
2007-11-20 22:03:56 +00:00
|
|
|
lyx_view_->updateLayoutList();
|
2007-11-12 22:15:51 +00:00
|
|
|
lyx_view_->setBusy(false);
|
2007-11-19 10:04:14 +00:00
|
|
|
need_resize_ = false;
|
2007-11-12 22:15:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GuiWorkArea::showCursor()
|
|
|
|
{
|
|
|
|
if (cursor_visible_)
|
|
|
|
return;
|
|
|
|
|
|
|
|
CursorShape shape = BAR_SHAPE;
|
|
|
|
|
|
|
|
Font const & realfont = buffer_view_->cursor().real_current_font;
|
|
|
|
BufferParams const & bp = buffer_view_->buffer().params();
|
|
|
|
bool const samelang = realfont.language() == bp.language;
|
|
|
|
bool const isrtl = realfont.isVisibleRightToLeft();
|
|
|
|
|
|
|
|
if (!samelang || isrtl != bp.language->rightToLeft()) {
|
|
|
|
shape = L_SHAPE;
|
|
|
|
if (isrtl)
|
|
|
|
shape = REVERSED_L_SHAPE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// The ERT language hack needs fixing up
|
|
|
|
if (realfont.language() == latex_language)
|
|
|
|
shape = BAR_SHAPE;
|
|
|
|
|
|
|
|
Font const font = buffer_view_->cursor().getFont();
|
|
|
|
FontMetrics const & fm = theFontMetrics(font);
|
|
|
|
int const asc = fm.maxAscent();
|
|
|
|
int const des = fm.maxDescent();
|
|
|
|
int h = asc + des;
|
|
|
|
int x = 0;
|
|
|
|
int y = 0;
|
|
|
|
buffer_view_->cursor().getPos(x, y);
|
|
|
|
y -= asc;
|
|
|
|
|
|
|
|
// if it doesn't touch the screen, don't try to show it
|
2007-11-14 14:34:55 +00:00
|
|
|
if (y + h < 0 || y >= viewport()->height())
|
2007-11-12 22:15:51 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
cursor_visible_ = true;
|
|
|
|
showCursor(x, y, h, shape);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GuiWorkArea::hideCursor()
|
|
|
|
{
|
|
|
|
if (!cursor_visible_)
|
|
|
|
return;
|
|
|
|
|
|
|
|
cursor_visible_ = false;
|
|
|
|
removeCursor();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GuiWorkArea::toggleCursor()
|
|
|
|
{
|
|
|
|
if (cursor_visible_)
|
|
|
|
hideCursor();
|
|
|
|
else
|
|
|
|
showCursor();
|
2008-02-02 03:05:54 +00:00
|
|
|
}
|
|
|
|
|
2007-11-12 22:15:51 +00:00
|
|
|
|
2007-11-14 17:39:16 +00:00
|
|
|
void GuiWorkArea::updateScrollbar()
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
2008-01-17 17:47:01 +00:00
|
|
|
ScrollbarParameters const & scroll_ = buffer_view_->scrollbarParameters();
|
|
|
|
|
2008-01-17 17:06:55 +00:00
|
|
|
verticalScrollBar()->setRange(scroll_.min, scroll_.max);
|
|
|
|
verticalScrollBar()->setPageStep(scroll_.page_step);
|
|
|
|
verticalScrollBar()->setSingleStep(scroll_.single_step);
|
2008-01-29 12:54:23 +00:00
|
|
|
// Block the scrollbar signal to prevent recursive signal/slot calling.
|
|
|
|
verticalScrollBar()->blockSignals(true);
|
2007-11-14 17:39:16 +00:00
|
|
|
verticalScrollBar()->setValue(scroll_.position);
|
2008-01-17 17:47:01 +00:00
|
|
|
verticalScrollBar()->setSliderPosition(scroll_.position);
|
2008-01-29 12:54:23 +00:00
|
|
|
verticalScrollBar()->blockSignals(false);
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
2006-06-26 16:55:35 +00:00
|
|
|
|
2008-01-29 12:54:23 +00:00
|
|
|
void GuiWorkArea::scrollTo(int value)
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
2007-09-15 13:59:26 +00:00
|
|
|
stopBlinkingCursor();
|
2008-01-29 12:54:23 +00:00
|
|
|
buffer_view_->scrollDocView(value);
|
2007-09-15 13:59:26 +00:00
|
|
|
|
|
|
|
if (lyxrc.cursor_follows_scrollbar) {
|
|
|
|
buffer_view_->setCursorFromScrollbar();
|
2007-11-20 22:03:56 +00:00
|
|
|
lyx_view_->updateLayoutList();
|
2007-09-15 13:59:26 +00:00
|
|
|
}
|
|
|
|
// Show the cursor immediately after any operation.
|
|
|
|
startBlinkingCursor();
|
2007-06-02 07:58:11 +00:00
|
|
|
QApplication::syncX();
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-12-25 18:53:38 +00:00
|
|
|
bool GuiWorkArea::event(QEvent * e)
|
|
|
|
{
|
2008-01-10 08:19:54 +00:00
|
|
|
switch (e->type()) {
|
|
|
|
case QEvent::ToolTip: {
|
|
|
|
QHelpEvent * helpEvent = static_cast<QHelpEvent *>(e);
|
|
|
|
if (lyxrc.use_tooltip) {
|
|
|
|
QPoint pos = helpEvent->pos();
|
|
|
|
if (pos.x() < viewport()->width()) {
|
|
|
|
QString s = toqstr(buffer_view_->toolTip(pos.x(), pos.y()));
|
|
|
|
QToolTip::showText(helpEvent->globalPos(), s);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
QToolTip::hideText();
|
|
|
|
}
|
|
|
|
// Don't forget to accept the event!
|
|
|
|
e->accept();
|
|
|
|
return true;
|
|
|
|
}
|
2008-01-10 09:04:30 +00:00
|
|
|
|
|
|
|
case QEvent::ShortcutOverride: {
|
|
|
|
// We catch this event in order to catch the Tab or Shift+Tab key press
|
|
|
|
// which are otherwise reserved to focus switching between controls
|
|
|
|
// within a dialog.
|
|
|
|
QKeyEvent * ke = static_cast<QKeyEvent*>(e);
|
2008-01-18 08:26:38 +00:00
|
|
|
if ((ke->key() != Qt::Key_Tab && ke->key() != Qt::Key_Backtab)
|
|
|
|
|| ke->modifiers() & Qt::ControlModifier)
|
2008-01-10 09:04:30 +00:00
|
|
|
return QAbstractScrollArea::event(e);
|
|
|
|
keyPressEvent(ke);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2008-01-10 08:19:54 +00:00
|
|
|
default:
|
|
|
|
return QAbstractScrollArea::event(e);
|
|
|
|
}
|
|
|
|
return false;
|
2007-12-25 18:53:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-12-25 20:12:07 +00:00
|
|
|
void GuiWorkArea::contextMenuEvent(QContextMenuEvent * e)
|
|
|
|
{
|
|
|
|
QPoint pos = e->pos();
|
2007-12-26 12:40:58 +00:00
|
|
|
docstring name = buffer_view_->contextMenu(pos.x(), pos.y());
|
|
|
|
if (name.empty()) {
|
|
|
|
QAbstractScrollArea::contextMenuEvent(e);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
QMenu * menu = guiApp->menus().menu(toqstr(name));
|
|
|
|
if (!menu) {
|
|
|
|
QAbstractScrollArea::contextMenuEvent(e);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// Position the menu to the right.
|
|
|
|
// FIXME: menu position should be different for RTL text.
|
|
|
|
pos.rx() += menu->width();
|
|
|
|
// FIXME: correct vertical position of the menu WRT screen espace.
|
|
|
|
//pos.ry() += menu->height();
|
|
|
|
menu->exec(pos);
|
2007-12-26 12:48:36 +00:00
|
|
|
e->accept();
|
2007-12-25 20:12:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-10-27 23:26:52 +00:00
|
|
|
void GuiWorkArea::focusInEvent(QFocusEvent * /*event*/)
|
|
|
|
{
|
2007-02-14 14:51:47 +00:00
|
|
|
// Repaint the whole screen.
|
|
|
|
// Note: this is different from redraw() as only the backing pixmap
|
|
|
|
// will be redrawn, which is cheap.
|
|
|
|
viewport()->repaint();
|
|
|
|
|
2006-12-21 14:50:46 +00:00
|
|
|
startBlinkingCursor();
|
2006-10-27 23:26:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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;
|
2007-10-17 18:28:45 +00:00
|
|
|
FuncRequest cmd(LFUN_MOUSE_TRIPLE, e->x(), e->y(),
|
2007-03-27 17:26:11 +00:00
|
|
|
q_button_state(e->button()));
|
2006-07-13 16:37:55 +00:00
|
|
|
dispatch(cmd);
|
2006-03-05 17:24:44 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-04-01 09:14:08 +00:00
|
|
|
inputContext()->reset();
|
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
FuncRequest const cmd(LFUN_MOUSE_PRESS, e->x(), e->y(),
|
2007-01-27 10:41:03 +00:00
|
|
|
q_button_state(e->button()));
|
|
|
|
dispatch(cmd, q_key_state(e->modifiers()));
|
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
|
|
|
{
|
2007-03-27 17:31:29 +00:00
|
|
|
// we kill the triple click if we move
|
2007-03-27 17:26:11 +00:00
|
|
|
doubleClickTimeout();
|
2006-03-05 17:24:44 +00:00
|
|
|
FuncRequest cmd(LFUN_MOUSE_MOTION, e->x(), e->y(),
|
2008-02-07 13:40:31 +00:00
|
|
|
q_motion_state(e->buttons()));
|
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;
|
2008-02-07 13:40:31 +00:00
|
|
|
|
|
|
|
synthetic_mouse_event_.restart_timeout = true;
|
|
|
|
synthetic_mouse_event_.timeout.start();
|
|
|
|
// Fall through to handle this event...
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
} 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();
|
2008-02-07 13:40:31 +00:00
|
|
|
if (e->x() == synthetic_mouse_event_.x_old
|
|
|
|
&& e->y() == synthetic_mouse_event_.y_old
|
|
|
|
&& scrollbar_value == synthetic_mouse_event_.scrollbar_value_old) {
|
|
|
|
// Nothing changed on-screen since the last QMouseEvent.
|
|
|
|
return;
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
2008-02-07 13:40:31 +00:00
|
|
|
|
|
|
|
// Yes something has changed. 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.
|
|
|
|
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)
|
2008-01-30 21:20:29 +00:00
|
|
|
double const lines = qApp->wheelScrollLines()
|
|
|
|
* lyxrc.mouse_wheel_speed
|
|
|
|
* e->delta() / 120.0;
|
2008-02-05 13:26:22 +00:00
|
|
|
LYXERR(Debug::SCROLLING, "wheelScrollLines = " << qApp->wheelScrollLines()
|
2008-01-30 21:20:29 +00:00
|
|
|
<< " delta = " << e->delta()
|
2008-02-05 13:26:22 +00:00
|
|
|
<< " lines = " << lines);
|
2006-03-16 20:34:20 +00:00
|
|
|
verticalScrollBar()->setValue(verticalScrollBar()->value() -
|
2008-01-30 21:20:29 +00:00
|
|
|
int(lines * verticalScrollBar()->singleStep()));
|
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
|
|
|
{
|
2008-02-05 13:26:22 +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
|
|
|
|
2007-09-17 18:41:03 +00:00
|
|
|
void GuiWorkArea::keyPressEvent(QKeyEvent * ev)
|
2006-03-12 17:29:34 +00:00
|
|
|
{
|
2007-06-02 07:58:11 +00:00
|
|
|
// do nothing if there are other events
|
|
|
|
// (the auto repeated events come too fast)
|
2007-06-02 08:01:12 +00:00
|
|
|
// \todo FIXME: remove hard coded Qt keys, process the key binding
|
2007-06-02 07:58:11 +00:00
|
|
|
#ifdef Q_WS_X11
|
2007-09-17 18:41:03 +00:00
|
|
|
if (XEventsQueued(QX11Info::display(), 0) > 1 && ev->isAutoRepeat()
|
2007-06-02 07:58:11 +00:00
|
|
|
&& (Qt::Key_PageDown || Qt::Key_PageUp)) {
|
2007-11-29 21:10:35 +00:00
|
|
|
LYXERR(Debug::KEY, "system is busy: scroll key event ignored");
|
2007-09-17 18:41:03 +00:00
|
|
|
ev->ignore();
|
2007-06-02 07:58:11 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
2007-05-17 08:24:44 +00:00
|
|
|
|
2007-11-29 21:10:35 +00:00
|
|
|
LYXERR(Debug::KEY, " count: " << ev->count()
|
|
|
|
<< " text: " << fromqstr(ev->text())
|
|
|
|
<< " isAutoRepeat: " << ev->isAutoRepeat() << " key: " << ev->key());
|
2006-03-12 17:29:34 +00:00
|
|
|
|
2007-09-17 18:41:03 +00:00
|
|
|
KeySymbol sym;
|
|
|
|
setKeySymbol(&sym, ev);
|
|
|
|
processKeySym(sym, q_key_state(ev->modifiers()));
|
2008-01-10 09:04:30 +00:00
|
|
|
ev->accept();
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
|
|
|
|
void GuiWorkArea::doubleClickTimeout()
|
|
|
|
{
|
2006-03-05 17:24:44 +00:00
|
|
|
dc_event_.active = false;
|
|
|
|
}
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
|
2007-09-17 18:41:03 +00:00
|
|
|
void GuiWorkArea::mouseDoubleClickEvent(QMouseEvent * ev)
|
2007-03-27 08:05:31 +00:00
|
|
|
{
|
2007-11-12 22:15:51 +00:00
|
|
|
dc_event_ = DoubleClick(ev);
|
2007-03-27 17:31:29 +00:00
|
|
|
QTimer::singleShot(QApplication::doubleClickInterval(), this,
|
|
|
|
SLOT(doubleClickTimeout()));
|
2007-03-27 17:26:11 +00:00
|
|
|
FuncRequest cmd(LFUN_MOUSE_DOUBLE,
|
2007-09-17 18:41:03 +00:00
|
|
|
ev->x(), ev->y(),
|
|
|
|
q_button_state(ev->button()));
|
2007-03-27 17:26:11 +00:00
|
|
|
dispatch(cmd);
|
2007-03-27 08:05:31 +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 08:46:09 +00:00
|
|
|
QAbstractScrollArea::resizeEvent(ev);
|
2007-01-04 12:36:17 +00:00
|
|
|
need_resize_ = true;
|
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-11-26 02:18:32 +00:00
|
|
|
viewport()->repaint(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::paintEvent(QPaintEvent * ev)
|
|
|
|
{
|
2007-05-28 22:27:45 +00:00
|
|
|
QRect const rc = ev->rect();
|
2007-11-29 21:10:35 +00:00
|
|
|
// LYXERR(Debug::PAINTING, "paintEvent begin: x: " << rc.x()
|
|
|
|
// << " y: " << rc.y() << " w: " << rc.width() << " h: " << rc.height());
|
2006-11-02 22:53:10 +00:00
|
|
|
|
2007-01-04 12:36:17 +00:00
|
|
|
if (need_resize_) {
|
|
|
|
screen_ = QPixmap(viewport()->width(), viewport()->height());
|
|
|
|
resizeBufferView();
|
2008-02-05 13:17:05 +00:00
|
|
|
|
|
|
|
// Update scrollbars which might have changed due different
|
|
|
|
// BufferView dimension. This is especially important when the
|
|
|
|
// BufferView goes from zero-size to the real-size for the first time,
|
|
|
|
// as the scrollbar paramters are then set for the first time.
|
|
|
|
updateScrollbar();
|
|
|
|
BOOST_ASSERT(need_resize_ == false);
|
|
|
|
|
2007-01-04 12:36:17 +00:00
|
|
|
updateScreen();
|
2007-11-12 22:15:51 +00:00
|
|
|
hideCursor();
|
|
|
|
showCursor();
|
2007-01-04 12:36:17 +00:00
|
|
|
}
|
|
|
|
|
2006-11-02 22:53:10 +00:00
|
|
|
QPainter pain(viewport());
|
|
|
|
pain.drawPixmap(rc, screen_, rc);
|
2006-11-12 07:50:18 +00:00
|
|
|
cursor_->draw(pain);
|
2006-11-02 22:53:10 +00:00
|
|
|
}
|
2006-10-23 08:46:09 +00:00
|
|
|
|
|
|
|
|
2007-01-04 12:36:17 +00:00
|
|
|
void GuiWorkArea::updateScreen()
|
2006-11-02 22:53:10 +00:00
|
|
|
{
|
2007-08-31 22:16:11 +00:00
|
|
|
GuiPainter pain(&screen_);
|
2007-08-27 22:53:16 +00:00
|
|
|
buffer_view_->draw(pain);
|
2006-06-02 12:01:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
{
|
2007-01-18 21:47:27 +00:00
|
|
|
if (schedule_redraw_) {
|
2007-11-06 08:32:25 +00:00
|
|
|
buffer_view_->updateMetrics();
|
2007-08-21 07:33:46 +00:00
|
|
|
updateScreen();
|
|
|
|
viewport()->update(QRect(0, 0, viewport()->width(), viewport()->height()));
|
2007-01-18 21:47:27 +00:00
|
|
|
schedule_redraw_ = false;
|
2007-01-16 15:16:09 +00:00
|
|
|
// Show the cursor immediately after the update.
|
|
|
|
hideCursor();
|
|
|
|
toggleCursor();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2006-11-12 07:50:18 +00:00
|
|
|
cursor_->update(x, y, h, shape);
|
2006-10-23 11:19:17 +00:00
|
|
|
cursor_->show();
|
2006-11-12 08:29:05 +00:00
|
|
|
viewport()->update(cursor_->rect());
|
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:19:17 +00:00
|
|
|
cursor_->hide();
|
2006-11-12 08:29:05 +00:00
|
|
|
//if (!qApp->focusWidget())
|
|
|
|
viewport()->update(cursor_->rect());
|
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
|
|
|
{
|
2007-04-01 09:14:08 +00:00
|
|
|
QString const & commit_string = e->commitString();
|
|
|
|
docstring const & preedit_string
|
|
|
|
= qstring_to_ucs4(e->preeditString());
|
|
|
|
|
|
|
|
if (!commit_string.isEmpty()) {
|
2006-06-26 16:55:35 +00:00
|
|
|
|
2007-11-29 21:10:35 +00:00
|
|
|
LYXERR(Debug::KEY, "preeditString: " << fromqstr(e->preeditString())
|
|
|
|
<< " commitString: " << fromqstr(e->commitString()));
|
2006-06-26 16:55:35 +00:00
|
|
|
|
2006-03-12 17:29:34 +00:00
|
|
|
int key = 0;
|
2007-02-10 16:30:11 +00:00
|
|
|
|
2007-04-01 09:14:08 +00:00
|
|
|
// FIXME Iwami 04/01/07: we should take care also of UTF16 surrogates here.
|
2007-11-29 21:10:35 +00:00
|
|
|
for (int i = 0; i != commit_string.size(); ++i) {
|
2007-04-01 09:14:08 +00:00
|
|
|
QKeyEvent ev(QEvent::KeyPress, key, Qt::NoModifier, commit_string[i]);
|
2007-02-10 16:30:11 +00:00
|
|
|
keyPressEvent(&ev);
|
|
|
|
}
|
2006-03-12 17:29:34 +00:00
|
|
|
}
|
2007-04-01 09:14:08 +00:00
|
|
|
|
2007-05-28 22:27:45 +00:00
|
|
|
// Hide the cursor during the kana-kanji transformation.
|
2007-04-01 09:14:08 +00:00
|
|
|
if (preedit_string.empty())
|
|
|
|
startBlinkingCursor();
|
|
|
|
else
|
|
|
|
stopBlinkingCursor();
|
|
|
|
|
2007-04-01 15:12:19 +00:00
|
|
|
// last_width : for checking if last preedit string was/wasn't empty.
|
2007-04-01 14:56:55 +00:00
|
|
|
static bool last_width = false;
|
2007-04-01 09:14:08 +00:00
|
|
|
if (!last_width && preedit_string.empty()) {
|
2007-05-28 22:27:45 +00:00
|
|
|
// if last_width is last length of preedit string.
|
2007-04-01 09:14:08 +00:00
|
|
|
e->accept();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-08-31 22:16:11 +00:00
|
|
|
GuiPainter pain(&screen_);
|
2007-11-06 08:32:25 +00:00
|
|
|
buffer_view_->updateMetrics();
|
2007-08-27 22:53:16 +00:00
|
|
|
buffer_view_->draw(pain);
|
2007-10-28 18:51:54 +00:00
|
|
|
FontInfo font = buffer_view_->cursor().getFont().fontInfo();
|
2007-04-01 09:14:08 +00:00
|
|
|
FontMetrics const & fm = theFontMetrics(font);
|
|
|
|
int height = fm.maxHeight();
|
|
|
|
int cur_x = cursor_->rect().left();
|
|
|
|
int cur_y = cursor_->rect().bottom();
|
|
|
|
|
|
|
|
// redraw area of preedit string.
|
2007-11-14 14:34:55 +00:00
|
|
|
update(0, cur_y - height, viewport()->width(),
|
2007-04-01 09:14:08 +00:00
|
|
|
(height + 1) * preedit_lines_);
|
|
|
|
|
|
|
|
if (preedit_string.empty()) {
|
2007-04-01 14:56:55 +00:00
|
|
|
last_width = false;
|
2007-04-01 09:14:08 +00:00
|
|
|
preedit_lines_ = 1;
|
|
|
|
e->accept();
|
|
|
|
return;
|
|
|
|
}
|
2007-04-01 14:56:55 +00:00
|
|
|
last_width = true;
|
2007-04-01 09:14:08 +00:00
|
|
|
|
2007-04-01 15:12:19 +00:00
|
|
|
// att : stores an IM attribute.
|
2007-04-01 14:56:55 +00:00
|
|
|
QList<QInputMethodEvent::Attribute> const & att = e->attributes();
|
2007-04-01 09:14:08 +00:00
|
|
|
|
|
|
|
// get attributes of input method cursor.
|
2007-04-01 15:12:19 +00:00
|
|
|
// cursor_pos : cursor position in preedit string.
|
2007-04-01 14:56:55 +00:00
|
|
|
size_t cursor_pos = 0;
|
|
|
|
bool cursor_is_visible = false;
|
2007-11-29 21:10:35 +00:00
|
|
|
for (int i = 0; i != att.size(); ++i) {
|
2007-04-01 09:14:08 +00:00
|
|
|
if (att.at(i).type == QInputMethodEvent::Cursor) {
|
2007-04-01 14:56:55 +00:00
|
|
|
cursor_pos = att.at(i).start;
|
|
|
|
cursor_is_visible = att.at(i).length != 0;
|
2007-04-01 09:14:08 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t preedit_length = preedit_string.length();
|
|
|
|
|
|
|
|
// get position of selection in input method.
|
|
|
|
// FIXME: isn't there a way to do this simplier?
|
2007-04-01 15:12:19 +00:00
|
|
|
// rStart : cursor position in selected string in IM.
|
2007-04-01 14:56:55 +00:00
|
|
|
size_t rStart = 0;
|
2007-04-01 15:12:19 +00:00
|
|
|
// rLength : selected string length in IM.
|
2007-04-01 14:56:55 +00:00
|
|
|
size_t rLength = 0;
|
|
|
|
if (cursor_pos < preedit_length) {
|
2007-11-29 21:10:35 +00:00
|
|
|
for (int i = 0; i != att.size(); ++i) {
|
2007-04-01 09:14:08 +00:00
|
|
|
if (att.at(i).type == QInputMethodEvent::TextFormat) {
|
2007-04-01 14:56:55 +00:00
|
|
|
if (att.at(i).start <= int(cursor_pos)
|
|
|
|
&& int(cursor_pos) < att.at(i).start + att.at(i).length) {
|
2007-04-01 09:14:08 +00:00
|
|
|
rStart = att.at(i).start;
|
|
|
|
rLength = att.at(i).length;
|
2007-04-01 14:56:55 +00:00
|
|
|
if (!cursor_is_visible)
|
|
|
|
cursor_pos += rLength;
|
2007-04-01 09:14:08 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2007-04-01 14:56:55 +00:00
|
|
|
rStart = cursor_pos;
|
2007-04-01 09:14:08 +00:00
|
|
|
rLength = 0;
|
|
|
|
}
|
|
|
|
|
2007-04-25 16:39:21 +00:00
|
|
|
int const right_margin = rightMargin();
|
2007-04-01 09:14:08 +00:00
|
|
|
Painter::preedit_style ps;
|
|
|
|
// Most often there would be only one line:
|
|
|
|
preedit_lines_ = 1;
|
|
|
|
for (size_t pos = 0; pos != preedit_length; ++pos) {
|
|
|
|
char_type const typed_char = preedit_string[pos];
|
|
|
|
// reset preedit string style
|
|
|
|
ps = Painter::preedit_default;
|
|
|
|
|
|
|
|
// if we reached the right extremity of the screen, go to next line.
|
2007-11-14 14:34:55 +00:00
|
|
|
if (cur_x + fm.width(typed_char) > viewport()->width() - right_margin) {
|
2007-04-01 09:14:08 +00:00
|
|
|
cur_x = right_margin;
|
|
|
|
cur_y += height + 1;
|
|
|
|
++preedit_lines_;
|
|
|
|
}
|
|
|
|
// preedit strings are displayed with dashed underline
|
|
|
|
// and partial strings are displayed white on black indicating
|
|
|
|
// that we are in selecting mode in the input method.
|
|
|
|
// FIXME: rLength == preedit_length is not a changing condition
|
|
|
|
// FIXME: should be put out of the loop.
|
2007-05-28 22:27:45 +00:00
|
|
|
if (pos >= rStart
|
2007-04-01 09:14:08 +00:00
|
|
|
&& pos < rStart + rLength
|
2007-04-01 14:56:55 +00:00
|
|
|
&& !(cursor_pos < rLength && rLength == preedit_length))
|
2007-04-01 09:14:08 +00:00
|
|
|
ps = Painter::preedit_selecting;
|
|
|
|
|
2007-04-01 14:56:55 +00:00
|
|
|
if (pos == cursor_pos
|
|
|
|
&& (cursor_pos < rLength && rLength == preedit_length))
|
2007-04-01 09:14:08 +00:00
|
|
|
ps = Painter::preedit_cursor;
|
|
|
|
|
|
|
|
// draw one character and update cur_x.
|
|
|
|
cur_x += pain.preeditText(cur_x, cur_y, typed_char, font, ps);
|
|
|
|
}
|
|
|
|
|
|
|
|
// update the preedit string screen area.
|
2007-11-14 14:34:55 +00:00
|
|
|
update(0, cur_y - preedit_lines_*height, viewport()->width(),
|
2007-04-01 09:14:08 +00:00
|
|
|
(height + 1) * preedit_lines_);
|
|
|
|
|
|
|
|
// Don't forget to accept the event!
|
2006-03-12 17:29:34 +00:00
|
|
|
e->accept();
|
|
|
|
}
|
2006-06-26 16:55:35 +00:00
|
|
|
|
2007-04-01 09:14:08 +00:00
|
|
|
|
|
|
|
QVariant GuiWorkArea::inputMethodQuery(Qt::InputMethodQuery query) const
|
|
|
|
{
|
|
|
|
QRect cur_r(0,0,0,0);
|
|
|
|
switch (query) {
|
|
|
|
// this is the CJK-specific composition window position.
|
|
|
|
case Qt::ImMicroFocus:
|
|
|
|
cur_r = cursor_->rect();
|
|
|
|
if (preedit_lines_ != 1)
|
|
|
|
cur_r.moveLeft(10);
|
|
|
|
cur_r.moveBottom(cur_r.bottom() + cur_r.height() * preedit_lines_);
|
|
|
|
// return lower right of cursor in LyX.
|
|
|
|
return cur_r;
|
|
|
|
default:
|
|
|
|
return QWidget::inputMethodQuery(query);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-10-17 18:28:45 +00:00
|
|
|
|
2007-11-12 22:15:51 +00:00
|
|
|
void GuiWorkArea::updateWindowTitle()
|
|
|
|
{
|
|
|
|
docstring maximize_title;
|
|
|
|
docstring minimize_title;
|
|
|
|
|
|
|
|
Buffer & buf = buffer_view_->buffer();
|
|
|
|
FileName const fileName = buf.fileName();
|
|
|
|
if (!fileName.empty()) {
|
|
|
|
maximize_title = fileName.displayName(30);
|
|
|
|
minimize_title = from_utf8(fileName.onlyFileName());
|
|
|
|
if (!buf.isClean()) {
|
|
|
|
maximize_title += _(" (changed)");
|
|
|
|
minimize_title += char_type('*');
|
|
|
|
}
|
|
|
|
if (buf.isReadonly())
|
|
|
|
maximize_title += _(" (read only)");
|
|
|
|
}
|
|
|
|
|
2007-11-14 12:31:31 +00:00
|
|
|
QString title = windowTitle();
|
|
|
|
QString new_title = toqstr(maximize_title);
|
|
|
|
if (title == new_title)
|
|
|
|
return;
|
|
|
|
|
|
|
|
QWidget::setWindowTitle(new_title);
|
|
|
|
QWidget::setWindowIconText(toqstr(minimize_title));
|
|
|
|
titleChanged(this);
|
2007-11-12 22:15:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GuiWorkArea::setReadOnly(bool)
|
|
|
|
{
|
|
|
|
updateWindowTitle();
|
|
|
|
if (this == lyx_view_->currentWorkArea())
|
2007-11-18 00:01:14 +00:00
|
|
|
lyx_view_->updateBufferDependent(false);
|
2007-11-12 22:15:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-06 15:48:58 +00:00
|
|
|
////////////////////////////////////////////////////////////////////
|
2007-10-17 18:28:45 +00:00
|
|
|
//
|
|
|
|
// TabWorkArea
|
|
|
|
//
|
2007-10-06 15:48:58 +00:00
|
|
|
////////////////////////////////////////////////////////////////////
|
2007-10-17 18:28:45 +00:00
|
|
|
|
2007-11-12 22:15:51 +00:00
|
|
|
TabWorkArea::TabWorkArea(QWidget * parent) : QTabWidget(parent)
|
2007-10-06 15:48:58 +00:00
|
|
|
{
|
2007-10-11 19:00:18 +00:00
|
|
|
QPalette pal = palette();
|
2007-11-12 22:15:51 +00:00
|
|
|
pal.setColor(QPalette::Active, QPalette::Button,
|
|
|
|
pal.color(QPalette::Active, QPalette::Window));
|
|
|
|
pal.setColor(QPalette::Disabled, QPalette::Button,
|
|
|
|
pal.color(QPalette::Disabled, QPalette::Window));
|
|
|
|
pal.setColor(QPalette::Inactive, QPalette::Button,
|
|
|
|
pal.color(QPalette::Inactive, QPalette::Window));
|
2007-10-11 19:00:18 +00:00
|
|
|
|
|
|
|
QToolButton * closeTabButton = new QToolButton(this);
|
|
|
|
closeTabButton->setPalette(pal);
|
2007-10-17 18:28:45 +00:00
|
|
|
closeTabButton->setIcon(QIcon(":/images/closetab.png"));
|
|
|
|
closeTabButton->setText("Close");
|
2007-10-11 19:00:18 +00:00
|
|
|
closeTabButton->setAutoRaise(true);
|
2007-10-06 15:48:58 +00:00
|
|
|
closeTabButton->setCursor(Qt::ArrowCursor);
|
|
|
|
closeTabButton->setToolTip(tr("Close tab"));
|
|
|
|
closeTabButton->setEnabled(true);
|
|
|
|
|
|
|
|
QObject::connect(this, SIGNAL(currentChanged(int)),
|
|
|
|
this, SLOT(on_currentTabChanged(int)));
|
|
|
|
QObject::connect(closeTabButton, SIGNAL(clicked()),
|
|
|
|
this, SLOT(closeCurrentTab()));
|
|
|
|
|
|
|
|
setCornerWidget(closeTabButton);
|
|
|
|
setUsesScrollButtons(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void TabWorkArea::showBar(bool show)
|
|
|
|
{
|
2007-11-19 11:21:45 +00:00
|
|
|
tabBar()->setEnabled(show);
|
2007-10-06 15:48:58 +00:00
|
|
|
tabBar()->setVisible(show);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-16 06:50:09 +00:00
|
|
|
GuiWorkArea * TabWorkArea::currentWorkArea()
|
|
|
|
{
|
|
|
|
if (count() == 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
GuiWorkArea * wa = dynamic_cast<GuiWorkArea *>(currentWidget());
|
|
|
|
BOOST_ASSERT(wa);
|
|
|
|
return wa;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
GuiWorkArea * TabWorkArea::workArea(Buffer & buffer)
|
|
|
|
{
|
|
|
|
for (int i = 0; i != count(); ++i) {
|
|
|
|
GuiWorkArea * wa = dynamic_cast<GuiWorkArea *>(widget(i));
|
|
|
|
BOOST_ASSERT(wa);
|
|
|
|
if (&wa->bufferView().buffer() == &buffer)
|
|
|
|
return wa;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-07 08:12:20 +00:00
|
|
|
void TabWorkArea::closeAll()
|
|
|
|
{
|
|
|
|
while (count()) {
|
|
|
|
GuiWorkArea * wa = dynamic_cast<GuiWorkArea *>(widget(0));
|
|
|
|
BOOST_ASSERT(wa);
|
|
|
|
removeTab(0);
|
|
|
|
delete wa;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-07 08:05:02 +00:00
|
|
|
bool TabWorkArea::setCurrentWorkArea(GuiWorkArea * work_area)
|
|
|
|
{
|
|
|
|
BOOST_ASSERT(work_area);
|
|
|
|
int index = indexOf(work_area);
|
|
|
|
if (index == -1)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (index == currentIndex())
|
|
|
|
// Make sure the work area is up to date.
|
|
|
|
on_currentTabChanged(index);
|
|
|
|
else
|
|
|
|
// Switch to the work area.
|
|
|
|
setCurrentIndex(index);
|
|
|
|
work_area->setFocus();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-11-19 10:04:14 +00:00
|
|
|
GuiWorkArea * TabWorkArea::addWorkArea(Buffer & buffer, GuiView & view)
|
|
|
|
{
|
|
|
|
GuiWorkArea * wa = new GuiWorkArea(buffer, view);
|
|
|
|
wa->setUpdatesEnabled(false);
|
2007-11-19 12:03:38 +00:00
|
|
|
// Hide tabbar if there's no tab (avoid a resize and a flashing tabbar
|
|
|
|
// when hiding it again below).
|
|
|
|
showBar(count() > 0);
|
2007-11-19 10:04:14 +00:00
|
|
|
addTab(wa, wa->windowTitle());
|
|
|
|
QObject::connect(wa, SIGNAL(titleChanged(GuiWorkArea *)),
|
|
|
|
this, SLOT(updateTabText(GuiWorkArea *)));
|
|
|
|
// Hide tabbar if there's only one tab.
|
|
|
|
showBar(count() > 1);
|
|
|
|
return wa;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-07 08:05:02 +00:00
|
|
|
bool TabWorkArea::removeWorkArea(GuiWorkArea * work_area)
|
|
|
|
{
|
|
|
|
BOOST_ASSERT(work_area);
|
|
|
|
int index = indexOf(work_area);
|
|
|
|
if (index == -1)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
work_area->setUpdatesEnabled(false);
|
|
|
|
removeTab(index);
|
|
|
|
delete work_area;
|
|
|
|
|
|
|
|
if (count()) {
|
|
|
|
// make sure the next work area is enabled.
|
|
|
|
currentWidget()->setUpdatesEnabled(true);
|
|
|
|
// Hide tabbar if there's only one tab.
|
|
|
|
showBar(count() > 1);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-06 15:48:58 +00:00
|
|
|
void TabWorkArea::on_currentTabChanged(int i)
|
|
|
|
{
|
|
|
|
GuiWorkArea * wa = dynamic_cast<GuiWorkArea *>(widget(i));
|
|
|
|
BOOST_ASSERT(wa);
|
|
|
|
BufferView & bv = wa->bufferView();
|
|
|
|
bv.cursor().fixIfBroken();
|
2007-11-19 10:04:14 +00:00
|
|
|
bv.updateMetrics();
|
2007-10-06 15:48:58 +00:00
|
|
|
wa->setUpdatesEnabled(true);
|
|
|
|
wa->redraw();
|
|
|
|
wa->setFocus();
|
|
|
|
///
|
|
|
|
currentWorkAreaChanged(wa);
|
|
|
|
|
2007-11-15 20:04:51 +00:00
|
|
|
LYXERR(Debug::GUI, "currentTabChanged " << i
|
|
|
|
<< "File" << bv.buffer().absFileName());
|
2007-10-06 15:48:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void TabWorkArea::closeCurrentTab()
|
|
|
|
{
|
|
|
|
lyx::dispatch(FuncRequest(LFUN_BUFFER_CLOSE));
|
|
|
|
}
|
|
|
|
|
2007-11-11 22:30:21 +00:00
|
|
|
|
|
|
|
void TabWorkArea::updateTabText(GuiWorkArea * wa)
|
|
|
|
{
|
|
|
|
int const i = indexOf(wa);
|
|
|
|
if (i < 0)
|
|
|
|
return;
|
|
|
|
setTabText(i, wa->windowTitle());
|
|
|
|
}
|
|
|
|
|
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"
|