]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiCompleter.h
* escape hides the completion
[lyx.git] / src / frontends / qt4 / GuiCompleter.h
1 // -*- C++ -*-
2 /**
3  * \file GuiCompleter.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Stefan Schimanski
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #ifndef GUICOMPLETER_H
13 #define GUICOMPLETER_H
14
15 #include "frontends/WorkArea.h"
16
17 #include "DocIterator.h"
18 #include "FuncRequest.h"
19 #include "qt_helpers.h"
20 #include "support/docstring.h"
21
22 #include <QAbstractItemModel>
23 #include <QCompleter>
24 #include <QStringListModel>
25 #include <QTimer>
26
27 namespace lyx {
28
29 class Buffer;
30
31 namespace frontend {
32
33 class GuiWorkArea;
34 class RtlItemDelegate;
35
36 class GuiCompleter : private QCompleter
37 {
38         Q_OBJECT
39
40 public:
41         ///
42         GuiCompleter(GuiWorkArea * gui, QObject * parent = 0);
43         ///
44         virtual ~GuiCompleter();
45
46         ///
47         bool popupVisible() const;
48         ///
49         bool inlineVisible() const;
50         ///
51         bool popupPossible(Cursor const & cur) const;
52         ///
53         bool inlinePossible(Cursor const & cur) const;
54         /// Activate the current completion, i.e. finalize it.
55         void activate();
56         /// Do a completion as far as it is unique, but at least one character.
57         void tab();
58         
59         /// Update the visibility of the popup and the inline completion.
60         /// This method might set the update flags of the cursor to request
61         /// a redraw.
62         void updateVisibility(Cursor & cur, bool start, bool keep, bool cursorInView = true);
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);
66         ///
67         QString currentCompletion() const;
68         ///
69         docstring longestUniqueCompletion() const;
70         
71 public Q_SLOTS:
72         /// Show the popup.
73         void showPopup();
74         /// Show the inline completion.
75         void showInline();
76
77         /// Hide the popup.
78         void hidePopup();
79         /// Hide the inline completion.
80         void hideInline();
81
82 private Q_SLOTS:
83         ///
84         void popupActivated(const QString & completion);
85         ///
86         void popupHighlighted(const QString & completion);
87         
88 private:
89         ///
90         void setCurrentCompletion(QString const & s);
91         ///
92         void showPopup(Cursor & cur);
93         ///
94         void showInline(Cursor & cur);
95         ///
96         void hidePopup(Cursor & cur);
97         ///
98         void hideInline(Cursor & cur);
99         ///
100         void updatePopup(Cursor & cur);
101         ///
102         void updateInline(Cursor & cur, QString const & completion);
103         ///
104         void updatePrefix(Cursor & cur);
105         ///
106         void updateModel(Cursor & cur, bool popupUpdate, bool inlineUpdate);
107         ///
108         bool eventFilter(QObject * watched, QEvent * event);
109
110         ///
111         GuiWorkArea * gui_;
112         ///
113         DocIterator old_cursor_;
114         ///
115         QTimer popup_timer_;
116         ///
117         QTimer inline_timer_;
118         ///
119         QString last_selection_;
120         /// lock to stop updates of the inline completion
121         int updateLock_;
122         /// the BufferView::inlineCursorPos might be reset by destructive
123         /// operations like backspace. Hence, we have to keep this flag
124         /// in addition to know whether the completion is to be kept visible.
125         bool inlineVisible_;
126         ///
127         RtlItemDelegate * rtlItemDelegate_;
128 }; // GuiCompleter
129
130 } // namespace frontend
131 } // namespace lyx
132
133 #endif // GUICOMPLETER_H