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