basetexteditor.h 22.4 KB
Newer Older
1
/**************************************************************************
con's avatar
con committed
2
3
4
**
** This file is part of Qt Creator
**
5
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
con's avatar
con committed
6
**
7
** Contact: Nokia Corporation (qt-info@nokia.com)
con's avatar
con committed
8
**
9
** Commercial Usage
10
**
11
12
13
14
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
15
**
16
** GNU Lesser General Public License Usage
17
**
18
19
20
21
22
23
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24
**
25
** If you are unsure which license is appropriate for your use, please
hjk's avatar
hjk committed
26
** contact the sales department at http://qt.nokia.com/contact.
con's avatar
con committed
27
**
28
**************************************************************************/
hjk's avatar
hjk committed
29

con's avatar
con committed
30
31
32
33
34
35
36
#ifndef BASETEXTEDITOR_H
#define BASETEXTEDITOR_H

#include "displaysettings.h"
#include "tabsettings.h"
#include "itexteditable.h"

37
38
#include <find/ifindsupport.h>

con's avatar
con committed
39
40
41
#include <QtGui/QPlainTextEdit>

QT_BEGIN_NAMESPACE
42
class QKeyEvent;
con's avatar
con committed
43
class QToolBar;
44
class QTimeLine;
con's avatar
con committed
45
46
QT_END_NAMESPACE

47
48
namespace Utils {
    class LineColumnLabel;
49
    class ChangeSet;
con's avatar
con committed
50
51
52
53
54
55
}

namespace TextEditor {

namespace Internal {
    class BaseTextEditorPrivate;
56
    class TextEditorOverlay;
con's avatar
con committed
57
58
59
60
61
62
63
64
65
66
67
68
}

class ITextMark;
class ITextMarkable;

class TextEditorActionHandler;
class BaseTextDocument;
class FontSettings;
struct StorageSettings;

struct Parenthesis;
typedef QVector<Parenthesis> Parentheses;
69

con's avatar
con committed
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
struct TEXTEDITOR_EXPORT Parenthesis
{
    enum Type { Opened, Closed };

    inline Parenthesis() : type(Opened), pos(-1) {}
    inline Parenthesis(Type t, QChar c, int position)
        : type(t), chr(c), pos(position) {}
    Type type;
    QChar chr;
    int pos;
    static int collapseAtPos(const Parentheses &parentheses, QChar *character = 0);
    static int closeCollapseAtPos(const Parentheses &parentheses);
    static bool hasClosingCollapse(const Parentheses &parentheses);
};


86
87
class TEXTEDITOR_EXPORT TextBlockUserData : public QTextBlockUserData
{
con's avatar
con committed
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
public:

    enum CollapseMode { NoCollapse , CollapseThis, CollapseAfter };
    enum ClosingCollapseMode { NoClosingCollapse, ClosingCollapse, ClosingCollapseAtEnd };

    inline TextBlockUserData()
        : m_collapseIncludesClosure(false),
          m_collapseMode(NoCollapse),
          m_closingCollapseMode(NoClosingCollapse),
          m_collapsed(false),
          m_ifdefedOut(false) {}
    ~TextBlockUserData();

    inline TextMarks marks() const { return m_marks; }
    inline void addMark(ITextMark *mark) { m_marks += mark; }
    inline bool removeMark(ITextMark *mark) { return m_marks.removeAll(mark); }
    inline bool hasMark(ITextMark *mark) const { return m_marks.contains(mark); }
    inline void clearMarks() { m_marks.clear(); }
    inline void documentClosing() { Q_FOREACH(ITextMark *tm, m_marks) { tm->documentClosing(); } m_marks.clear();}

    inline CollapseMode collapseMode() const { return (CollapseMode)m_collapseMode; }
    inline void setCollapseMode(CollapseMode c) { m_collapseMode = c; }

