KTextEditor

katecompletionwidget.h
1/*
2 SPDX-FileCopyrightText: 2005-2006 Hamish Rodda <rodda@kde.org>
3 SPDX-FileCopyrightText: 2007-2008 David Nolden <david.nolden.kdevelop@art-master.de>
4 SPDX-FileCopyrightText: 2022-2024 Waqar Ahmed <waqar.17a@gmail.com>
5
6 SPDX-License-Identifier: LGPL-2.0-or-later
7*/
8
9#ifndef KATECOMPLETIONWIDGET_H
10#define KATECOMPLETIONWIDGET_H
11
12#include <QFrame>
13#include <QObject>
14#include <QPointer>
15
16#include <ktexteditor_export.h>
17
18#include <ktexteditor/codecompletionmodel.h>
19#include <ktexteditor/movingrange.h>
20
21class QToolButton;
22class QPushButton;
23class QLabel;
24class QTimer;
25
26namespace KTextEditor
27{
28class ViewPrivate;
29}
30class DocTip;
32class KateCompletionTree;
33class KateArgumentHintTree;
34class KateArgumentHintModel;
35class ArgumentHintWidget;
36
37/**
38 * This is the code completion's main widget, and also contains the
39 * core interface logic.
40 *
41 * @author Hamish Rodda <rodda@kde.org>
42 */
43class KTEXTEDITOR_EXPORT KateCompletionWidget : public QFrame
44{
45 Q_OBJECT
46
47public:
48 explicit KateCompletionWidget(KTextEditor::ViewPrivate *parent);
49 ~KateCompletionWidget() override;
50
51 KTextEditor::ViewPrivate *view() const;
52 KateCompletionTree *treeView() const;
53
54 bool isCompletionActive() const;
55 void startCompletion(KTextEditor::CodeCompletionModel::InvocationType invocationType,
57 void startCompletion(KTextEditor::Range word,
59 KTextEditor::CodeCompletionModel::InvocationType invocationType = KTextEditor::CodeCompletionModel::ManualInvocation);
60 void startCompletion(KTextEditor::Range word,
62 KTextEditor::CodeCompletionModel::InvocationType invocationType = KTextEditor::CodeCompletionModel::ManualInvocation);
63 void userInvokedCompletion();
64
65public Q_SLOTS:
66 // Executed when return is pressed while completion is active.
67 bool execute();
68 void cursorDown();
69 void cursorUp();
70
71public:
72 enum Direction {
73 Down,
74 Up,
75 };
76
77 void tabCompletion(Direction direction = Down);
78
79 void toggleDocumentation();
80
81 const KateCompletionModel *model() const;
82 KateCompletionModel *model();
83
84 void registerCompletionModel(KTextEditor::CodeCompletionModel *model);
85 void unregisterCompletionModel(KTextEditor::CodeCompletionModel *model);
86 bool isCompletionModelRegistered(KTextEditor::CodeCompletionModel *model) const;
87 QList<KTextEditor::CodeCompletionModel *> codeCompletionModels() const;
88
89 int automaticInvocationDelay() const;
90 void setAutomaticInvocationDelay(int delay);
91
92 void setIgnoreBufferSignals(bool ignore) const;
93
94 bool m_ignoreBufferSignals = false;
95
96 struct CompletionRange {
97 CompletionRange()
98 {
99 }
100 explicit CompletionRange(KTextEditor::MovingRange *r)
101 : range(r)
102 {
103 }
104
105 bool operator==(const CompletionRange &rhs) const
106 {
107 return range->toRange() == rhs.range->toRange();
108 }
109
110 KTextEditor::MovingRange *range = nullptr;
111 // Whenever the cursor goes before this position, the completion is stopped, unless it is invalid.
112 KTextEditor::Cursor leftBoundary;
113 };
114
115 KTextEditor::MovingRange *completionRange(KTextEditor::CodeCompletionModel *model = nullptr) const;
117
118 // Navigation
119 void pageDown();
120 void pageUp();
121 void top();
122 void bottom();
123
124 QWidget *currentEmbeddedWidget();
125
126 void updatePosition(bool force = false);
127 bool eventFilter(QObject *watched, QEvent *event) override;
128
129 KateArgumentHintModel *argumentHintModel() const;
130
131 /// Called by KateViewInternal, because we need the specific information from the event.
132
133 void updateHeight();
134
135 void showDocTip(const QModelIndex &idx);
136 DocTip *docTip() const
137 {
138 return m_docTip;
139 }
140
141 bool handleShortcutOverride(QKeyEvent *e);
142
143public Q_SLOTS:
144 void waitForModelReset();
145
146 void abortCompletion();
147 void automaticInvocation();
148
149 /* void updateFocus();*/
150 void argumentHintsChanged(bool hasContent);
151
152 bool navigateUp();
153 bool navigateDown();
154 bool navigateLeft();
155 bool navigateRight();
156 bool navigateAccept();
157 bool navigateBack();
158
159protected:
160 void showEvent(QShowEvent *event) override;
161 void resizeEvent(QResizeEvent *event) override;
162 void moveEvent(QMoveEvent *event) override;
163 void focusOutEvent(QFocusEvent *event) override;
164
165private Q_SLOTS:
166 void completionModelReset();
167 void modelDestroyed(QObject *model);
168 void modelContentChanged();
169 void cursorPositionChanged();
170 void modelReset();
171 void rowsInserted(const QModelIndex &parent, int row, int rowEnd);
172 void viewFocusOut();
173
174 void wrapLine(KTextEditor::Document *document, KTextEditor::Cursor position);
175 void unwrapLine(KTextEditor::Document *, int line);
176 void insertText(KTextEditor::Document *, KTextEditor::Cursor position, const QString &text);
177 void removeText(KTextEditor::Document *, KTextEditor::Range range, const QString &);
178
179private:
180 KTEXTEDITOR_NO_EXPORT
181 void updateAndShow();
182 KTEXTEDITOR_NO_EXPORT
183 void updateArgumentHintGeometry();
184 KTEXTEDITOR_NO_EXPORT
185 QModelIndex selectedIndex() const;
186
187 KTEXTEDITOR_NO_EXPORT
188 void clear();
189
190 KTEXTEDITOR_NO_EXPORT
191 void completionRangeChanged(KTextEditor::CodeCompletionModel *, const KTextEditor::Range &word);
192
193 KTEXTEDITOR_NO_EXPORT
194 QString tailString() const;
195
196 KTEXTEDITOR_NO_EXPORT
197 void deleteCompletionRanges();
198
199private:
201 KateCompletionModel *m_presentationModel;
202
205
206 KTextEditor::Cursor m_lastCursorPosition;
207
208 KTextEditor::ViewPrivate *m_view;
209 KateCompletionTree *m_entryList;
210 KateArgumentHintModel *m_argumentHintModel;
211 // KateArgumentHintTree *m_argumentHintTree;
212 ArgumentHintWidget *m_argumentHintWidget;
213 DocTip *m_docTip;
214
215 QTimer *m_automaticInvocationTimer;
216
217 KTextEditor::Cursor m_automaticInvocationAt;
218 QString m_automaticInvocationLine;
219 int m_automaticInvocationDelay;
220
221 bool m_lastInsertionByUser;
222 bool m_isSuspended;
223 bool m_dontShowArgumentHints; // Used temporarily to prevent flashing
224 bool m_needShow;
225
226 bool m_hadCompletionNavigation;
227
228 bool m_haveExactMatch;
229
230 bool m_noAutoHide;
231
232 /**
233 * is a completion edit ongoing?
234 */
235 bool m_completionEditRunning;
236
237 int m_expandedAddedHeightBase;
238
239 KTextEditor::CodeCompletionModel::InvocationType m_lastInvocationType;
240};
241
242#endif
An item model for providing code completion, and meta information for enhanced presentation.
The Cursor represents a position in a Document.
Definition cursor.h:75
A KParts derived class representing a text document.
Definition document.h:284
A range that is bound to a specific Document, and maintains its position.
const Range toRange() const
Convert this clever range into a dumb one.
An object representing a section of text, from one Cursor to another.
This class has the responsibility for filtering, sorting, and manipulating code completion data provi...
This is the code completion's main widget, and also contains the core interface logic.
The KTextEditor namespace contains all the public API that is required to use the KTextEditor compone...
Q_SLOTSQ_SLOTS
virtual bool eventFilter(QObject *watched, QEvent *event)
virtual void focusOutEvent(QFocusEvent *event)
virtual void moveEvent(QMoveEvent *event)
virtual void resizeEvent(QResizeEvent *event)
virtual void showEvent(QShowEvent *event)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Jun 14 2024 11:57:25 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.