2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2014-01-07 13:27:11 +01:00
|
|
|
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
|
2012-10-02 09:12:39 +02:00
|
|
|
** Contact: http://www.qt-project.org/legal
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** 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.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** GNU Lesser General Public License Usage
|
2012-10-02 09:12:39 +02:00
|
|
|
** 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.
|
|
|
|
|
**
|
|
|
|
|
** In addition, as a special exception, Digia gives you certain additional
|
|
|
|
|
** rights. These rights are described in the Digia Qt LGPL Exception
|
2010-12-17 16:01:08 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2008-12-02 16:19:05 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
#ifndef BASETEXTEDITOR_P_H
|
|
|
|
|
#define BASETEXTEDITOR_P_H
|
|
|
|
|
|
|
|
|
|
#include "basetexteditor.h"
|
2009-12-09 16:27:34 +01:00
|
|
|
#include "behaviorsettings.h"
|
2009-12-08 17:43:01 +01:00
|
|
|
#include "displaysettings.h"
|
2014-01-09 14:44:25 +01:00
|
|
|
#include "marginsettings.h"
|
2009-12-08 17:43:01 +01:00
|
|
|
#include "fontsettings.h"
|
2010-07-02 13:47:14 +02:00
|
|
|
#include "refactoroverlay.h"
|
2009-12-08 17:43:01 +01:00
|
|
|
|
2012-11-21 21:47:17 +02:00
|
|
|
#include <coreplugin/id.h>
|
2009-11-26 12:19:58 +01:00
|
|
|
#include <utils/changeset.h>
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QBasicTimer>
|
2013-01-09 13:31:15 +08:00
|
|
|
#include <QSharedPointer>
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QPointer>
|
|
|
|
|
#include <QScopedPointer>
|
2013-03-12 12:06:15 +01:00
|
|
|
#include <QTextBlock>
|
2013-05-24 12:53:35 +02:00
|
|
|
#include <QTimer>
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
namespace TextEditor {
|
|
|
|
|
|
|
|
|
|
class BaseTextDocument;
|
2011-04-15 16:19:23 +02:00
|
|
|
class CodeAssistant;
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
namespace Internal {
|
2011-08-18 14:23:06 +02:00
|
|
|
class TextEditorOverlay;
|
2012-03-12 17:38:54 +01:00
|
|
|
class ClipboardAssistProvider;
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2010-11-01 16:29:45 +01:00
|
|
|
class TEXTEDITOR_EXPORT BaseTextBlockSelection
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
|
|
bool isValid() const{ return !firstBlock.isNull() && !lastBlock.isNull(); }
|
|
|
|
|
void clear() { firstBlock = lastBlock = QTextCursor(); }
|
|
|
|
|
|
|
|
|
|
QTextCursor firstBlock; // defines the first block
|
|
|
|
|
QTextCursor lastBlock; // defines the last block
|
|
|
|
|
int firstVisualColumn; // defines the first visual column of the selection
|
|
|
|
|
int lastVisualColumn; // defines the last visual column of the selection
|
|
|
|
|
enum Anchor {TopLeft = 0, TopRight, BottomLeft, BottomRight} anchor;
|
|
|
|
|
BaseTextBlockSelection():firstVisualColumn(0), lastVisualColumn(0), anchor(BottomRight){}
|
|
|
|
|
void moveAnchor(int blockNumber, int visualColumn);
|
|
|
|
|
inline int anchorColumnNumber() const { return (anchor % 2) ? lastVisualColumn : firstVisualColumn; }
|
|
|
|
|
inline int anchorBlockNumber() const {
|
|
|
|
|
return (anchor <= TopRight ? firstBlock.blockNumber() : lastBlock.blockNumber()); }
|
|
|
|
|
QTextCursor selection(const TabSettings &ts) const;
|
|
|
|
|
void fromSelection(const TabSettings &ts, const QTextCursor &selection);
|
|
|
|
|
};
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
//================BaseTextEditorPrivate==============
|
|
|
|
|
|
2009-04-23 17:28:53 +02:00
|
|
|
struct BaseTextEditorPrivateHighlightBlocks
|
|
|
|
|
{
|
|
|
|
|
QList<int> open;
|
|
|
|
|
QList<int> close;
|
|
|
|
|
QList<int> visualIndent;
|
2009-04-28 11:43:13 +02:00
|
|
|
inline int count() const { return visualIndent.size(); }
|
2009-04-24 16:44:48 +02:00
|
|
|
inline bool isEmpty() const { return open.isEmpty() || close.isEmpty() || visualIndent.isEmpty(); }
|
2009-04-23 17:28:53 +02:00
|
|
|
inline bool operator==(const BaseTextEditorPrivateHighlightBlocks &o) const {
|
|
|
|
|
return (open == o.open && close == o.close && visualIndent == o.visualIndent);
|
|
|
|
|
}
|
|
|
|
|
inline bool operator!=(const BaseTextEditorPrivateHighlightBlocks &o) const { return !(*this == o); }
|
|
|
|
|
};
|
|
|
|
|
|
2009-04-28 18:34:58 +02:00
|
|
|
|
2012-02-16 14:23:36 +01:00
|
|
|
class BaseTextEditorWidgetPrivate
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2012-02-16 14:23:36 +01:00
|
|
|
BaseTextEditorWidgetPrivate(const BaseTextEditorWidgetPrivate &);
|
|
|
|
|
BaseTextEditorWidgetPrivate &operator=(const BaseTextEditorWidgetPrivate &);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
public:
|
2012-02-16 14:23:36 +01:00
|
|
|
BaseTextEditorWidgetPrivate();
|
|
|
|
|
~BaseTextEditorWidgetPrivate();
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2014-01-09 18:04:45 +01:00
|
|
|
void setupDocumentSignals();
|
2008-12-02 12:01:29 +01:00
|
|
|
void updateLineSelectionColor();
|
|
|
|
|
|
|
|
|
|
void print(QPrinter *printer);
|
|
|
|
|
|
|
|
|
|
QTextBlock m_firstVisible;
|
|
|
|
|
int m_lastScrollPos;
|
|
|
|
|
int m_lineNumber;
|
|
|
|
|
|
2011-02-21 16:02:26 +01:00
|
|
|
BaseTextEditorWidget *q;
|
2008-12-02 12:01:29 +01:00
|
|
|
bool m_contentsChanged;
|
2009-03-19 14:18:26 +01:00
|
|
|
bool m_lastCursorChangeWasInteresting;
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
QList<QTextEdit::ExtraSelection> m_syntaxHighlighterSelections;
|
|
|
|
|
QTextEdit::ExtraSelection m_lineSelection;
|
|
|
|
|
|
2013-01-09 13:31:15 +08:00
|
|
|
QSharedPointer<BaseTextDocument> m_document;
|
2008-12-02 12:01:29 +01:00
|
|
|
QByteArray m_tempState;
|
2009-04-02 17:56:20 +02:00
|
|
|
QByteArray m_tempNavigationState;
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
bool m_parenthesesMatchingEnabled;
|
|
|
|
|
QTimer *m_updateTimer;
|
|
|
|
|
|
|
|
|
|
// parentheses matcher
|
|
|
|
|
bool m_formatRange;
|
|
|
|
|
QTextCharFormat m_matchFormat;
|
|
|
|
|
QTextCharFormat m_mismatchFormat;
|
2013-05-24 12:53:35 +02:00
|
|
|
QTimer m_parenthesesMatchingTimer;
|
2008-12-02 12:01:29 +01:00
|
|
|
// end parentheses matcher
|
|
|
|
|
|
|
|
|
|
QWidget *m_extraArea;
|
2009-12-09 16:27:34 +01:00
|
|
|
|
2012-11-21 21:47:17 +02:00
|
|
|
Core::Id m_tabSettingsId;
|
2011-08-16 10:45:23 +02:00
|
|
|
ICodeStylePreferences *m_codeStylePreferences;
|
2008-12-02 12:01:29 +01:00
|
|
|
DisplaySettings m_displaySettings;
|
2014-01-09 14:44:25 +01:00
|
|
|
MarginSettings m_marginSettings;
|
2009-12-09 16:27:34 +01:00
|
|
|
FontSettings m_fontSettings;
|
|
|
|
|
BehaviorSettings m_behaviorSettings;
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
int extraAreaSelectionAnchorBlockNumber;
|
|
|
|
|
int extraAreaToggleMarkBlockNumber;
|
2010-05-20 15:10:26 +02:00
|
|
|
int extraAreaHighlightFoldedBlockNumber;
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2009-11-25 15:55:45 +01:00
|
|
|
TextEditorOverlay *m_overlay;
|
2010-01-19 12:28:50 +01:00
|
|
|
TextEditorOverlay *m_snippetOverlay;
|
2009-11-25 15:55:45 +01:00
|
|
|
TextEditorOverlay *m_searchResultOverlay;
|
2010-11-02 15:35:42 +01:00
|
|
|
bool snippetCheckCursor(const QTextCursor &cursor);
|
2010-01-19 12:28:50 +01:00
|
|
|
void snippetTabOrBacktab(bool forward);
|
2010-03-29 16:44:27 +02:00
|
|
|
QTextCharFormat m_occurrencesFormat;
|
|
|
|
|
QTextCharFormat m_occurrenceRenameFormat;
|
2009-11-25 15:55:45 +01:00
|
|
|
|
2010-07-02 13:47:14 +02:00
|
|
|
RefactorOverlay *m_refactorOverlay;
|
|
|
|
|
|
2010-05-20 15:10:26 +02:00
|
|
|
QBasicTimer foldedBlockTimer;
|
|
|
|
|
int visibleFoldedBlockNumber;
|
|
|
|
|
int suggestedVisibleFoldedBlockNumber;
|
|
|
|
|
void clearVisibleFoldedBlock();
|
|
|
|
|
bool m_mouseOnFoldedMarker;
|
|
|
|
|
void foldLicenseHeader();
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
QBasicTimer autoScrollTimer;
|
|
|
|
|
uint m_marksVisible : 1;
|
|
|
|
|
uint m_codeFoldingVisible : 1;
|
2009-03-16 17:23:50 +01:00
|
|
|
uint m_codeFoldingSupported : 1;
|
2008-12-02 12:01:29 +01:00
|
|
|
uint m_revisionsVisible : 1;
|
|
|
|
|
uint m_lineNumbersVisible : 1;
|
|
|
|
|
uint m_highlightCurrentLine : 1;
|
|
|
|
|
uint m_requestMarkEnabled : 1;
|
|
|
|
|
uint m_lineSeparatorsAllowed : 1;
|
2011-10-06 16:48:47 +02:00
|
|
|
uint autoParenthesisOverwriteBackup : 1;
|
|
|
|
|
uint surroundWithEnabledOverwriteBackup : 1;
|
2011-12-08 13:23:41 +01:00
|
|
|
uint m_maybeFakeTooltipEvent : 1;
|
2008-12-02 12:01:29 +01:00
|
|
|
int m_visibleWrapColumn;
|
|
|
|
|
|
2009-09-08 13:03:24 +02:00
|
|
|
QTextCharFormat m_linkFormat;
|
2011-02-21 16:02:26 +01:00
|
|
|
BaseTextEditorWidget::Link m_currentLink;
|
2009-11-03 14:29:49 +01:00
|
|
|
bool m_linkPressed;
|
2009-09-08 13:03:24 +02:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
QTextCharFormat m_ifdefedOutFormat;
|
|
|
|
|
|
|
|
|
|
QRegExp m_searchExpr;
|
2014-01-13 16:17:34 +01:00
|
|
|
Core::FindFlags m_findFlags;
|
2008-12-02 12:01:29 +01:00
|
|
|
QTextCharFormat m_searchResultFormat;
|
|
|
|
|
QTextCharFormat m_searchScopeFormat;
|
|
|
|
|
QTextCharFormat m_currentLineFormat;
|
2009-04-27 14:10:54 +02:00
|
|
|
QTextCharFormat m_currentLineNumberFormat;
|
2009-12-02 10:57:05 +01:00
|
|
|
void highlightSearchResults(const QTextBlock &block, TextEditorOverlay *overlay);
|
2013-05-24 12:53:35 +02:00
|
|
|
QTimer m_delayedUpdateTimer;
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2011-02-21 16:02:26 +01:00
|
|
|
BaseTextEditor *m_editor;
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2011-02-21 16:02:26 +01:00
|
|
|
QList<QTextEdit::ExtraSelection> m_extraSelections[BaseTextEditorWidget::NExtraSelectionKinds];
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
// block selection mode
|
|
|
|
|
bool m_inBlockSelectionMode;
|
|
|
|
|
void clearBlockSelection();
|
|
|
|
|
QString copyBlockSelection();
|
|
|
|
|
void removeBlockSelection(const QString &text = QString());
|
2009-04-23 19:24:57 +02:00
|
|
|
bool m_moveLineUndoHack;
|
2009-09-08 13:03:24 +02:00
|
|
|
|
2010-04-13 12:06:26 +02:00
|
|
|
QTextCursor m_findScopeStart;
|
|
|
|
|
QTextCursor m_findScopeEnd;
|
2010-08-05 15:01:20 +02:00
|
|
|
int m_findScopeVerticalBlockSelectionFirstColumn;
|
|
|
|
|
int m_findScopeVerticalBlockSelectionLastColumn;
|
|
|
|
|
|
2008-12-04 19:25:20 +01:00
|
|
|
QTextCursor m_selectBlockAnchor;
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2010-08-05 15:01:20 +02:00
|
|
|
Internal::BaseTextBlockSelection m_blockSelection;
|
|
|
|
|
|
2009-02-13 16:29:30 +01:00
|
|
|
void moveCursorVisible(bool ensureVisible = true);
|
2009-04-23 17:28:53 +02:00
|
|
|
|
|
|
|
|
int visualIndent(const QTextBlock &block) const;
|
|
|
|
|
BaseTextEditorPrivateHighlightBlocks m_highlightBlocksInfo;
|
2013-05-24 12:53:35 +02:00
|
|
|
QTimer m_highlightBlocksTimer;
|
2009-04-23 17:28:53 +02:00
|
|
|
|
2011-04-15 16:19:23 +02:00
|
|
|
QScopedPointer<CodeAssistant> m_codeAssistant;
|
|
|
|
|
bool m_assistRelevantContentAdded;
|
2010-07-19 14:06:00 +02:00
|
|
|
|
2009-04-28 18:34:58 +02:00
|
|
|
QPointer<BaseTextEditorAnimator> m_animator;
|
2009-12-01 15:55:55 +01:00
|
|
|
int m_cursorBlockNumber;
|
2010-11-05 14:27:16 +01:00
|
|
|
|
2012-10-09 22:32:44 +02:00
|
|
|
QPoint m_markDragStart;
|
|
|
|
|
bool m_markDragging;
|
|
|
|
|
|
2010-11-08 16:11:26 +01:00
|
|
|
QScopedPointer<AutoCompleter> m_autoCompleter;
|
2012-03-12 17:38:54 +01:00
|
|
|
|
|
|
|
|
QScopedPointer<Internal::ClipboardAssistProvider> m_clipboardAssistProvider;
|
2008-12-02 12:01:29 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace TextEditor
|
|
|
|
|
|
|
|
|
|
#endif // BASETEXTEDITOR_P_H
|