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;
77 /// Show the inline completion.
82 /// Hide the inline completion.
87 void popupActivated(const QString & completion);
89 void popupHighlighted(const QString & completion);
91 void updateAvailability();
92 /// the asynchronous part of updatePopup(cur)
93 void asyncUpdatePopup();
94 /// the asynchronous part of hidePopup(cur)
95 void asyncHidePopup();
96 /// the asynchronous part of hideInline(cur)
97 void asyncHideInline();
101 void setCurrentCompletion(QString const & s);
103 void showPopup(Cursor & cur);
105 void showInline(Cursor & cur);
107 void hidePopup(Cursor & cur);
109 void hideInline(Cursor & cur);
111 void updatePopup(Cursor & cur);
113 void updateInline(Cursor & cur, QString const & completion);
115 void updatePrefix(Cursor & cur);
117 void updateModel(Cursor & cur, bool popupUpdate, bool inlineUpdate);
119 bool eventFilter(QObject * watched, QEvent * event);
124 DocIterator old_cursor_;
128 QTimer inline_timer_;
130 QString last_selection_;
131 /// lock to stop updates of the inline completion
133 /// the BufferView::inlineCursorPos might be reset by destructive
134 /// operations like backspace. Hence, we have to keep this flag
135 /// in addition to know whether the completion is to be kept visible.
139 /// the model reset is asynchronous in hidePopup/Inline. So let's mark
140 /// a coming reset here by setting it to false.
143 CompleterItemDelegate * itemDelegate_;
145 GuiCompletionModel * model_;
148 } // namespace frontend
151 #endif // GUICOMPLETER_H