    inline void setClosingCollapseMode(ClosingCollapseMode c) { m_closingCollapseMode = c; }
    inline ClosingCollapseMode closingCollapseMode() const { return (ClosingCollapseMode) m_closingCollapseMode; }

    inline bool hasClosingCollapse() const { return closingCollapseMode() != NoClosingCollapse; }
    inline bool hasClosingCollapseAtEnd() const { return closingCollapseMode() == ClosingCollapseAtEnd; }
    inline bool hasClosingCollapseInside() const { return closingCollapseMode() == ClosingCollapse; }

    inline void setCollapsed(bool b) { m_collapsed = b; }
    inline bool collapsed() const { return m_collapsed; }

    inline void setCollapseIncludesClosure(bool b) { m_collapseIncludesClosure = b; }
    inline bool collapseIncludesClosure() const { return m_collapseIncludesClosure; }

    inline void setParentheses(const Parentheses &parentheses) { m_parentheses = parentheses; }
    inline void clearParentheses() { m_parentheses.clear(); }
    inline const Parentheses &parentheses() const { return m_parentheses; }
    inline bool hasParentheses() const { return !m_parentheses.isEmpty(); }
128
    int braceDepthDelta() const;
con's avatar
con committed
129
130
131
132
133

    inline bool setIfdefedOut() { bool result = m_ifdefedOut; m_ifdefedOut = true; return !result; }
    inline bool clearIfdefedOut() { bool result = m_ifdefedOut; m_ifdefedOut = false; return result;}
    inline bool ifdefedOut() const { return m_ifdefedOut; }

134
    inline static TextBlockUserData *canCollapse(const QTextBlock &block) {
con's avatar
con committed
135
136
137
        TextBlockUserData *data = static_cast<TextBlockUserData*>(block.userData());
        if (!data || data->collapseMode() != CollapseAfter) {
            data = static_cast<TextBlockUserData*>(block.next().userData());
mae's avatar
mae committed
138
            if (!data || data->collapseMode() != TextBlockUserData::CollapseThis)
con's avatar
con committed
139
140
                data = 0;
        }
mae's avatar
mae committed
141
142
        if (data && data->m_ifdefedOut)
            data = 0;
con's avatar
con committed
143
144
145
        return data;
    }

146
147
    inline static bool hasCollapseAfter(const QTextBlock & block)
    {
148
        if (!block.isValid()) {
mae's avatar
mae committed
149
150
            return false;
        } else if (block.next().isValid()) {
151
            TextBlockUserData *data = static_cast<TextBlockUserData*>(block.next().userData());
152
153
154
155
156
157
            if (data && data->collapseMode() == TextBlockUserData::CollapseThis &&  !data->m_ifdefedOut)
                return true;
        }
        return false;
    }

con's avatar
con committed
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
    inline static bool hasClosingCollapse(const QTextBlock &block) {
        TextBlockUserData *data = static_cast<TextBlockUserData*>(block.userData());
        return (data && data->hasClosingCollapse());
    }

    inline static bool hasClosingCollapseAtEnd(const QTextBlock &block) {
        TextBlockUserData *data = static_cast<TextBlockUserData*>(block.userData());
        return (data && data->hasClosingCollapseAtEnd());
    }

    inline static bool hasClosingCollapseInside(const QTextBlock &block) {
        TextBlockUserData *data = static_cast<TextBlockUserData*>(block.userData());
        return (data && data->hasClosingCollapseInside());
    }

    static QTextBlock testCollapse(const QTextBlock& block);
    static void doCollapse(const QTextBlock& block, bool visible);

    int collapseAtPos() const;

