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 "qt_helpers.h"
19 #include "support/docstring.h"
21 #include <QAbstractItemModel>
23 #include <QStringListModel>
33 class CompleterItemDelegate;
34 class GuiCompletionModel;
36 class GuiCompleter : private QCompleter
42 GuiCompleter(GuiWorkArea * gui, QObject * parent = 0);
44 virtual ~GuiCompleter();
47 bool popupVisible() const;
49 bool inlineVisible() const;
51 bool popupPossible(Cursor const & cur) const;
53 bool inlinePossible(Cursor const & cur) const;
55 bool completionAvailable() const;
56 /// Activate the current completion, i.e. finalize it.
58 /// Do a completion as far as it is unique, but at least one character.
61 /// Update the visibility of the popup and the inline completion.
62 /// This method might set the update flags of the cursor to request
64 void updateVisibility(Cursor & cur, bool start, bool keep);
65 /// Update the visibility of the popup and the inline completion.
66 /// This method handles the redraw if needed.
67 void updateVisibility(bool start, bool keep);
69 QString currentCompletion() const;
71 docstring longestUniqueCompletion() const;
73 bool uniqueCompletionAvailable() const;
78 /// Show the inline completion.
83 /// Hide the inline completion.
88 void popupActivated(const QString & completion);
90 void popupHighlighted(const QString & completion);
92 void updateAvailability();
93 /// the asynchronous part of updatePopup(cur)
94 void asyncUpdatePopup();
95 /// the asynchronous part of hidePopup(cur)
96 void asyncHidePopup();
97 /// the asynchronous part of hideInline(cur)
98 void asyncHideInline();
102 void setCurrentCompletion(QString const & s);
104 void showPopup(Cursor const & cur);
106 void showInline(Cursor const & cur);
108 void hidePopup(Cursor & cur);
110 void hideInline(Cursor const & cur);
112 void updatePopup(Cursor const & cur);
114 void updateInline(Cursor const & cur, QString const & completion);
116 void updatePrefix(Cursor const & cur);
118 void updateModel(Cursor const & cur, bool popupUpdate, bool inlineUpdate);
120 bool eventFilter(QObject * watched, QEvent * event);
125 DocIterator old_cursor_;
129 QTimer inline_timer_;
131 QString last_selection_;
132 /// lock to stop updates of the inline completion
134 /// the BufferView::inlineCursorPos might be reset by destructive
135 /// operations like backspace. Hence, we have to keep this flag
136 /// in addition to know whether the completion is to be kept visible.
140 /// the model reset is asynchronous in hidePopup/Inline. So let's mark
141 /// a coming reset here by setting it to false.
144 CompleterItemDelegate * itemDelegate_;
146 GuiCompletionModel * model_;
149 } // namespace frontend
152 #endif // GUICOMPLETER_H