basetexteditor.h 20.2 KB
Newer Older
hjk's avatar
hjk committed
1
/****************************************************************************
con's avatar
con committed
2
**
3
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
hjk's avatar
hjk committed
4
** Contact: http://www.qt-project.org/legal
con's avatar
con committed
5
**
hjk's avatar
hjk committed
6
** This file is part of Qt Creator.
con's avatar
con committed
7
**
hjk's avatar
hjk committed
8
9
10
11
12
13
14
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia.  For licensing terms and
** conditions see http://qt.digia.com/licensing.  For further information
** use the contact form at http://qt.digia.com/contact-us.
15
**
16
** GNU Lesser General Public License Usage
hjk's avatar
hjk committed
17
18
19
20
21
22
** 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.
23
**
hjk's avatar
hjk committed
24
25
** In addition, as a special exception, Digia gives you certain additional
** rights.  These rights are described in the Digia Qt LGPL Exception
con's avatar
con committed
26
27
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
hjk's avatar
hjk committed
28
****************************************************************************/
hjk's avatar
hjk committed
29

con's avatar
con committed
30
31
32
#ifndef BASETEXTEDITOR_H
#define BASETEXTEDITOR_H

33
#include "itexteditor.h"
Leandro Melo's avatar
Leandro Melo committed
34
#include "codeassist/assistenums.h"
con's avatar
con committed
35

36
#include <coreplugin/editormanager/editormanager.h>
Orgad Shaneh's avatar
Orgad Shaneh committed
37
#include <find/ifindsupport.h>
38

39
#include <QPlainTextEdit>
40
#include <QSharedPointer>
con's avatar
con committed
41
42
43

QT_BEGIN_NAMESPACE
class QToolBar;
44
class QTimeLine;
Friedemann Kleint's avatar
Friedemann Kleint committed
45
class QPrinter;
con's avatar
con committed
46
47
QT_END_NAMESPACE

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

namespace TextEditor {
54
class TabSettings;
55
56
class RefactorOverlay;
struct RefactorMarker;
Leandro Melo's avatar
Leandro Melo committed
57
58
59
class IAssistMonitorInterface;
class IAssistInterface;
class IAssistProvider;
Jarek Kobus's avatar
Jarek Kobus committed
60
class ICodeStylePreferences;
61
class CompletionAssistProvider;
Christian Stenger's avatar
Christian Stenger committed
62
typedef QList<RefactorMarker> RefactorMarkers;
con's avatar
con committed
63
64

namespace Internal {
65
    class BaseTextEditorWidgetPrivate;
66
    class TextEditorOverlay;
67
    typedef QString (QString::*TransformationMethod)() const;
con's avatar
con committed
68
69
70
71
72
}

class ITextMarkable;

class BaseTextDocument;
73
class BaseTextEditor;
con's avatar
con committed
74
class FontSettings;
75
76
77
class BehaviorSettings;
class CompletionSettings;
class DisplaySettings;
Jarek Kobus's avatar
Jarek Kobus committed
78
class TypingSettings;
79
class StorageSettings;
80
class Indenter;
81
class AutoCompleter;
82
class ExtraEncodingSettings;
con's avatar
con committed
83

84
85
86
87
88
89
90
class TEXTEDITOR_EXPORT BaseTextEditorAnimator : public QObject
{
    Q_OBJECT

public:
    BaseTextEditorAnimator(QObject *parent);

91
92
    inline void setPosition(int position) { m_position = position; }
    inline int position() const { return m_position; }
93
94
95
96
97
98

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

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

99
100
    inline qreal value() const { return m_value; }
    inline QPointF lastDrawPos() const { return m_lastDrawPos; }
101
102
103

