]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiCompleter.h
Add a function to translate QStrings
[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 <QCompleter>
22 #include <QTimer>
23
24 namespace lyx {
25
26 class Buffer;
27
28 namespace frontend {
29
30 class GuiWorkArea;
31 class CompleterItemDelegate;
32 class GuiCompletionModel;
33
34 class GuiCompleter : private QCompleter
35 {
36         Q_OBJECT
37
38 public:
39         ///
40         GuiCompleter(GuiWorkArea * gui, QObject * parent = 0);
41         ///
42         virtual ~GuiCompleter();
43
44         ///
45         bool popupVisible() const;
46         ///
47         bool inlineVisible() const;
48         ///
49         bool popupPossible(Cursor const & cur) const;
50         ///
51         bool inlinePossible(Cursor const & cur) const;
52         ///
53         bool completionAvailable() 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);
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         bool uniqueCompletionAvailable() const;
72         
73 public Q_SLOTS:
74         /// Show the popup.
75         void showPopup();
76         /// Show the inline completion.
77         void showInline();
78
79         /// Hide the popup.
80         void hidePopup();
81         /// Hide the inline completion.
82         void hideInline();
83
84 private Q_SLOTS:
85         ///
86         void popupActivated(const QString & completion);
87         ///
88         void popupHighlighted(const QString & completion);
89         ///
90         void updateAvailability();
91         /// the asynchronous part of updatePopup(cur)
92         void asyncUpdatePopup();
93         /// the asynchronous part of hidePopup(cur)
94         void asyncHidePopup();
95         /// the asynchronous part of hideInline(cur)
96         void asyncHideInline();
97         
98 private:
99         ///
100         void setCurrentCompletion(QString const & s);
101         ///
102         void showPopup(Cursor const & cur);
103         ///
104         void showInline(Cursor const & cur);
105         ///
106         void hideInline(Cursor const & cur);
107         ///
108         void updatePopup(Cursor const & cur);
109         ///
110         void updateInline(Cursor const & cur, QString const & completion);
111         ///
112         void updatePrefix(Cursor const & cur);
113         ///
114         void updateModel(Cursor const & cur, bool popupUpdate, bool inlineUpdate);
115         ///
116         bool eventFilter(QObject * watched, QEvent * event);
117
118         ///
119         GuiWorkArea * gui_;
120         ///
121         DocIterator old_cursor_;
122         ///
123         QTimer popup_timer_;
124         ///
125         QTimer inline_timer_;
126         ///
127         QString last_selection_;
128         /// lock to stop updates of the inline completion
129         int updateLock_;
130         /// the BufferView::inlineCursorPos might be reset by destructive
131         /// operations like backspace. Hence, we have to keep this flag
132         /// in addition to know whether the completion is to be kept visible.
133         bool inlineVisible_;
134         ///
135         bool popupVisible_;
136         /// the model reset is asynchronous in hidePopup/Inline. So let's mark
137         /// a coming reset here by setting it to false.
138         bool modelActive_;
139         ///
140         CompleterItemDelegate * itemDelegate_;
141         ///
142         GuiCompletionModel * model_;
143 }; // GuiCompleter
144
145 } // namespace frontend
146 } // namespace lyx
147
148 #endif // GUICOMPLETER_H