]> git.lyx.org Git - features.git/commitdiff
* small indicator in the cursor to show that a completion is available by pressing tab
authorStefan Schimanski <sts@lyx.org>
Thu, 28 Feb 2008 12:41:57 +0000 (12:41 +0000)
committerStefan Schimanski <sts@lyx.org>
Thu, 28 Feb 2008 12:41:57 +0000 (12:41 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@23313 a592a061-630c-0410-9148-cb99ea01b6c8

src/frontends/qt4/GuiCompleter.cpp
src/frontends/qt4/GuiCompleter.h
src/frontends/qt4/GuiWorkArea.cpp

index 1eafa25fa4b6688e72f24837fd7d0fbf45ca2b5a..b5c223c1f9b774050b72e72f96464f6e2590b848 100644 (file)
@@ -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
index 36d3d14597a2f9305db514f6c6f545dee3a26998..b53220c16124c579397bd75414af02fcd09dd603 100644 (file)
@@ -86,6 +86,8 @@ private Q_SLOTS:
        void popupActivated(const QString & completion);
        ///
        void popupHighlighted(const QString & completion);
+       ///
+       void updateAvailability();
        
 private:
        ///
index 9ba9bfcf992a6fa170347a518c25e049d34ed064..bbd653397ce07047aa0d409973d18034e34c85a8 100644 (file)
@@ -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);