4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
7 * \author Stefan Schimanski
9 * Full author contact details are available in file CREDITS.
12 #ifndef GUICOMPLETER_H
13 #define GUICOMPLETER_H
15 #include "DocIterator.h"
16 #include "support/docstring.h"
26 class CompleterItemDelegate;
27 class GuiCompletionModel;
29 class GuiCompleter : private QCompleter
35 GuiCompleter(GuiWorkArea * gui, QObject * parent = 0);
37 virtual ~GuiCompleter();
40 bool popupVisible() const;
42 bool inlineVisible() const;
44 bool popupPossible(Cursor const & cur) const;
46 bool inlinePossible(Cursor const & cur) const;
48 bool completionAvailable() const;
49 /// Activate the current completion, i.e. finalize it.
51 /// Do a completion as far as it is unique, but at least one character.
54 /// Update the visibility of the popup and the inline completion.
55 /// This method might set the update flags of the cursor to request
57 void updateVisibility(Cursor & cur, bool start, bool keep);
58 /// Update the visibility of the popup and the inline completion.
59 /// This method handles the redraw if needed.
60 void updateVisibility(bool start, bool keep);
62 QString currentCompletion() const;
64 docstring longestUniqueCompletion() const;
66 bool uniqueCompletionAvailable() const;
71 /// Show the inline completion.
76 /// Hide the inline completion.
81 void popupActivated(const QString & completion);
83 void popupHighlighted(const QString & completion);
85 void updateAvailability();
86 /// the asynchronous part of updatePopup(cur)
87 void asyncUpdatePopup();
88 /// the asynchronous part of hidePopup(cur)
89 void asyncHidePopup();
90 /// the asynchronous part of hideInline(cur)
91 void asyncHideInline();
95 void setCurrentCompletion(QString const & s);
97 void showPopup(Cursor const & cur);
99 void showInline(Cursor const & cur);
101 void hideInline(Cursor const & cur);
103 void updatePopup(Cursor const & cur);
105 void updateInline(Cursor const & cur, QString const & completion);
107 void updatePrefix(Cursor const & cur);
109 void updateModel(Cursor const & cur, bool popupUpdate, bool inlineUpdate);
111 bool eventFilter(QObject * watched, QEvent * event) override;
116 DocIterator old_cursor_;
120 QTimer inline_timer_;
122 QString last_selection_;
123 /// lock to stop updates of the inline completion
125 /// the BufferView::inlineCursorPos might be reset by destructive
126 /// operations like backspace. Hence, we have to keep this flag
127 /// in addition to know whether the completion is to be kept visible.
131 /// the model reset is asynchronous in hidePopup/Inline. So let's mark
132 /// a coming reset here by setting it to false.
135 CompleterItemDelegate * itemDelegate_;
137 GuiCompletionModel * model_;
140 } // namespace frontend
143 #endif // GUICOMPLETER_H