From 399ef7f80c8775822a84993b31c78a184035d641 Mon Sep 17 00:00:00 2001 From: Stefan Schimanski Date: Thu, 28 Feb 2008 12:41:57 +0000 Subject: [PATCH] * small indicator in the cursor to show that a completion is available by pressing tab git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@23313 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/frontends/qt4/GuiCompleter.cpp | 35 +++++++++++++++++--- src/frontends/qt4/GuiCompleter.h | 2 ++ src/frontends/qt4/GuiWorkArea.cpp | 52 +++++++++++++++++------------- 3 files changed, 62 insertions(+), 27 deletions(-) diff --git a/src/frontends/qt4/GuiCompleter.cpp b/src/frontends/qt4/GuiCompleter.cpp index 1eafa25fa4..b5c223c1f9 100644 --- a/src/frontends/qt4/GuiCompleter.cpp +++ b/src/frontends/qt4/GuiCompleter.cpp @@ -236,7 +236,14 @@ bool GuiCompleter::inlinePossible(Cursor const & cur) const bool GuiCompleter::completionAvailable() const { - return popup()->model()->rowCount() > 0; + size_t n = popup()->model()->rowCount(); + + // if there is exactly one, we have to check whether it is a + // real completion, i.e. longer than the current prefix. + if (n == 1 && completionPrefix() == currentCompletion()) + return false; + + return n > 0; } @@ -286,10 +293,14 @@ void GuiCompleter::updateVisibility(Cursor & cur, bool start, bool keep, bool cu && cur.inset().automaticInlineCompletion()) inline_timer_.start(int(lyxrc.completion_inline_delay * 1000)); - // update prefix if popup is visible or if it will be visible soon - if (popupVisible() || inlineVisible() - || popup_timer_.isActive() || inline_timer_.isActive()) - updatePrefix(cur); + // update prefix if any completion is possible + bool modelActive = model()->rowCount() > 0; + if (possiblePopupState || possibleInlineState) { + if (modelActive) + updatePrefix(cur); + else + updateAvailability(); + } } @@ -392,6 +403,20 @@ void GuiCompleter::updatePopup(Cursor & cur) } +void GuiCompleter::updateAvailability() +{ + // this should really only be of interest if no completion is + // visible yet, i.e. especially if automatic completion is disabled. + if (inlineVisible() || popupVisible()) + return; + Cursor & cur = gui_->bufferView().cursor(); + if (!popupPossible(cur) && !inlinePossible(cur)) + return; + + updateModel(cur, false, false); +} + + void GuiCompleter::updateModel(Cursor & cur, bool popupUpdate, bool inlineUpdate) { // value which should be kept selected diff --git a/src/frontends/qt4/GuiCompleter.h b/src/frontends/qt4/GuiCompleter.h index 36d3d14597..b53220c161 100644 --- a/src/frontends/qt4/GuiCompleter.h +++ b/src/frontends/qt4/GuiCompleter.h @@ -86,6 +86,8 @@ private Q_SLOTS: void popupActivated(const QString & completion); /// void popupHighlighted(const QString & completion); + /// + void updateAvailability(); private: /// diff --git a/src/frontends/qt4/GuiWorkArea.cpp b/src/frontends/qt4/GuiWorkArea.cpp index 9ba9bfcf99..bbd653397c 100644 --- a/src/frontends/qt4/GuiWorkArea.cpp +++ b/src/frontends/qt4/GuiWorkArea.cpp @@ -68,7 +68,7 @@ int const CursorWidth = 2; #else int const CursorWidth = 1; #endif -int const TabIndicatorWidth = 4; +int const TabIndicatorWidth = 3; #undef KeyPress #undef NoModifier @@ -125,29 +125,33 @@ public: if (!show_ || !rect_.isValid()) return; + int y = rect_.top(); int l = x_ - rect_.left(); int r = rect_.right() - x_; - int h = rect_.height(); + int bot = rect_.bottom(); - painter.fillRect(x_, y_, CursorWidth, h, color_); + // draw vertica linel + painter.fillRect(x_, y, CursorWidth, rect_.height(), color_); + + // draw RTL/LTR indication painter.setPen(color_); if (l_shape_) { if (rtl_) - painter.drawLine(x_, y_ + h, x_ - l, y_ + h); + painter.drawLine(x_, bot, x_ - l, bot); else - painter.drawLine(x_ + CursorWidth, y_ + h, - x_ + CursorWidth + r, y_ + h); + painter.drawLine(x_, bot, x_ + CursorWidth + r, bot); } + // draw completion triangle if (completable_) { - int m = y_ + h / 2; + int m = y + rect_.height() / 2; int d = TabIndicatorWidth - 1; if (rtl_) { - painter.drawLine(x_ - 1 , m - d, x_ - d - 1, m); - painter.drawLine(x_ - 1 , m + d, x_ - d - 1, m); + painter.drawLine(x_ - 1, m - d, x_ - 1 - d, m); + painter.drawLine(x_ - 1, m + d, x_ - 1 - d, m); } else { - painter.drawLine(x_ + CursorWidth , m - d, x_ + d + CursorWidth, m); - painter.drawLine(x_ + CursorWidth , m + d, x_ + d + CursorWidth, m); + painter.drawLine(x_ + CursorWidth, m - d, x_ + CursorWidth + d, m); + painter.drawLine(x_ + CursorWidth, m + d, x_ + CursorWidth + d, m); } } } @@ -160,10 +164,12 @@ public: rtl_ = rtl; completable_ = completable; x_ = x; - y_ = y; + + // extension to left and right int l = 0; int r = 0; + // RTL/LTR indication if (l_shape_) { if (rtl) l += h / 3; @@ -171,13 +177,15 @@ public: r += h / 3; } + // completion triangle if (completable_) { if (rtl) - l = max(r, TabIndicatorWidth); + l = max(l, TabIndicatorWidth); else - r = max(l, TabIndicatorWidth); + r = max(r, TabIndicatorWidth); } + // compute overall rectangle rect_ = QRect(x - l, y, CursorWidth + r + l, h); } @@ -187,22 +195,20 @@ public: QRect const & rect() { return rect_; } private: - /// + /// cursor is in RTL or LTR text bool rtl_; - /// + /// indication for RTL or LTR bool l_shape_; - /// + /// triangle to show that a completion is available bool completable_; /// bool show_; /// QColor color_; - /// + /// rectangle, possibly with l_shape and completion triangle QRect rect_; - /// + /// x position (were the vertical line is drawn) int x_; - /// - int y_; }; @@ -487,7 +493,9 @@ void GuiWorkArea::showCursor() cursorInView = false; // show cursor on screen - bool completable = completer_.completionAvailable(); + bool completable = completer_.completionAvailable() + && !completer_.popupVisible() + && !completer_.inlineVisible(); if (cursorInView) { cursor_visible_ = true; showCursor(x, y, h, l_shape, isrtl, completable);