]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiCompleter.h
Disable CheckTeX while buffer is processed
[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 "DocIterator.h"
16 #include "support/docstring.h"
17
18 #include <QCompleter>
19 #include <QTimer>
20
21 namespace lyx {
22
23 class Buffer;
24
25 namespace frontend {
26
27 class GuiWorkArea;
28 class CompleterItemDelegate;
29 class GuiCompletionModel;
30
31 class GuiCompleter : private QCompleter
32 {
33         Q_OBJECT
34
35 public:
36         ///
37         GuiCompleter(GuiWorkArea * gui, QObject * parent = 0);
38         ///
39         virtual ~GuiCompleter();
40
41         ///
42         bool popupVisible() const;
43         ///
44         bool inlineVisible() const;
45         ///
46         bool popupPossible(Cursor const & cur) const;
47         ///
48         bool inlinePossible(Cursor const & cur) const;
49         ///
50         bool completionAvailable() const;
51         /// Activate the current completion, i.e. finalize it.
52         void activate();
53         /// Do a completion as far as it is unique, but at least one character.
54         void tab();
55
56         /// Update the visibility of the popup and the inline completion.
57         /// This method might set the update flags of the cursor to request
58         /// a redraw.
59         void updateVisibility(Cursor & cur, bool start, bool keep);
60         /// Update the visibility of the popup and the inline completion.
61         /// This method handles the redraw if needed.
62         void updateVisibility(bool start, bool keep);
63         ///
64         QString currentCompletion() const;
65         ///
66         docstring longestUniqueCompletion() const;
67         ///
68         bool uniqueCompletionAvailable() const;
69
70 public Q_SLOTS:
71         /// Show the popup.
72         void showPopup();
73         /// Show the inline completion.
74         void showInline();
75
76         /// Hide the popup.
77         void hidePopup();
78         /// Hide the inline completion.
79         void hideInline();
80
81 private Q_SLOTS:
82         ///
83         void popupActivated(const QString & completion);
84         ///
85         void popupHighlighted(const QString & completion);
86         ///
87         void updateAvailability();
88         /// the asynchronous part of updatePopup(cur)
89         void asyncUpdatePopup();
90         /// the asynchronous part of hidePopup(cur)
91         void asyncHidePopup();
92         /// the asynchronous part of hideInline(cur)
93         void asyncHideInline();
94
95 private:
96         ///
97         void setCurrentCompletion(QString const & s);
98         ///
99         void showPopup(Cursor const & cur);
100         ///
101         void showInline(Cursor const & cur);
102         ///
103         void hideInline(Cursor const & cur);
104         ///
105         void updatePopup(Cursor const & cur);
106         ///
107         void updateInline(Cursor const & cur, QString const & completion);
108         ///
109         void updatePrefix(Cursor const & cur);
110         ///
111         void updateModel(Cursor const & cur, bool popupUpdate, bool inlineUpdate);
112         ///
113         bool eventFilter(QObject * watched, QEvent * event);
114
115         ///
116         GuiWorkArea * gui_;
117         ///
118         DocIterator old_cursor_;
119         ///
120         QTimer popup_timer_;
121         ///
122         QTimer inline_timer_;
123         ///
124         QString last_selection_;
125         /// lock to stop updates of the inline completion
126         int updateLock_;
127         /// the BufferView::inlineCursorPos might be reset by destructive
128         /// operations like backspace. Hence, we have to keep this flag
129         /// in addition to know whether the completion is to be kept visible.
130         bool inlineVisible_;
131         ///
132         bool popupVisible_;
133         /// the model reset is asynchronous in hidePopup/Inline. So let's mark
134         /// a coming reset here by setting it to false.
135         bool modelActive_;
136         ///
137         CompleterItemDelegate * itemDelegate_;
138         ///
139         GuiCompletionModel * model_;
140 }; // GuiCompleter
141
142 } // namespace frontend
143 } // namespace lyx
144
145 #endif // GUICOMPLETER_H