]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiCompleter.h
* completion infrastructure
[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
35 class GuiCompleter : private QCompleter
36 {
37         Q_OBJECT
38
39 public:
40         ///
41         GuiCompleter(GuiWorkArea * gui, QObject * parent = 0);
42         ///
43         virtual ~GuiCompleter();
44
45         ///
46         bool popupVisible() const;
47         ///
48         bool inlineVisible() const;
49         ///
50         bool popupPossible(Cursor const & cur) const;
51         ///
52         bool inlinePossible(Cursor const & cur) const;
53         /// Activate the current completion, i.e. finalize it.
54         void activate();
55         /// Do a completion as far as it is unique, but at least one character.
56         void tab();
57         
58         /// Update the visibility of the popup and the inline completion.
59         /// This method might set the update flags of the cursor to request
60         /// a redraw.
61         void updateVisibility(Cursor & cur, bool start, bool keep, bool cursorInView = true);
62         /// Update the visibility of the popup and the inline completion.
63         /// This method handles the redraw if needed.
64         void updateVisibility(bool start, bool keep);
65         ///
66         QString currentCompletion() const;
67         ///
68         docstring longestUniqueCompletion() const;
69         
70 public Q_SLOTS:
71         /// Show the popup.
72         void showPopup();
73         /// Show the inline completion.
74         void showInline();
75
76 private Q_SLOTS:
77         ///
78         void popupActivated(const QString & completion);
79         ///
80         void popupHighlighted(const QString & completion);
81         
82 private:
83         ///
84         void setCurrentCompletion(QString const & s);
85         ///
86         void showPopup(Cursor & cur);
87         ///
88         void showInline(Cursor & cur);
89         ///
90         void updatePopup(Cursor & cur);
91         ///
92         void updateInline(Cursor & cur, QString const & completion);
93         ///
94         void updatePrefix(Cursor & cur);
95         ///
96         void updateModel(Cursor & cur, bool popupUpdate, bool inlineUpdate);
97         ///
98         bool eventFilter(QObject * watched, QEvent * event);
99
100         ///
101         GuiWorkArea * gui_;
102         ///
103         DocIterator old_cursor_;
104         ///
105         QTimer popup_timer_;
106         ///
107         QTimer inline_timer_;
108         ///
109         QString last_selection_;
110 }; // GuiCompleter
111
112 } // namespace frontend
113 } // namespace lyx
114
115 #endif // GUICOMPLETER_H