    enum MatchType { NoMatch, Match, Mismatch  };
    static MatchType checkOpenParenthesis(QTextCursor *cursor, QChar c);
    static MatchType checkClosedParenthesis(QTextCursor *cursor, QChar c);
    static MatchType matchCursorBackward(QTextCursor *cursor);
    static MatchType matchCursorForward(QTextCursor *cursor);
183
184
    static bool findPreviousOpenParenthesis(QTextCursor *cursor, bool select = false);
    static bool findNextClosingParenthesis(QTextCursor *cursor, bool select = false);
con's avatar
con committed
185

mae's avatar
mae committed
186
    static bool findPreviousBlockOpenParenthesis(QTextCursor *cursor, bool checkStartPosition = false);
187
188
    static bool findNextBlockClosingParenthesis(QTextCursor *cursor);

con's avatar
con committed
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217

private:
    TextMarks m_marks;
    uint m_collapseIncludesClosure : 1;
    uint m_collapseMode : 4;
    uint m_closingCollapseMode : 4;
    uint m_collapsed : 1;
    uint m_ifdefedOut : 1;
    Parentheses m_parentheses;
};


class TEXTEDITOR_EXPORT TextEditDocumentLayout : public QPlainTextDocumentLayout
{
    Q_OBJECT

public:
    TextEditDocumentLayout(QTextDocument *doc);
    ~TextEditDocumentLayout();

    QRectF blockBoundingRect(const QTextBlock &block) const;

    static void setParentheses(const QTextBlock &block, const Parentheses &parentheses);
    static void clearParentheses(const QTextBlock &block) { setParentheses(block, Parentheses());}
    static Parentheses parentheses(const QTextBlock &block);
    static bool hasParentheses(const QTextBlock &block);
    static bool setIfdefedOut(const QTextBlock &block);
    static bool clearIfdefedOut(const QTextBlock &block);
    static bool ifdefedOut(const QTextBlock &block);
218
219
220
221
    static int braceDepthDelta(const QTextBlock &block);
    static int braceDepth(const QTextBlock &block);
    static void setBraceDepth(QTextBlock &block, int depth);
    static void changeBraceDepth(QTextBlock &block, int delta);
con's avatar
con committed
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241

    static TextBlockUserData *testUserData(const QTextBlock &block) {
        return static_cast<TextBlockUserData*>(block.userData());
    }
    static TextBlockUserData *userData(const QTextBlock &block) {
        TextBlockUserData *data = static_cast<TextBlockUserData*>(block.userData());
        if (!data && block.isValid())
            const_cast<QTextBlock &>(block).setUserData((data = new TextBlockUserData));
        return data;
    }


    void emitDocumentSizeChanged() { emit documentSizeChanged(documentSize()); }
    int lastSaveRevision;
    bool hasMarks;
};


class BaseTextEditorEditable;

242
243
244
245
246
247
248
class TEXTEDITOR_EXPORT BaseTextEditorAnimator : public QObject
{
    Q_OBJECT

public:
    BaseTextEditorAnimator(QObject *parent);

249
250
    inline void setPosition(int position) { m_position = position; }
    inline int position() const { return m_position; }
251
252
253
254
255
256

    void setData(QFont f, QPalette pal, const QString &text);

    void draw(QPainter *p, const QPointF &pos);
    QRectF rect() const;

257
258
    inline qreal value() const { return m_value; }
    inline QPointF lastDrawPos() const { return m_lastDrawPos; }
259
260
261

