]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/GuiCompleter.cpp
* completion cursor
[lyx.git] / src / frontends / qt4 / GuiCompleter.cpp
index df061cb9401b1dbfb7a9d43231c1b828610c09f0..1eafa25fa4b6688e72f24837fd7d0fbf45ca2b5a 100644 (file)
@@ -130,9 +130,10 @@ public:
                if (role != Qt::DisplayRole && role != Qt::EditRole)
                    return QVariant();
                    
-               if (index.column() == 0)
-                       return toqstr(list_->data(index.row()));
-               else if (index.column() == 1) {
+               if (index.column() == 0) {
+                       docstring const word = list_->data(index.row());
+                       return toqstr(word);
+               } else if (index.column() == 1) {
                        // get icon from cache
                        QPixmap scaled;
                        QString const name = ":" + toqstr(list_->icon(index.row()));
@@ -233,6 +234,12 @@ bool GuiCompleter::inlinePossible(Cursor const & cur) const
 }
 
 
+bool GuiCompleter::completionAvailable() const
+{
+       return popup()->model()->rowCount() > 0;
+}
+
+
 bool GuiCompleter::popupVisible() const
 {
        return popup()->isVisible();
@@ -378,9 +385,10 @@ void GuiCompleter::updatePopup(Cursor & cur)
                rect = QRect(x, y - dim.ascent() - 3, 200, dim.height() + 6);
        
        // show/update popup
-       complete(rect);
        QTreeView * p = static_cast<QTreeView *>(popup());
        p->setColumnWidth(0, popup()->width() - 22 - p->verticalScrollBar()->width());
+
+       complete(rect);
 }
 
 
@@ -453,6 +461,9 @@ void GuiCompleter::hidePopup(Cursor & cur)
        popup()->hide();
        if (popup_timer_.isActive())
                popup_timer_.stop();
+       
+       if (!inlineVisible())
+               setModel(new GuiCompletionModel(this, 0));
 }
 
 
@@ -469,6 +480,9 @@ void GuiCompleter::hideInline(Cursor & cur)
 {
        gui_->bufferView().setInlineCompletion(cur, DocIterator(), docstring());
        inlineVisible_ = false;
+       
+       if (!popupVisible())
+               setModel(new GuiCompletionModel(this, 0));
 }