    void finish();

mae's avatar
mae committed
104
105
    bool isRunning() const;

106
signals:
107
    void updateRequest(int position, QPointF lastPos, QRectF rect);
108
109
110
111
112
113
114
115
116


private slots:
    void step(qreal v);

private:
    QTimeLine *m_timeline;
    qreal m_value;
    int m_position;
117
    QPointF m_lastDrawPos;
118
119
120
121
122
123
124
    QFont m_font;
    QPalette m_palette;
    QString m_text;
    QSizeF m_size;
};


125
class TEXTEDITOR_EXPORT BaseTextEditorWidget : public QPlainTextEdit
con's avatar
con committed
126
127
{
    Q_OBJECT
mae's avatar
mae committed
128
129
    Q_PROPERTY(int verticalBlockSelectionFirstColumn READ verticalBlockSelectionFirstColumn)
    Q_PROPERTY(int verticalBlockSelectionLastColumn READ verticalBlockSelectionLastColumn)
hjk's avatar
hjk committed
130

con's avatar
con committed
131
public:
132
133
    BaseTextEditorWidget(QWidget *parent);
    ~BaseTextEditorWidget();
con's avatar
con committed
134

135
136
137
    const Utils::ChangeSet &changeSet() const;
    void setChangeSet(const Utils::ChangeSet &changeSet);

con's avatar
con committed
138
    // EditorInterface
139
    Core::IDocument *editorDocument() const;
140
    virtual bool open(QString *errorString, const QString &fileName, const QString &realFileName);
con's avatar
con committed
141
142
143
    QByteArray saveState() const;
    bool restoreState(const QByteArray &state);

144
    void gotoLine(int line, int column = 0);
con's avatar
con committed
145

hjk's avatar
hjk committed
146
147
    int position(ITextEditor::PositionOperation posOp = ITextEditor::Current,
         int at = -1) const;
con's avatar
con committed
148
149
    void convertPosition(int pos, int *line, int *column) const;

150
    BaseTextEditor *editor() const;
con's avatar
con committed
151
152
153
154
155
156
    ITextMarkable *markableInterface() const;

    void print(QPrinter *);

    void setSuggestedFileName(const QString &suggestedFileName);
    QString mimeType() const;
Erik Verbruggen's avatar
Erik Verbruggen committed
157
    virtual void setMimeType(const QString &mt);
con's avatar
con committed
158

hjk's avatar
hjk committed
159
    void appendMenuActionsFromContext(QMenu *menu, Core::Id menuContextId);
160
161
    void appendStandardContextMenuActions(QMenu *menu);

con's avatar
con committed
162
163
164
165
166
167
168
169
170
171
172
    // 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;

173
174
    void setAlwaysOpenLinksInNextSplit(bool b);
    bool alwaysOpenLinksInNextSplit() const;
175

con's avatar
con committed
176
177
178
179
180
181
182
183
184
    void setMarksVisible(bool b);
    bool marksVisible() const;

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

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

185
    void updateCodeFoldingVisible();
con's avatar
con committed
186
187
    bool codeFoldingVisible() const;

188
189
190
    void setCodeFoldingSupported(bool b);
    bool codeFoldingSupported() const;

191
192
193
    void setMouseNavigationEnabled(bool b);
    bool mouseNavigationEnabled() const;

194
195
196
    void setScrollWheelZoomingEnabled(bool b);
    bool scrollWheelZoomingEnabled() const;

197
198
199
    void setConstrainTooltips(bool b);
    bool constrainTooltips() const;

200
201
202
    void setCamelCaseNavigationEnabled(bool b);
    bool camelCaseNavigationEnabled() const;

con's avatar
con committed
203
204
205
206
207
208
    void setRevisionsVisible(bool b);
    bool revisionsVisible() const;

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

209
210
211
    int columnCount() const;
    int rowCount() const;

hjk's avatar
hjk committed
212
    void setActionHack(QObject *hack);
con's avatar
con committed
213
214
215
216
    QObject *actionHack() const;

    void setReadOnly(bool b);

217
218
    void setTextCursor(const QTextCursor &cursor);

mae's avatar
mae committed
219
    void insertCodeSnippet(const QTextCursor &cursor, const QString &snippet);
220

221
222
    void setBlockSelection(bool on);
    bool hasBlockSelection() const;
223

mae's avatar
mae committed
224
225
    int verticalBlockSelectionFirstColumn() const;
    int verticalBlockSelectionLastColumn() const;
226

227
228
    QRegion translatedLineRegion(int lineStart, int lineEnd) const;

229
    void setIndenter(Indenter *indenter);
230
    Indenter *indenter() const;
231

232
233
234
    void setAutoCompleter(AutoCompleter *autoCompleter);
    AutoCompleter *autoCompleter() const;

235
236
    QPoint toolTipPosition(const QTextCursor &c) const;

Leandro Melo's avatar
Leandro Melo committed
237
238
239
240
    void invokeAssist(AssistKind assistKind, IAssistProvider *provider = 0);

    virtual IAssistInterface *createAssistInterface(AssistKind assistKind,
                                                    AssistReason assistReason) const;
241
    QMimeData *duplicateMimeData(const QMimeData *source) const;
Leandro Melo's avatar
Leandro Melo committed
242

243
244
    static QString msgTextTooLarge(quint64 size);

con's avatar
con committed
245
public slots:
246
    virtual void copy();
mae's avatar
mae committed
247
248
    virtual void paste();
    virtual void cut();
249
    virtual void selectAll();
con's avatar
con committed
250

251
    void circularPaste();
252
    void switchUtf8bom();
253

con's avatar
con committed
254
255
    void zoomIn(int range = 1);
    void zoomOut(int range = 1);
mae's avatar
mae committed
256
    void zoomReset();
con's avatar
con committed
257

258
    void cutLine();
259
    void copyLine();
con's avatar
con committed
260
    void deleteLine();
261
262
263
264
    void deleteEndOfWord();
    void deleteEndOfWordCamelCase();
    void deleteStartOfWord();
    void deleteStartOfWordCamelCase();
mae's avatar
mae committed
265
266
267
    void unfoldAll();
    void fold();
    void unfold();
con's avatar
con committed
268
    void selectEncoding();
269
    void updateTextCodecLabel();
con's avatar
con committed
270

271
272
273
274
275
    void gotoBlockStart();
    void gotoBlockEnd();
    void gotoBlockStartWithSelection();
    void gotoBlockEndWithSelection();

mae's avatar
mae committed
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
    void gotoLineStart();
    void gotoLineStartWithSelection();
    void gotoLineEnd();
    void gotoLineEndWithSelection();
    void gotoNextLine();
    void gotoNextLineWithSelection();
    void gotoPreviousLine();
    void gotoPreviousLineWithSelection();
    void gotoPreviousCharacter();
    void gotoPreviousCharacterWithSelection();
    void gotoNextCharacter();
    void gotoNextCharacterWithSelection();
    void gotoPreviousWord();
    void gotoPreviousWordWithSelection();
    void gotoNextWord();
    void gotoNextWordWithSelection();
mae's avatar
mae committed
292
293
294
295
    void gotoPreviousWordCamelCase();
    void gotoPreviousWordCamelCaseWithSelection();
    void gotoNextWordCamelCase();
    void gotoNextWordCamelCaseWithSelection();
296

297
298
    bool selectBlockUp();
    bool selectBlockDown();
299

300
301
302
    void moveLineUp();
    void moveLineDown();

303
304
305
    void copyLineUp();
    void copyLineDown();

306
    void joinLines();
307

308
309
310
    void insertLineAbove();
    void insertLineBelow();

311
312
313
    void uppercaseSelection();
    void lowercaseSelection();

314
315
    void cleanWhitespace();

316
317
318
    void indent();
    void unindent();

319
    void openLinkUnderCursor();
320
    void openLinkUnderCursorInNextSplit();
321

322
323
324
    /// Abort code assistant if it is running.
    void abortAssist();

con's avatar
con committed
325
326
signals:
    void changed();
327
    void assistFinished();
con's avatar
con committed
328
329
330
331
332
333
334
335
336

    // ITextEditor
    void contentsChanged();

protected:
    bool event(QEvent *e);
    void keyPressEvent(QKeyEvent *e);
    void wheelEvent(QWheelEvent *e);
    void changeEvent(QEvent *e);
337
    void focusInEvent(QFocusEvent *e);
mae's avatar
mae committed
338
    void focusOutEvent(QFocusEvent *e);
con's avatar
con committed
339

mae's avatar
mae committed
340
341
    void showEvent(QShowEvent *);

con's avatar
con committed
342
343
344
345
    QMimeData *createMimeDataFromSelection() const;
    bool canInsertFromMimeData(const QMimeData *source) const;
    void insertFromMimeData(const QMimeData *source);

346
    virtual QString plainTextFromSelection(const QTextCursor &cursor) const;
347
348
349
350
    static QString convertToPlainText(const QString &txt);

    virtual QString lineNumber(int blockNumber) const;
    virtual int lineNumberDigits() const;
jkobus's avatar
jkobus committed
351
    virtual bool selectionVisible(int blockNumber) const;
352
    virtual bool replacementVisible(int blockNumber) const;
jkobus's avatar
jkobus committed
353
    virtual QColor replacementPenColor(int blockNumber) const;
354

355
356
private:
    void maybeSelectLine();
357
    void updateCannotDecodeInfo();
358

con's avatar
con committed
359
public:
360
    void duplicateFrom(BaseTextEditorWidget *editor);
361

con's avatar
con committed
362
protected:
363
364
    QSharedPointer<BaseTextDocument> baseTextDocument() const;
    void setBaseTextDocument(const QSharedPointer<BaseTextDocument> &doc);
con's avatar
con committed
365
366
367

    void setDefaultPath(const QString &defaultPath);

368
    virtual BaseTextEditor *createEditor() = 0;
con's avatar
con committed
369
370
371

private slots:
    void editorContentsChange(int position, int charsRemoved, int charsAdded);
mae's avatar
mae committed
372
    void documentAboutToBeReloaded();
373
    void documentReloadFinished(bool success);
374
    void highlightSearchResults(const QString &txt, Find::FindFlags findFlags);
mae's avatar
mae committed
375
376
377
    void setFindScope(const QTextCursor &start, const QTextCursor &end, int, int);
    bool inFindScope(const QTextCursor &cursor);
    bool inFindScope(int selectionStart, int selectionEnd);
378
    void inSnippetMode(bool *active);
379
    void onCodeStylePreferencesDestroyed();
con's avatar
con committed
380
381

private:
382
383
    Internal::BaseTextEditorWidgetPrivate *d;
    friend class Internal::BaseTextEditorWidgetPrivate;
384
    friend class Internal::TextEditorOverlay;
385
    friend class RefactorOverlay;
con's avatar
con committed
386
387
388
389
390
391

public:
    QWidget *extraArea() const;
    virtual int extraAreaWidth(int *markWidthPtr = 0) const;
    virtual void extraAreaPaintEvent(QPaintEvent *);
    virtual void extraAreaLeaveEvent(QEvent *);
392
    virtual void extraAreaContextMenuEvent(QContextMenuEvent *);
393
    virtual void extraAreaMouseEvent(QMouseEvent *);
394
    void updateFoldingHighlight(const QPoint &pos);
con's avatar
con committed
395
396

    const TabSettings &tabSettings() const;
Orgad Shaneh's avatar
Orgad Shaneh committed
397
398
    void setLanguageSettingsId(Core::Id settingsId);
    Core::Id languageSettingsId() const;
399

Jarek Kobus's avatar
Jarek Kobus committed
400
    void setCodeStyle(ICodeStylePreferences *settings);
401

con's avatar
con committed
402
403
404
405
406
407
    const DisplaySettings &displaySettings() const;

    void markBlocksAsChanged(QList<int> blockNumbers);

    void ensureCursorVisible();

408
409
410
411
412
    enum ExtraSelectionKind {
        CurrentLineSelection,
        ParenthesesMatchingSelection,
        CodeWarningsSelection,
        CodeSemanticsSelection,
413
        UndefinedSymbolSelection,
Roberto Raggi's avatar
Roberto Raggi committed
414
        UnusedSymbolSelection,
hjk's avatar
hjk committed
415
        FakeVimSelection,
Roberto Raggi's avatar
Roberto Raggi committed
416
        OtherSelection,
417
        SnippetPlaceholderSelection,
Erik Verbruggen's avatar
Erik Verbruggen committed
418
        ObjCSelection,
Aurindam Jana's avatar
Aurindam Jana committed
419
        DebuggerExceptionSelection,
420
421
422
423
        NExtraSelectionKinds
    };
    void setExtraSelections(ExtraSelectionKind kind, const QList<QTextEdit::ExtraSelection> &selections);
    QList<QTextEdit::ExtraSelection> extraSelections(ExtraSelectionKind kind) const;
424
    QString extraSelectionTooltip(int pos) const;
con's avatar
con committed
425

Christian Stenger's avatar
Christian Stenger committed
426
427
    RefactorMarkers refactorMarkers() const;
    void setRefactorMarkers(const RefactorMarkers &markers);
428
signals:
429
    void refactorMarkerClicked(const TextEditor::RefactorMarker &marker);
430
431

public:
con's avatar
con committed
432
    // the blocks list must be sorted
433
    void setIfdefedOutBlocks(const QList<BlockRange> &blocks);
con's avatar
con committed
434
435

public slots:
436
    virtual void format();
437
    virtual void rewrapParagraph();
438
439
    virtual void unCommentSelection();
    virtual void setFontSettings(const TextEditor::FontSettings &);
mae's avatar
mae committed
440
    void setFontSettingsIfVisible(const TextEditor::FontSettings &);
con's avatar
con committed
441
442
    virtual void setTabSettings(const TextEditor::TabSettings &);
    virtual void setDisplaySettings(const TextEditor::DisplaySettings &);
443
    virtual void setBehaviorSettings(const TextEditor::BehaviorSettings &);
Jarek Kobus's avatar
Jarek Kobus committed
444
    virtual void setTypingSettings(const TextEditor::TypingSettings &);
445
    virtual void setStorageSettings(const TextEditor::StorageSettings &);
446
    virtual void setCompletionSettings(const TextEditor::CompletionSettings &);
447
    virtual void setExtraEncodingSettings(const TextEditor::ExtraEncodingSettings &);
con's avatar
con committed
448
449
450
451
452
453
454
455
456

protected:
    bool viewportEvent(QEvent *event);

    void resizeEvent(QResizeEvent *);
    void paintEvent(QPaintEvent *);
    void timerEvent(QTimerEvent *);
    void mouseMoveEvent(QMouseEvent *);
    void mousePressEvent(QMouseEvent *);
457
    void mouseReleaseEvent(QMouseEvent *);
458
    void mouseDoubleClickEvent(QMouseEvent *);
459
460
    void leaveEvent(QEvent *);
    void keyReleaseEvent(QKeyEvent *);
con's avatar
con committed
461

462
463
    void dragEnterEvent(QDragEnterEvent *e);

464
465
    void showDefaultContextMenu(QContextMenuEvent *e, const Core::Id menuContextId);

466
public:
467
    void indentInsertedText(const QTextCursor &tc);
468
469
    void indent(QTextDocument *doc, const QTextCursor &cursor, QChar typedChar);
    void reindent(QTextDocument *doc, const QTextCursor &cursor);
con's avatar
con committed
470

471
472
    struct Link
    {
David Schulz's avatar
David Schulz committed
473
474
475
476
477
478
        Link(const QString &fileName = QString(), int line = 0, int column = 0)
            : linkTextStart(-1)
            , linkTextEnd(-1)
            , targetFileName(fileName)
            , targetLine(line)
            , targetColumn(column)
479
480
        {}

David Schulz's avatar
David Schulz committed
481
482
483
484
485
        bool hasValidTarget() const
        { return !targetFileName.isEmpty(); }

        bool hasValidLinkText() const
        { return linkTextStart != linkTextEnd; }
486

487
        bool operator==(const Link &other) const
David Schulz's avatar
David Schulz committed
488
        { return linkTextStart == other.linkTextStart && linkTextEnd == other.linkTextEnd; }
489

David Schulz's avatar
David Schulz committed
490
491
        int linkTextStart;
        int linkTextEnd;
492

David Schulz's avatar
David Schulz committed
493
494
495
        QString targetFileName;
        int targetLine;
        int targetColumn;
496
497
    };

498
protected:
499
500
501
502
503
504
505
506
507
508
    /*!
       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
Tobias Hunger's avatar
Tobias Hunger committed
509
       opened. Returns whether the link was opened successfully.
510
     */
511
    virtual bool openLink(const Link &link, bool inNextSplit = false);
512

513
514
    void maybeClearSomeExtraSelections(const QTextCursor &cursor);

515
516
517
518
    /*!
      Reimplement this function to change the default replacement text.
      */
    virtual QString foldReplacementText(const QTextBlock &block) const;
519
520
521
522
523
524
    virtual void drawCollapsedBlockPopup(QPainter &painter,
                                         const QTextBlock &block,
                                         QPointF offset,
                                         const QRect &clip);
    int visibleFoldedBlockNumber() const;

525

con's avatar
con committed
526
protected slots:
527
    virtual void slotUpdateExtraArea();
con's avatar
con committed
528
529
530
531
532
    virtual void slotUpdateExtraAreaWidth();
    virtual void slotModificationChanged(bool);
    virtual void slotUpdateRequest(const QRect &r, int dy);
    virtual void slotCursorPositionChanged();
    virtual void slotUpdateBlockNotify(const QTextBlock &);
533
    virtual void slotCodeStyleSettingsChanged(const QVariant &);
con's avatar
con committed
534
535

signals:
mae's avatar
mae committed
536
537
    void requestFontZoom(int zoom);
    void requestZoomReset();
con's avatar
con committed
538
539
540
541
542
543
    void requestBlockUpdate(const QTextBlock &);

private:
    void indentOrUnindent(bool doIndent);
    void handleHomeKey(bool anchor);
    void handleBackspaceKey();
544
    void moveLineUpDown(bool up);
545
    void copyLineUpDown(bool up);
546
    void saveCurrentCursorPositionForNavigation();
con's avatar
con committed
547
    void updateHighlights();
548
    void updateCurrentLineHighlight();
con's avatar
con committed
549

550
551
552
553
554
    void drawFoldingMarker(QPainter *painter, const QPalette &pal,
                           const QRect &rect,
                           bool expanded,
                           bool active,
                           bool hovered) const;
555

con's avatar
con committed
556
    void toggleBlockVisible(const QTextBlock &block);
mae's avatar
mae committed
557
    QRect foldBox();
con's avatar
con committed
558

mae's avatar
mae committed
559
    QTextBlock foldedBlockAt(const QPoint &pos, QRect *box = 0) const;
con's avatar
con committed
560

561
    void updateLink(QMouseEvent *e);
562
563
    void showLink(const Link &);
    void clearLink();
mae's avatar
mae committed
564

565
566
    void universalHelper(); // test function for development

567
568
569
    bool cursorMoveKeyEvent(QKeyEvent *e);
    bool camelCaseRight(QTextCursor &cursor, QTextCursor::MoveMode mode);
    bool camelCaseLeft(QTextCursor &cursor, QTextCursor::MoveMode mode);
570
571

    void processTooltipRequest(const QTextCursor &c);
572

573
    void transformSelection(Internal::TransformationMethod method);
574
    void transformBlockSelection(Internal::TransformationMethod method);
575

con's avatar
con committed
576
private slots:
mae's avatar
mae committed
577
578
    void handleBlockSelection(int diff_row, int diff_col);

579
    // parentheses matcher
con's avatar
con committed
580
    void _q_matchParentheses();
581
    void _q_highlightBlocks();
con's avatar
con committed
582
    void slotSelectionChanged();
583
    void _q_animateUpdate(int position, QPointF lastPos, QRectF rect);
584
    void doFoo();
con's avatar
con committed
585
586
587
};


588
class TEXTEDITOR_EXPORT BaseTextEditor : public ITextEditor
con's avatar
con committed
589
590
{
    Q_OBJECT
591

con's avatar
con committed
592
public:
593
594
    BaseTextEditor(BaseTextEditorWidget *editorWidget);
    ~BaseTextEditor();
con's avatar
con committed
595

596
    friend class BaseTextEditorWidget;
hjk's avatar
hjk committed
597
    BaseTextEditorWidget *editorWidget() const { return m_editorWidget; }
con's avatar
con committed
598

599
    // IEditor
hjk's avatar
hjk committed
600
601
602
603
604
    Core::IDocument *document() { return m_editorWidget->editorDocument(); }
    bool open(QString *errorString, const QString &fileName, const QString &realFileName);

    QByteArray saveState() const { return m_editorWidget->saveState(); }
    bool restoreState(const QByteArray &state) { return m_editorWidget->restoreState(state); }
605
    QWidget *toolBar();
con's avatar
con committed
606

607
608
609
    enum Side { Left, Right };
    void insertExtraToolBarWidget(Side side, QWidget *widget);

con's avatar
con committed
610
611
612
    // ITextEditor
    int currentLine() const;
    int currentColumn() const;
hjk's avatar
hjk committed
613
    void gotoLine(int line, int column = 0) { m_editorWidget->gotoLine(line, column); }
614
615
    int columnCount() const;
    int rowCount() const;
con's avatar
con committed
616

617
    int position(PositionOperation posOp = Current, int at = -1) const
hjk's avatar
hjk committed
618
    { return m_editorWidget->position(posOp, at); }
619
    void convertPosition(int pos, int *line, int *column) const
hjk's avatar
hjk committed
620
    { m_editorWidget->convertPosition(pos, line, column); }
con's avatar
con committed
621
622
623
624
    QRect cursorRect(int pos = -1) const;

    QString selectedText() const;

hjk's avatar
hjk committed
625
    ITextMarkable *markableInterface() { return m_editorWidget->markableInterface(); }
con's avatar
con committed
626
627
628

    QString contextHelpId() const; // from IContext

629
    // ITextEditor
con's avatar
con committed
630
631
632
    void remove(int length);
    void insert(const QString &string);
    void replace(int length, const QString &string);
633
    void setCursorPosition(int pos);
con's avatar
con committed
634
    void select(int toPos);
hjk's avatar
hjk committed
635
    const Utils::CommentDefinition *commentDefinition() const;
636

637
638
    virtual CompletionAssistProvider *completionAssistProvider();

con's avatar
con committed
639
640
private slots:
    void updateCursorPosition();
641
    void openGotoLocator();
642
643
    void setFileEncodingLabelVisible(bool visible);
    void setFileEncodingLabelText(const QString &text);
con's avatar
con committed
644
645

private:
hjk's avatar
hjk committed
646
647
648
    // Note: This is always a copy of IContext::m_widget.
    BaseTextEditorWidget *m_editorWidget;

con's avatar
con committed
649
    QToolBar *m_toolBar;
650
651
    QWidget *m_stretchWidget;
    QAction *m_cursorPositionLabelAction;
652
    Utils::LineColumnLabel *m_cursorPositionLabel;
653
654
    QAction *m_fileEncodingLabelAction;
    Utils::LineColumnLabel *m_fileEncodingLabel;
con's avatar
con committed
655
656
657
658
};

} // namespace TextEditor

659
Q_DECLARE_METATYPE(TextEditor::BaseTextEditorWidget::Link)
660

con's avatar
con committed
661
#endif // BASETEXTEDITOR_H