]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiCompleter.h
* factored out hidePopup and hideInline
[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 RtlItemDelegate;
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         /// 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, bool cursorInView = true);
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 public Q_SLOTS:
72         /// Show the popup.
73         void showPopup();
74         /// Show the inline completion.
75         void showInline();
76
77 private Q_SLOTS:
78         ///
79         void popupActivated(const QString & completion);
80         ///
81         void popupHighlighted(const QString & completion);
82         
83 private:
84         ///
85         void setCurrentCompletion(QString const & s);
86         ///
87         void showPopup(Cursor & cur);
88         ///
89         void showInline(Cursor & cur);
90         ///
91         void hidePopup(Cursor & cur);
92         ///
93         void hideInline(Cursor & cur);
94         ///
95         void updatePopup(Cursor & cur);
96         ///
97         void updateInline(Cursor & cur, QString const & completion);
98         ///
99         void updatePrefix(Cursor & cur);
100         ///
101         void updateModel(Cursor & cur, bool popupUpdate, bool inlineUpdate);
102         ///
103         bool eventFilter(QObject * watched, QEvent * event);
104
105         ///
106         GuiWorkArea * gui_;
107         ///
108         DocIterator old_cursor_;
109         ///
110         QTimer popup_timer_;
111         ///
112         QTimer inline_timer_;
113         ///
114         QString last_selection_;
115         /// lock to stop updates of the inline completion
116         int updateLock_;
117         /// the BufferView::inlineCursorPos might be reset by destructive
118         /// operations like backspace. Hence, we have to keep this flag
119         /// in addition to know whether the completion is to be kept visible.
120         bool inlineVisible_;
121         ///
122         RtlItemDelegate * rtlItemDelegate_;
123 }; // GuiCompleter
124
125 } // namespace frontend
126 } // namespace lyx
127
128 #endif // GUICOMPLETER_H