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
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 class KateView;
00045 class KateIconBorder;
00046 class KateScrollBar;
00047 class KateSmartRange;
00048 class KateTextLayout;
00049
00050 class QScrollBar;
00051
00052 class KateViewInternal : public QWidget, private KTextEditor::SmartRangeWatcher
00053 {
00054 Q_OBJECT
00055
00056 friend class KateView;
00057 friend class KateIconBorder;
00058 friend class KateScrollBar;
00059 friend class CalculatingCursor;
00060 friend class BoundedCursor;
00061 friend class WrappingCursor;
00062
00063 public:
00064 enum Bias
00065 {
00066 left = -1,
00067 none = 0,
00068 right = 1
00069 };
00070
00071 public:
00072 KateViewInternal ( KateView *view, KateDocument *doc );
00073 ~KateViewInternal ();
00074
00075
00076 public:
00077 void editStart ();
00078 void editEnd (int editTagLineStart, int editTagLineEnd, bool tagFrom);
00079
00080 void editSetCursor (const KTextEditor::Cursor &cursor);
00081
00082 private:
00083 uint editSessionNumber;
00084 bool editIsRunning;
00085 KTextEditor::Cursor editOldCursor;
00086
00087
00088
00089 public:
00090 bool tagLine (const KTextEditor::Cursor& virtualCursor);
00091
00092 bool tagLines (int start, int end, bool realLines = false);
00093
00094 bool tagLines (KTextEditor::Cursor start, KTextEditor::Cursor end, bool realCursors = false);
00095
00096 bool tagRange(const KTextEditor::Range& range, bool realCursors);
00097
00098 void tagAll ();
00099
00100 void relayoutRange(const KTextEditor::Range& range, bool realCursors = true);
00101
00102 void updateDirty();
00103
00104 void clear ();
00105
00106 Q_SIGNALS:
00107
00108 void requestViewUpdate(bool changed);
00109
00110
00111 private Q_SLOTS:
00112
00113 void updateView (bool changed = false, int viewLinesScrolled = 0);
00114
00115 private:
00116
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
00122 inline const KTextEditor::Cursor& startPos() const { return m_startPos; }
00123 inline int startLine () const { return m_startPos.line(); }
00124 inline 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 KateView *view () { return m_view; }
00135
00136 public Q_SLOTS:
00137 void slotIncFontSizes();
00138 void slotDecFontSizes();
00139
00140 private Q_SLOTS:
00141 void scrollLines(int line);
00142 void scrollViewLines(int offset);
00143 void scrollAction(int action);
00144 void scrollNextPage();
00145 void scrollPrevPage();
00146 void scrollPrevLine();
00147 void scrollNextLine();
00148 void scrollColumns (int x);
00149 void viewSelectionChanged ();
00150
00151 public:
00152 void doReturn();
00153 void doDelete();
00154 void doBackspace();
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;
00180 QPoint cursorToCoordinate(const KTextEditor::Cursor& cursor, bool realCursor = true, bool includeBorder = true) const;
00181 QPoint cursorCoordinates(bool includeBorder = true) const;
00182
00183
00184 private:
00185 void fixDropEvent(QDropEvent *event);
00186 protected:
00187 virtual void hideEvent(QHideEvent* e);
00188 virtual void paintEvent(QPaintEvent *e);
00189 virtual bool eventFilter( QObject *obj, QEvent *e );
00190 virtual void keyPressEvent( QKeyEvent* );
00191 virtual void keyReleaseEvent( QKeyEvent* );
00192 virtual void resizeEvent( QResizeEvent* );
00193 virtual void mousePressEvent( QMouseEvent* );
00194 virtual void mouseDoubleClickEvent( QMouseEvent* );
00195 virtual void mouseReleaseEvent( QMouseEvent* );
00196 virtual void mouseMoveEvent( QMouseEvent* );
00197 virtual void leaveEvent( QEvent* );
00198 virtual void dragEnterEvent( QDragEnterEvent* );
00199 virtual void dragMoveEvent( QDragMoveEvent* );
00200 virtual void dropEvent( QDropEvent* );
00201 virtual void showEvent ( QShowEvent *);
00202 virtual void wheelEvent(QWheelEvent* e);
00203 virtual void focusInEvent (QFocusEvent *);
00204 virtual void focusOutEvent (QFocusEvent *);
00205 virtual void inputMethodEvent(QInputMethodEvent* e);
00206
00207 void contextMenuEvent ( QContextMenuEvent * e );
00208
00209 private Q_SLOTS:
00210 void tripleClickTimeout();
00211
00212 Q_SIGNALS:
00213
00214 void dropEventPass(QDropEvent*);
00215
00216 private Q_SLOTS:
00217 void slotRegionVisibilityChangedAt(unsigned int);
00218 void slotRegionBeginEndAddedRemoved(unsigned int);
00219 void slotCodeFoldingChanged();
00220
00221 private:
00222 void moveChar( Bias bias, bool sel );
00223 void moveEdge( Bias bias, bool sel );
00224 KTextEditor::Cursor maxStartPos(bool changed = false);
00225 void scrollPos(KTextEditor::Cursor& c, bool force = false, bool calledExternally = false);
00226 void scrollLines( int lines, bool sel );
00227
00228 int linesDisplayed() const;
00229
00230 int lineToY(int viewLine) const;
00231
00232 void updateSelection( const KTextEditor::Cursor&, bool keepSel );
00233 void updateCursor( const KTextEditor::Cursor& newCursor, bool force = false, bool center = false, bool calledExternally = false );
00234 void updateBracketMarks();
00235
00236 void paintCursor();
00237
00238 void placeCursor( const QPoint& p, bool keepSelection = false, bool updateSelection = true );
00239 bool isTargetSelected( const QPoint& p );
00240
00241 void doDrag();
00242
00243 inline KateView* view() const { return m_view; }
00244 KateRenderer* renderer() const;
00245
00246 KateView *m_view;
00247 KateDocument* m_doc;
00248 class KateIconBorder *m_leftBorder;
00249
00250 int m_mouseX;
00251 int m_mouseY;
00252 int m_scrollX;
00253 int m_scrollY;
00254
00255 Qt::CursorShape m_mouseCursor;
00256
00257 KateSmartCursor m_cursor;
00258 KTextEditor::Cursor m_mouse;
00259 KTextEditor::Cursor m_displayCursor;
00260 int m_cursorX;
00261
00262 bool m_possibleTripleClick;
00263
00264
00265 KateSmartRange *m_bm, *m_bmStart, *m_bmEnd;
00266 bool m_bmHighlighted;
00267 void updateBracketMarkAttributes();
00268
00269 enum DragState { diNone, diPending, diDragging };
00270
00271 struct _dragInfo {
00272 DragState state;
00273 QPoint start;
00274 QDrag* dragObject;
00275 } m_dragInfo;
00276
00277 uint m_iconBorderHeight;
00278
00279
00280
00281
00282 KateScrollBar *m_lineScroll;
00283 QWidget* m_dummy;
00284
00285
00286
00287 KateSmartCursor m_startPos;
00288
00289
00290
00291 bool m_madeVisible;
00292 bool m_shiftKeyPressed;
00293
00294
00295 void setAutoCenterLines(int viewLines, bool updateView = true);
00296 int m_autoCenterLines;
00297 int m_minLinesVisible;
00298
00299
00300
00301
00302 QScrollBar *m_columnScroll;
00303 int m_startX;
00304
00305
00306 bool m_selChangedByUser;
00307 KTextEditor::Cursor m_selectAnchor;
00308
00309 enum SelectionMode { Default=0, Mouse, Word, Line };
00310 uint m_selectionMode;
00311
00312
00313
00314 KTextEditor::Range m_selectionCached;
00315
00316
00317 int maxLen(int startLine);
00318
00319
00320 bool columnScrollingPossible ();
00321
00322
00323 int lineMaxCursorX(const KateTextLayout& line);
00324 int lineMaxCol(const KateTextLayout& line);
00325
00326 class KateLayoutCache* cache() const;
00327 KateLayoutCache* m_layoutCache;
00328
00329
00330 KateTextLayout currentLayout() const;
00331 KateTextLayout previousLayout() const;
00332 KateTextLayout nextLayout() const;
00333
00334
00335
00336
00337 KTextEditor::Cursor viewLineOffset(const KTextEditor::Cursor& virtualCursor, int offset, bool keepX = false);
00338
00339 KTextEditor::Cursor toRealCursor(const KTextEditor::Cursor& virtualCursor) const;
00340 KTextEditor::Cursor toVirtualCursor(const KTextEditor::Cursor& realCursor) const;
00341
00342
00343 bool m_preserveMaxX;
00344 int m_currentMaxX;
00345
00346 bool m_usePlainLines;
00347
00348 inline KateTextLine::Ptr textLine( int realLine ) const
00349 {
00350 if (m_usePlainLines)
00351 return m_doc->plainKateTextLine(realLine);
00352 else
00353 return m_doc->kateTextLine(realLine);
00354 }
00355
00356 bool m_updatingView;
00357 int m_wrapChangeViewLine;
00358 KTextEditor::Cursor m_cachedMaxStartPos;
00359
00360 private Q_SLOTS:
00361 void doDragScroll();
00362 void startDragScroll();
00363 void stopDragScroll();
00364
00365 private:
00366
00367 QTimer m_dragScrollTimer;
00368 QTimer m_scrollTimer;
00369 QTimer m_cursorTimer;
00370 QTimer m_textHintTimer;
00371
00372 static const int s_scrollTime = 30;
00373 static const int s_scrollMargin = 16;
00374
00375 private Q_SLOTS:
00376 void scrollTimeout ();
00377 void cursorTimeout ();
00378 void textHintTimeout ();
00379
00380
00381 public:
00382 void enableTextHints(int timeout);
00383 void disableTextHints();
00384
00385 private:
00386 bool m_textHintEnabled;
00387 int m_textHintTimeout;
00388 int m_textHintMouseX;
00389 int m_textHintMouseY;
00390
00394 public:
00395 virtual QVariant inputMethodQuery(Qt::InputMethodQuery query) const;
00396
00397 private:
00398 KTextEditor::SmartRange* m_imPreedit;
00399
00400
00401 public:
00402 void addHighlightRange(KTextEditor::SmartRange* range);
00403 void removeHighlightRange(KTextEditor::SmartRange* range);
00404
00405 private:
00406
00407 struct DynamicRangeHL {
00408 DynamicRangeHL(KateSmartRange* top);
00409 ~DynamicRangeHL();
00410
00411 KateSmartRange* top;
00412 bool isView;
00413 KateSmartRange* caretOver;
00414 KateSmartRange* mouseOver;
00415 QHash<KateSmartRange*, QPointer<class KateDynamicAnimation> > caretAnimations;
00416 QHash<KateSmartRange*, QPointer<KateDynamicAnimation> > mouseAnimations;
00417 };
00418
00419 void mouseMoved();
00420 void cursorMoved();
00421 void dynamicMoved(bool mouse);
00422 void startDynamic(DynamicRangeHL* hl, KateSmartRange* range, KTextEditor::Attribute::ActivationType type);
00423 void endDynamic(DynamicRangeHL* hl, KateSmartRange* range, KTextEditor::Attribute::ActivationType type);
00424
00425 private:
00426
00427 void rangePositionChanged(KTextEditor::SmartRange* range);
00428 void rangeDeleted(KTextEditor::SmartRange* range);
00429 void childRangeInserted(KTextEditor::SmartRange* range, KTextEditor::SmartRange* child);
00430 void childRangeRemoved(KTextEditor::SmartRange* range, KTextEditor::SmartRange* child);
00431 void rangeAttributeChanged(KTextEditor::SmartRange* range, KTextEditor::Attribute::Ptr currentAttribute, KTextEditor::Attribute::Ptr previousAttribute);
00432
00433 public Q_SLOTS:
00434 void dynamicHighlightAdded(KateSmartRange* range);
00435 void dynamicHighlightRemoved(KateSmartRange* range);
00436 void rangeDeleted(KateSmartRange* range);
00437
00438 void updateRange(KateSmartRange* range);
00439
00440 private:
00441 QHash<KateSmartRange*, DynamicRangeHL*> m_dynamicHighlights;
00442 bool m_smartDirty;
00443
00444 void removeWatcher(KTextEditor::SmartRange* range, KTextEditor::SmartRangeWatcher* watcher);
00445 void addWatcher(KTextEditor::SmartRange* range, KTextEditor::SmartRangeWatcher* watcher);
00446 int m_watcherCount1, m_watcherCount3;
00447 };
00448
00449 #endif
00450
00451