texteditor.h 21.8 KB
Newer Older
hjk's avatar
hjk committed
1
/****************************************************************************
con's avatar
con committed
2
**
Eike Ziller's avatar
Eike Ziller committed
3 4
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing
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
** 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
Eike Ziller's avatar
Eike Ziller committed
12 13
** a written agreement between you and The Qt Company.  For licensing terms and
** conditions see http://www.qt.io/terms-conditions.  For further information
Eike Ziller's avatar
Eike Ziller committed
14
** use the contact form at http://www.qt.io/contact-us.
15
**
16
** GNU Lesser General Public License Usage
hjk's avatar
hjk committed
17
** Alternatively, this file may be used under the terms of the GNU Lesser
Eike Ziller's avatar
Eike Ziller committed
18 19 20 21 22 23
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file.  Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24
**
Eike Ziller's avatar
Eike Ziller committed
25 26
** In addition, as a special exception, The Qt Company gives you certain additional
** rights.  These rights are described in The Qt Company LGPL Exception
con's avatar
con committed
27 28
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
hjk's avatar
hjk committed
29
****************************************************************************/
hjk's avatar
hjk committed
30

31 32
#ifndef TEXTEDITOR_H
#define TEXTEDITOR_H
con's avatar
con committed
33

hjk's avatar
hjk committed
34
#include "texteditor_global.h"
35
#include "blockrange.h"
36
#include "codeassist/assistenums.h"
con's avatar
con committed
37

hjk's avatar
hjk committed
38
#include <coreplugin/editormanager/ieditor.h>
39
#include <coreplugin/editormanager/ieditorfactory.h>
40

41 42
#include <utils/uncommentselection.h>

43
#include <QLabel>
44
#include <QPlainTextEdit>
45
#include <QSharedPointer>
46
#include <functional>
con's avatar
con committed
47 48 49

QT_BEGIN_NAMESPACE
class QToolBar;
Friedemann Kleint's avatar
Friedemann Kleint committed
50
class QPrinter;
hjk's avatar
hjk committed
51 52 53 54 55
class QMenu;
class QPainter;
class QPoint;
class QRect;
class QTextBlock;
con's avatar
con committed
56 57 58
QT_END_NAMESPACE

