~ubuntu-branches/ubuntu/vivid/kate/vivid-proposed

« back to all changes in this revision

Viewing changes to part/view/kateviewinternal.h

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2014-12-04 16:49:41 UTC
  • mfrom: (1.6.6)
  • Revision ID: package-import@ubuntu.com-20141204164941-l3qbvsly83hhlw2v
Tags: 4:14.11.97-0ubuntu1
* New upstream release
* Update build-deps and use pkg-kde v3 for Qt 5 build
* kate-data now kate5-data for co-installability

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* This file is part of the KDE libraries
2
 
   Copyright (C) 2002-2007 Hamish Rodda <rodda@kde.org>
3
 
   Copyright (C) 2002 John Firebaugh <jfirebaugh@kde.org>
4
 
   Copyright (C) 2002 Joseph Wenninger <jowenn@kde.org>
5
 
   Copyright (C) 2002 Christoph Cullmann <cullmann@kde.org>
6
 
   Copyright (C) 2007 Mirko Stocker <me@misto.ch>
7
 
 
8
 
   Based on:
9
 
     KWriteView : Copyright (C) 1999 Jochen Wilhelmy <digisnap@cs.tu-berlin.de>
10
 
 
11
 
   This library is free software; you can redistribute it and/or
12
 
   modify it under the terms of the GNU Library General Public
13
 
   License version 2 as published by the Free Software Foundation.
14
 
 
15
 
   This library is distributed in the hope that it will be useful,
16
 
   but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18
 
   Library General Public License for more details.
19
 
 
20
 
   You should have received a copy of the GNU Library General Public License
21
 
   along with this library; see the file COPYING.LIB.  If not, write to
22
 
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
23
 
   Boston, MA 02110-1301, USA.
24
 
*/
25
 
 
26
 
#ifndef _KATE_VIEW_INTERNAL_
27
 
#define _KATE_VIEW_INTERNAL_
28
 
 
29
 
#include <ktexteditor/attribute.h>
30
 
 
31
 
#include "katetextcursor.h"
32
 
#include "katelinelayout.h"
33
 
#include "katetextline.h"
34
 
#include "katedocument.h"
35
 
#include "kateview.h"
36
 
#include "katerenderer.h"
37
 
 
38
 
#include <QtCore/QPoint>
39
 
#include <QtCore/QTimer>
40
 
#include <QtGui/QDrag>
41
 
#include <QtGui/QWidget>
42
 
#include <QtCore/QSet>
43
 
#include <QtCore/QPointer>
44
 
 
45
 
namespace KTextEditor {
46
 
  class MovingRange;
47
 
}
48
 
 
49
 
class KateIconBorder;
50
 
class KateScrollBar;
51
 
class KateTextLayout;
52
 
class KateTextAnimation;
53
 
 
54
 
class KateViInputModeManager;
55
 
 
56
 
class QScrollBar;
57
 
 
58
 
class KateViewInternal : public QWidget
59
 
