Files
qt-creator/src/plugins/texteditor/basetexteditor_p.h

309 lines
9.6 KiB
C
Raw Normal View History

/**************************************************************************
2008-12-02 12:01:29 +01:00
**
** This file is part of Qt Creator
**
2011-01-11 16:28:15 +01:00
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
2008-12-02 12:01:29 +01:00
**
2011-04-13 08:42:33 +02:00
** Contact: Nokia Corporation (info@qt.nokia.com)
2008-12-02 12:01:29 +01:00
**
**
** GNU Lesser General Public License Usage
**
2011-04-13 08:42:33 +02:00
** 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.
**
2010-12-17 16:01:08 +01:00
** In addition, as a special exception, Nokia gives you certain additional
2011-04-13 08:42:33 +02:00
** rights. These rights are described in the Nokia Qt LGPL Exception
2010-12-17 16:01:08 +01:00
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
2011-04-13 08:42:33 +02:00
** Other Usage
**
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
2010-12-17 16:01:08 +01:00
** If you have questions regarding the use of this file, please contact
** Nokia at info@qt.nokia.com.
2008-12-02 12:01:29 +01: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"
#include "behaviorsettings.h"
2009-12-08 17:43:01 +01:00
#include "displaysettings.h"
#include "texteditoroverlay.h"
2009-12-08 17:43:01 +01:00
#include "fontsettings.h"
#include "refactoroverlay.h"
2009-12-08 17:43:01 +01:00
#include <utils/changeset.h>
2008-12-02 12:01:29 +01:00
#include <QtCore/QBasicTimer>
#include <QtCore/QSharedData>
#include <QtCore/QPointer>
#include <QtCore/QScopedPointer>
2008-12-02 12:01:29 +01:00
#include <QtGui/QPixmap>
#include <QtGui/QTextEdit>
2008-12-02 12:01:29 +01:00
namespace TextEditor {
class BaseTextDocument;
class TextEditorActionHandler;
class CodeAssistant;
2008-12-02 12:01:29 +01:00
namespace Internal {
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
//========== Pointers with reference count ==========
template <class T> class QRefCountData : public QSharedData
{
public:
QRefCountData(T *data) { m_data = data; }
~QRefCountData() { delete m_data; }
T *m_data;
};
/* MOSTLY COPIED FROM QSHAREDDATA(-POINTER) */
template <class T> class QRefCountPointer
{
public:
inline T &operator*() { return d ? *(d->m_data) : 0; }
inline const T &operator*() const { return d ? *(d->m_data) : 0; }
inline T *operator->() { return d ? d->m_data : 0; }
inline const T *operator->() const { return d ? d->m_data : 0; }
inline operator T *() { return d ? d->m_data : 0; }
inline operator const T *() const { return d ? d->m_data : 0; }
inline bool operator==(const QRefCountPointer<T> &other) const { return d == other.d; }
inline bool operator!=(const QRefCountPointer<T> &other) const { return d != other.d; }
inline QRefCountPointer() { d = 0; }
inline ~QRefCountPointer() { if (d && !d->ref.deref()) delete d; }
explicit QRefCountPointer(T *data) {
if (data) {
d = new QRefCountData<T>(data);
d->ref.ref();
}
else {
d = 0;
}
}
inline QRefCountPointer(const QRefCountPointer<T> &o) : d(o.d) { if (d) d->ref.ref(); }
inline QRefCountPointer<T> & operator=(const QRefCountPointer<T> &o) {
if (o.d != d) {
if (d && !d->ref.deref())
delete d;
//todo: atomic assign of pointers
d = o.d;
if (d)
d->ref.ref();
}
return *this;
}
inline QRefCountPointer &operator=(T *o) {
if (d == 0 || d->m_data != o) {
if (d && !d->ref.deref())
delete d;
d = new QRefCountData<T>(o);
if (d)
d->ref.ref();
}
return *this;
}
inline bool operator!() const { return !d; }
private:
QRefCountData<T> *d;
};
//================BaseTextEditorPrivate==============
struct BaseTextEditorPrivateHighlightBlocks
{
QList<int> open;
QList<int> close;
QList<int> visualIndent;
inline int count() const { return visualIndent.size(); }
inline bool isEmpty() const { return open.isEmpty() || close.isEmpty() || visualIndent.isEmpty(); }
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); }
};
2008-12-02 12:01:29 +01:00
class BaseTextEditorPrivate
{
BaseTextEditorPrivate(const BaseTextEditorPrivate &);
BaseTextEditorPrivate &operator=(const BaseTextEditorPrivate &);
public:
BaseTextEditorPrivate();
~BaseTextEditorPrivate();
void setupBasicEditActions(TextEditorActionHandler *actionHandler);
void setupDocumentSignals(BaseTextDocument *document);
void updateLineSelectionColor();
void print(QPrinter *printer);
QTextBlock m_firstVisible;
int m_lastScrollPos;
int m_lineNumber;
BaseTextEditorWidget *q;
2008-12-02 12:01:29 +01:00
bool m_contentsChanged;
bool m_lastCursorChangeWasInteresting;
2008-12-02 12:01:29 +01:00
QList<QTextEdit::ExtraSelection> m_syntaxHighlighterSelections;
QTextEdit::ExtraSelection m_lineSelection;
QRefCountPointer<BaseTextDocument> m_document;
QByteArray m_tempState;
QByteArray m_tempNavigationState;
2008-12-02 12:01:29 +01:00
QString m_displayName;
bool m_parenthesesMatchingEnabled;
QTimer *m_updateTimer;
Utils::ChangeSet m_changeSet;
2008-12-02 12:01:29 +01:00
// parentheses matcher
bool m_formatRange;
QTextCharFormat m_matchFormat;
QTextCharFormat m_mismatchFormat;
QTextCharFormat m_rangeFormat;
QTimer *m_parenthesesMatchingTimer;
// end parentheses matcher
QWidget *m_extraArea;
QString m_tabSettingsId;
TabPreferences *m_tabPreferences;
IFallbackPreferences *m_codeStylePreferences;
2008-12-02 12:01:29 +01:00
DisplaySettings m_displaySettings;
FontSettings m_fontSettings;
BehaviorSettings m_behaviorSettings;
2008-12-02 12:01:29 +01:00
int extraAreaSelectionAnchorBlockNumber;
int extraAreaToggleMarkBlockNumber;
int extraAreaHighlightFoldedBlockNumber;
2008-12-02 12:01:29 +01:00
TextEditorOverlay *m_overlay;
TextEditorOverlay *m_snippetOverlay;
TextEditorOverlay *m_searchResultOverlay;
bool snippetCheckCursor(const QTextCursor &cursor);
void snippetTabOrBacktab(bool forward);
QTextCharFormat m_occurrencesFormat;
QTextCharFormat m_occurrenceRenameFormat;
RefactorOverlay *m_refactorOverlay;
QBasicTimer foldedBlockTimer;
int visibleFoldedBlockNumber;
int suggestedVisibleFoldedBlockNumber;
void clearVisibleFoldedBlock();
bool m_mouseOnFoldedMarker;
void foldLicenseHeader();
2008-12-02 12:01:29 +01:00
QBasicTimer autoScrollTimer;
void updateMarksLineNumber();
void updateMarksBlock(const QTextBlock &block);
uint m_marksVisible : 1;
uint m_codeFoldingVisible : 1;
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;
int m_visibleWrapColumn;
QTextCharFormat m_linkFormat;
BaseTextEditorWidget::Link m_currentLink;
bool m_linkPressed;
2008-12-02 12:01:29 +01:00
QTextCharFormat m_ifdefedOutFormat;
QRegExp m_searchExpr;
Find::FindFlags m_findFlags;
2008-12-02 12:01:29 +01:00
QTextCharFormat m_searchResultFormat;
QTextCharFormat m_searchScopeFormat;
QTextCharFormat m_currentLineFormat;
QTextCharFormat m_currentLineNumberFormat;
void highlightSearchResults(const QTextBlock &block, TextEditorOverlay *overlay);
QTimer *m_delayedUpdateTimer;
2008-12-02 12:01:29 +01:00
BaseTextEditor *m_editor;
2008-12-02 12:01:29 +01:00
QObject *m_actionHack;
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());
bool m_moveLineUndoHack;
QTextCursor m_findScopeStart;
QTextCursor m_findScopeEnd;
int m_findScopeVerticalBlockSelectionFirstColumn;
int m_findScopeVerticalBlockSelectionLastColumn;
QTextCursor m_selectBlockAnchor;
2008-12-02 12:01:29 +01:00
Internal::BaseTextBlockSelection m_blockSelection;
void moveCursorVisible(bool ensureVisible = true);
int visualIndent(const QTextBlock &block) const;
BaseTextEditorPrivateHighlightBlocks m_highlightBlocksInfo;
QTimer *m_highlightBlocksTimer;
QScopedPointer<CodeAssistant> m_codeAssistant;
bool m_assistRelevantContentAdded;
2010-07-19 14:06:00 +02:00
QPointer<BaseTextEditorAnimator> m_animator;
int m_cursorBlockNumber;
QScopedPointer<AutoCompleter> m_autoCompleter;
QScopedPointer<Indenter> m_indenter;
2008-12-02 12:01:29 +01:00
};
} // namespace Internal
} // namespace TextEditor
#endif // BASETEXTEDITOR_P_H