Kate
kateviewinternal.h
Go to the documentation of this file.
00001 /* This file is part of the KDE libraries 00002 Copyright (C) 2002-2007 Hamish Rodda <rodda@kde.org> 00003 Copyright (C) 2002 John Firebaugh <jfirebaugh@kde.org> 00004 Copyright (C) 2002 Joseph Wenninger <jowenn@kde.org> 00005 Copyright (C) 2002 Christoph Cullmann <cullmann@kde.org> 00006 Copyright (C) 2007 Mirko Stocker <me@misto.ch> 00007 00008 Based on: 00009 KWriteView : Copyright (C) 1999 Jochen Wilhelmy <digisnap@cs.tu-berlin.de> 00010 00011 This library is free software; you can redistribute it and/or 00012 modify it under the terms of the GNU Library General Public 00013 License version 2 as published by the Free Software Foundation. 00014 00015 This library is distributed in the hope that it will be useful, 00016 but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00018 Library General Public License for more details. 00019 00020 You should have received a copy of the GNU Library General Public License 00021 along with this library; see the file COPYING.LIB. If not, write to 00022 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00023 Boston, MA 02110-1301, USA. 00024 */ 00025 00026 #ifndef _KATE_VIEW_INTERNAL_ 00027 #define _KATE_VIEW_INTERNAL_ 00028 00029 #include <ktexteditor/attribute.h> 00030 00031 #include "katetextcursor.h" 00032 #include "katelinelayout.h" 00033 #include "katetextline.h" 00034 #include "katedocument.h" 00035 #include "kateview.h" 00036 00037 #include <QtCore/QPoint> 00038 #include <QtCore/QTimer> 00039 #include <QtGui/QDrag> 00040 #include <QtGui/QWidget> 00041 #include <QtCore/QSet> 00042 #include <QtCore/QPointer> 00043 00044 namespace KTextEditor { 00045 class MovingRange; 00046 } 00047 00048 class KateIconBorder; 00049 class KateScrollBar; 00050 class KateTextLayout; 00051 00052 class KateViInputModeManager; 00053 00054 class QScrollBar; 00055 00056 class KateViewInternal : public QWidget 00057 { 00058 Q_OBJECT 00059 00060 friend class KateView; 00061 friend class KateIconBorder; 00062 friend class KateScrollBar; 00063 friend class CalculatingCursor; 00064 friend class BoundedCursor; 00065 friend class WrappingCursor; 00066 friend class KateViModeBase; 00067 00068 public: 00069 enum Bias 00070 { 00071 left = -1, 00072 none = 0, 00073 right = 1 00074 }; 00075 00076 public: 00077 KateViewInternal ( KateView *view ); 00078 ~KateViewInternal (); 00079 KateView *view() const { return m_view; } 00080 00081 //BEGIN EDIT STUFF 00082 public: 00083 void editStart (); 00084 void editEnd (int editTagLineStart, int editTagLineEnd, bool tagFrom); 00085 00086 void editSetCursor (const KTextEditor::Cursor &cursor); 00087 00088 private: 00089 uint editSessionNumber; 00090 bool editIsRunning; 00091 KTextEditor::Cursor editOldCursor; 00092 //END 00093 00094 //BEGIN TAG & CLEAR & UPDATE STUFF 00095 public: 00096 bool tagLine (const KTextEditor::Cursor& virtualCursor); 00097 00098 bool tagLines (int start, int end, bool realLines = false); 00099 // cursors not const references as they are manipulated within 00100 bool tagLines (KTextEditor::Cursor start, KTextEditor::Cursor end, bool realCursors = false); 00101 00102 bool tagRange(const KTextEditor::Range& range, bool realCursors); 00103 00104 void tagAll (); 00105 00106 void updateDirty(); 00107 00108 void clear (); 00109 //END 00110 00111 private Q_SLOTS: 00112 // Updates the view and requests a redraw. 00113 void updateView (bool changed = false, int viewLinesScrolled = 0); 00114 00115 private: 00116 // Actually performs the updating, but doesn't call update(). 00117 void doUpdateView(bool changed = false, int viewLinesScrolled = 0); 00118 void makeVisible (const KTextEditor::Cursor& c, int endCol, bool force = false, bool center = false, bool calledExternally = false); 00119 00120 public: 00121 // Start Position is a virtual cursor 00122 KTextEditor::Cursor startPos() const { return m_startPos; } 00123 int startLine () const { return m_startPos.line(); } 00124 int startX () const { return m_startX; } 00125 00126 KTextEditor::Cursor endPos () const; 00127 int endLine () const; 00128 00129 KateTextLayout yToKateTextLayout(int y) const; 00130 00131 void prepareForDynWrapChange(); 00132 void dynWrapChanged(); 00133 00134 public Q_SLOTS: 00135 void slotIncFontSizes(); 00136 void slotDecFontSizes(); 00137 00138 private Q_SLOTS: 00139 void scrollLines(int line); // connected to the sliderMoved of the m_lineScroll 00140 void scrollViewLines(int offset); 00141 void scrollAction(int action); 00142 void scrollNextPage(); 00143 void scrollPrevPage(); 00144 void scrollPrevLine(); 00145 void scrollNextLine(); 00146 void scrollColumns (int x); // connected to the valueChanged of the m_columnScroll 00147 void viewSelectionChanged (); 00148 00149 public: 00150 void doReturn(); 00151 void doSmartNewline(); 00152 void doDelete(); 00153 void doBackspace(); 00154 void doTabulator(); 00155 void doTranspose(); 00156 void doDeleteWordLeft(); 00157 void doDeleteWordRight(); 00158 00159 void cursorLeft(bool sel=false); 00160 void cursorRight(bool sel=false); 00161 void wordLeft(bool sel=false); 00162 void wordRight(bool sel=false); 00163 void home(bool sel=false); 00164 void end(bool sel=false); 00165 void cursorUp(bool sel=false); 00166 void cursorDown(bool sel=false); 00167 void cursorToMatchingBracket(bool sel=false); 00168 void scrollUp(); 00169 void scrollDown(); 00170 void topOfView(bool sel=false); 00171 void bottomOfView(bool sel=false); 00172 void pageUp(bool sel=false); 00173 void pageDown(bool sel=false); 00174 void top(bool sel=false); 00175 void bottom(bool sel=false); 00176 void top_home(bool sel=false); 00177 void bottom_end(bool sel=false); 00178 00179 KTextEditor::Cursor getCursor() const { return m_cursor; } 00180 KTextEditor::Cursor getMouse() const { return m_mouse; } 00181 00182 QPoint cursorToCoordinate(const KTextEditor::Cursor& cursor, bool realCursor = true, bool includeBorder = true) const; 00183 //Always works on coordinates of the whole widget, eg. offsetted by the border 00184 KTextEditor::Cursor coordinatesToCursor(const QPoint& coord) const; 00185 QPoint cursorCoordinates(bool includeBorder = true) const; 00186 KTextEditor::Cursor findMatchingBracket(); 00187 00188 // EVENT HANDLING STUFF - IMPORTANT 00189 private: 00190 void fixDropEvent(QDropEvent *event); 00191 protected: 00192 virtual void hideEvent(QHideEvent* e); 00193 virtual void paintEvent(QPaintEvent *e); 00194 virtual bool eventFilter( QObject *obj, QEvent *e ); 00195 virtual void keyPressEvent( QKeyEvent* ); 00196 virtual void keyReleaseEvent( QKeyEvent* ); 00197 virtual void resizeEvent( QResizeEvent* ); 00198 virtual void mousePressEvent( QMouseEvent* ); 00199 virtual void mouseDoubleClickEvent( QMouseEvent* ); 00200 virtual void mouseReleaseEvent( QMouseEvent* ); 00201 virtual void mouseMoveEvent( QMouseEvent* ); 00202 virtual void leaveEvent( QEvent* ); 00203 virtual void dragEnterEvent( QDragEnterEvent* ); 00204 virtual void dragMoveEvent( QDragMoveEvent* ); 00205 virtual void dropEvent( QDropEvent* ); 00206 virtual void showEvent ( QShowEvent *); 00207 virtual void wheelEvent(QWheelEvent* e); 00208 virtual void focusInEvent (QFocusEvent *); 00209 virtual void focusOutEvent (QFocusEvent *); 00210 virtual void inputMethodEvent(QInputMethodEvent* e); 00211 00212 void contextMenuEvent ( QContextMenuEvent * e ); 00213 00214 private Q_SLOTS: 00215 void tripleClickTimeout(); 00216 00217 Q_SIGNALS: 00218 // emitted when KateViewInternal is not handling its own URI drops 00219 void dropEventPass(QDropEvent*); 00220 00221 private Q_SLOTS: 00222 void slotRegionVisibilityChangedAt(unsigned int,bool clear_cache); 00223 void slotRegionBeginEndAddedRemoved(unsigned int); 00224 void slotCodeFoldingChanged(); 00225 00226 private: 00227 void moveChar( Bias bias, bool sel ); 00228 void moveEdge( Bias bias, bool sel ); 00229 KTextEditor::Cursor maxStartPos(bool changed = false); 00230 void scrollPos(KTextEditor::Cursor& c, bool force = false, bool calledExternally = false); 00231 void scrollLines( int lines, bool sel ); 00232 00233 int linesDisplayed() const; 00234 00235 int lineToY(int viewLine) const; 00236 00237 void updateSelection( const KTextEditor::Cursor&, bool keepSel ); 00238 void setSelection( const KTextEditor::Range& ); 00239 void moveCursorToSelectionEdge(); 00240 //The smart-lock should not be locked when this is called 00241 void updateCursor( const KTextEditor::Cursor& newCursor, bool force = false, bool center = false, bool calledExternally = false ); 00242 void updateBracketMarks(); 00243 00244 void paintCursor(); 00245 00246 void placeCursor( const QPoint& p, bool keepSelection = false, bool updateSelection = true ); 00247 bool isTargetSelected( const QPoint& p ); 00248 //Returns whether the given range affects the area currently visible in the view 00249 bool rangeAffectsView(const KTextEditor::Range& range, bool realCursors) const; 00250 00251 void doDrag(); 00252 00253 KateRenderer* renderer() const; 00254 00255 KateView *m_view; 00256 class KateIconBorder *m_leftBorder; 00257 00258 int m_mouseX; 00259 int m_mouseY; 00260 int m_scrollX; 00261 int m_scrollY; 00262 00263 Qt::CursorShape m_mouseCursor; 00264 00265 Kate::TextCursor m_cursor; 00266 KTextEditor::Cursor m_mouse; 00267 KTextEditor::Cursor m_displayCursor; 00268 00269 bool m_possibleTripleClick; 00270 00271 //Whether the current completion-item was expanded while the last press of ALT 00272 bool m_completionItemExpanded; 00273 QTime m_altDownTime; 00274 00275 // Bracket mark and corresponding decorative ranges 00276 KTextEditor::MovingRange *m_bm, *m_bmStart, *m_bmEnd; 00277 void updateBracketMarkAttributes(); 00278 00279 enum DragState { diNone, diPending, diDragging }; 00280 00281 struct _dragInfo { 00282 DragState state; 00283 QPoint start; 00284 QDrag* dragObject; 00285 } m_dragInfo; 00286 00287 uint m_iconBorderHeight; 00288 00289 // 00290 // line scrollbar + first visible (virtual) line in the current view 00291 // 00292 KateScrollBar *m_lineScroll; 00293 QWidget* m_dummy; 00294 00295 // These are now cursors to account for word-wrap. 00296 // Start Position is a virtual cursor 00297 Kate::TextCursor m_startPos; 00298 //Count of lines that are visible behind m_startPos. 00299 //This does not respect dynamic word wrap, so take it as an approximation. 00300 uint m_visibleLineCount; 00301 00302 // This is set to false on resize or scroll (other than that called by makeVisible), 00303 // so that makeVisible is again called when a key is pressed and the cursor is in the same spot 00304 bool m_madeVisible; 00305 bool m_shiftKeyPressed; 00306 00307 // How many lines to should be kept visible above/below the cursor when possible 00308 void setAutoCenterLines(int viewLines, bool updateView = true); 00309 int m_autoCenterLines; 00310 int m_minLinesVisible; 00311 00312 // 00313 // column scrollbar + x position 00314 // 00315 QScrollBar *m_columnScroll; 00316 int m_startX; 00317 00318 // has selection changed while your mouse or shift key is pressed 00319 bool m_selChangedByUser; 00320 KTextEditor::Cursor m_selectAnchor; 00321 00322 enum SelectionMode { Default=0, Mouse, Word, Line }; 00323 uint m_selectionMode; 00324 // when drag selecting after double/triple click, keep the initial selected 00325 // word/line independent of direction. 00326 // They get set in the event of a double click, and is used with mouse move + leftbutton 00327 KTextEditor::Range m_selectionCached; 00328 00329 // maximal length of textlines visible from given startLine 00330 int maxLen(int startLine); 00331 00332 // are we allowed to scroll columns? 00333 bool columnScrollingPossible (); 00334 00335 // returns the maximum X value / col value a cursor can take for a specific line range 00336 int lineMaxCursorX(const KateTextLayout& line); 00337 int lineMaxCol(const KateTextLayout& line); 00338 00339 class KateLayoutCache* cache() const; 00340 KateLayoutCache* m_layoutCache; 00341 00342 // convenience methods 00343 KateTextLayout currentLayout() const; 00344 KateTextLayout previousLayout() const; 00345 KateTextLayout nextLayout() const; 00346 00347 // find the cursor offset by (offset) view lines from a cursor. 00348 // when keepX is true, the column position will be calculated based on the x 00349 // position of the specified cursor. 00350 KTextEditor::Cursor viewLineOffset(const KTextEditor::Cursor& virtualCursor, int offset, bool keepX = false); 00351 00352 KTextEditor::Cursor toRealCursor(const KTextEditor::Cursor& virtualCursor) const; 00353 KTextEditor::Cursor toVirtualCursor(const KTextEditor::Cursor& realCursor) const; 00354 00355 // These variable holds the most recent maximum real & visible column number 00356 bool m_preserveX; 00357 int m_preservedX; 00358 00359 bool m_updatingView; 00360 int m_wrapChangeViewLine; 00361 KTextEditor::Cursor m_cachedMaxStartPos; 00362 00363 private Q_SLOTS: 00364 void doDragScroll(); 00365 void startDragScroll(); 00366 void stopDragScroll(); 00367 00368 private: 00369 // Timers 00370 QTimer m_dragScrollTimer; 00371 QTimer m_scrollTimer; 00372 QTimer m_cursorTimer; 00373 QTimer m_textHintTimer; 00374 00375 static const int s_scrollTime = 30; 00376 static const int s_scrollMargin = 16; 00377 00378 private Q_SLOTS: 00379 void scrollTimeout (); 00380 void cursorTimeout (); 00381 void textHintTimeout (); 00382 00383 //TextHint 00384 public: 00385 void enableTextHints(int timeout); 00386 void disableTextHints(); 00387 00388 private: 00389 bool m_textHintEnabled; 00390 int m_textHintTimeout; 00391 int m_textHintMouseX; 00392 int m_textHintMouseY; 00393 00397 public: 00398 virtual QVariant inputMethodQuery(Qt::InputMethodQuery query) const; 00399 00400 private: 00401 KTextEditor::MovingRange *m_imPreeditRange; 00402 QList<KTextEditor::MovingRange *> m_imPreeditRangeChildren; 00403 00404 private: 00405 void mouseMoved(); 00406 void cursorMoved(); 00407 00408 private: 00409 bool m_smartDirty; 00410 00411 private: 00412 inline KateDocument *doc() { return m_view->doc(); } 00413 inline KateDocument *doc() const { return m_view->doc(); } 00414 00415 // vi Mode 00416 private: 00417 bool m_viInputMode; 00418 bool m_viInputModeStealKeys; 00419 00423 ViMode getCurrentViMode(); 00424 00429 KateViInputModeManager* m_viInputModeManager; 00430 00434 KateViInputModeManager* getViInputModeManager(); 00435 }; 00436 00437 #endif 00438 00439 // kate: space-indent on; indent-width 2; replace-tabs on;
KDE 4.6 API Reference