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