{
60
 
    Q_OBJECT
61
 
 
62
 
    friend class KateView;
63
 
    friend class KateIconBorder;
64
 
    friend class KateScrollBar;
65
 
    friend class CalculatingCursor;
66
 
    friend class BoundedCursor;
67
 
    friend class WrappingCursor;
68
 
    friend class KateViModeBase;
69
 
 
70
 
  public:
71
 
    enum Bias
72
 
    {
73
 
        left  = -1,
74
 
        none  =  0,
75
 
        right =  1
76
 
    };
77
 
 
78
 
  public:
79
 
    KateViewInternal ( KateView *view );
80
 
    ~KateViewInternal ();
81
 
    KateView *view() const { return m_view; }
82
 
 
83
 
  //BEGIN EDIT STUFF
84
 
  public:
85
 
    void editStart ();
86
 
    void editEnd (int editTagLineStart, int editTagLineEnd, bool tagFrom);
87
 
 
88
 
    void editSetCursor (const KTextEditor::Cursor &cursor);
89
 
 
90
 
  private:
91
 
    uint editSessionNumber;
92
 
    bool editIsRunning;
93
 
    KTextEditor::Cursor editOldCursor;
94
 
    KTextEditor::Range editOldSelection;
95
 
  //END
96
 
 
97
 
  //BEGIN TAG & CLEAR & UPDATE STUFF
98
 
  public:
99
 
    bool tagLine (const KTextEditor::Cursor& virtualCursor);
100
 
 
101
 
    bool tagLines (int start, int end, bool realLines = false);
102
 
    // cursors not const references as they are manipulated within
103
 
    bool tagLines (KTextEditor::Cursor start, KTextEditor::Cursor end, bool realCursors = false);
104
 
 
105
 
    bool tagRange(const KTextEditor::Range& range, bool realCursors);
106
 
 
107
 
    void tagAll ();
108
 
 
109
 
    void updateDirty();
110
 
 
111
 
    void clear ();
112
 
  //END
113
 
 
114
 
  private Q_SLOTS:
115
 
    // Updates the view and requests a redraw.
116
 
    void updateView (bool changed = false, int viewLinesScrolled = 0);
117
 
 
118
 
  private:
119
 
    // Actually performs the updating, but doesn't call update().
120
 
    void doUpdateView(bool changed = false, int viewLinesScrolled = 0);
121
 
    void makeVisible (const KTextEditor::Cursor& c, int endCol, bool force = false, bool center = false, bool calledExternally = false);
122
 
 
123
 
  public:
124
 
    // Start Position is a virtual cursor
125
 
    KTextEditor::Cursor startPos() const { return m_startPos; }
126
 
    int startLine () const { return m_startPos.line(); }
127
 
    int startX () const { return m_startX; }
128
 
 
129
 
    KTextEditor::Cursor endPos () const;
130
 
    int endLine () const;
131
 
 
132
 
    KateTextLayout yToKateTextLayout(int y) const;
133
 
 
134
 
    void prepareForDynWrapChange();
135
 
    void dynWrapChanged();
136
 
 
137
 
  public Q_SLOTS:
138
 
    void slotIncFontSizes();
139
 
    void slotDecFontSizes();
140
 
 
141
 
  private Q_SLOTS:
142
 
    void scrollLines(int line); // connected to the sliderMoved of the m_lineScroll
143
 
    void scrollViewLines(int offset);
144
 
    void scrollAction(int action);
145
 
    void scrollNextPage();
146
 
    void scrollPrevPage();
147
 
    void scrollPrevLine();
148
 
    void scrollNextLine();
149
 
    void scrollColumns (int x); // connected to the valueChanged of the m_columnScroll
150
 
    void viewSelectionChanged ();
151
 
 
152
 
  public:
153
 
    void doReturn();
154
 
    void doSmartNewline();
155
 
    void doDelete();
156
 
    void doBackspace();
157
 
    void doTabulator();
158
 
    void doTranspose();
159
 
    void doDeletePrevWord();
160
 
    void doDeleteNextWord();
161
 
 
162
 
    /**
163
 
     * Set the caret's style.
164
 
     * The caret can be a box or a line; see the documentation
165
 
     * of KateRenderer::caretStyles for other options.
166
 
     * @param style the caret style
167
 
     * @param repaint whether to update the caret instantly.
168
 
     *        This also resets the caret's timer.
169
 
     */
170
 
    void setCaretStyle( KateRenderer::caretStyles style, bool repaint = false );
171
 
    void cursorPrevChar(bool sel=false);
172
 
    void cursorNextChar(bool sel=false);
173
 
    void wordPrev(bool sel=false);
174
 
    void wordNext(bool sel=false);
175
 
    void home(bool sel=false);
176
 
    void end(bool sel=false);
177
 
    void cursorUp(bool sel=false);
178
 
    void cursorDown(bool sel=false);
179
 
    void cursorToMatchingBracket(bool sel=false);
180
 
    void scrollUp();
181
 
    void scrollDown();
182
 
    void topOfView(bool sel=false);
183
 
    void bottomOfView(bool sel=false);
184
 
    void pageUp(bool sel=false, bool half=false);
185
 
    void pageDown(bool sel=false, bool half=false);
186
 
    void top(bool sel=false);
187
 
    void bottom(bool sel=false);
188
 
    void top_home(bool sel=false);
189
 
    void bottom_end(bool sel=false);
190
 
 
191
 
    KTextEditor::Cursor getCursor() const { return m_cursor; }
192
 
    KTextEditor::Cursor getMouse() const { return m_mouse; }
193
 
 
194
 
    QPoint cursorToCoordinate(const KTextEditor::Cursor& cursor, bool realCursor = true, bool includeBorder = true) const;
195
 
    // by default, works on coordinates of the whole widget, eg. offsetted by the border
196
 
    KTextEditor::Cursor coordinatesToCursor(const QPoint& coord, bool includeBorder = true) const;
197
 
    QPoint cursorCoordinates(bool includeBorder = true) const;
198
 
    KTextEditor::Cursor findMatchingBracket();
199
 
 
200
 
  // EVENT HANDLING STUFF - IMPORTANT
201
 
  private:
202
 
    void fixDropEvent(QDropEvent *event);
203
 
  protected:
204
 
    virtual void hideEvent(QHideEvent* e);
205
 
    virtual void paintEvent(QPaintEvent *e);
206
 
    virtual bool eventFilter( QObject *obj, QEvent *e );
207
 
    virtual void keyPressEvent( QKeyEvent* );
208
 
    virtual void keyReleaseEvent( QKeyEvent* );
209
 
    virtual void resizeEvent( QResizeEvent* );
210
 
    virtual void mousePressEvent(       QMouseEvent* );
211
 
    virtual void mouseDoubleClickEvent( QMouseEvent* );
212
 
    virtual void mouseReleaseEvent(     QMouseEvent* );
213
 
    virtual void mouseMoveEvent(        QMouseEvent* );
214
 
    virtual void leaveEvent( QEvent* );
215
 
    virtual void dragEnterEvent( QDragEnterEvent* );
216
 
    virtual void dragMoveEvent( QDragMoveEvent* );
217
 
    virtual void dropEvent( QDropEvent* );
218
 
    virtual void showEvent ( QShowEvent *);
219
 
    virtual void wheelEvent(QWheelEvent* e);
220
 
    virtual void focusInEvent (QFocusEvent *);
221
 
    virtual void focusOutEvent (QFocusEvent *);
222
 
    virtual void inputMethodEvent(QInputMethodEvent* e);
223
 
 
224
 
    void contextMenuEvent ( QContextMenuEvent * e );
225
 
 
226
 
  private Q_SLOTS:
227
 
    void tripleClickTimeout();
228
 
 
229
 
  Q_SIGNALS:
230
 
    // emitted when KateViewInternal is not handling its own URI drops
231
 
    void dropEventPass(QDropEvent*);
232
 
 
233
 
  private Q_SLOTS:
234
 
    void slotRegionVisibilityChanged();
235
 
    void slotRegionBeginEndAddedRemoved(unsigned int);
236
 
 
237
 
  private:
238
 
    void moveChar( Bias bias, bool sel );
239
 
    void moveEdge( Bias bias, bool sel );
240
 
    KTextEditor::Cursor maxStartPos(bool changed = false);
241
 
    void scrollPos(KTextEditor::Cursor& c, bool force = false, bool calledExternally = false);
242
 
    void scrollLines( int lines, bool sel );
243
 
 
244
 
    int linesDisplayed() const;
245
 
 
246
 
    int lineToY(int viewLine) const;
247
 
 
248
 
    void updateSelection( const KTextEditor::Cursor&, bool keepSel );
249
 
    void setSelection( const KTextEditor::Range& );
250
 
    void moveCursorToSelectionEdge();
251
 
    void updateCursor( const KTextEditor::Cursor& newCursor, bool force = false, bool center = false, bool calledExternally = false );
252
 
    void updateBracketMarks();
253
 
 
254
 
    void paintCursor();
255
 
 
256
 
    void placeCursor( const QPoint& p, bool keepSelection = false, bool updateSelection = true );
257
 
    bool isTargetSelected( const QPoint& p );
258
 
    //Returns whether the given range affects the area currently visible in the view
259
 
    bool rangeAffectsView(const KTextEditor::Range& range, bool realCursors) const;
260
 
 
261
 
    void doDrag();
262
 
 
263
 
    KateRenderer* renderer() const;
264
 
 
265
 
    KateView *m_view;
266
 
    class KateIconBorder *m_leftBorder;
267
 
 
268
 
    int m_mouseX;
269
 
    int m_mouseY;
270
 
    int m_scrollX;
271
 
    int m_scrollY;
272
 
 
273
 
    Qt::CursorShape m_mouseCursor;
274
 
 
275
 
    Kate::TextCursor m_cursor;
276
 
    KTextEditor::Cursor m_mouse;
277
 
    KTextEditor::Cursor m_displayCursor;
278
 
 
279
 
    bool m_possibleTripleClick;
280
 
 
281
 
    //Whether the current completion-item was expanded while the last press of ALT
282
 
    bool m_completionItemExpanded;
283
 
    QTime m_altDownTime;
284
 
 
285
 
    // Bracket mark and corresponding decorative ranges
286
 
    KTextEditor::MovingRange *m_bm, *m_bmStart, *m_bmEnd;
287
 
    KTextEditor::MovingCursor * m_bmLastFlashPos;
288
 
    void updateBracketMarkAttributes();
289
 
 
290
 
    enum DragState { diNone, diPending, diDragging };
291
 
 
292
 
    struct _dragInfo {
293
 
      DragState    state;
294
 
      QPoint       start;
295
 
      QDrag*   dragObject;
296
 
    } m_dragInfo;
297
 
 
298
 
    //
299
 
    // line scrollbar + first visible (virtual) line in the current view
300
 
    //
301
 
    KateScrollBar *m_lineScroll;
302
 
    QWidget* m_dummy;
303
 
 
304
 
    // These are now cursors to account for word-wrap.
305
 
    // Start Position is a virtual cursor
306
 
    Kate::TextCursor m_startPos;
307
 
    //Count of lines that are visible behind m_startPos.
308
 
    //This does not respect dynamic word wrap, so take it as an approximation.
309
 
    uint m_visibleLineCount;
310
 
 
311
 
    // This is set to false on resize or scroll (other than that called by makeVisible),
312
 
    // so that makeVisible is again called when a key is pressed and the cursor is in the same spot
313
 
    bool m_madeVisible;
314
 
    bool m_shiftKeyPressed;
315
 
 
316
 
    // How many lines to should be kept visible above/below the cursor when possible
317
 
    void setAutoCenterLines(int viewLines, bool updateView = true);
318
 
    int m_autoCenterLines;
319
 
    int m_minLinesVisible;
320
 
 
321
 
    //
322
 
    // column scrollbar + x position
323
 
    //
324
 
    QScrollBar *m_columnScroll;
325
 
    int m_startX;
326
 
 
327
 
    // has selection changed while your mouse or shift key is pressed
328
 
    bool m_selChangedByUser;
329
 
    KTextEditor::Cursor m_selectAnchor;
330
 
 
331
 
    enum SelectionMode { Default=0, Mouse, Word, Line }; ///< for drag selection.
332
 
    uint m_selectionMode;
333
 
    // when drag selecting after double/triple click, keep the initial selected
334
 
    // word/line independent of direction.
335
 
    // They get set in the event of a double click, and is used with mouse move + leftbutton
336
 
    KTextEditor::Range m_selectionCached;
337
 
 
338
 
    // maximal length of textlines visible from given startLine
339
 
    int maxLen(int startLine);
340
 
 
341
 
    // are we allowed to scroll columns?
342
 
    bool columnScrollingPossible ();
343
 
 
344
 
    // returns the maximum X value / col value a cursor can take for a specific line range
345
 
    int lineMaxCursorX(const KateTextLayout& line);
346
 
    int lineMaxCol(const KateTextLayout& line);
347
 
 
348
 
    class KateLayoutCache* cache() const;
349
 
    KateLayoutCache* m_layoutCache;
350
 
 
351
 
    // convenience methods
352
 
    KateTextLayout currentLayout() const;
353
 
    KateTextLayout previousLayout() const;
354
 
    KateTextLayout nextLayout() const;
355
 
 
356
 
    // find the cursor offset by (offset) view lines from a cursor.
357
 
    // when keepX is true, the column position will be calculated based on the x
358
 
    // position of the specified cursor.
359
 
    KTextEditor::Cursor viewLineOffset(const KTextEditor::Cursor& virtualCursor, int offset, bool keepX = false);
360
 
 
361
 
    KTextEditor::Cursor toRealCursor(const KTextEditor::Cursor& virtualCursor) const;
362
 
    KTextEditor::Cursor toVirtualCursor(const KTextEditor::Cursor& realCursor) const;
363
 
 
364
 
    // These variable holds the most recent maximum real & visible column number
365
 
    bool m_preserveX;
366
 
    int m_preservedX;
367
 
 
368
 
    int m_wrapChangeViewLine;
369
 
    KTextEditor::Cursor m_cachedMaxStartPos;
370
 
 
371
 
  //
372
 
  // implementation details for KTextEditor::FlashTextInterface
373
 
  //
374
 
  public:
375
 
    void flashChar(const KTextEditor::Cursor & pos, KTextEditor::Attribute::Ptr attribute);
376
 
  private:
377
 
    QPointer<KateTextAnimation> m_textAnimation;
378
 
 
379
 
  private Q_SLOTS:
380
 
    void doDragScroll();
381
 
    void startDragScroll();
382
 
    void stopDragScroll();
383
 
 
384
 
  private:
385
 
    // Timers
386
 
    QTimer m_dragScrollTimer;
387
 
    QTimer m_scrollTimer;
388
 
    QTimer m_cursorTimer;
389
 
    QTimer m_textHintTimer;
390
 
 
391
 
    static const int s_scrollTime = 30;
392
 
    static const int s_scrollMargin = 16;
393
 
 
394
 
  private Q_SLOTS:
395
 
    void scrollTimeout ();
396
 
    void cursorTimeout ();
397
 
    void textHintTimeout ();
398
 
 
399
 
  //TextHint
400
 
 public:
401
 
   void enableTextHints(int timeout);
402
 
   void disableTextHints();
403
 
 
404
 
 private:
405
 
   bool m_textHintEnabled;
406
 
   int m_textHintTimeout;
407
 
   QPoint m_textHintPos;
408
 
 
409
 
  /**
410
 
   * IM input stuff
411
 
   */
412
 
  public:
413
 
    virtual QVariant inputMethodQuery(Qt::InputMethodQuery query) const;
414
 
 
415
 
  private:
416
 
    KTextEditor::MovingRange *m_imPreeditRange;
417
 
    QList<KTextEditor::MovingRange *> m_imPreeditRangeChildren;
418
 
 
419
 
  private:
420
 
    void mouseMoved();
421
 
    void cursorMoved();
422
 
 
423
 
  private:
424
 
    inline KateDocument *doc() { return m_view->doc(); }
425
 
    inline KateDocument *doc() const { return m_view->doc(); }
426
 
 
427
 
  // vi Mode
428
 
  private:
429
 
    bool m_viInputMode;
430
 
    bool m_viInputModeStealKeys;
431
 
    bool m_viRelLineNumbers;
432
 
 
433
 
    /**
434
 
     * returns the current vi mode
435
 
     */
436
 
    ViMode getCurrentViMode();
437
 
 
438
 
    /**
439
 
     * an instance of KateViInputModeManager. used for interacting with the vi input mode when
440
 
     * enabled
441
 
     */
442
 
    KateViInputModeManager* m_viInputModeManager;
443
 
 
444
 
    /**
445
 
     * @return a pointer to a KateViInputModeManager
446
 
     */
447
 
    KateViInputModeManager* getViInputModeManager();
448
 
 
449
 
    /**
450
 
     * @return a pointer to a new KateViInputModeManager
451
 
     */
452
 
    KateViInputModeManager* resetViInputModeManager();
453
 
};
454
 
 
455
 
#endif
456
 
 
457
 
// kate: space-indent on; indent-width 2; replace-tabs on;