KTextEditor

katecompletionwidget.h
1 /*
2  SPDX-FileCopyrightText: 2005-2006 Hamish Rodda <[email protected]>
3  SPDX-FileCopyrightText: 2007-2008 David Nolden <[email protected]>
4 
5  SPDX-License-Identifier: LGPL-2.0-or-later
6 */
7 
8 #ifndef KATECOMPLETIONWIDGET_H
9 #define KATECOMPLETIONWIDGET_H
10 
11 #include <QFrame>
12 #include <QObject>
13 
14 #include <ktexteditor_export.h>
15 
16 #include <ktexteditor/codecompletioninterface.h>
17 #include <ktexteditor/codecompletionmodel.h>
18 #include <ktexteditor/movingrange.h>
19 
20 class QToolButton;
21 class QPushButton;
22 class QLabel;
23 class QTimer;
24 
25 namespace KTextEditor
26 {
27 class ViewPrivate;
28 }
30 class KateCompletionTree;
31 class KateArgumentHintTree;
32 class KateArgumentHintModel;
33 
40 class KTEXTEDITOR_EXPORT KateCompletionWidget : public QFrame
41 {
42  Q_OBJECT
43 
44 public:
45  explicit KateCompletionWidget(KTextEditor::ViewPrivate *parent);
46  ~KateCompletionWidget() override;
47 
48  KTextEditor::ViewPrivate *view() const;
49  KateCompletionTree *treeView() const;
50 
51  bool isCompletionActive() const;
52  void startCompletion(KTextEditor::CodeCompletionModel::InvocationType invocationType, const QList<KTextEditor::CodeCompletionModel *> &models = QList<KTextEditor::CodeCompletionModel *>());
53  void startCompletion(const KTextEditor::Range &word, KTextEditor::CodeCompletionModel *model, KTextEditor::CodeCompletionModel::InvocationType invocationType = KTextEditor::CodeCompletionModel::ManualInvocation);
54  void startCompletion(const KTextEditor::Range &word,
56  KTextEditor::CodeCompletionModel::InvocationType invocationType = KTextEditor::CodeCompletionModel::ManualInvocation);
57  void userInvokedCompletion();
58 
59 public Q_SLOTS:
60  // Executed when return is pressed while completion is active.
61  void execute();
62  void cursorDown();
63  void cursorUp();
64 
65 public:
66  void tab(bool shift);
67 
69  bool toggleExpanded(bool forceExpand = false, bool forceUnExpand = false);
70 
71  const KateCompletionModel *model() const;
72  KateCompletionModel *model();
73 
74  void registerCompletionModel(KTextEditor::CodeCompletionModel *model);
75  void unregisterCompletionModel(KTextEditor::CodeCompletionModel *model);
76  bool isCompletionModelRegistered(KTextEditor::CodeCompletionModel *model) const;
77  QList<KTextEditor::CodeCompletionModel *> codeCompletionModels() const;
78 
79  int automaticInvocationDelay() const;
80  void setAutomaticInvocationDelay(int delay);
81 
82  struct CompletionRange {
83  CompletionRange()
84  {
85  }
86  explicit CompletionRange(KTextEditor::MovingRange *r)
87  : range(r)
88  {
89  }
90 
91  bool operator==(const CompletionRange &rhs) const
92  {
93  return range->toRange() == rhs.range->toRange();
94  }
95 
96  KTextEditor::MovingRange *range = nullptr;
97  // Whenever the cursor goes before this position, the completion is stopped, unless it is invalid.
98  KTextEditor::Cursor leftBoundary;
99  };
100 
101  KTextEditor::MovingRange *completionRange(KTextEditor::CodeCompletionModel *model = nullptr) const;
103 
104  // Navigation
105  void pageDown();
106  void pageUp();
107  void top();
108  void bottom();
109 
110  QWidget *currentEmbeddedWidget();
111 
112  bool canExpandCurrentItem() const;
113 
114  bool canCollapseCurrentItem() const;
115 
116  void setCurrentItemExpanded(bool);
117 
118  // Returns true if a screen border has been hit
119  bool updatePosition(bool force = false);
120 
121  bool eventFilter(QObject *watched, QEvent *event) override;
122 
123  KateArgumentHintTree *argumentHintTree() const;
124 
125  KateArgumentHintModel *argumentHintModel() const;
126 
128 
129  void updateHeight();
130 
131 public Q_SLOTS:
132  void waitForModelReset();
133 
134  void abortCompletion();
135  void showConfig();
136  /* void viewFocusIn();
137  void viewFocusOut();*/
138  void updatePositionSlot();
139  void automaticInvocation();
140 
141  /* void updateFocus();*/
142  void argumentHintsChanged(bool hasContent);
143 
144  bool navigateUp();
145  bool navigateDown();
146  bool navigateLeft();
147  bool navigateRight();
148  bool navigateAccept();
149  bool navigateBack();
150 
151  bool hadNavigation() const;
152  void resetHadNavigation();
153 
154 protected:
155  void showEvent(QShowEvent *event) override;
156  void resizeEvent(QResizeEvent *event) override;
157  void moveEvent(QMoveEvent *event) override;
158  void focusOutEvent(QFocusEvent *event) override;
159 
160 private Q_SLOTS:
161  void completionModelReset();
162  void modelDestroyed(QObject *model);
163  void modelContentChanged();
164  void cursorPositionChanged();
165  void modelReset();
166  void rowsInserted(const QModelIndex &parent, int row, int rowEnd);
167  void viewFocusOut();
168 
169  void wrapLine(const KTextEditor::Cursor &position);
170  void unwrapLine(int line);
171  void insertText(const KTextEditor::Cursor &position, const QString &text);
172  void removeText(const KTextEditor::Range &range);
173 
174 private:
175  void updateAndShow();
176  void updateArgumentHintGeometry();
177  QModelIndex selectedIndex() const;
178 
179  void clear();
180  // Switch cursor between argument-hint list / completion-list
181  void switchList();
182  KTextEditor::Range determineRange() const;
183  void completionRangeChanged(KTextEditor::CodeCompletionModel *, const KTextEditor::Range &word);
184 
185  void deleteCompletionRanges();
186 
188  KateCompletionModel *m_presentationModel;
189 
192 
193  KTextEditor::Cursor m_lastCursorPosition;
194 
195  KateCompletionTree *m_entryList;
196  KateArgumentHintModel *m_argumentHintModel;
197  KateArgumentHintTree *m_argumentHintTree;
198 
199  QTimer *m_automaticInvocationTimer;
200  // QTimer* m_updateFocusTimer;
201  QWidget *m_statusBar;
202  QToolButton *m_sortButton;
203  QLabel *m_sortText;
204  QToolButton *m_filterButton;
205  QLabel *m_filterText;
206  QPushButton *m_configButton;
207 
208  KTextEditor::Cursor m_automaticInvocationAt;
209  QString m_automaticInvocationLine;
210  int m_automaticInvocationDelay;
211  bool m_filterInstalled;
212 
213  class KateCompletionConfig *m_configWidget;
214  bool m_lastInsertionByUser;
215  bool m_inCompletionList; // Are we in the completion-list? If not, we're in the argument-hint list
216  bool m_isSuspended;
217  bool m_dontShowArgumentHints; // Used temporarily to prevent flashing
218  bool m_needShow;
219 
220  bool m_hadCompletionNavigation;
221 
222  bool m_haveExactMatch;
223 
224  bool m_noAutoHide;
225 
229  bool m_completionEditRunning;
230 
231  int m_expandedAddedHeightBase;
232  KTextEditor::CodeCompletionModel::InvocationType m_lastInvocationType;
233 };
234 
235 #endif
This class has the responsibility for filtering, sorting, and manipulating code completion data provi...
A range that is bound to a specific Document, and maintains its position.
Definition: movingrange.h:143
The Cursor represents a position in a Document.
Definition: cursor.h:71
This is the code completion&#39;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...
An object representing a section of text, from one Cursor to another.
An item model for providing code completion, and meta information for enhanced presentation.
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Thu Sep 17 2020 22:57:33 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.