]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/GuiCompleter.cpp
Remove special code for Qt5 to manage HiDPI. It's not needed anymore and leads to...
[lyx.git] / src / frontends / qt4 / GuiCompleter.cpp
index 06ed395221ddec7e2e2f611b57cb9a902e88a05a..0f974f1d97f9016dca9b6b1652a49d23f76ba7e5 100644 (file)
 #include "LyX.h"
 #include "LyXRC.h"
 #include "Paragraph.h"
+#include "qt_helpers.h"
 #include "version.h"
 
 #include "support/lassert.h"
+#include "support/lstrings.h"
 #include "support/debug.h"
 
 #include <QApplication>
@@ -90,9 +92,10 @@ public:
        ~GuiCompletionModel() { delete list_; }
        ///
        void setList(CompletionList const * l) {
+               beginResetModel();
                delete list_;
                list_ = l;
-               reset();
+               endResetModel();
        }
        ///
        bool sorted() const
@@ -135,6 +138,8 @@ public:
                // get icon from cache
                QPixmap scaled;
                QString const name = ":" + toqstr(list_->icon(index.row()));
+               if (name == ":")
+                       return scaled;
                if (!QPixmapCache::find("completion" + name, scaled)) {
                        // load icon from disk
                        QPixmap p = QPixmap(name);
@@ -297,7 +302,7 @@ void GuiCompleter::updateVisibility(Cursor & cur, bool start, bool keep)
 
        // we moved or popup state is not ok for popup?
        if ((moved && !keep) || !possiblePopupState)
-               hidePopup(cur);
+               hidePopup();
 
        // we moved or inline state is not ok for inline completion?
        if ((moved && !keep) || !possibleInlineState)
@@ -390,9 +395,9 @@ void GuiCompleter::updateInline(Cursor const & cur, QString const & completion)
        docstring postfix = qstring_to_ucs4(completion.mid(prefix.length()));
        
        // shorten it if necessary
-       if (lyxrc.completion_inline_dots != -1
-           && postfix.size() > unsigned(lyxrc.completion_inline_dots))
-               postfix = postfix.substr(0, lyxrc.completion_inline_dots - 1) + "...";
+       if (lyxrc.completion_inline_dots != -1)
+               support::truncateWithEllipsis(postfix,
+                                                                         unsigned(lyxrc.completion_inline_dots));
 
        // set inline completion at cursor position
        size_t uniqueTo = max(longestUniqueCompletion().size(), prefix.size());
@@ -444,8 +449,8 @@ void GuiCompleter::asyncUpdatePopup()
        // has a bad memory about it and we have to tell him again and again.
        QTreeView * listView = static_cast<QTreeView *>(popup());
        listView->header()->setStretchLastSection(false);
-       listView->header()->setResizeMode(0, QHeaderView::Stretch);
-       listView->header()->setResizeMode(1, QHeaderView::Fixed);
+       setSectionResizeMode(listView->header(), 0, QHeaderView::Stretch);
+       setSectionResizeMode(listView->header(), 1, QHeaderView::Fixed);
        listView->header()->resizeSection(1, 22);
        
        // show/update popup
@@ -530,26 +535,6 @@ void GuiCompleter::showPopup(Cursor const & cur)
 }
 
 
-void GuiCompleter::hidePopup(Cursor &)
-{
-       popupVisible_ = false;
-
-       if (popup_timer_.isActive())
-               popup_timer_.stop();
-
-       // hide popup asynchronously because we might be here inside of
-       // LFUN dispatchers. Hiding a popup can trigger a focus event on the 
-       // workarea which then redisplays the cursor. But the metrics are not
-       // yet up to date such that the coord cache has not all insets yet. The
-       // cursorPos methods would triggers asserts in the coord cache then.
-       QTimer::singleShot(0, this, SLOT(asyncHidePopup()));
-       
-       // mark that the asynchronous part will reset the model
-       if (!inlineVisible())
-               modelActive_ = false;
-}
-
-
 void GuiCompleter::asyncHidePopup()
 {
        popup()->hide();
@@ -621,14 +606,21 @@ void GuiCompleter::showInline()
 
 void GuiCompleter::hidePopup()
 {
-       Cursor cur = gui_->bufferView().cursor();
-       cur.screenUpdateFlags(Update::None);
-       
-       hidePopup(cur);
+       popupVisible_ = false;
+
+       if (popup_timer_.isActive())
+               popup_timer_.stop();
+
+       // hide popup asynchronously because we might be here inside of
+       // LFUN dispatchers. Hiding a popup can trigger a focus event on the
+       // workarea which then redisplays the cursor. But the metrics are not
+       // yet up to date such that the coord cache has not all insets yet. The
+       // cursorPos methods would triggers asserts in the coord cache then.
+       QTimer::singleShot(0, this, SLOT(asyncHidePopup()));
        
-       // redraw if needed
-       if (cur.result().screenUpdate())
-               gui_->bufferView().processUpdateFlags(cur.result().screenUpdate());
+       // mark that the asynchronous part will reset the model
+       if (!inlineVisible())
+               modelActive_ = false;
 }
 
 
@@ -695,7 +687,7 @@ void GuiCompleter::tab()
                cur.inset().insertCompletion(cur, docstring(), true);
                
                // hide popup and inline completion
-               hidePopup(cur);
+               hidePopup();
                hideInline(cur);
                updateVisibility(false, false);
                cur.endUndoGroup();
@@ -799,7 +791,8 @@ void GuiCompleter::setCurrentCompletion(QString const & s)
                        i = n;
                else
                        i = l;
-               LASSERT(i <= n, /**/);
+               // we can try to recover
+               LASSERT(i <= n, i = 0);
        }
 
        // select the first if none was found
@@ -888,7 +881,7 @@ void GuiCompleter::popupActivated(const QString & completion)
        docstring prefix = cur.inset().completionPrefix(cur);
        docstring postfix = qstring_to_ucs4(completion.mid(prefix.length()));
        cur.inset().insertCompletion(cur, postfix, true);
-       hidePopup(cur);
+       hidePopup();
        hideInline(cur);
        
        if (cur.result().screenUpdate())