mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-26 11:16:55 +00:00
cursor is no more damaging the background. L-shaped cursor is broken right now. will fix later
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@15503 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
387b8a1394
commit
4774536389
@ -55,20 +55,13 @@
|
|||||||
#define USE_EVENT_PRUNING 0
|
#define USE_EVENT_PRUNING 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
using std::endl;
|
using std::endl;
|
||||||
using std::string;
|
using std::string;
|
||||||
|
|
||||||
namespace os = lyx::support::os;
|
namespace os = lyx::support::os;
|
||||||
|
|
||||||
|
|
||||||
volatile int NN;
|
|
||||||
|
|
||||||
void recCalled()
|
|
||||||
{
|
|
||||||
++NN;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
namespace lyx {
|
namespace lyx {
|
||||||
|
|
||||||
/// return the LyX key state from Qt's
|
/// return the LyX key state from Qt's
|
||||||
@ -106,7 +99,7 @@ static mouse_button::state q_button_state(Qt::MouseButton button)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// retddurn the LyX mouse button state from Qt's
|
/// return the LyX mouse button state from Qt's
|
||||||
mouse_button::state q_motion_state(Qt::MouseButton state)
|
mouse_button::state q_motion_state(Qt::MouseButton state)
|
||||||
{
|
{
|
||||||
mouse_button::state b = mouse_button::none;
|
mouse_button::state b = mouse_button::none;
|
||||||
@ -122,6 +115,63 @@ mouse_button::state q_motion_state(Qt::MouseButton state)
|
|||||||
|
|
||||||
namespace frontend {
|
namespace frontend {
|
||||||
|
|
||||||
|
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_;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
// This is a 'heartbeat' generating synthetic mouse move events when the
|
// 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
|
// cursor is at the top or bottom edge of the viewport. One scroll per 0.2 s
|
||||||
SyntheticMouseEvent::SyntheticMouseEvent()
|
SyntheticMouseEvent::SyntheticMouseEvent()
|
||||||
@ -133,6 +183,8 @@ SyntheticMouseEvent::SyntheticMouseEvent()
|
|||||||
GuiWorkArea::GuiWorkArea(int w, int h, LyXView & lyx_view)
|
GuiWorkArea::GuiWorkArea(int w, int h, LyXView & lyx_view)
|
||||||
: WorkArea(lyx_view)
|
: WorkArea(lyx_view)
|
||||||
{
|
{
|
||||||
|
cursor_ = new frontend::CursorWidget(this);
|
||||||
|
|
||||||
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
|
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
|
||||||
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||||
setAcceptDrops(true);
|
setAcceptDrops(true);
|
||||||
@ -485,47 +537,6 @@ void GuiWorkArea::doGreyOut(QLPainter & pain)
|
|||||||
|
|
||||||
void GuiWorkArea::paintEvent(QPaintEvent * ev)
|
void GuiWorkArea::paintEvent(QPaintEvent * ev)
|
||||||
{
|
{
|
||||||
//setAttribute(Qt::WA_PaintOutsidePaintEvent, true);
|
|
||||||
QRect const rc = ev->rect();
|
|
||||||
lyxerr << "paintEvent begin: x: " << rc.x()
|
|
||||||
<< " y: " << rc.y()
|
|
||||||
<< " w: " << rc.width()
|
|
||||||
<< " h: " << rc.height() << endl;
|
|
||||||
|
|
||||||
if (!buffer_view_) {
|
|
||||||
lyxerr << "no bufferview" << endl;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
QLPainter pain(viewport());
|
|
||||||
|
|
||||||
if (rc.width() == 3) { // FIXME HACK
|
|
||||||
// Assume splash screen drawing is requested when
|
|
||||||
// widht == 3
|
|
||||||
doGreyOut(pain);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!buffer_view_->buffer()) {
|
|
||||||
lyxerr << "no buffer: " << endl;
|
|
||||||
doGreyOut(pain);
|
|
||||||
updateScrollbar();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (rc.width() != 2) { // FIXME HACK
|
|
||||||
// Assumes cursor drawing is requested when the
|
|
||||||
// width is 2
|
|
||||||
lyxerr << "Real drawing requested" << endl;
|
|
||||||
ViewMetricsInfo const & vi = buffer_view_->viewMetricsInfo();
|
|
||||||
paintText(*buffer_view_, vi, pain);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
//
|
|
||||||
lyxerr << "only cursor drawing requested" << endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
lyxerr[Debug::GUI] << BOOST_CURRENT_FUNCTION
|
lyxerr[Debug::GUI] << BOOST_CURRENT_FUNCTION
|
||||||
<< "\n QWidget width\t" << this->width()
|
<< "\n QWidget width\t" << this->width()
|
||||||
@ -541,17 +552,43 @@ void GuiWorkArea::paintEvent(QPaintEvent * ev)
|
|||||||
<< endl;
|
<< endl;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
//pain.drawPixmap(e->rect(), paint_device_, e->rect());
|
QRect const rc = ev->rect();
|
||||||
|
//lyxerr << "paintEvent begin: x: " << rc.x()
|
||||||
|
// << " y: " << rc.y()
|
||||||
|
// << " w: " << rc.width()
|
||||||
|
// << " h: " << rc.height() << endl;
|
||||||
|
|
||||||
if (show_vcursor_)
|
if (!buffer_view_) {
|
||||||
pain.drawPixmap(cursor_x_, cursor_y_, vcursor_);
|
lyxerr << "no bufferview" << endl;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (show_hcursor_)
|
|
||||||
pain.drawPixmap(cursor_x_, cursor_y_ + cursor_h_ - 1, hcursor_);
|
if (rc.width() == 3) { // FIXME HACK
|
||||||
lyxerr << "paintEvent end" << endl;
|
// Assume splash screen drawing is requested when
|
||||||
|
// width == 3
|
||||||
|
lyxerr << "splash screen requested" << endl;
|
||||||
|
QLPainter pain(viewport());
|
||||||
|
doGreyOut(pain);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!buffer_view_->buffer()) {
|
||||||
|
lyxerr << "no buffer: " << endl;
|
||||||
|
QLPainter pain(viewport());
|
||||||
|
doGreyOut(pain);
|
||||||
|
updateScrollbar();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//lyxerr << "real drawing" << endl;
|
||||||
|
QLPainter pain(viewport());
|
||||||
|
ViewMetricsInfo const & vi = buffer_view_->viewMetricsInfo();
|
||||||
|
paintText(*buffer_view_, vi, pain);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void GuiWorkArea::expose(int x, int y, int w, int h)
|
void GuiWorkArea::expose(int x, int y, int w, int h)
|
||||||
{
|
{
|
||||||
update(x, y, w, h);
|
update(x, y, w, h);
|
||||||
@ -563,67 +600,16 @@ void GuiWorkArea::showCursor(int x, int y, int h, CursorShape shape)
|
|||||||
if (!qApp->focusWidget())
|
if (!qApp->focusWidget())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
show_vcursor_ = true;
|
cursor_->move(x, y);
|
||||||
|
cursor_->shape_ = shape;
|
||||||
QColor const & required_color = guiApp->colorCache().get(LColor::cursor);
|
cursor_->on_ = true;
|
||||||
|
cursor_->show();
|
||||||
if (x==cursor_x_ && y==cursor_y_ && h==cursor_h_
|
|
||||||
&& cursor_color_ == required_color
|
|
||||||
&& cursor_shape_ == shape) {
|
|
||||||
show_hcursor_ = lshape_cursor_;
|
|
||||||
update(cursor_x_, cursor_y_, cursor_w_, cursor_h_);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Cache the dimensions of the cursor.
|
|
||||||
cursor_x_ = x;
|
|
||||||
cursor_y_ = y;
|
|
||||||
cursor_h_ = h;
|
|
||||||
cursor_color_ = required_color;
|
|
||||||
cursor_shape_ = shape;
|
|
||||||
|
|
||||||
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.
|
|
||||||
vcursor_ = QPixmap(cursor_w_, cursor_h_);
|
|
||||||
vcursor_.fill(cursor_color_);
|
|
||||||
|
|
||||||
// Draw the new (horizontal) cursor if necessary.
|
|
||||||
if (lshape_cursor_) {
|
|
||||||
hcursor_ = QPixmap(cursor_w_, 1);
|
|
||||||
hcursor_.fill(cursor_color_);
|
|
||||||
show_hcursor_ = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
update(cursor_x_, cursor_y_, cursor_w_, cursor_h_);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void GuiWorkArea::removeCursor()
|
void GuiWorkArea::removeCursor()
|
||||||
{
|
{
|
||||||
show_vcursor_ = false;
|
cursor_->hide();
|
||||||
show_hcursor_ = false;
|
|
||||||
|
|
||||||
update(cursor_x_, cursor_y_, cursor_w_, cursor_h_);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -23,7 +23,6 @@
|
|||||||
#include <QResizeEvent>
|
#include <QResizeEvent>
|
||||||
#include <QKeyEvent>
|
#include <QKeyEvent>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
#include <QPixmap>
|
|
||||||
|
|
||||||
#include <queue>
|
#include <queue>
|
||||||
|
|
||||||
@ -85,6 +84,7 @@ public:
|
|||||||
* Qt-specific implementation of the work area
|
* Qt-specific implementation of the work area
|
||||||
* (buffer view GUI)
|
* (buffer view GUI)
|
||||||
*/
|
*/
|
||||||
|
class CursorWidget;
|
||||||
class GuiWorkArea : public QAbstractScrollArea, public WorkArea
|
class GuiWorkArea : public QAbstractScrollArea, public WorkArea
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@ -115,30 +115,29 @@ public:
|
|||||||
private:
|
private:
|
||||||
void doGreyOut(QLPainter & pain);
|
void doGreyOut(QLPainter & pain);
|
||||||
///
|
///
|
||||||
void dragEnterEvent(QDragEnterEvent * event);
|
void dragEnterEvent(QDragEnterEvent * ev);
|
||||||
///
|
///
|
||||||
void dropEvent(QDropEvent* event);
|
void dropEvent(QDropEvent * ev);
|
||||||
/// repaint part of the widget
|
/// repaint part of the widget
|
||||||
void paintEvent(QPaintEvent * e);
|
void paintEvent(QPaintEvent * ev);
|
||||||
/// widget has been resized
|
/// widget has been resized
|
||||||
void resizeEvent(QResizeEvent * e);
|
void resizeEvent(QResizeEvent * ev);
|
||||||
/// mouse button press
|
/// mouse button press
|
||||||
void mousePressEvent(QMouseEvent * e);
|
void mousePressEvent(QMouseEvent * ev);
|
||||||
/// mouse button release
|
/// mouse button release
|
||||||
void mouseReleaseEvent(QMouseEvent * e);
|
void mouseReleaseEvent(QMouseEvent * ev);
|
||||||
/// mouse double click of button
|
/// mouse double click of button
|
||||||
void mouseDoubleClickEvent(QMouseEvent * e);
|
void mouseDoubleClickEvent(QMouseEvent * ev);
|
||||||
/// mouse motion
|
/// mouse motion
|
||||||
void mouseMoveEvent(QMouseEvent * e);
|
void mouseMoveEvent(QMouseEvent * ev);
|
||||||
/// wheel event
|
/// wheel event
|
||||||
void wheelEvent(QWheelEvent * e);
|
void wheelEvent(QWheelEvent * ev);
|
||||||
/// key press
|
/// key press
|
||||||
void keyPressEvent(QKeyEvent * e);
|
void keyPressEvent(QKeyEvent * ev);
|
||||||
/// IM events
|
/// IM events
|
||||||
void inputMethodEvent(QInputMethodEvent * e);
|
void inputMethodEvent(QInputMethodEvent * ev);
|
||||||
|
|
||||||
public Q_SLOTS:
|
public Q_SLOTS:
|
||||||
|
|
||||||
/// Timeout event Slot for keyboard bufferring.
|
/// Timeout event Slot for keyboard bufferring.
|
||||||
/// \todo This is not used currently in the code, remove?
|
/// \todo This is not used currently in the code, remove?
|
||||||
void keyeventTimeout();
|
void keyeventTimeout();
|
||||||
@ -157,30 +156,13 @@ private:
|
|||||||
|
|
||||||
///
|
///
|
||||||
SyntheticMouseEvent synthetic_mouse_event_;
|
SyntheticMouseEvent synthetic_mouse_event_;
|
||||||
|
|
||||||
/// Our client side painting device.
|
|
||||||
//QPixmap paint_device_;
|
|
||||||
|
|
||||||
/// \todo remove
|
/// \todo remove
|
||||||
QTimer step_timer_;
|
QTimer step_timer_;
|
||||||
|
|
||||||
/// \todo remove
|
/// \todo remove
|
||||||
std::queue<boost::shared_ptr<QKeyEvent> > keyeventQueue_;
|
std::queue<boost::shared_ptr<QKeyEvent> > keyeventQueue_;
|
||||||
|
///
|
||||||
double_click dc_event_;
|
double_click dc_event_;
|
||||||
|
|
||||||
///
|
|
||||||
int cursor_x_;
|
|
||||||
///
|
|
||||||
int cursor_y_;
|
|
||||||
///
|
|
||||||
int cursor_w_;
|
|
||||||
///
|
|
||||||
int cursor_h_;
|
|
||||||
///
|
|
||||||
QPixmap hcursor_;
|
|
||||||
///
|
|
||||||
QPixmap vcursor_;
|
|
||||||
///
|
///
|
||||||
bool show_hcursor_;
|
bool show_hcursor_;
|
||||||
///
|
///
|
||||||
@ -191,6 +173,8 @@ private:
|
|||||||
QColor cursor_color_;
|
QColor cursor_color_;
|
||||||
///
|
///
|
||||||
CursorShape cursor_shape_;
|
CursorShape cursor_shape_;
|
||||||
|
///
|
||||||
|
CursorWidget * cursor_;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace frontend
|
} // namespace frontend
|
||||||
|
@ -177,7 +177,7 @@ void MathMacroTemplate::read(Buffer const &, LyXLex & lex)
|
|||||||
docstring const str = lex.getDocString();
|
docstring const str = lex.getDocString();
|
||||||
lex.next(); // eat that macro definition
|
lex.next(); // eat that macro definition
|
||||||
lex.next(); // eat the \\end_insrt line
|
lex.next(); // eat the \\end_insrt line
|
||||||
lyxerr << "Got to read from: " << to_utf8(str) << endl;
|
//lyxerr << "Got to read from: " << to_utf8(str) << endl;
|
||||||
mathed_parse_cell(ar, str);
|
mathed_parse_cell(ar, str);
|
||||||
if (ar.size() != 1 || !ar[0]->asMacroTemplate()) {
|
if (ar.size() != 1 || !ar[0]->asMacroTemplate()) {
|
||||||
lyxerr << "Cannot read macro from '" << ar << "'" << endl;
|
lyxerr << "Cannot read macro from '" << ar << "'" << endl;
|
||||||
|
Loading…
Reference in New Issue
Block a user