X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Ffrontends%2Fqt%2FGuiCompleter.cpp;h=661178575b1f860e2a71ce82bedd42dd5470456f;hb=8863d6d785358680d05b4b34b35ca09a15cccb82;hp=1c91fb78a609e89585f964817c2af56b2ac9946d;hpb=c293be56bd12c5dc46e5cedd2828e33918fccef7;p=lyx.git diff --git a/src/frontends/qt/GuiCompleter.cpp b/src/frontends/qt/GuiCompleter.cpp index 1c91fb78a6..661178575b 100644 --- a/src/frontends/qt/GuiCompleter.cpp +++ b/src/frontends/qt/GuiCompleter.cpp @@ -12,24 +12,26 @@ #include "GuiCompleter.h" +#include "GuiApplication.h" +#include "GuiWorkArea.h" +#include "GuiView.h" +#include "qt_helpers.h" + #include "Buffer.h" #include "BufferView.h" #include "CompletionList.h" #include "Cursor.h" #include "Dimension.h" -#include "GuiWorkArea.h" -#include "GuiView.h" #include "LyX.h" #include "LyXRC.h" #include "Paragraph.h" -#include "qt_helpers.h" #include "version.h" +#include "support/debug.h" #include "support/lassert.h" #include "support/lstrings.h" -#include "support/debug.h" +#include "support/qstring_helpers.h" -#include #include #include #include @@ -57,7 +59,7 @@ public: protected: void paint(QPainter *painter, const QStyleOptionViewItem &option, - const QModelIndex &index) const + const QModelIndex &index) const override { if (index.column() == 0) { QItemDelegate::paint(painter, option, index); @@ -105,12 +107,12 @@ public: return false; } /// - int columnCount(const QModelIndex & /*parent*/ = QModelIndex()) const + int columnCount(const QModelIndex & /*parent*/ = QModelIndex()) const override { return 2; } /// - int rowCount(const QModelIndex & /*parent*/ = QModelIndex()) const + int rowCount(const QModelIndex & /*parent*/ = QModelIndex()) const override { if (list_ == 0) return 0; @@ -118,7 +120,7 @@ public: } /// - QVariant data(const QModelIndex & index, int role) const + QVariant data(const QModelIndex & index, int role) const override { if (list_ == 0) return QVariant(); @@ -137,18 +139,18 @@ public: // get icon from cache QPixmap scaled; - QString const name = ":" + toqstr(list_->icon(index.row())); - if (name == ":") + QString const name = toqstr(list_->icon(index.row())); + if (name.isEmpty()) return scaled; - if (!QPixmapCache::find("completion" + name, scaled)) { + if (!QPixmapCache::find("completion:" + name, &scaled)) { // load icon from disk - QPixmap p = QPixmap(name); + QPixmap p = getPixmap("images", name, "svgz,png"); if (!p.isNull()) { // scale it to 16x16 or smaller scaled = p.scaled(min(16, p.width()), min(16, p.height()), Qt::KeepAspectRatio, Qt::SmoothTransformation); } - QPixmapCache::insert("completion" + name, scaled); + QPixmapCache::insert("completion:" + name, scaled); } return scaled; } @@ -346,8 +348,7 @@ void GuiCompleter::updateVisibility(bool start, bool keep) updateVisibility(cur, start, keep); - if (cur.result().screenUpdate()) - gui_->bufferView().processUpdateFlags(cur.result().screenUpdate()); + gui_->bufferView().processUpdateFlags(cur.result().screenUpdate()); } @@ -438,8 +439,8 @@ void GuiCompleter::asyncUpdatePopup() // get dimensions of completion prefix Dimension dim; - int x; - int y; + int x = 0; + int y = 0; cur.inset().completionPosAndDim(cur, x, y, dim); // and calculate the rect of the popup @@ -454,8 +455,8 @@ void GuiCompleter::asyncUpdatePopup() // has a bad memory about it and we have to tell him again and again. QTreeView * listView = static_cast(popup()); listView->header()->setStretchLastSection(false); - setSectionResizeMode(listView->header(), 0, QHeaderView::Stretch); - setSectionResizeMode(listView->header(), 1, QHeaderView::Fixed); + listView->header()->setSectionResizeMode(0, QHeaderView::Stretch); + listView->header()->setSectionResizeMode(1, QHeaderView::Fixed); listView->header()->resizeSection(1, 22); // show/update popup @@ -595,8 +596,7 @@ void GuiCompleter::showPopup() showPopup(cur); // redraw if needed - if (cur.result().screenUpdate()) - gui_->bufferView().processUpdateFlags(cur.result().screenUpdate()); + gui_->bufferView().processUpdateFlags(cur.result().screenUpdate()); } @@ -608,8 +608,7 @@ void GuiCompleter::showInline() showInline(cur); // redraw if needed - if (cur.result().screenUpdate()) - gui_->bufferView().processUpdateFlags(cur.result().screenUpdate()); + gui_->bufferView().processUpdateFlags(cur.result().screenUpdate()); } @@ -641,8 +640,7 @@ void GuiCompleter::hideInline() hideInline(cur); // redraw if needed - if (cur.result().screenUpdate()) - gui_->bufferView().processUpdateFlags(cur.result().screenUpdate()); + gui_->bufferView().processUpdateFlags(cur.result().screenUpdate()); } @@ -657,8 +655,8 @@ void GuiCompleter::activate() void GuiCompleter::tab() { - BufferView * bv = &gui_->bufferView(); - Cursor cur = bv->cursor(); + BufferView & bv = gui_->bufferView(); + Cursor cur = bv.cursor(); cur.screenUpdateFlags(Update::None); // check that inline completion is active @@ -684,9 +682,8 @@ void GuiCompleter::tab() return; } - // Make undo possible - UndoGroupHelper ugh; - cur.recordUndo(); + // Prepare for undo (recordUndo is invoked in the insets' insertCompletion methods) + UndoGroupHelper ugh(cur.buffer()); // If completion is active, at least complete by one character docstring prefix = cur.inset().completionPrefix(cur); @@ -699,6 +696,9 @@ void GuiCompleter::tab() hidePopup(); hideInline(cur); updateVisibility(false, false); + + // redraw if needed + bv.processUpdateFlags(cur.result().screenUpdate()); return; } docstring nextchar = completion.substr(prefix.size(), 1); @@ -710,8 +710,8 @@ void GuiCompleter::tab() docstring longestCompletion = longestUniqueCompletion(); prefix = cur.inset().completionPrefix(cur); docstring postfix = longestCompletion.substr(min(longestCompletion.size(), prefix.size())); - cur.inset().insertCompletion(cur, postfix, false); - old_cursor_ = bv->cursor(); + cur.inset().insertCompletion(cur, postfix, uniqueCompletionAvailable()); + old_cursor_ = bv.cursor(); updatePrefix(cur); // show popup without delay because the completion was not unique @@ -721,8 +721,7 @@ void GuiCompleter::tab() popup_timer_.start(0); // redraw if needed - if (cur.result().screenUpdate()) - gui_->bufferView().processUpdateFlags(cur.result().screenUpdate()); + bv.processUpdateFlags(cur.result().screenUpdate()); } @@ -889,8 +888,7 @@ void GuiCompleter::popupActivated(const QString & completion) hidePopup(); hideInline(cur); - if (cur.result().screenUpdate()) - gui_->bufferView().processUpdateFlags(cur.result().screenUpdate()); + gui_->bufferView().processUpdateFlags(cur.result().screenUpdate()); cur.endUndoGroup(); } @@ -906,8 +904,7 @@ void GuiCompleter::popupHighlighted(const QString & completion) if (inlineVisible()) updateInline(cur, completion); - if (cur.result().screenUpdate()) - gui_->bufferView().processUpdateFlags(cur.result().screenUpdate()); + gui_->bufferView().processUpdateFlags(cur.result().screenUpdate()); } } // namespace frontend