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"
31 class CompleterItemDelegate;
32 class GuiCompletionModel;
34 class GuiCompleter : private QCompleter
40 GuiCompleter(GuiWorkArea * gui, QObject * parent = 0);
42 virtual ~GuiCompleter();
45 bool popupVisible() const;
47 bool inlineVisible() const;
49 bool popupPossible(Cursor const & cur) const;
51 bool inlinePossible(Cursor const & cur) const;
53 bool completionAvailable() const;
54 /// Activate the current completion, i.e. finalize it.
56 /// Do a completion as far as it is unique, but at least one character.
59 /// Update the visibility of the popup and the inline completion.
60 /// This method might set the update flags of the cursor to request
62 void updateVisibility(Cursor & cur, bool start, bool keep);
63 /// Update the visibility of the popup and the inline completion.
64 /// This method handles the redraw if needed.
65 void updateVisibility(bool start, bool keep);
67 QString currentCompletion() const;
69 docstring longestUniqueCompletion() const;
71 bool uniqueCompletionAvailable() const;
76 /// Show the inline completion.
81 /// Hide the inline completion.
86 void popupActivated(const QString & completion);
88 void popupHighlighted(const QString & completion);
90 void updateAvailability();
91 /// the asynchronous part of updatePopup(cur)
92 void asyncUpdatePopup();
93 /// the asynchronous part of hidePopup(cur)
94 void asyncHidePopup();
95 /// the asynchronous part of hideInline(cur)
96 void asyncHideInline();
100 void setCurrentCompletion(QString const & s);
102 void showPopup(Cursor const & cur);
104 void showInline(Cursor const & cur);
106 void hideInline(Cursor const & cur);
108 void updatePopup(Cursor const & cur);
110 void updateInline(Cursor const & cur, QString const & completion);
112 void updatePrefix(Cursor const & cur);
114 void updateModel(Cursor const & cur, bool popupUpdate, bool inlineUpdate);
116 bool eventFilter(QObject * watched, QEvent * event);
121 DocIterator old_cursor_;
125 QTimer inline_timer_;
127 QString last_selection_;
128 /// lock to stop updates of the inline completion
130 /// the BufferView::inlineCursorPos might be reset by destructive
131 /// operations like backspace. Hence, we have to keep this flag
132 /// in addition to know whether the completion is to be kept visible.
136 /// the model reset is asynchronous in hidePopup/Inline. So let's mark
137 /// a coming reset here by setting it to false.
140 CompleterItemDelegate * itemDelegate_;
142 GuiCompletionModel * model_;
145 } // namespace frontend
148 #endif // GUICOMPLETER_H