]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiCompleter.h
46f9a15878a16c5c3a115564fc3a0809d280b56c
[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 public Q_SLOTS:
75         /// Show the popup.
76         void showPopup();
77         /// Show the inline completion.
78         void showInline();
79
80         /// Hide the popup.
81         void hidePopup();
82         /// Hide the inline completion.
83         void hideInline();
84
85 private Q_SLOTS:
86         ///
87         void popupActivated(const QString & completion);
88         ///
89         void popupHighlighted(const QString & completion);
90         ///
91         void updateAvailability();
92         /// the asynchronous part of updatePopup(cur)
93         void asyncUpdatePopup();
94         /// the asynchronous part of hidePopup(cur)
95         void asyncHidePopup();
96         /// the asynchronous part of hideInline(cur)
97         void asyncHideInline();
98         
99 private:
100         ///
101         void setCurrentCompletion(QString const & s);
102         ///
103         void showPopup(Cursor & cur);
104         ///
105         void showInline(Cursor & cur);
106         ///
107         void hidePopup(Cursor & cur);
108         ///
109         void hideInline(Cursor & cur);
110         ///
111         void updatePopup(Cursor & cur);
112         ///
113         void updateInline(Cursor & cur, QString const & completion);
114         ///
115         void updatePrefix(Cursor & cur);
116         ///
117         void updateModel(Cursor & cur, bool popupUpdate, bool inlineUpdate);
118         ///
119         bool eventFilter(QObject * watched, QEvent * event);
120
121         ///
122         GuiWorkArea * gui_;
123         ///
124         DocIterator old_cursor_;
125         ///
126         QTimer popup_timer_;
127         ///
128         QTimer inline_timer_;
129         ///
130         QString last_selection_;
131         /// lock to stop updates of the inline completion
132         int updateLock_;
133         /// the BufferView::inlineCursorPos might be reset by destructive
134         /// operations like backspace. Hence, we have to keep this flag
135         /// in addition to know whether the completion is to be kept visible.
136         bool inlineVisible_;
137         ///
138         bool popupVisible_;
139         /// the model reset is asynchronous in hidePopup/Inline. So let's mark
140         /// a coming reset here by setting it to false.
141         bool modelActive_;
142         ///
143         CompleterItemDelegate * itemDelegate_;
144         ///
145         GuiCompletionModel * model_;
146 }; // GuiCompleter
147
148 } // namespace frontend
149 } // namespace lyx
150
151 #endif // GUICOMPLETER_H