mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-30 05:12:40 +00:00
* completion cursor
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@23312 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
0ca318af55
commit
7e2c8ea4ff
@ -234,6 +234,12 @@ bool GuiCompleter::inlinePossible(Cursor const & cur) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool GuiCompleter::completionAvailable() const
|
||||||
|
{
|
||||||
|
return popup()->model()->rowCount() > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
bool GuiCompleter::popupVisible() const
|
bool GuiCompleter::popupVisible() const
|
||||||
{
|
{
|
||||||
return popup()->isVisible();
|
return popup()->isVisible();
|
||||||
@ -455,6 +461,9 @@ void GuiCompleter::hidePopup(Cursor & cur)
|
|||||||
popup()->hide();
|
popup()->hide();
|
||||||
if (popup_timer_.isActive())
|
if (popup_timer_.isActive())
|
||||||
popup_timer_.stop();
|
popup_timer_.stop();
|
||||||
|
|
||||||
|
if (!inlineVisible())
|
||||||
|
setModel(new GuiCompletionModel(this, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -471,6 +480,9 @@ void GuiCompleter::hideInline(Cursor & cur)
|
|||||||
{
|
{
|
||||||
gui_->bufferView().setInlineCompletion(cur, DocIterator(), docstring());
|
gui_->bufferView().setInlineCompletion(cur, DocIterator(), docstring());
|
||||||
inlineVisible_ = false;
|
inlineVisible_ = false;
|
||||||
|
|
||||||
|
if (!popupVisible())
|
||||||
|
setModel(new GuiCompletionModel(this, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -51,6 +51,8 @@ public:
|
|||||||
bool popupPossible(Cursor const & cur) const;
|
bool popupPossible(Cursor const & cur) const;
|
||||||
///
|
///
|
||||||
bool inlinePossible(Cursor const & cur) const;
|
bool inlinePossible(Cursor const & cur) const;
|
||||||
|
///
|
||||||
|
bool completionAvailable() const;
|
||||||
/// Activate the current completion, i.e. finalize it.
|
/// Activate the current completion, i.e. finalize it.
|
||||||
void activate();
|
void activate();
|
||||||
/// Do a completion as far as it is unique, but at least one character.
|
/// Do a completion as far as it is unique, but at least one character.
|
||||||
|
@ -68,6 +68,7 @@ int const CursorWidth = 2;
|
|||||||
#else
|
#else
|
||||||
int const CursorWidth = 1;
|
int const CursorWidth = 1;
|
||||||
#endif
|
#endif
|
||||||
|
int const TabIndicatorWidth = 4;
|
||||||
|
|
||||||
#undef KeyPress
|
#undef KeyPress
|
||||||
#undef NoModifier
|
#undef NoModifier
|
||||||
@ -121,48 +122,63 @@ public:
|
|||||||
|
|
||||||
void draw(QPainter & painter)
|
void draw(QPainter & painter)
|
||||||
{
|
{
|
||||||
if (show_ && rect_.isValid()) {
|
if (!show_ || !rect_.isValid())
|
||||||
switch (shape_) {
|
return;
|
||||||
case L_SHAPE:
|
|
||||||
painter.fillRect(rect_.x(), rect_.y(),
|
int l = x_ - rect_.left();
|
||||||
CursorWidth, rect_.height(), color_);
|
int r = rect_.right() - x_;
|
||||||
painter.setPen(color_);
|
int h = rect_.height();
|
||||||
painter.drawLine(rect_.bottomLeft().x() + CursorWidth,
|
|
||||||
rect_.bottomLeft().y(),
|
painter.fillRect(x_, y_, CursorWidth, h, color_);
|
||||||
rect_.bottomRight().x(), rect_.bottomLeft().y());
|
painter.setPen(color_);
|
||||||
break;
|
if (l_shape_) {
|
||||||
|
if (rtl_)
|
||||||
case REVERSED_L_SHAPE:
|
painter.drawLine(x_, y_ + h, x_ - l, y_ + h);
|
||||||
painter.fillRect(rect_.x() + rect_.height() / 3, rect_.y(),
|
else
|
||||||
CursorWidth, rect_.height(), color_);
|
painter.drawLine(x_ + CursorWidth, y_ + h,
|
||||||
painter.setPen(color_);
|
x_ + CursorWidth + r, y_ + h);
|
||||||
painter.drawLine(rect_.bottomRight().x() - CursorWidth,
|
}
|
||||||
rect_.bottomLeft().y(),
|
|
||||||
rect_.bottomLeft().x(), rect_.bottomLeft().y());
|
if (completable_) {
|
||||||
break;
|
int m = y_ + h / 2;
|
||||||
|
int d = TabIndicatorWidth - 1;
|
||||||
default:
|
if (rtl_) {
|
||||||
painter.fillRect(rect_, color_);
|
painter.drawLine(x_ - 1 , m - d, x_ - d - 1, m);
|
||||||
break;
|
painter.drawLine(x_ - 1 , m + d, x_ - d - 1, m);
|
||||||
|
} else {
|
||||||
|
painter.drawLine(x_ + CursorWidth , m - d, x_ + d + CursorWidth, m);
|
||||||
|
painter.drawLine(x_ + CursorWidth , m + d, x_ + d + CursorWidth, m);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void update(int x, int y, int h, CursorShape shape)
|
void update(int x, int y, int h, bool l_shape,
|
||||||
|
bool rtl, bool completable)
|
||||||
{
|
{
|
||||||
color_ = guiApp->colorCache().get(Color_cursor);
|
color_ = guiApp->colorCache().get(Color_cursor);
|
||||||
shape_ = shape;
|
l_shape_ = l_shape;
|
||||||
switch (shape) {
|
rtl_ = rtl;
|
||||||
case L_SHAPE:
|
completable_ = completable;
|
||||||
rect_ = QRect(x, y, CursorWidth + h / 3, h);
|
x_ = x;
|
||||||
break;
|
y_ = y;
|
||||||
case REVERSED_L_SHAPE:
|
int l = 0;
|
||||||
rect_ = QRect(x - h / 3, y, CursorWidth + h / 3, h);
|
int r = 0;
|
||||||
break;
|
|
||||||
default:
|
if (l_shape_) {
|
||||||
rect_ = QRect(x, y, CursorWidth, h);
|
if (rtl)
|
||||||
break;
|
l += h / 3;
|
||||||
|
else
|
||||||
|
r += h / 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (completable_) {
|
||||||
|
if (rtl)
|
||||||
|
l = max(r, TabIndicatorWidth);
|
||||||
|
else
|
||||||
|
r = max(l, TabIndicatorWidth);
|
||||||
|
}
|
||||||
|
|
||||||
|
rect_ = QRect(x - l, y, CursorWidth + r + l, h);
|
||||||
}
|
}
|
||||||
|
|
||||||
void show(bool set_show = true) { show_ = set_show; }
|
void show(bool set_show = true) { show_ = set_show; }
|
||||||
@ -172,13 +188,21 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
///
|
///
|
||||||
CursorShape shape_;
|
bool rtl_;
|
||||||
|
///
|
||||||
|
bool l_shape_;
|
||||||
|
///
|
||||||
|
bool completable_;
|
||||||
///
|
///
|
||||||
bool show_;
|
bool show_;
|
||||||
///
|
///
|
||||||
QColor color_;
|
QColor color_;
|
||||||
///
|
///
|
||||||
QRect rect_;
|
QRect rect_;
|
||||||
|
///
|
||||||
|
int x_;
|
||||||
|
///
|
||||||
|
int y_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -432,22 +456,19 @@ void GuiWorkArea::showCursor()
|
|||||||
if (cursor_visible_)
|
if (cursor_visible_)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
CursorShape shape = BAR_SHAPE;
|
// RTL or not RTL
|
||||||
|
bool l_shape = false;
|
||||||
Font const & realfont = buffer_view_->cursor().real_current_font;
|
Font const & realfont = buffer_view_->cursor().real_current_font;
|
||||||
BufferParams const & bp = buffer_view_->buffer().params();
|
BufferParams const & bp = buffer_view_->buffer().params();
|
||||||
bool const samelang = realfont.language() == bp.language;
|
bool const samelang = realfont.language() == bp.language;
|
||||||
bool const isrtl = realfont.isVisibleRightToLeft();
|
bool const isrtl = realfont.isVisibleRightToLeft();
|
||||||
|
|
||||||
if (!samelang || isrtl != bp.language->rightToLeft()) {
|
if (!samelang || isrtl != bp.language->rightToLeft())
|
||||||
shape = L_SHAPE;
|
l_shape = true;
|
||||||
if (isrtl)
|
|
||||||
shape = REVERSED_L_SHAPE;
|
|
||||||
}
|
|
||||||
|
|
||||||
// The ERT language hack needs fixing up
|
// The ERT language hack needs fixing up
|
||||||
if (realfont.language() == latex_language)
|
if (realfont.language() == latex_language)
|
||||||
shape = BAR_SHAPE;
|
l_shape = false;
|
||||||
|
|
||||||
Font const font = buffer_view_->cursor().getFont();
|
Font const font = buffer_view_->cursor().getFont();
|
||||||
FontMetrics const & fm = theFontMetrics(font);
|
FontMetrics const & fm = theFontMetrics(font);
|
||||||
@ -466,9 +487,10 @@ void GuiWorkArea::showCursor()
|
|||||||
cursorInView = false;
|
cursorInView = false;
|
||||||
|
|
||||||
// show cursor on screen
|
// show cursor on screen
|
||||||
|
bool completable = completer_.completionAvailable();
|
||||||
if (cursorInView) {
|
if (cursorInView) {
|
||||||
cursor_visible_ = true;
|
cursor_visible_ = true;
|
||||||
showCursor(x, y, h, shape);
|
showCursor(x, y, h, l_shape, isrtl, completable);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -849,7 +871,8 @@ void GuiWorkArea::updateScreen()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void GuiWorkArea::showCursor(int x, int y, int h, CursorShape shape)
|
void GuiWorkArea::showCursor(int x, int y, int h,
|
||||||
|
bool l_shape, bool rtl, bool completable)
|
||||||
{
|
{
|
||||||
if (schedule_redraw_) {
|
if (schedule_redraw_) {
|
||||||
buffer_view_->updateMetrics();
|
buffer_view_->updateMetrics();
|
||||||
@ -862,7 +885,7 @@ void GuiWorkArea::showCursor(int x, int y, int h, CursorShape shape)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
cursor_->update(x, y, h, shape);
|
cursor_->update(x, y, h, l_shape, rtl, completable);
|
||||||
cursor_->show();
|
cursor_->show();
|
||||||
viewport()->update(cursor_->rect());
|
viewport()->update(cursor_->rect());
|
||||||
}
|
}
|
||||||
|
@ -50,16 +50,6 @@ namespace frontend {
|
|||||||
class GuiView;
|
class GuiView;
|
||||||
class GuiWorkArea;
|
class GuiWorkArea;
|
||||||
|
|
||||||
/// types of cursor in work area
|
|
||||||
enum CursorShape {
|
|
||||||
/// normal I-beam
|
|
||||||
BAR_SHAPE,
|
|
||||||
/// L-shape for locked insets of a different language
|
|
||||||
L_SHAPE,
|
|
||||||
/// reverse L-shape for RTL text
|
|
||||||
REVERSED_L_SHAPE
|
|
||||||
};
|
|
||||||
|
|
||||||
/// for emulating triple click
|
/// for emulating triple click
|
||||||
class DoubleClick {
|
class DoubleClick {
|
||||||
public:
|
public:
|
||||||
@ -167,7 +157,8 @@ private:
|
|||||||
void updateScreen();
|
void updateScreen();
|
||||||
|
|
||||||
/// paint the cursor and store the background
|
/// paint the cursor and store the background
|
||||||
virtual void showCursor(int x, int y, int h, CursorShape shape);
|
virtual void showCursor(int x, int y, int h,
|
||||||
|
bool l_shape, bool rtl, bool completable);
|
||||||
|
|
||||||
/// hide the cursor
|
/// hide the cursor
|
||||||
virtual void removeCursor();
|
virtual void removeCursor();
|
||||||
|
Loading…
Reference in New Issue
Block a user