namespace TextEditor {
59
class TextDocument;
60
class BaseHoverHandler;
61
class TabSettings;
62 63
class RefactorOverlay;
struct RefactorMarker;
64
class SyntaxHighlighter;
Leandro Melo's avatar
Leandro Melo committed
65
class IAssistMonitorInterface;
66
class AssistInterface;
Leandro Melo's avatar
Leandro Melo committed
67
class IAssistProvider;
Jarek Kobus's avatar
Jarek Kobus committed
68
class ICodeStylePreferences;
69
class CompletionAssistProvider;
Christian Stenger's avatar
Christian Stenger committed
70
typedef QList<RefactorMarker> RefactorMarkers;
con's avatar
con committed
71 72

namespace Internal {
hjk's avatar
hjk committed
73 74 75 76
class BaseTextEditorPrivate;
class TextEditorFactoryPrivate;
class TextEditorWidgetPrivate;
class TextEditorOverlay;
con's avatar
con committed
77 78
}

79 80
class AutoCompleter;
class BaseTextEditor;
81 82
class TextEditorFactory;
class TextEditorWidget;
83 84
class PlainTextEditorFactory;

85 86 87
class BehaviorSettings;
class CompletionSettings;
class DisplaySettings;
88 89 90
class ExtraEncodingSettings;
class FontSettings;
class Indenter;
91
class MarginSettings;
92
class StorageSettings;
93
class TypingSettings;
con's avatar
con committed
94

95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
enum TextPositionOperation
{
    CurrentPosition = 1,
    EndOfLinePosition = 2,
    StartOfLinePosition = 3,
    AnchorPosition = 4,
    EndOfDocPosition = 5
};

enum TextMarkRequestKind
{
    BreakpointRequest,
    BookmarkRequest,
    TaskMarkRequest
};

111
class TEXTEDITOR_EXPORT BaseTextEditor : public Core::IEditor
112 113 114 115
{
    Q_OBJECT

public:
116
    BaseTextEditor();
117
    ~BaseTextEditor();
118

119 120
    virtual void finalizeInitialization() {}

121
    static BaseTextEditor *currentTextEditor();
122

123
    TextEditorWidget *editorWidget() const;
124
    TextDocument *textDocument() const;
125 126 127 128 129 130

    // Some convenience text access
    void setTextCursor(const QTextCursor &cursor);
    QTextCursor textCursor() const;
    QChar characterAt(int pos) const;
    QString textAt(int from, int to) const;
131

132 133
    void addContext(Core::Id id);

134
    // IEditor
135
    Core::IDocument *document() override;
mae's avatar
mae committed
136

137
    IEditor *duplicate() override;
138

139 140 141
    QByteArray saveState() const override;
    bool restoreState(const QByteArray &state) override;
    QWidget *toolBar() override;
142

143 144
    QString contextHelpId() const override; // from IContext
    void setContextHelpId(const QString &id) override;
145

146 147 148
    int currentLine() const override;
    int currentColumn() const override;
    void gotoLine(int line, int column = 0, bool centerLine = true) override;
149 150 151 152 153 154 155 156

    /*! Returns the amount of visible columns (in characters) in the editor */
    int columnCount() const;

    /*! Returns the amount of visible lines (in characters) in the editor */
    int rowCount() const;

    /*! Returns the position at \a posOp in characters from the beginning of the document */
157
    virtual int position(TextPositionOperation posOp = CurrentPosition, int at = -1) const;
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174

    /*! Converts the \a pos in characters from beginning of document to \a line and \a column */
    virtual void convertPosition(int pos, int *line, int *column) const;

    virtual QString selectedText() const;

    /*! Removes \a length characters to the right of the cursor. */
    virtual void remove(int length);
    /*! Inserts the given string to the right of the cursor. */
    virtual void insert(const QString &string);
    /*! Replaces \a length characters to the right of the cursor with the given string. */
    virtual void replace(int length, const QString &string);
    /*! Sets current cursor position to \a pos. */
    virtual void setCursorPosition(int pos);
    /*! Selects text between current cursor position and \a toPos. */
    virtual void select(int toPos);

175
private:
176
    friend class TextEditorFactory;
hjk's avatar
hjk committed
177
    friend class Internal::TextEditorFactoryPrivate;
hjk's avatar
hjk committed
178
    Internal::BaseTextEditorPrivate *d;
179 180 181
};


182
class TEXTEDITOR_EXPORT TextEditorWidget : public QPlainTextEdit
con's avatar
con committed
183 184
{
    Q_OBJECT
mae's avatar
mae committed
185 186
    Q_PROPERTY(int verticalBlockSelectionFirstColumn READ verticalBlockSelectionFirstColumn)
    Q_PROPERTY(int verticalBlockSelectionLastColumn READ verticalBlockSelectionLastColumn)
hjk's avatar
hjk committed
187

con's avatar
con committed
188
public:
189
    TextEditorWidget(QWidget *parent = 0);
190
    ~TextEditorWidget() override;
con's avatar
con committed
191

192
    void setTextDocument(const QSharedPointer<TextDocument> &doc);
193
    TextDocument *textDocument() const;
194
    QSharedPointer<TextDocument> textDocumentPtr() const;
195

196 197
    virtual void aboutToOpen(const QString &fileName, const QString &realFileName);
    virtual void openFinishedSuccessfully();
198
    // IEditor
con's avatar
con committed
199 200
    QByteArray saveState() const;
    bool restoreState(const QByteArray &state);
201
    void gotoLine(int line, int column = 0, bool centerLine = true);
202
    int position(TextPositionOperation posOp = CurrentPosition,
hjk's avatar
hjk committed
203
         int at = -1) const;
con's avatar
con committed
204
    void convertPosition(int pos, int *line, int *column) const;
205 206 207
    using QPlainTextEdit::cursorRect;
    QRect cursorRect(int pos) const;
    void setCursorPosition(int pos);
con's avatar
con committed
208 209 210

    void print(QPrinter *);

211 212
    void appendStandardContextMenuActions(QMenu *menu);

213 214 215
    void setAutoCompleter(AutoCompleter *autoCompleter);
    AutoCompleter *autoCompleter() const;

con's avatar
con committed
216 217 218 219 220 221 222 223 224 225 226
    // 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;

227 228
    void setAlwaysOpenLinksInNextSplit(bool b);
    bool alwaysOpenLinksInNextSplit() const;
229

con's avatar
con committed
230 231 232 233 234 235 236 237 238 239 240
    void setMarksVisible(bool b);
    bool marksVisible() const;

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

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

    bool codeFoldingVisible() const;

241 242 243
    void setCodeFoldingSupported(bool b);
    bool codeFoldingSupported() const;

244 245 246
    void setMouseNavigationEnabled(bool b);
    bool mouseNavigationEnabled() const;

247 248 249
    void setMouseHidingEnabled(bool b);
    bool mouseHidingEnabled() const;

250 251 252
    void setScrollWheelZoomingEnabled(bool b);
    bool scrollWheelZoomingEnabled() const;

253 254 255
    void setConstrainTooltips(bool b);
    bool constrainTooltips() const;

256 257 258
    void setCamelCaseNavigationEnabled(bool b);
    bool camelCaseNavigationEnabled() const;

con's avatar
con committed
259 260 261 262 263 264
    void setRevisionsVisible(bool b);
    bool revisionsVisible() const;

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

265 266 267
    int columnCount() const;
    int rowCount() const;

con's avatar
con committed
268 269
    void setReadOnly(bool b);

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

272
    void setBlockSelection(bool on);
David Schulz's avatar
David Schulz committed
273 274 275 276
    void setBlockSelection(int positionBlock, int positionColumn, int anchhorBlock,
                           int anchorColumn);
    void setBlockSelection(const QTextCursor &cursor);
    QTextCursor blockSelection() const;
277
    bool hasBlockSelection() const;
278

mae's avatar
mae committed
279 280
    int verticalBlockSelectionFirstColumn() const;
    int verticalBlockSelectionLastColumn() const;
281

282 283
    QRegion translatedLineRegion(int lineStart, int lineEnd) const;

284 285
    QPoint toolTipPosition(const QTextCursor &c) const;

Leandro Melo's avatar
Leandro Melo committed
286 287
    void invokeAssist(AssistKind assistKind, IAssistProvider *provider = 0);

288
    virtual TextEditor::AssistInterface *createAssistInterface(AssistKind assistKind,
Leandro Melo's avatar
Leandro Melo committed
289
                                                    AssistReason assistReason) const;
290
    static QMimeData *duplicateMimeData(const QMimeData *source);
Leandro Melo's avatar
Leandro Melo committed
291

292 293
    static QString msgTextTooLarge(quint64 size);

David Schulz's avatar
David Schulz committed
294
    void insertPlainText(const QString &text);
295

296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313
    QWidget *extraArea() const;
    virtual int extraAreaWidth(int *markWidthPtr = 0) const;
    virtual void extraAreaPaintEvent(QPaintEvent *);
    virtual void extraAreaLeaveEvent(QEvent *);
    virtual void extraAreaContextMenuEvent(QContextMenuEvent *);
    virtual void extraAreaMouseEvent(QMouseEvent *);
    void updateFoldingHighlight(const QPoint &pos);

    void setLanguageSettingsId(Core::Id settingsId);
    Core::Id languageSettingsId() const;

    void setCodeStyle(ICodeStylePreferences *settings);

    const DisplaySettings &displaySettings() const;
    const MarginSettings &marginSettings() const;

    void ensureCursorVisible();

314 315 316 317 318 319 320 321 322 323 324 325
    static Core::Id FakeVimSelection;
    static Core::Id SnippetPlaceholderSelection;
    static Core::Id CurrentLineSelection;
    static Core::Id ParenthesesMatchingSelection;
    static Core::Id CodeWarningsSelection;
    static Core::Id CodeSemanticsSelection;
    static Core::Id UndefinedSymbolSelection;
    static Core::Id UnusedSymbolSelection;
    static Core::Id OtherSelection;
    static Core::Id ObjCSelection;
    static Core::Id DebuggerExceptionSelection;

326 327
    void setExtraSelections(Core::Id kind, const QList<QTextEdit::ExtraSelection> &selections);
    QList<QTextEdit::ExtraSelection> extraSelections(Core::Id kind) const;
328 329 330 331 332 333 334
    QString extraSelectionTooltip(int pos) const;

    RefactorMarkers refactorMarkers() const;
    void setRefactorMarkers(const RefactorMarkers &markers);

    // the blocks list must be sorted
    void setIfdefedOutBlocks(const QList<BlockRange> &blocks);
335
    bool isMissingSyntaxDefinition() const;
David Schulz's avatar
David Schulz committed
336

337 338 339
    enum Side { Left, Right };
    void insertExtraToolBarWidget(Side side, QWidget *widget);

340
    virtual void copy();
mae's avatar
mae committed
341 342
    virtual void paste();
    virtual void cut();
343
    virtual void selectAll();
con's avatar
con committed
344

345 346 347
    virtual void format();
    virtual void rewrapParagraph();
    virtual void unCommentSelection();
348

349 350
    virtual void encourageApply();

351
public slots: // Qt4-style connect used in EditorConfiguration
352
    virtual void setDisplaySettings(const TextEditor::DisplaySettings &);
hjk's avatar
hjk committed
353
    virtual void setMarginSettings(const TextEditor::MarginSettings &);
354 355 356 357 358
    void setBehaviorSettings(const TextEditor::BehaviorSettings &);
    void setTypingSettings(const TextEditor::TypingSettings &);
    void setStorageSettings(const TextEditor::StorageSettings &);
    void setCompletionSettings(const TextEditor::CompletionSettings &);
    void setExtraEncodingSettings(const TextEditor::ExtraEncodingSettings &);
359

360
public:
361
    void circularPaste();
362
    void switchUtf8bom();
363

364
    void zoomF(float delta);
mae's avatar
mae committed
365
    void zoomReset();
con's avatar
con committed
366

367
    void cutLine();
368
    void copyLine();
con's avatar
con committed
369
    void deleteLine();
370 371 372 373
    void deleteEndOfWord();
    void deleteEndOfWordCamelCase();
    void deleteStartOfWord();
    void deleteStartOfWordCamelCase();
mae's avatar
mae committed
374 375 376
    void unfoldAll();
    void fold();
    void unfold();
con's avatar
con committed
377
    void selectEncoding();
378
    void updateTextCodecLabel();
con's avatar
con committed
379

380 381 382 383 384
    void gotoBlockStart();
    void gotoBlockEnd();
    void gotoBlockStartWithSelection();
    void gotoBlockEndWithSelection();

mae's avatar
mae committed
385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400
    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
401 402 403 404
    void gotoPreviousWordCamelCase();
    void gotoPreviousWordCamelCaseWithSelection();
    void gotoNextWordCamelCase();
    void gotoNextWordCamelCaseWithSelection();
405

406 407
    bool selectBlockUp();
    bool selectBlockDown();
408

409 410 411
    void moveLineUp();
    void moveLineDown();

412 413 414 415 416
    void viewPageUp();
    void viewPageDown();
    void viewLineUp();
    void viewLineDown();

417 418 419
    void copyLineUp();
    void copyLineDown();

420
    void joinLines();
421

422 423 424
    void insertLineAbove();
    void insertLineBelow();

425 426 427
    void uppercaseSelection();
    void lowercaseSelection();

428 429
    void cleanWhitespace();

430 431 432
    void indent();
    void unindent();

David Schulz's avatar
David Schulz committed
433 434 435
    void undo();
    void redo();

436
    void openLinkUnderCursor();
437
    void openLinkUnderCursorInNextSplit();
438

439 440
    /// Abort code assistant if it is running.
    void abortAssist();
441

442
    void configureGenericHighlighter();
443 444

    Q_INVOKABLE void inSnippetMode(bool *active); // Used by FakeVim.
445

446 447 448 449 450 451 452 453 454 455 456 457 458 459 460
    /*! Returns the document line number for the visible \a row.
     *
     * The first visible row is 0, the last visible row is rowCount() - 1.
     *
     * Any invalid row will return -1 as line number.
     */
    int lineForVisibleRow(int row) const;

    /*! Returns the first visible line of the document. */
    int firstVisibleLine() const;
    /*! Returns the last visible line of the document. */
    int lastVisibleLine() const;
    /*! Returns the line visible closest to the vertical center of the editor. */
    int centerVisibleLine() const;

con's avatar
con committed
461
signals:
462
    void assistFinished(); // Used in tests.
463
    void readOnlyChanged();
464 465

    void requestBlockUpdate(const QTextBlock &);
con's avatar
con committed
466 467

protected:
468
    QTextBlock blockForVisibleRow(int row) const;
469 470 471 472 473 474 475 476 477 478 479
    bool event(QEvent *e) override;
    void inputMethodEvent(QInputMethodEvent *e) override;
    void keyPressEvent(QKeyEvent *e) override;
    void wheelEvent(QWheelEvent *e) override;
    void changeEvent(QEvent *e) override;
    void focusInEvent(QFocusEvent *e) override;
    void focusOutEvent(QFocusEvent *e) override;
    void showEvent(QShowEvent *) override;
    bool viewportEvent(QEvent *event) override;
    void resizeEvent(QResizeEvent *) override;
    void paintEvent(QPaintEvent *) override;
480 481 482 483 484
    virtual void paintBlock(QPainter *painter,
                            const QTextBlock &block,
                            const QPointF &offset,
                            const QVector<QTextLayout::FormatRange> &selections,
                            const QRect &clipRect) const;
485 486 487 488 489 490 491 492 493 494 495 496
    void timerEvent(QTimerEvent *) override;
    void mouseMoveEvent(QMouseEvent *) override;
    void mousePressEvent(QMouseEvent *) override;
    void mouseReleaseEvent(QMouseEvent *) override;
    void mouseDoubleClickEvent(QMouseEvent *) override;
    void leaveEvent(QEvent *) override;
    void keyReleaseEvent(QKeyEvent *) override;
    void dragEnterEvent(QDragEnterEvent *e) override;

    QMimeData *createMimeDataFromSelection() const override;
    bool canInsertFromMimeData(const QMimeData *source) const override;
    void insertFromMimeData(const QMimeData *source) override;
con's avatar
con committed
497

498
    virtual QString plainTextFromSelection(const QTextCursor &cursor) const;
499 500 501 502
    static QString convertToPlainText(const QString &txt);

    virtual QString lineNumber(int blockNumber) const;
    virtual int lineNumberDigits() const;
jkobus's avatar
jkobus committed
503
    virtual bool selectionVisible(int blockNumber) const;
504
    virtual bool replacementVisible(int blockNumber) const;
jkobus's avatar
jkobus committed
505
    virtual QColor replacementPenColor(int blockNumber) const;
506

507
    virtual void triggerPendingUpdates();
508
    virtual void applyFontSettings();
con's avatar
con committed
509

510 511
    virtual void onRefactorMarkerClicked(const RefactorMarker &) {}

512
    void showDefaultContextMenu(QContextMenuEvent *e, Core::Id menuContextId);
513
    virtual void finalizeInitialization() {}
514
    virtual void finalizeInitializationAfterDuplication(TextEditorWidget *) {}
515

516
public:
517 518
    struct Link
    {
David Schulz's avatar
David Schulz committed
519 520 521 522 523 524
        Link(const QString &fileName = QString(), int line = 0, int column = 0)
            : linkTextStart(-1)
            , linkTextEnd(-1)
            , targetFileName(fileName)
            , targetLine(line)
            , targetColumn(column)
525 526
        {}

David Schulz's avatar
David Schulz committed
527 528 529 530 531
        bool hasValidTarget() const
        { return !targetFileName.isEmpty(); }

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

533
        bool operator==(const Link &other) const
David Schulz's avatar
David Schulz committed
534
        { return linkTextStart == other.linkTextStart && linkTextEnd == other.linkTextEnd; }
535

David Schulz's avatar
David Schulz committed
536 537
        int linkTextStart;
        int linkTextEnd;
538

David Schulz's avatar
David Schulz committed
539 540 541
        QString targetFileName;
        int targetLine;
        int targetColumn;
542 543
    };

544 545
    QString selectedText() const;

546
    void setupGenericHighlighter();
547
    void setupFallBackEditor(Core::Id id);
548

549 550 551 552 553
    void remove(int length);
    void replace(int length, const QString &string);
    QChar characterAt(int pos) const;
    QString textAt(int from, int to) const;

554 555 556
    QString contextHelpId();
    void setContextHelpId(const QString &id);

557 558
    static TextEditorWidget *currentTextEditorWidget();

559
protected:
560 561 562 563 564 565
    /*!
       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).
     */
566 567
    virtual Link findLinkAt(const QTextCursor &, bool resolveTarget = true,
                            bool inNextSplit = false);
568 569

    /*!
570
       Returns whether the link was opened successfully.
571
     */
572
    bool openLink(const Link &link, bool inNextSplit = false);
573

574 575 576 577
    /*!
      Reimplement this function to change the default replacement text.
      */
    virtual QString foldReplacementText(const QTextBlock &block) const;
578 579 580 581 582
    virtual void drawCollapsedBlockPopup(QPainter &painter,
                                         const QTextBlock &block,
                                         QPointF offset,
                                         const QRect &clip);
    int visibleFoldedBlockNumber() const;
583 584
    void doSetTextCursor(const QTextCursor &cursor) override;
    void doSetTextCursor(const QTextCursor &cursor, bool keepBlockSelection);
585

586
signals:
587
    void markRequested(TextEditor::TextEditorWidget *widget,
588
        int line, TextEditor::TextMarkRequestKind kind);
589 590 591
    void markContextMenuRequested(TextEditor::TextEditorWidget *widget,
        int line, QMenu *menu);
    void tooltipOverrideRequested(TextEditor::TextEditorWidget *widget,
592
        const QPoint &globalPos, int position, bool *handled);
593
    void tooltipRequested(const QPoint &globalPos, int position);
594 595
    void markTooltipRequested(TextEditor::TextEditorWidget *widget,
        const QPoint &globalPos, int line);
596
    void activateEditor();
597

con's avatar
con committed
598
protected slots:
599 600
    virtual void slotCursorPositionChanged(); // Used in VcsBase
    virtual void slotCodeStyleSettingsChanged(const QVariant &); // Used in CppEditor
con's avatar
con committed
601

602 603 604
    bool inFindScope(const QTextCursor &cursor);
    bool inFindScope(int selectionStart, int selectionEnd);

605
    void doFoo();
606 607

private:
608
    Internal::TextEditorWidgetPrivate *d;
609
    friend class BaseTextEditor;
610
    friend class TextEditorFactory;
hjk's avatar
hjk committed
611
    friend class Internal::TextEditorFactoryPrivate;
612
    friend class Internal::TextEditorWidgetPrivate;
613 614
    friend class Internal::TextEditorOverlay;
    friend class RefactorOverlay;
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
class TEXTEDITOR_EXPORT TextEditorLinkLabel : public QLabel
{
public:
    TextEditorLinkLabel(QWidget *parent = 0);

    void setLink(TextEditorWidget::Link link);
    TextEditorWidget::Link link() const;

protected:
    void mousePressEvent(QMouseEvent *event);
    void mouseMoveEvent(QMouseEvent *event);
    void mouseReleaseEvent(QMouseEvent *event);

private:
    QPoint m_dragStartPosition;
    TextEditorWidget::Link m_link;
};

635
class TEXTEDITOR_EXPORT TextEditorFactory : public Core::IEditorFactory
636 637 638 639
{
    Q_OBJECT

public:
640
    TextEditorFactory(QObject *parent = 0);
641
    ~TextEditorFactory();
642

643
    typedef std::function<BaseTextEditor *()> EditorCreator;
644
    typedef std::function<TextDocument *()> DocumentCreator;
645
    typedef std::function<TextEditorWidget *()> EditorWidgetCreator;
646 647 648 649
    typedef std::function<SyntaxHighlighter *()> SyntaxHighLighterCreator;
    typedef std::function<Indenter *()> IndenterCreator;
    typedef std::function<AutoCompleter *()> AutoCompleterCreator;

650 651 652 653 654
    void setDocumentCreator(DocumentCreator &&creator);
    void setEditorWidgetCreator(EditorWidgetCreator &&creator);
    void setEditorCreator(EditorCreator &&creator);
    void setIndenterCreator(IndenterCreator &&creator);
    void setSyntaxHighlighterCreator(SyntaxHighLighterCreator &&creator);
655
    void setUseGenericHighlighter(bool enabled);
656
    void setAutoCompleterCreator(AutoCompleterCreator &&creator);
657 658 659 660

    void setEditorActionHandlers(Core::Id contextId, uint optionalActions);
    void setEditorActionHandlers(uint optionalActions);

661
    void addHoverHandler(BaseHoverHandler *handler);
662
    void setCompletionAssistProvider(CompletionAssistProvider *provider);
663

664
    void setCommentStyle(Utils::CommentDefinition::Style style);
665
    void setDuplicatedSupported(bool on);
hjk's avatar
hjk committed
666 667 668
    void setMarksVisible(bool on);
    void setParenthesesMatchingEnabled(bool on);
    void setCodeFoldingSupported(bool on);
669

670 671
    Core::IEditor *createEditor();

672
private:
673
    friend class BaseTextEditor;
674
    friend class PlainTextEditorFactory;
hjk's avatar
hjk committed
675
    Internal::TextEditorFactoryPrivate *d;
676 677
};

con's avatar
con committed
678 679
} // namespace TextEditor

680
Q_DECLARE_METATYPE(TextEditor::TextEditorWidget::Link)
681

682
#endif // TEXTEDITOR_H