From b220fcb1a88cba554335e15588590a1cdbb20db9 Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Thu, 5 May 2011 10:38:43 +0200 Subject: remove some dependencies to QTextEdit QSyntaxHighlighter is now free of dependencies to QtWidgets. QTextImageHandler still needs some work to get the url resolving to work again. --- src/gui/text/qsyntaxhighlighter.cpp | 21 +++++++++------------ src/gui/text/qsyntaxhighlighter.h | 2 -- src/gui/text/qtextimagehandler.cpp | 8 +++++--- src/gui/widgets/qtextedit.h | 1 + 4 files changed, 15 insertions(+), 17 deletions(-) (limited to 'src') diff --git a/src/gui/text/qsyntaxhighlighter.cpp b/src/gui/text/qsyntaxhighlighter.cpp index 6a3355b90d..5edd6375c9 100644 --- a/src/gui/text/qsyntaxhighlighter.cpp +++ b/src/gui/text/qsyntaxhighlighter.cpp @@ -50,7 +50,6 @@ #include #include #include -#include #include QT_BEGIN_NAMESPACE @@ -311,10 +310,19 @@ void QSyntaxHighlighterPrivate::reformatBlock(const QTextBlock &block) /*! Constructs a QSyntaxHighlighter with the given \a parent. + + If the parent is a QTextEdit, it installs the syntaxhighlighter on the + parents document. The specified QTextEdit also becomes the owner of + the QSyntaxHighlighter. */ QSyntaxHighlighter::QSyntaxHighlighter(QObject *parent) : QObject(*new QSyntaxHighlighterPrivate, parent) { + if (parent->inherits("QTextEdit")) { + QTextDocument *doc = qobject_cast(parent->property("document").value()); + if (doc) + setDocument(doc); + } } /*! @@ -328,17 +336,6 @@ QSyntaxHighlighter::QSyntaxHighlighter(QTextDocument *parent) setDocument(parent); } -/*! - Constructs a QSyntaxHighlighter and installs it on \a parent 's - QTextDocument. The specified QTextEdit also becomes the owner of - the QSyntaxHighlighter. -*/ -QSyntaxHighlighter::QSyntaxHighlighter(QTextEdit *parent) - : QObject(*new QSyntaxHighlighterPrivate, parent) -{ - setDocument(parent->document()); -} - /*! Destructor. Uninstalls this syntax highlighter from the text document. */ diff --git a/src/gui/text/qsyntaxhighlighter.h b/src/gui/text/qsyntaxhighlighter.h index 9cd5778074..33006cdd9e 100644 --- a/src/gui/text/qsyntaxhighlighter.h +++ b/src/gui/text/qsyntaxhighlighter.h @@ -61,7 +61,6 @@ class QTextCharFormat; class QFont; class QColor; class QTextBlockUserData; -class QTextEdit; class Q_GUI_EXPORT QSyntaxHighlighter : public QObject { @@ -70,7 +69,6 @@ class Q_GUI_EXPORT QSyntaxHighlighter : public QObject public: QSyntaxHighlighter(QObject *parent); QSyntaxHighlighter(QTextDocument *parent); - QSyntaxHighlighter(QTextEdit *parent); virtual ~QSyntaxHighlighter(); void setDocument(QTextDocument *doc); diff --git a/src/gui/text/qtextimagehandler.cpp b/src/gui/text/qtextimagehandler.cpp index 7cfaa3c88c..d04b758bc9 100644 --- a/src/gui/text/qtextimagehandler.cpp +++ b/src/gui/text/qtextimagehandler.cpp @@ -48,7 +48,6 @@ #include #include #include -#include #include QT_BEGIN_NAMESPACE @@ -73,7 +72,8 @@ static QPixmap getPixmap(QTextDocument *doc, const QTextImageFormat &format) if (pm.isNull()) { QString context; -#ifndef QT_NO_TEXTBROWSER +#if 0 + // ### Qt5 QTextBrowser *browser = qobject_cast(doc->parent()); if (browser) context = browser->source().toString(); @@ -150,7 +150,9 @@ static QImage getImage(QTextDocument *doc, const QTextImageFormat &format) if (image.isNull()) { QString context; -#ifndef QT_NO_TEXTBROWSER + +#if 0 + // ### Qt5 QTextBrowser *browser = qobject_cast(doc->parent()); if (browser) context = browser->source().toString(); diff --git a/src/gui/widgets/qtextedit.h b/src/gui/widgets/qtextedit.h index d2d86d5ed7..459f9bdd5e 100644 --- a/src/gui/widgets/qtextedit.h +++ b/src/gui/widgets/qtextedit.h @@ -90,6 +90,7 @@ class Q_GUI_EXPORT QTextEdit : public QAbstractScrollArea Q_PROPERTY(bool acceptRichText READ acceptRichText WRITE setAcceptRichText) Q_PROPERTY(int cursorWidth READ cursorWidth WRITE setCursorWidth) Q_PROPERTY(Qt::TextInteractionFlags textInteractionFlags READ textInteractionFlags WRITE setTextInteractionFlags) + Q_PROPERTY(QObject *document READ document) public: enum LineWrapMode { NoWrap, -- cgit v1.2.3