Kate
katecompletionwidget.h
Go to the documentation of this file.
00001 /* This file is part of the KDE libraries and the Kate part. 00002 * 00003 * Copyright (C) 2005-2006 Hamish Rodda <rodda@kde.org> 00004 * Copyright (C) 2007-2008 David Nolden <david.nolden.kdevelop@art-master.de> 00005 * 00006 * This library is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU Library General Public 00008 * License as published by the Free Software Foundation; either 00009 * version 2 of the License, or (at your option) any later version. 00010 * 00011 * This library is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 * Library General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU Library General Public License 00017 * along with this library; see the file COPYING.LIB. If not, write to 00018 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00019 * Boston, MA 02110-1301, USA. 00020 */ 00021 00022 #ifndef KATECOMPLETIONWIDGET_H 00023 #define KATECOMPLETIONWIDGET_H 00024 00025 #include <QtGui/QFrame> 00026 #include <QObject> 00027 00028 #include "katepartprivate_export.h" 00029 00030 #include <ktexteditor/movingrange.h> 00031 #include <ktexteditor/codecompletioninterface.h> 00032 #include <ktexteditor/codecompletionmodel.h> 00033 00034 class QToolButton; 00035 class QPushButton; 00036 class QLabel; 00037 class QTimer; 00038 00039 class KateView; 00040 class KateCompletionModel; 00041 class KateCompletionTree; 00042 class KateArgumentHintTree; 00043 class KateArgumentHintModel; 00044 00045 namespace KTextEditor { 00046 class EmbeddedWidgetInterface; 00047 } 00048 00055 class KATEPART_TESTS_EXPORT KateCompletionWidget : public QFrame 00056 { 00057 Q_OBJECT 00058 00059 public: 00060 explicit KateCompletionWidget(KateView* parent); 00061 ~KateCompletionWidget(); 00062 00063 KateView* view() const; 00064 KateCompletionTree* treeView() const; 00065 00066 bool isCompletionActive() const; 00067 void startCompletion(KTextEditor::CodeCompletionModel::InvocationType invocationType, const QList<KTextEditor::CodeCompletionModel*>& models = QList<KTextEditor::CodeCompletionModel*>()); 00068 void startCompletion(const KTextEditor::Range& word, KTextEditor::CodeCompletionModel* model, KTextEditor::CodeCompletionModel::InvocationType invocationType = KTextEditor::CodeCompletionModel::ManualInvocation); 00069 void startCompletion(const KTextEditor::Range& word, const QList<KTextEditor::CodeCompletionModel*>& models = QList<KTextEditor::CodeCompletionModel*>(), KTextEditor::CodeCompletionModel::InvocationType invocationType = KTextEditor::CodeCompletionModel::ManualInvocation); 00070 void userInvokedCompletion(); 00071 00072 //Executed when return is pressed while completion is active. 00073 void execute(); 00074 void cursorDown(); 00075 void cursorUp(); 00076 00077 void tab(bool shift); 00078 00080 bool toggleExpanded(bool forceExpand = false, bool forceUnExpand = false); 00081 00082 const KateCompletionModel* model() const; 00083 KateCompletionModel* model(); 00084 00085 void registerCompletionModel(KTextEditor::CodeCompletionModel* model); 00086 void unregisterCompletionModel(KTextEditor::CodeCompletionModel* model); 00087 00088 int automaticInvocationDelay() const; 00089 void setAutomaticInvocationDelay(int delay); 00090 00091 struct CompletionRange{ 00092 CompletionRange() : range(0) { 00093 } 00094 CompletionRange(KTextEditor::MovingRange* r) : range(r) { 00095 } 00096 00097 bool operator==(const CompletionRange& rhs) const { 00098 return range->toRange() == rhs.range->toRange(); 00099 } 00100 00101 KTextEditor::MovingRange* range; 00102 //Whenever the cursor goes before this position, the completion is stopped, unless it is invalid. 00103 KTextEditor::Cursor leftBoundary; 00104 }; 00105 00106 KTextEditor::MovingRange* completionRange(KTextEditor::CodeCompletionModel* model = 0) const; 00107 QMap<KTextEditor::CodeCompletionModel*, CompletionRange> completionRanges( ) const; 00108 00109 // Navigation 00110 void pageDown(); 00111 void pageUp(); 00112 void top(); 00113 void bottom(); 00114 00115 QWidget* currentEmbeddedWidget(); 00116 00117 bool canExpandCurrentItem() const; 00118 00119 bool canCollapseCurrentItem() const; 00120 00121 void setCurrentItemExpanded( bool ); 00122 00123 //Returns true if a screen border has been hit 00124 bool updatePosition(bool force = false); 00125 00126 virtual bool eventFilter( QObject * watched, QEvent * event ); 00127 00128 KateArgumentHintTree* argumentHintTree() const; 00129 00130 KateArgumentHintModel* argumentHintModel() const; 00131 00133 00134 void updateHeight(); 00135 00136 public Q_SLOTS: 00137 void waitForModelReset(); 00138 00139 void abortCompletion(); 00140 void showConfig(); 00141 /* void viewFocusIn(); 00142 void viewFocusOut();*/ 00143 void updatePositionSlot(); 00144 void automaticInvocation(); 00145 00146 /* void updateFocus();*/ 00147 void argumentHintsChanged(bool hasContent); 00148 00149 bool navigateUp(); 00150 bool navigateDown(); 00151 bool navigateLeft(); 00152 bool navigateRight(); 00153 bool navigateAccept(); 00154 bool navigateBack(); 00155 00156 bool hadNavigation() const; 00157 void resetHadNavigation(); 00158 00159 protected: 00160 virtual void showEvent ( QShowEvent * event ); 00161 virtual void resizeEvent ( QResizeEvent * event ); 00162 // virtual void focusInEvent ( QFocusEvent * event ); 00163 00164 private Q_SLOTS: 00165 void completionModelReset(); 00166 void modelDestroyed(QObject* model); 00167 void modelContentChanged(); 00168 void cursorPositionChanged(); 00169 void modelReset(); 00170 void rowsInserted(const QModelIndex& parent, int row, int rowEnd); 00171 void viewFocusOut(); 00172 00173 void wrapLine (const KTextEditor::Cursor &position); 00174 void unwrapLine (int line); 00175 void insertText (const KTextEditor::Cursor &position, const QString &text); 00176 void removeText (const KTextEditor::Range &range); 00177 00178 private: 00179 void updateAndShow(); 00180 void updateArgumentHintGeometry(); 00181 QModelIndex selectedIndex() const; 00182 00183 void clear(); 00184 //Switch cursor between argument-hint list / completion-list 00185 void switchList(); 00186 KTextEditor::Range determineRange() const; 00187 void completionRangeChanged(KTextEditor::CodeCompletionModel*, const KTextEditor::Range& word); 00188 00189 void deleteCompletionRanges(); 00190 00191 QList<KTextEditor::CodeCompletionModel*> m_sourceModels; 00192 KateCompletionModel* m_presentationModel; 00193 00194 QMap<KTextEditor::CodeCompletionModel*, CompletionRange> m_completionRanges; 00195 QSet<KTextEditor::CodeCompletionModel*> m_waitingForReset; 00196 00197 KTextEditor::Cursor m_lastCursorPosition; 00198 00199 KateCompletionTree* m_entryList; 00200 KateArgumentHintModel* m_argumentHintModel; 00201 KateArgumentHintTree* m_argumentHintTree; 00202 00203 QTimer* m_automaticInvocationTimer; 00204 //QTimer* m_updateFocusTimer; 00205 QWidget* m_statusBar; 00206 QToolButton* m_sortButton; 00207 QLabel* m_sortText; 00208 QToolButton* m_filterButton; 00209 QLabel* m_filterText; 00210 QPushButton* m_configButton; 00211 00212 KTextEditor::Cursor m_automaticInvocationAt; 00213 QString m_automaticInvocationLine; 00214 int m_automaticInvocationDelay; 00215 bool m_filterInstalled; 00216 00217 class KateCompletionConfig* m_configWidget; 00218 bool m_lastInsertionByUser; 00219 bool m_inCompletionList; //Are we in the completion-list? If not, we're in the argument-hint list 00220 bool m_isSuspended; 00221 bool m_dontShowArgumentHints; //Used temporarily to prevent flashing 00222 bool m_needShow; 00223 00224 bool m_hadCompletionNavigation; 00225 00226 bool m_haveExactMatch; 00227 00228 bool m_noAutoHide; 00229 00233 bool m_completionEditRunning; 00234 00235 int m_expandedAddedHeightBase; 00236 KTextEditor::CodeCompletionModel::InvocationType m_lastInvocationType; 00237 }; 00238 00239 #endif
KDE 4.6 API Reference