Newer
Older
/**************************************************************************
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
** Contact: Nokia Corporation (qt-info@nokia.com)
** 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.
** GNU Lesser General Public License Usage
** 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.
** If you are unsure which license is appropriate for your use, please
**************************************************************************/
#include "basetextdocumentlayout.h"
#include "completionsettings.h"
#include "texteditorconstants.h"
#include "texteditorplugin.h"
#include <aggregation/aggregate.h>
#include <coreplugin/actionmanager/actionmanager.h>
#include <coreplugin/actionmanager/actioncontainer.h>
#include <coreplugin/actionmanager/command.h>
#include <coreplugin/coreconstants.h>
#include <coreplugin/editormanager/editormanager.h>
#include <coreplugin/icore.h>
#include <coreplugin/manhattanstyle.h>
#include <extensionsystem/pluginmanager.h>
#include <find/basetextfind.h>
#include <utils/linecolumnlabel.h>
#include <QtCore/QCoreApplication>
#include <QtCore/QTextCodec>
#include <QtCore/QFile>
#include <QtCore/QDebug>
#include <QtCore/QTimer>
#include <QtCore/QTimeLine>
#include <QtGui/QAbstractTextDocumentLayout>
#include <QtGui/QApplication>
#include <QtGui/QKeyEvent>
#include <QtGui/QLabel>
#include <QtGui/QLayout>
#include <QtGui/QPainter>
#include <QtGui/QPrinter>
#include <QtGui/QPrintDialog>
#include <QtGui/QScrollBar>
#include <QtGui/QShortcut>
#include <QtGui/QStyle>
#include <QtGui/QSyntaxHighlighter>
#include <QtGui/QTextCursor>
#include <QtGui/QTextDocumentFragment>
#include <QtGui/QTextBlock>
#include <QtGui/QTextLayout>
#include <QtGui/QToolBar>
#include <QtGui/QToolTip>
#include <QtGui/QInputDialog>
#include <QtGui/QMenu>
using namespace TextEditor;
using namespace TextEditor::Internal;
namespace {
class Locker {
bool *m_bool;
public:
inline Locker(bool *b):m_bool(b){ *m_bool = true; }
inline ~Locker() { *m_bool = false; }
};
}
namespace Internal {
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
128
129
130
131
132
133
134
class TextEditExtraArea : public QWidget {
BaseTextEditor *textEdit;
public:
TextEditExtraArea(BaseTextEditor *edit):QWidget(edit) {
textEdit = edit;
setAutoFillBackground(true);
}
public:
QSize sizeHint() const {
return QSize(textEdit->extraAreaWidth(), 0);
}
protected:
void paintEvent(QPaintEvent *event){
textEdit->extraAreaPaintEvent(event);
}
void mousePressEvent(QMouseEvent *event){
textEdit->extraAreaMouseEvent(event);
}
void mouseMoveEvent(QMouseEvent *event){
textEdit->extraAreaMouseEvent(event);
}
void mouseReleaseEvent(QMouseEvent *event){
textEdit->extraAreaMouseEvent(event);
}
void leaveEvent(QEvent *event){
textEdit->extraAreaLeaveEvent(event);
}
void wheelEvent(QWheelEvent *event) {
QCoreApplication::sendEvent(textEdit->viewport(), event);
}
};
} // namespace Internal
} // namespace TextEditor
const QString &editorKind,
bool *newEditor)
Core::EditorManager *editorManager = Core::EditorManager::instance();
editorManager->addCurrentPositionToNavigationHistory();
Core::IEditor *editor = editorManager->openEditor(fileName, editorKind,
Core::EditorManager::IgnoreNavigationHistory, newEditor);
TextEditor::ITextEditor *texteditor = qobject_cast<TextEditor::ITextEditor *>(editor);
if (texteditor) {
texteditor->gotoLine(line, column);
return texteditor;
}
static void convertToPlainText(QString &txt)
{
QChar *uc = txt.data();
QChar *e = uc + txt.size();
for (; uc != e; ++uc) {
switch (uc->unicode()) {
case 0xfdd0: // QTextBeginningOfFrame
case 0xfdd1: // QTextEndOfFrame
case QChar::ParagraphSeparator:
case QChar::LineSeparator:
*uc = QLatin1Char('\n');
break;
case QChar::Nbsp:
*uc = QLatin1Char(' ');
break;
default:
;
}
}
}
BaseTextEditor::BaseTextEditor(QWidget *parent)
: QPlainTextEdit(parent)
{
d = new BaseTextEditorPrivate;
d->q = this;
d->m_extraArea = new TextEditExtraArea(this);
d->m_extraArea->setMouseTracking(true);
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
d->m_overlay = new TextEditorOverlay(this);
d->m_snippetOverlay = new TextEditorOverlay(this);
d->m_searchResultOverlay = new TextEditorOverlay(this);
Loading
Loading full blame...