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 RtlItemDelegate;
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, bool cursorInView = true);
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;
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();
92 void asyncCompletePopup();
96 void setCurrentCompletion(QString const & s);
98 void showPopup(Cursor & cur);
100 void showInline(Cursor & cur);
102 void hidePopup(Cursor & cur);
104 void hideInline(Cursor & cur);
106 void updatePopup(Cursor & cur);
108 void updateInline(Cursor & cur, QString const & completion);
110 void updatePrefix(Cursor & cur);
112 void updateModel(Cursor & cur, bool popupUpdate, bool inlineUpdate);
114 bool eventFilter(QObject * watched, QEvent * event);
119 DocIterator old_cursor_;
123 QTimer inline_timer_;
125 QString last_selection_;
126 /// lock to stop updates of the inline completion
128 /// the BufferView::inlineCursorPos might be reset by destructive
129 /// operations like backspace. Hence, we have to keep this flag
130 /// in addition to know whether the completion is to be kept visible.
135 RtlItemDelegate * rtlItemDelegate_;
138 } // namespace frontend
141 #endif // GUICOMPLETER_H