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"
28 class CompleterItemDelegate;
29 class GuiCompletionModel;
31 class GuiCompleter : private QCompleter
37 GuiCompleter(GuiWorkArea * gui, QObject * parent = 0);
39 virtual ~GuiCompleter();
42 bool popupVisible() const;
44 bool inlineVisible() const;
46 bool popupPossible(Cursor const & cur) const;
48 bool inlinePossible(Cursor const & cur) const;
50 bool completionAvailable() const;
51 /// Activate the current completion, i.e. finalize it.
53 /// Do a completion as far as it is unique, but at least one character.
56 /// Update the visibility of the popup and the inline completion.
57 /// This method might set the update flags of the cursor to request
59 void updateVisibility(Cursor & cur, bool start, bool keep);
60 /// Update the visibility of the popup and the inline completion.
61 /// This method handles the redraw if needed.
62 void updateVisibility(bool start, bool keep);
64 QString currentCompletion() const;
66 docstring longestUniqueCompletion() const;
68 bool uniqueCompletionAvailable() const;
73 /// Show the inline completion.
78 /// Hide the inline completion.
83 void popupActivated(const QString & completion);
85 void popupHighlighted(const QString & completion);
87 void updateAvailability();
88 /// the asynchronous part of updatePopup(cur)
89 void asyncUpdatePopup();
90 /// the asynchronous part of hidePopup(cur)
91 void asyncHidePopup();
92 /// the asynchronous part of hideInline(cur)
93 void asyncHideInline();
97 void setCurrentCompletion(QString const & s);
99 void showPopup(Cursor const & cur);
101 void showInline(Cursor const & cur);
103 void hideInline(Cursor const & cur);
105 void updatePopup(Cursor const & cur);
107 void updateInline(Cursor const & cur, QString const & completion);
109 void updatePrefix(Cursor const & cur);
111 void updateModel(Cursor const & cur, bool popupUpdate, bool inlineUpdate);
113 bool eventFilter(QObject * watched, QEvent * event);
118 DocIterator old_cursor_;
122 QTimer inline_timer_;
124 QString last_selection_;
125 /// lock to stop updates of the inline completion
127 /// the BufferView::inlineCursorPos might be reset by destructive
128 /// operations like backspace. Hence, we have to keep this flag
129 /// in addition to know whether the completion is to be kept visible.
133 /// the model reset is asynchronous in hidePopup/Inline. So let's mark
134 /// a coming reset here by setting it to false.
137 CompleterItemDelegate * itemDelegate_;
139 GuiCompletionModel * model_;
142 } // namespace frontend
145 #endif // GUICOMPLETER_H