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