Kate
katecompletionwidget.h
Go to the documentation of this file.00001 /* This file is part of the KDE libraries 00002 Copyright (C) 2005-2006 Hamish Rodda <rodda@kde.org> 00003 00004 This library is free software; you can redistribute it and/or 00005 modify it under the terms of the GNU Library General Public 00006 License version 2 as published by the Free Software Foundation. 00007 00008 This library is distributed in the hope that it will be useful, 00009 but WITHOUT ANY WARRANTY; without even the implied warranty of 00010 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00011 Library General Public License for more details. 00012 00013 You should have received a copy of the GNU Library General Public License 00014 along with this library; see the file COPYING.LIB. If not, write to 00015 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00016 Boston, MA 02110-1301, USA. 00017 */ 00018 #ifndef KATECOMPLETIONWIDGET_H 00019 #define KATECOMPLETIONWIDGET_H 00020 00021 #include <QtGui/QFrame> 00022 #include <QObject> 00023 00024 #include <ktexteditor/range.h> 00025 #include <ktexteditor/codecompletioninterface.h> 00026 #include <ktexteditor/codecompletionmodel.h> 00027 00028 class QToolButton; 00029 class QPushButton; 00030 class QLabel; 00031 class QTimer; 00032 00033 class KateView; 00034 class KateSmartRange; 00035 class KateCompletionModel; 00036 class KateCompletionTree; 00037 class KateEditInfo; 00038 class KateArgumentHintTree; 00039 class KateArgumentHintModel; 00040 00047 class KateCompletionWidget : public QFrame 00048 { 00049 Q_OBJECT 00050 00051 public: 00052 explicit KateCompletionWidget(KateView* parent); 00053 ~KateCompletionWidget(); 00054 00055 KateView* view() const; 00056 KateCompletionTree* treeView() const; 00057 00058 bool isCompletionActive() const; 00059 void startCompletion(const KTextEditor::Range& word, KTextEditor::CodeCompletionModel* model, KTextEditor::CodeCompletionModel::InvocationType invocationType = KTextEditor::CodeCompletionModel::ManualInvocation); 00060 void userInvokedCompletion(); 00061 00062 //Executed when return is pressed while completion is active. With shift, only the item selected within the expanding-widget will be executed 00063 void execute(bool shift); 00064 //Callbacks for keyboard-input, they return true when the event was handled, and should not be reached on. 00065 bool cursorLeft( bool shift ); 00066 bool cursorRight( bool shift ); 00067 void cursorDown(bool shift); 00068 void cursorUp(bool shift); 00069 00070 const KateCompletionModel* model() const; 00071 KateCompletionModel* model(); 00072 00073 void registerCompletionModel(KTextEditor::CodeCompletionModel* model); 00074 void unregisterCompletionModel(KTextEditor::CodeCompletionModel* model); 00075 00076 int automaticInvocationDelay() const; 00077 void setAutomaticInvocationDelay(int delay); 00078 00079 KateSmartRange* completionRange() const; 00080 00081 // Navigation 00082 void pageDown(); 00083 void pageUp(); 00084 void top(); 00085 void bottom(); 00086 00087 bool canExpandCurrentItem() const; 00088 00089 bool canCollapseCurrentItem() const; 00090 00091 void setCurrentItemExpanded( bool ); 00092 00093 void updatePosition(bool force = false); 00094 00095 virtual bool eventFilter( QObject * watched, QEvent * event ); 00096 00097 KateArgumentHintTree* argumentHintTree() const; 00098 00099 KateArgumentHintModel* argumentHintModel() const; 00100 00102 00103 void updateHeight(); 00104 00105 public Q_SLOTS: 00106 void abortCompletion(); 00107 void showConfig(); 00108 /* void viewFocusIn(); 00109 void viewFocusOut();*/ 00110 void updatePositionSlot(); 00111 void automaticInvocation(); 00112 00113 /* void updateFocus();*/ 00114 void argumentHintsChanged(bool hasContent); 00115 00116 protected: 00117 virtual void showEvent ( QShowEvent * event ); 00118 virtual void resizeEvent ( QResizeEvent * event ); 00119 virtual void hideEvent ( QHideEvent * event ); 00120 // virtual void focusInEvent ( QFocusEvent * event ); 00121 00122 private Q_SLOTS: 00123 void modelContentChanged(); 00124 void cursorPositionChanged(); 00125 void editDone(KateEditInfo* edit); 00126 void modelReset(); 00127 void startCharacterDeleted(KTextEditor::SmartCursor* cursor, bool deletedBefore); 00128 void rowsInserted(const QModelIndex& parent, int row, int rowEnd); 00129 void viewFocusOut(); 00130 private: 00131 void updateAndShow(); 00132 void updateArgumentHintGeometry(); 00133 QModelIndex selectedIndex() const; 00134 00135 void clear(); 00136 //Switch cursor between argument-hint list / completion-list 00137 void switchList(); 00138 KTextEditor::Range determineRange() const; 00139 00140 QList<KTextEditor::CodeCompletionModel*> m_sourceModels; 00141 KateCompletionModel* m_presentationModel; 00142 00143 KateSmartRange* m_completionRange; 00144 KTextEditor::Cursor m_lastCursorPosition; 00145 00146 KateCompletionTree* m_entryList; 00147 KateArgumentHintModel* m_argumentHintModel; 00148 KateArgumentHintTree* m_argumentHintTree; 00149 00150 QTimer* m_automaticInvocationTimer; 00151 //QTimer* m_updateFocusTimer; 00152 QWidget* m_statusBar; 00153 QToolButton* m_sortButton; 00154 QLabel* m_sortText; 00155 QToolButton* m_filterButton; 00156 QLabel* m_filterText; 00157 QPushButton* m_configButton; 00158 00159 QString m_automaticInvocationLine; 00160 int m_automaticInvocationDelay; 00161 bool m_filterInstalled; 00162 00163 class KateCompletionConfig* m_configWidget; 00164 bool m_inCompletionList; //Are we in the completion-list? If not, we're in the argument-hint list 00165 bool m_isSuspended; 00166 bool m_dontShowArgumentHints; //Used temporarily to prevent flashing 00167 bool m_needShow; 00168 00169 int m_expandedAddedHeightBase; 00170 int m_expandingAddedHeight; 00171 }; 00172 00173 #endif