00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifndef _KATE_VIEW_INTERNAL_
00027 #define _KATE_VIEW_INTERNAL_
00028
00029 #include <ktexteditor/attribute.h>
00030 #include <ktexteditor/rangefeedback.h>
00031
00032 #include "katesmartcursor.h"
00033 #include "katelinelayout.h"
00034 #include "katetextline.h"
00035 #include "katedocument.h"
00036 #include "kateview.h"
00037
00038 #include <QtCore/QPoint>
00039 #include <QtCore/QTimer>
00040 #include <QtGui/QDrag>
00041 #include <QtGui/QWidget>
00042 #include <QtCore/QSet>
00043 #include <QtCore/QPointer>
00044
00045 class KateIconBorder;
00046 class KateScrollBar;
00047 class KateSmartRange;
00048 class KateTextLayout;
00049
00050 class KateViInputModeManager;
00051
00052 class QScrollBar;
00053
00054 class KateViewInternal : public QWidget, private KTextEditor::SmartRangeWatcher
00055 {
00056 Q_OBJECT
00057
00058 friend class KateView;
00059 friend class KateIconBorder;
00060 friend class KateScrollBar;
00061 friend class CalculatingCursor;
00062 friend class BoundedCursor;
00063 friend class WrappingCursor;
00064 friend class KateViModeBase;
00065
00066 public:
00067 enum Bias
00068 {
00069 left = -1,
00070 none = 0,
00071 right = 1
00072 };
00073
00074 public:
00075 KateViewInternal ( KateView *view, KateDocument *doc );
00076 ~KateViewInternal ();
00077
00078
00079 public:
00080 void editStart ();
00081 void editEnd (int editTagLineStart, int editTagLineEnd, bool tagFrom);
00082
00083 void editSetCursor (const KTextEditor::Cursor &cursor);
00084
00085 private:
00086 uint editSessionNumber;
00087 bool editIsRunning;
00088 KTextEditor::Cursor editOldCursor;
00089
00090
00091
00092 public:
00093 bool tagLine (const KTextEditor::Cursor& virtualCursor);
00094
00095 bool tagLines (int start, int end, bool realLines = false);
00096
00097 bool tagLines (KTextEditor::Cursor start, KTextEditor::Cursor end, bool realCursors = false);
00098
00099 bool tagRange(const KTextEditor::Range& range, bool realCursors);
00100
00101 void tagAll ();
00102
00103 void relayoutRange(const KTextEditor::Range& range, bool realCursors = true);
00104
00105 void updateDirty();
00106
00107 void clear ();
00108
00109 Q_SIGNALS:
00110
00111 void requestViewUpdate(bool changed);
00112
00113
00114 private Q_SLOTS:
00115
00116 void updateView (bool changed = false, int viewLinesScrolled = 0);
00117
00118 private:
00119
00120 void doUpdateView(bool changed = false, int viewLinesScrolled = 0);
00121 void makeVisible (const KTextEditor::Cursor& c, int endCol, bool force = false, bool center = false, bool calledExternally = false);
00122
00123 public:
00124
00125 inline const KTextEditor::Cursor& startPos() const { return m_startPos; }
00126 inline int startLine () const { return m_startPos.line(); }
00127 inline int startX () const { return m_startX; }
00128
00129 KTextEditor::Cursor endPos () const;
00130 int endLine () const;
00131
00132 KateTextLayout yToKateTextLayout(int y) const;
00133
00134 void prepareForDynWrapChange();
00135 void dynWrapChanged();
00136
00137 KateView *view () { return m_view; }
00138
00139 public Q_SLOTS:
00140 void slotIncFontSizes();
00141 void slotDecFontSizes();
00142
00143 private Q_SLOTS:
00144 void scrollLines(int line);
00145 void scrollViewLines(int offset);
00146 void scrollAction(int action);
00147 void scrollNextPage();
00148 void scrollPrevPage();
00149 void scrollPrevLine();
00150 void scrollNextLine();
00151 void scrollColumns (int x);
00152 void viewSelectionChanged ();
00153
00154 public:
00155 void doReturn();
00156 void doSmartNewline();
00157 void doDelete();
00158 void doBackspace();
00159 void doTranspose();
00160 void doDeleteWordLeft();
00161 void doDeleteWordRight();
00162
00163 void cursorLeft(bool sel=false);
00164 void cursorRight(bool sel=false);
00165 void wordLeft(bool sel=false);
00166 void wordRight(bool sel=false);
00167 void home(bool sel=false);
00168 void end(bool sel=false);
00169 void cursorUp(bool sel=false);
00170 void cursorDown(bool sel=false);
00171 void cursorToMatchingBracket(bool sel=false);
00172 void scrollUp();
00173 void scrollDown();
00174 void topOfView(bool sel=false);
00175 void bottomOfView(bool sel=false);
00176 void pageUp(bool sel=false);
00177 void pageDown(bool sel=false);
00178 void top(bool sel=false);
00179 void bottom(bool sel=false);
00180 void top_home(bool sel=false);
00181 void bottom_end(bool sel=false);
00182
00183 KTextEditor::Cursor getCursor() const;
00184 QPoint cursorToCoordinate(const KTextEditor::Cursor& cursor, bool realCursor = true, bool includeBorder = true) const;
00185
00186 KTextEditor::Cursor coordinatesToCursor(const QPoint& coord) const;
00187 QPoint cursorCoordinates(bool includeBorder = true) const;
00188 KTextEditor::Cursor findMatchingBracket();
00189
00190
00191 private:
00192 void fixDropEvent(QDropEvent *event);
00193 protected:
00194 virtual void hideEvent(QHideEvent* e);
00195 virtual void paintEvent(QPaintEvent *e);
00196 virtual bool eventFilter( QObject *obj, QEvent *e );
00197 virtual void keyPressEvent( QKeyEvent* );
00198 virtual void keyReleaseEvent( QKeyEvent* );
00199 virtual void resizeEvent( QResizeEvent* );
00200 virtual void mousePressEvent( QMouseEvent* );
00201 virtual void mouseDoubleClickEvent( QMouseEvent* );
00202 virtual void mouseReleaseEvent( QMouseEvent* );
00203 virtual void mouseMoveEvent( QMouseEvent* );
00204 virtual void leaveEvent( QEvent* );
00205 virtual void dragEnterEvent( QDragEnterEvent* );
00206 virtual void dragMoveEvent( QDragMoveEvent* );
00207 virtual void dropEvent( QDropEvent* );
00208 virtual void showEvent ( QShowEvent *);
00209 virtual void wheelEvent(QWheelEvent* e);
00210 virtual void focusInEvent (QFocusEvent *);
00211 virtual void focusOutEvent (QFocusEvent *);
00212 virtual void inputMethodEvent(QInputMethodEvent* e);
00213
00214 void contextMenuEvent ( QContextMenuEvent * e );
00215
00216 private Q_SLOTS:
00217 void tripleClickTimeout();
00218
00219 Q_SIGNALS:
00220
00221 void dropEventPass(QDropEvent*);
00222
00223 private Q_SLOTS:
00224 void slotRegionVisibilityChangedAt(unsigned int,bool clear_cache);
00225 void slotRegionBeginEndAddedRemoved(unsigned int);
00226 void slotCodeFoldingChanged();
00227
00228 private:
00229 void moveChar( Bias bias, bool sel );
00230 void moveEdge( Bias bias, bool sel );
00231 KTextEditor::Cursor maxStartPos(bool changed = false);
00232 void scrollPos(KTextEditor::Cursor& c, bool force = false, bool calledExternally = false);
00233 void scrollLines( int lines, bool sel );
00234
00235 int linesDisplayed() const;
00236
00237 int lineToY(int viewLine) const;
00238
00239 void updateSelection( const KTextEditor::Cursor&, bool keepSel );
00240 void updateCursor( const KTextEditor::Cursor& newCursor, bool force = false, bool center = false, bool calledExternally = false );
00241 void updateBracketMarks();
00242
00243 void paintCursor();
00244
00245 void placeCursor( const QPoint& p, bool keepSelection = false, bool updateSelection = true );
00246 bool isTargetSelected( const QPoint& p );
00247
00248 void doDrag();
00249
00250 inline KateView* view() const { return m_view; }
00251 KateRenderer* renderer() const;
00252
00253 KateView *m_view;
00254 KateDocument* m_doc;
00255 class KateIconBorder *m_leftBorder;
00256
00257 int m_mouseX;
00258 int m_mouseY;
00259 int m_scrollX;
00260 int m_scrollY;
00261
00262 Qt::CursorShape m_mouseCursor;
00263
00264 KateSmartCursor m_cursor;
00265 KTextEditor::Cursor m_mouse;
00266 KTextEditor::Cursor m_displayCursor;
00267 int m_cursorX;
00268
00269 bool m_possibleTripleClick;
00270
00271
00272 bool m_completionItemExpanded;
00273 QTime m_altDownTime;
00274
00275
00276 KateSmartRange *m_bm, *m_bmStart, *m_bmEnd;
00277 bool m_bmHighlighted;
00278 void updateBracketMarkAttributes();
00279
00280 enum DragState { diNone, diPending, diDragging };
00281
00282 struct _dragInfo {
00283 DragState state;
00284 QPoint start;
00285 QDrag* dragObject;
00286 } m_dragInfo;
00287
00288 uint m_iconBorderHeight;
00289
00290
00291
00292
00293 KateScrollBar *m_lineScroll;
00294 QWidget* m_dummy;
00295
00296
00297
00298 KateSmartCursor m_startPos;
00299
00300
00301
00302 bool m_madeVisible;
00303 bool m_shiftKeyPressed;
00304
00305
00306 void setAutoCenterLines(int viewLines, bool updateView = true);
00307 int m_autoCenterLines;
00308 int m_minLinesVisible;
00309
00310
00311
00312
00313 QScrollBar *m_columnScroll;
00314 int m_startX;
00315
00316
00317 bool m_selChangedByUser;
00318 KTextEditor::Cursor m_selectAnchor;
00319
00320 enum SelectionMode { Default=0, Mouse, Word, Line };
00321 uint m_selectionMode;
00322
00323
00324
00325 KTextEditor::Range m_selectionCached;
00326
00327
00328 int maxLen(int startLine);
00329
00330
00331 bool columnScrollingPossible ();
00332
00333
00334 int lineMaxCursorX(const KateTextLayout& line);
00335 int lineMaxCol(const KateTextLayout& line);
00336
00337 class KateLayoutCache* cache() const;
00338 KateLayoutCache* m_layoutCache;
00339
00340
00341 KateTextLayout currentLayout() const;
00342 KateTextLayout previousLayout() const;
00343 KateTextLayout nextLayout() const;
00344
00345
00346
00347
00348 KTextEditor::Cursor viewLineOffset(const KTextEditor::Cursor& virtualCursor, int offset, bool keepX = false);
00349
00350 KTextEditor::Cursor toRealCursor(const KTextEditor::Cursor& virtualCursor) const;
00351 KTextEditor::Cursor toVirtualCursor(const KTextEditor::Cursor& realCursor) const;
00352
00353
00354 bool m_preserveMaxX;
00355 int m_currentMaxX;
00356
00357 bool m_updatingView;
00358 int m_wrapChangeViewLine;
00359 KTextEditor::Cursor m_cachedMaxStartPos;
00360
00361 private Q_SLOTS:
00362 void doDragScroll();
00363 void startDragScroll();
00364 void stopDragScroll();
00365
00366 private:
00367
00368 QTimer m_dragScrollTimer;
00369 QTimer m_scrollTimer;
00370 QTimer m_cursorTimer;
00371 QTimer m_textHintTimer;
00372
00373 static const int s_scrollTime = 30;
00374 static const int s_scrollMargin = 16;
00375
00376 private Q_SLOTS:
00377 void scrollTimeout ();
00378 void cursorTimeout ();
00379 void textHintTimeout ();
00380
00381
00382 public:
00383 void enableTextHints(int timeout);
00384 void disableTextHints();
00385
00386 private:
00387 bool m_textHintEnabled;
00388 int m_textHintTimeout;
00389 int m_textHintMouseX;
00390 int m_textHintMouseY;
00391
00395 public:
00396 virtual QVariant inputMethodQuery(Qt::InputMethodQuery query) const;
00397
00398 private:
00399 KTextEditor::SmartRange* m_imPreedit;
00400
00401
00402 public:
00403 void addHighlightRange(KTextEditor::SmartRange* range);
00404 void removeHighlightRange(KTextEditor::SmartRange* range);
00405
00406 private:
00407
00408 struct DynamicRangeHL {
00409 DynamicRangeHL(KateSmartRange* top);
00410 ~DynamicRangeHL();
00411
00412 KateSmartRange* top;
00413 bool isView;
00414 KateSmartRange* caretOver;
00415 KateSmartRange* mouseOver;
00416 QHash<KateSmartRange*, QPointer<class KateDynamicAnimation> > caretAnimations;
00417 QHash<KateSmartRange*, QPointer<KateDynamicAnimation> > mouseAnimations;
00418 };
00419
00420 void mouseMoved();
00421 void cursorMoved();
00422 void dynamicMoved(bool mouse);
00423 void startDynamic(DynamicRangeHL* hl, KateSmartRange* range, KTextEditor::Attribute::ActivationType type);
00424 void endDynamic(DynamicRangeHL* hl, KateSmartRange* range, KTextEditor::Attribute::ActivationType type);
00425
00426 private:
00427
00428 void rangePositionChanged(KTextEditor::SmartRange* range);
00429 void rangeDeleted(KTextEditor::SmartRange* range);
00430 void childRangeInserted(KTextEditor::SmartRange* range, KTextEditor::SmartRange* child);
00431 void childRangeRemoved(KTextEditor::SmartRange* range, KTextEditor::SmartRange* child);
00432 void rangeAttributeChanged(KTextEditor::SmartRange* range, KTextEditor::Attribute::Ptr currentAttribute, KTextEditor::Attribute::Ptr previousAttribute);
00433
00434 public Q_SLOTS:
00435 void dynamicHighlightAdded(KateSmartRange* range);
00436 void dynamicHighlightRemoved(KateSmartRange* range);
00437 void rangeDeleted(KateSmartRange* range);
00438
00439 void updateRange(KateSmartRange* range);
00440
00441 private:
00442 QHash<KateSmartRange*, DynamicRangeHL*> m_dynamicHighlights;
00443 bool m_smartDirty;
00444
00445 void removeWatcher(KTextEditor::SmartRange* range, KTextEditor::SmartRangeWatcher* watcher);
00446 void addWatcher(KTextEditor::SmartRange* range, KTextEditor::SmartRangeWatcher* watcher);
00447 int m_watcherCount1, m_watcherCount3;
00448
00449
00450 private:
00451 bool m_viInputMode;
00452 bool m_viInputModeStealKeys;
00453
00454
00455
00456
00457
00458
00459
00460
00461
00462
00463
00468 ViMode getCurrentViMode();
00469
00474 KateViInputModeManager* m_viInputModeManager;
00475
00479 KateViInputModeManager* getViInputModeManager();
00480 };
00481
00482 #endif
00483
00484