    void finish();

mae's avatar
mae committed
262
263
    bool isRunning() const;

264
signals:
265
    void updateRequest(int position, QPointF lastPos, QRectF rect);
266
267
268
269
270
271
272
273
274


private slots:
    void step(qreal v);

private:
    QTimeLine *m_timeline;
    qreal m_value;
    int m_position;
275
    QPointF m_lastDrawPos;
276
277
278
279
280
281
282
    QFont m_font;
    QPalette m_palette;
    QString m_text;
    QSizeF m_size;
};


283
class TEXTEDITOR_EXPORT BaseTextEditor : public QPlainTextEdit
con's avatar
con committed
284
285
286
287
288
289
290
{
    Q_OBJECT

public:
    BaseTextEditor(QWidget *parent);
    ~BaseTextEditor();

291
292
    static ITextEditor *openEditorAt(const QString &fileName, int line, int column = 0,
                                     const QString &editorKind = QString());
con's avatar
con committed
293

294
295
296
    const Utils::ChangeSet &changeSet() const;
    void setChangeSet(const Utils::ChangeSet &changeSet);

con's avatar
con committed
297
298
299
300
301
302
303
304
305
306
    // EditorInterface
    Core::IFile * file();
    bool createNew(const QString &contents);
    bool open(const QString &fileName = QString());
    QByteArray saveState() const;
    bool restoreState(const QByteArray &state);
    QString displayName() const;

    // ITextEditor

307
    void gotoLine(int line, int column = 0);
con's avatar
con committed
308
309
310
311
312
313
314
315
316
317

    int position(
        ITextEditor::PositionOperation posOp = ITextEditor::Current
        , int at = -1) const;
    void convertPosition(int pos, int *line, int *column) const;

    ITextEditable *editableInterface() const;
    ITextMarkable *markableInterface() const;

    virtual void triggerCompletions();
Roberto Raggi's avatar
Roberto Raggi committed
318
    virtual void triggerQuickFix();
con's avatar
con committed
319
320
321
322
323
324
325
326
327
328

    QChar characterAt(int pos) const;

    void print(QPrinter *);

    void setSuggestedFileName(const QString &suggestedFileName);
    QString mimeType() const;
    void setMimeType(const QString &mt);


329
330
    void appendStandardContextMenuActions(QMenu *menu);

con's avatar
con committed
331
332
333
334
335
336
337
338
339
340
341
    // Works only in conjunction with a syntax highlighter that puts
    // parentheses into text block user data
    void setParenthesesMatchingEnabled(bool b);
    bool isParenthesesMatchingEnabled() const;

    void setHighlightCurrentLine(bool b);
    bool highlightCurrentLine() const;

    void setLineNumbersVisible(bool b);
    bool lineNumbersVisible() const;

342

con's avatar
con committed
343
344
345
346
347
348
349
350
351
352
353
354
    void setMarksVisible(bool b);
    bool marksVisible() const;

    void setRequestMarkEnabled(bool b);
    bool requestMarkEnabled() const;

    void setLineSeparatorsAllowed(bool b);
    bool lineSeparatorsAllowed() const;

    void setCodeFoldingVisible(bool b);
    bool codeFoldingVisible() const;

355
356
357
    void setCodeFoldingSupported(bool b);
    bool codeFoldingSupported() const;

358
359
360
    void setMouseNavigationEnabled(bool b);
    bool mouseNavigationEnabled() const;

con's avatar
con committed
361
362
363
364
365
366
367
368
369
370
371
372
373
374
    void setRevisionsVisible(bool b);
    bool revisionsVisible() const;

    void setVisibleWrapColumn(int column);
    int visibleWrapColumn() const;

    void setActionHack(QObject *);
    QObject *actionHack() const;

    void setTextCodec(QTextCodec *codec);
    QTextCodec *textCodec() const;

    void setReadOnly(bool b);

375
376
    void setTextCursor(const QTextCursor &cursor);

con's avatar
con committed
377
378
379
public slots:
    void setDisplayName(const QString &title);

380
    void paste();
con's avatar
con committed
381
382
383
384
385
    void cut();

    void zoomIn(int range = 1);
    void zoomOut(int range = 1);

386
    void cutLine();
con's avatar
con committed
387
388
389
390
391
392
    void deleteLine();
    void unCollapseAll();
    void collapse();
    void expand();
    void selectEncoding();

393
394
395
396
397
    void gotoBlockStart();
    void gotoBlockEnd();
    void gotoBlockStartWithSelection();
    void gotoBlockEndWithSelection();

398
399
400
    void selectBlockUp();
    void selectBlockDown();

401
402
403
    void moveLineUp();
    void moveLineDown();

404
405
406
    void copyLineUp();
    void copyLineDown();

407
408
    void cleanWhitespace();

con's avatar
con committed
409
410
411
412
413
414
415
416
417
418
419
420
signals:
    void changed();

    // ITextEditor
    void contentsChanged();

protected:
    bool event(QEvent *e);
    void keyPressEvent(QKeyEvent *e);
    void wheelEvent(QWheelEvent *e);
    void changeEvent(QEvent *e);

mae's avatar
mae committed
421
422
    void showEvent(QShowEvent *);

con's avatar
con committed
423
424
425
426
427
    // reimplemented to support block selection
    QMimeData *createMimeDataFromSelection() const;
    bool canInsertFromMimeData(const QMimeData *source) const;
    void insertFromMimeData(const QMimeData *source);

428
429
430
private:
    void maybeSelectLine();

con's avatar
con committed
431
432
public:
    void duplicateFrom(BaseTextEditor *editor);
433

con's avatar
con committed
434
435
436
437
438
439
440
441
442
443
444
445
protected:
    BaseTextDocument *baseTextDocument() const;
    void setBaseTextDocument(BaseTextDocument *doc);

    void setDefaultPath(const QString &defaultPath);

    virtual BaseTextEditorEditable *createEditableInterface() = 0;

private slots:
    void editorContentsChange(int position, int charsRemoved, int charsAdded);
    void memorizeCursorPosition();
    void restoreCursorPosition();
446
    void highlightSearchResults(const QString &txt, Find::IFindSupport::FindFlags findFlags);
con's avatar
con committed
447
448
449
450
451
452
    void setFindScope(const QTextCursor &);
    void currentEditorChanged(Core::IEditor *editor);

private:
    Internal::BaseTextEditorPrivate *d;
    friend class Internal::BaseTextEditorPrivate;
453
    friend class Internal::TextEditorOverlay;
con's avatar
con committed
454
455
456
457
458
459

public:
    QWidget *extraArea() const;
    virtual int extraAreaWidth(int *markWidthPtr = 0) const;
    virtual void extraAreaPaintEvent(QPaintEvent *);
    virtual void extraAreaLeaveEvent(QEvent *);
460
    virtual void extraAreaMouseEvent(QMouseEvent *);
con's avatar
con committed
461
462
463
464
465
466
467
468

    const TabSettings &tabSettings() const;
    const DisplaySettings &displaySettings() const;

    void markBlocksAsChanged(QList<int> blockNumbers);

    void ensureCursorVisible();

469
470
471
472
473
474
    enum ExtraSelectionKind {
        CurrentLineSelection,
        ParenthesesMatchingSelection,
        CodeWarningsSelection,
        CodeSemanticsSelection,
        OtherSelection,
hjk's avatar
hjk committed
475
        FakeVimSelection,
476
477
478
479
        NExtraSelectionKinds
    };
    void setExtraSelections(ExtraSelectionKind kind, const QList<QTextEdit::ExtraSelection> &selections);
    QList<QTextEdit::ExtraSelection> extraSelections(ExtraSelectionKind kind) const;
con's avatar
con committed
480

481
482
483
484
485
486
    struct BlockRange
    {
        BlockRange() : first(0), last(-1) {}
        BlockRange(int first_position, int last_position)
          : first(first_position), last(last_position)
        {}
con's avatar
con committed
487
488
489
490
491
492
        int first;
        int last;
        inline bool isNull() const { return last < first; }
    };

    // the blocks list must be sorted
493
    void setIfdefedOutBlocks(const QList<BlockRange> &blocks);
con's avatar
con committed
494
495

public slots:
496
    virtual void format();
497
    virtual void rewrapParagraph();
498
499
    virtual void unCommentSelection();
    virtual void setFontSettings(const TextEditor::FontSettings &);
mae's avatar
mae committed
500
    void setFontSettingsIfVisible(const TextEditor::FontSettings &);
con's avatar
con committed
501
502
    virtual void setTabSettings(const TextEditor::TabSettings &);
    virtual void setDisplaySettings(const TextEditor::DisplaySettings &);
503
    virtual void setStorageSettings(const TextEditor::StorageSettings &);
con's avatar
con committed
504
505
506
507
508
509
510
511
512

protected:
    bool viewportEvent(QEvent *event);

    void resizeEvent(QResizeEvent *);
    void paintEvent(QPaintEvent *);
    void timerEvent(QTimerEvent *);
    void mouseMoveEvent(QMouseEvent *);
    void mousePressEvent(QMouseEvent *);
513
514
515
    void mouseReleaseEvent(QMouseEvent *);
    void leaveEvent(QEvent *);
    void keyReleaseEvent(QKeyEvent *);
con's avatar
con committed
516

517
    // Returns true if key triggers an indent.
con's avatar
con committed
518
    virtual bool isElectricCharacter(const QChar &ch) const;
519
520
521
522
    // Returns the text to complete at the cursor position, or an empty string
    virtual QString autoComplete(QTextCursor &cursor, const QString &text) const;
    // Handles backspace. When returning true, backspace processing is stopped
    virtual bool autoBackspace(QTextCursor &cursor);
523
524
    // Hook to insert special characters on enter. Returns the number of extra blocks inserted.
    virtual int paragraphSeparatorAboutToBeInserted(QTextCursor &cursor);
con's avatar
con committed
525
526
527
528
    // Indent a text block based on previous line. Default does nothing
    virtual void indentBlock(QTextDocument *doc, QTextBlock block, QChar typedChar);
    // Indent at cursor. Calls indentBlock for selection or current line.
    virtual void indent(QTextDocument *doc, const QTextCursor &cursor, QChar typedChar);
mae's avatar
mae committed
529
530
    // Reindent at cursor. Selection will be adjusted according to the indentation change of the first block
    virtual void reindent(QTextDocument *doc, const QTextCursor &cursor);
con's avatar
con committed
531

532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
    struct Link
    {
        Link(const QString &fileName = QString(),
             int line = 0,
             int column = 0)
            : pos(-1)
            , length(-1)
            , fileName(fileName)
            , line(line)
            , column(column)
        {}

        bool isValid() const
        { return !(pos == -1 || length == -1); }

547
548
549
        bool operator==(const Link &other) const
        { return pos == other.pos && length == other.length; }

550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
        int pos;           // Link position
        int length;        // Link length

        QString fileName;  // Target file
        int line;          // Target line
        int column;        // Target column
    };

    /*!
       Reimplement this function to enable code navigation.

       \a resolveTarget is set to true when the target of the link is relevant
       (it isn't until the link is used).
     */
    virtual Link findLinkAt(const QTextCursor &, bool resolveTarget = true);

    /*!
       Reimplement this function if you want to customize the way a link is
       opened. Returns whether the link was opened succesfully.
     */
    virtual bool openLink(const Link &link);

con's avatar
con committed
572
573
574
575
576
577
578
579
protected slots:
    virtual void slotUpdateExtraAreaWidth();
    virtual void slotModificationChanged(bool);
    virtual void slotUpdateRequest(const QRect &r, int dy);
    virtual void slotCursorPositionChanged();
    virtual void slotUpdateBlockNotify(const QTextBlock &);

signals:
mae's avatar
mae committed
580
    void requestFontSize(int pointSize);
con's avatar
con committed
581
    void requestBlockUpdate(const QTextBlock &);
582
583
    void requestAutoCompletion(TextEditor::ITextEditable *editor, bool forced);
    void requestQuickFix(TextEditor::ITextEditable *editor);
con's avatar
con committed
584
585
586
587
588

private:
    void indentOrUnindent(bool doIndent);
    void handleHomeKey(bool anchor);
    void handleBackspaceKey();
589
    void moveLineUpDown(bool up);
590
    void copyLineUpDown(bool up);
591
    void saveCurrentCursorPositionForNavigation();
592
    void updateCurrentLineHighlight();
con's avatar
con committed
593

594
595
596
597
598
    void drawFoldingMarker(QPainter *painter, const QPalette &pal,
                           const QRect &rect,
                           bool expanded,
                           bool active,
                           bool hovered) const;
599

con's avatar
con committed
600
    void toggleBlockVisible(const QTextBlock &block);
601
    QRect collapseBox();
con's avatar
con committed
602
603
604

    QTextBlock collapsedBlockAt(const QPoint &pos, QRect *box = 0) const;

605
    void updateLink(QMouseEvent *e);
606
607
    void showLink(const Link &);
    void clearLink();
mae's avatar
mae committed
608

con's avatar
con committed
609
610
611
    // parentheses matcher
private slots:
    void _q_matchParentheses();
612
    void _q_highlightBlocks();
con's avatar
con committed
613
    void slotSelectionChanged();
614
    void _q_animateUpdate(int position, QPointF lastPos, QRectF rect);
con's avatar
con committed
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
};


class TEXTEDITOR_EXPORT BaseTextEditorEditable
  : public ITextEditable
{
    Q_OBJECT
    friend class BaseTextEditor;
public:
    BaseTextEditorEditable(BaseTextEditor *editor);
    ~BaseTextEditorEditable();

    inline BaseTextEditor *editor() const { return e; }

    // EditorInterface
    inline QWidget *widget() { return e; }
    inline Core::IFile * file() { return e->file(); }
    inline bool createNew(const QString &contents) { return e->createNew(contents); }
    inline bool open(const QString &fileName = QString())
    {
        return e->open(fileName);
    }
    inline QString displayName() const { return e->displayName(); }
    inline void setDisplayName(const QString &title) { e->setDisplayName(title); }

    inline QByteArray saveState() const { return e->saveState(); }
    inline bool restoreState(const QByteArray &state) { return e->restoreState(state); }
con's avatar
con committed
642
    QWidget *toolBar();
con's avatar
con committed
643
644
645
646
647
648

    // ITextEditor
    int find(const QString &string) const;

    int currentLine() const;
    int currentColumn() const;
649
    void gotoLine(int line, int column = 0) { e->gotoLine(line, column); }
con's avatar
con committed
650
651
652
653
654
655
656
657
658
659
660
661
662

    inline int position(
        ITextEditor::PositionOperation posOp = ITextEditor::Current
        , int at = -1) const { return e->position(posOp, at); }
    inline void convertPosition(int pos, int *line, int *column) const { e->convertPosition(pos, line, column); }
    QRect cursorRect(int pos = -1) const;

    QString contents() const;
    QString selectedText() const;
    QString textAt(int pos, int length) const;
    inline QChar characterAt(int pos) const { return e->characterAt(pos); }

    inline void triggerCompletions() { e->triggerCompletions(); } // slot?
Roberto Raggi's avatar
Roberto Raggi committed
663
664
    inline void triggerQuickFix() { e->triggerQuickFix(); } // slot?

con's avatar
con committed
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
    inline ITextMarkable *markableInterface() { return e->markableInterface(); }

    void setContextHelpId(const QString &id) { m_contextHelpId = id; }
    QString contextHelpId() const; // from IContext

    inline void setTextCodec(QTextCodec *codec) { e->setTextCodec(codec); }
    inline QTextCodec *textCodec() const { return e->textCodec(); }


    // ITextEditable
    void remove(int length);
    void insert(const QString &string);
    void replace(int length, const QString &string);
    void setCurPos(int pos);
    void select(int toPos);

private slots:
    void updateCursorPosition();

private:
    BaseTextEditor *e;
    mutable QString m_contextHelpId;
    QToolBar *m_toolBar;
688
    Utils::LineColumnLabel *m_cursorPositionLabel;
con's avatar
con committed
689
690
691
692
693
};

} // namespace TextEditor

#endif // BASETEXTEDITOR_H