Kate
kateviewinternal.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef _KATE_VIEW_INTERNAL_
00025 #define _KATE_VIEW_INTERNAL_
00026
00027 #include "katecursor.h"
00028 #include "katesupercursor.h"
00029 #include "katelinerange.h"
00030 #include "katetextline.h"
00031 #include "katedocument.h"
00032
00033 #include <qpoint.h>
00034 #include <qtimer.h>
00035 #include <qintdict.h>
00036
00037 class KateView;
00038 class KateIconBorder;
00039 class KateScrollBar;
00040
00041 class QHBoxLayout;
00042 class QVBoxLayout;
00043 class QScrollBar;
00044
00045 enum Bias
00046 {
00047 left = -1,
00048 none = 0,
00049 right = 1
00050 };
00051
00052 class KateViewInternal : public QWidget
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 KateViewInternal ( KateView *view, KateDocument *doc );
00065 ~KateViewInternal ();
00066
00067
00068 public:
00069 void editStart ();
00070 void editEnd (int editTagLineStart, int editTagLineEnd, bool tagFrom);
00071
00072 void editSetCursor (const KateTextCursor &cursor);
00073
00074 private:
00075 uint editSessionNumber;
00076 bool editIsRunning;
00077 KateTextCursor editOldCursor;
00078
00079
00080
00081 public:
00082 bool tagLine (const KateTextCursor& virtualCursor);
00083
00084 bool tagLines (int start, int end, bool realLines = false);
00085 bool tagLines (KateTextCursor start, KateTextCursor end, bool realCursors = false);
00086
00087 void tagAll ();
00088
00089 void clear ();
00090
00091
00092 private:
00093 void updateView (bool changed = false, int viewLinesScrolled = 0);
00094 void makeVisible (const KateTextCursor& c, uint endCol, bool force = false, bool center = false, bool calledExternally = false);
00095
00096 public:
00097 inline const KateTextCursor& startPos() const { return m_startPos; }
00098 inline uint startLine () const { return m_startPos.line(); }
00099 inline uint startX () const { return m_startX; }
00100
00101 KateTextCursor endPos () const;
00102 uint endLine () const;
00103
00104 KateLineRange yToKateLineRange(uint y) const;
00105
00106 void prepareForDynWrapChange();
00107 void dynWrapChanged();
00108
00109 KateView *view () { return m_view; }
00110
00111 public slots:
00112 void slotIncFontSizes();
00113 void slotDecFontSizes();
00114
00115 private slots:
00116 void scrollLines(int line);
00117 void scrollViewLines(int offset);
00118 void scrollNextPage();
00119 void scrollPrevPage();
00120 void scrollPrevLine();
00121 void scrollNextLine();
00122 void scrollColumns (int x);
00123 void viewSelectionChanged ();
00124
00125 public:
00126 void doReturn();
00127 void doDelete();
00128 void doBackspace();
00129 void doTranspose();
00130 void doDeleteWordLeft();
00131 void doDeleteWordRight();
00132
00133 void cursorLeft(bool sel=false);
00134 void cursorRight(bool sel=false);
00135 void wordLeft(bool sel=false);
00136 void wordRight(bool sel=false);
00137 void home(bool sel=false);
00138 void end(bool sel=false);
00139 void cursorUp(bool sel=false);
00140 void cursorDown(bool sel=false);
00141 void cursorToMatchingBracket(bool sel=false);
00142 void scrollUp();
00143 void scrollDown();
00144 void topOfView(bool sel=false);
00145 void bottomOfView(bool sel=false);
00146 void pageUp(bool sel=false);
00147 void pageDown(bool sel=false);
00148 void top(bool sel=false);
00149 void bottom(bool sel=false);
00150 void top_home(bool sel=false);
00151 void bottom_end(bool sel=false);
00152
00153 inline const KateTextCursor& getCursor() { return cursor; }
00154 QPoint cursorCoordinates();
00155
00156 void paintText (int x, int y, int width, int height, bool paintOnlyDirty = false);
00157
00158
00159 protected:
00160 void paintEvent(QPaintEvent *e);
00161 bool eventFilter( QObject *obj, QEvent *e );
00162 void keyPressEvent( QKeyEvent* );
00163 void keyReleaseEvent( QKeyEvent* );
00164 void resizeEvent( QResizeEvent* );
00165 void mousePressEvent( QMouseEvent* );
00166 void mouseDoubleClickEvent( QMouseEvent* );
00167 void mouseReleaseEvent( QMouseEvent* );
00168 void mouseMoveEvent( QMouseEvent* );
00169 void dragEnterEvent( QDragEnterEvent* );
00170 void dragMoveEvent( QDragMoveEvent* );
00171 void dropEvent( QDropEvent* );
00172 void showEvent ( QShowEvent *);
00173 void wheelEvent(QWheelEvent* e);
00174 void focusInEvent (QFocusEvent *);
00175 void focusOutEvent (QFocusEvent *);
00176
00177 void contextMenuEvent ( QContextMenuEvent * e );
00178
00179 private slots:
00180 void tripleClickTimeout();
00181
00182 signals:
00183
00184 void dropEventPass(QDropEvent*);
00185
00186 private slots:
00187 void slotRegionVisibilityChangedAt(unsigned int);
00188 void slotRegionBeginEndAddedRemoved(unsigned int);
00189 void slotCodeFoldingChanged();
00190
00191 private:
00192 void moveChar( Bias bias, bool sel );
00193 void moveEdge( Bias bias, bool sel );
00194 KateTextCursor maxStartPos(bool changed = false);
00195 void scrollPos(KateTextCursor& c, bool force = false, bool calledExternally = false);
00196 void scrollLines( int lines, bool sel );
00197
00198 uint linesDisplayed() const;
00199
00200 int lineToY(uint viewLine) const;
00201
00202 void updateSelection( const KateTextCursor&, bool keepSel );
00203 void updateCursor( const KateTextCursor& newCursor, bool force = false, bool center = false, bool calledExternally = false );
00204 void updateBracketMarks();
00205
00206 void paintCursor();
00207
00208 void updateMicroFocusHint();
00209
00210 void placeCursor( const QPoint& p, bool keepSelection = false, bool updateSelection = true );
00211 bool isTargetSelected( const QPoint& p );
00212
00213 void doDrag();
00214
00215 KateView *m_view;
00216 KateDocument* m_doc;
00217 class KateIconBorder *leftBorder;
00218
00219 int mouseX;
00220 int mouseY;
00221 int scrollX;
00222 int scrollY;
00223
00224 Qt::CursorShape m_mouseCursor;
00225
00226 KateSuperCursor cursor;
00227 KateTextCursor displayCursor;
00228 int cXPos;
00229
00230 bool possibleTripleClick;
00231
00232
00233 KateBracketRange bm;
00234
00235 enum DragState { diNone, diPending, diDragging };
00236
00237 struct _dragInfo {
00238 DragState state;
00239 QPoint start;
00240 QTextDrag* dragObject;
00241 } dragInfo;
00242
00243 uint iconBorderHeight;
00244
00245
00246
00247
00248 KateScrollBar *m_lineScroll;
00249 QWidget* m_dummy;
00250 QVBoxLayout* m_lineLayout;
00251 QHBoxLayout* m_colLayout;
00252
00253
00254 KateSuperCursor m_startPos;
00255
00256
00257
00258 bool m_madeVisible;
00259 bool m_shiftKeyPressed;
00260
00261
00262 void setAutoCenterLines(int viewLines, bool updateView = true);
00263 int m_autoCenterLines;
00264 int m_minLinesVisible;
00265
00266
00267
00268
00269 QScrollBar *m_columnScroll;
00270 int m_startX;
00271
00272
00273 bool m_selChangedByUser;
00274 KateTextCursor selectAnchor;
00275
00276 enum SelectionMode { Default=0, Word, Line, Mouse };
00277 uint m_selectionMode;
00278
00279
00280
00281 KateTextCursor selStartCached;
00282 KateTextCursor selEndCached;
00283
00284
00285
00286
00287 QMemArray<KateLineRange> lineRanges;
00288
00289
00290 int maxLen(uint startLine);
00291
00292
00293 bool columnScrollingPossible ();
00294
00295
00296 int lineMaxCursorX(const KateLineRange& range);
00297 int lineMaxCol(const KateLineRange& range);
00298
00299
00300
00301 KateLineRange range(int realLine, const KateLineRange* previous = 0L);
00302
00303 KateLineRange currentRange();
00304 KateLineRange previousRange();
00305 KateLineRange nextRange();
00306
00307
00308 KateLineRange range(const KateTextCursor& realCursor);
00309
00310
00311 KateLineRange range(uint realLine, int viewLine);
00312
00313
00314 uint viewLine(const KateTextCursor& realCursor);
00315
00316
00317
00318 int displayViewLine(const KateTextCursor& virtualCursor, bool limitToVisible = false);
00319
00320
00321 uint lastViewLine(uint realLine);
00322
00323
00324 uint viewLineCount(uint realLine);
00325
00326
00327
00328
00329 KateTextCursor viewLineOffset(const KateTextCursor& virtualCursor, int offset, bool keepX = false);
00330
00331
00332 bool m_preserveMaxX;
00333 int m_currentMaxX;
00334
00335 bool m_usePlainLines;
00336
00337 inline KateTextLine::Ptr textLine( int realLine )
00338 {
00339 if (m_usePlainLines)
00340 return m_doc->plainKateTextLine(realLine);
00341 else
00342 return m_doc->kateTextLine(realLine);
00343 }
00344
00345 bool m_updatingView;
00346 int m_wrapChangeViewLine;
00347 KateTextCursor m_cachedMaxStartPos;
00348
00349 private slots:
00350 void doDragScroll();
00351 void startDragScroll();
00352 void stopDragScroll();
00353
00354 private:
00355
00356 QTimer m_dragScrollTimer;
00357 QTimer m_scrollTimer;
00358 QTimer m_cursorTimer;
00359 QTimer m_textHintTimer;
00360
00361 static const int scrollTime = 30;
00362 static const int scrollMargin = 16;
00363
00364 private slots:
00365 void scrollTimeout ();
00366 void cursorTimeout ();
00367 void textHintTimeout ();
00368
00369
00370 public:
00371 void enableTextHints(int timeout);
00372 void disableTextHints();
00373
00374 private:
00375 bool m_textHintEnabled;
00376 int m_textHintTimeout;
00377 int m_textHintMouseX;
00378 int m_textHintMouseY;
00379
00383 protected:
00384 void imStartEvent( QIMEvent *e );
00385 void imComposeEvent( QIMEvent *e );
00386 void imEndEvent( QIMEvent *e );
00387
00388 private:
00389 int m_imPreeditStartLine;
00390 int m_imPreeditStart;
00391 int m_imPreeditLength;
00392 int m_imPreeditSelStart;
00393 };
00394
00395 #endif
00396
00397