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 "frontends/WorkArea.h"
17 #include "DocIterator.h"
18 #include "FuncRequest.h"
19 #include "qt_helpers.h"
20 #include "support/docstring.h"
22 #include <QAbstractItemModel>
24 #include <QStringListModel>
34 class CompleterItemDelegate;
35 class GuiCompletionModel;
37 class GuiCompleter : private QCompleter
43 GuiCompleter(GuiWorkArea * gui, QObject * parent = 0);
45 virtual ~GuiCompleter();
48 bool popupVisible() const;
50 bool inlineVisible() const;
52 bool popupPossible(Cursor const & cur) const;
54 bool inlinePossible(Cursor const & cur) const;
56 bool completionAvailable() const;
57 /// Activate the current completion, i.e. finalize it.
59 /// Do a completion as far as it is unique, but at least one character.
62 /// Update the visibility of the popup and the inline completion.
63 /// This method might set the update flags of the cursor to request
65 void updateVisibility(Cursor & cur, bool start, bool keep, bool cursorInView = true);
66 /// Update the visibility of the popup and the inline completion.
67 /// This method handles the redraw if needed.
68 void updateVisibility(bool start, bool keep);
70 QString currentCompletion() const;
72 docstring longestUniqueCompletion() const;
74 bool uniqueCompletionAvailable() const;
79 /// Show the inline completion.
84 /// Hide the inline completion.
89 void popupActivated(const QString & completion);
91 void popupHighlighted(const QString & completion);
93 void updateAvailability();
94 /// the asynchronous part of updatePopup(cur)
95 void asyncUpdatePopup();
96 /// the asynchronous part of hidePopup(cur)
97 void asyncHidePopup();
98 /// the asynchronous part of hideInline(cur)
99 void asyncHideInline();
103 void setCurrentCompletion(QString const & s);
105 void showPopup(Cursor & cur);
107 void showInline(Cursor & cur);
109 void hidePopup(Cursor & cur);
111 void hideInline(Cursor & cur);
113 void updatePopup(Cursor & cur);
115 void updateInline(Cursor & cur, QString const & completion);
117 void updatePrefix(Cursor & cur);
119 void updateModel(Cursor & cur, bool popupUpdate, bool inlineUpdate);
121 bool eventFilter(QObject * watched, QEvent * event);
126 DocIterator old_cursor_;
130 QTimer inline_timer_;
132 QString last_selection_;
133 /// lock to stop updates of the inline completion
135 /// the BufferView::inlineCursorPos might be reset by destructive
136 /// operations like backspace. Hence, we have to keep this flag
137 /// in addition to know whether the completion is to be kept visible.
141 /// the model reset is asynchronous in hidePopup/Inline. So let's mark
142 /// a coming reset here by setting it to false.
145 CompleterItemDelegate * itemDelegate_;
147 GuiCompletionModel * model_;
150 } // namespace frontend
153 #endif // GUICOMPLETER_H