From 08a9924cc69e0c44aae1abfd8500cd62f6e3d73a Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Tue, 17 Aug 2010 12:29:37 +0200 Subject: Designer: Add 'Simplify rich text' filter to rich text editor. Add an option to filter out style elements created by the text engine to keep the rich text simple. Acked-by: Jarek Kobus Task-number: QTBUG-10890 --- .../src/components/formeditor/formeditor.qrc | 2 + .../formeditor/images/mac/simplifyrichtext.png | Bin 0 -> 1988 bytes .../formeditor/images/win/simplifyrichtext.png | Bin 0 -> 1933 bytes tools/designer/src/lib/shared/richtexteditor.cpp | 202 ++++++++++++++++++--- tools/designer/src/lib/shared/richtexteditor_p.h | 1 + 5 files changed, 178 insertions(+), 27 deletions(-) create mode 100644 tools/designer/src/components/formeditor/images/mac/simplifyrichtext.png create mode 100644 tools/designer/src/components/formeditor/images/win/simplifyrichtext.png diff --git a/tools/designer/src/components/formeditor/formeditor.qrc b/tools/designer/src/components/formeditor/formeditor.qrc index 6510814..ed7e40e 100644 --- a/tools/designer/src/components/formeditor/formeditor.qrc +++ b/tools/designer/src/components/formeditor/formeditor.qrc @@ -153,6 +153,7 @@ images/win/textjustify.png images/win/textsuperscript.png images/win/textsubscript.png + images/win/simplifyrichtext.png images/win/back.png images/win/forward.png images/win/down.png @@ -167,6 +168,7 @@ images/mac/textjustify.png images/mac/textsuperscript.png images/mac/textsubscript.png + images/mac/simplifyrichtext.png defaultbrushes.xml diff --git a/tools/designer/src/components/formeditor/images/mac/simplifyrichtext.png b/tools/designer/src/components/formeditor/images/mac/simplifyrichtext.png new file mode 100644 index 0000000..a48e974 Binary files /dev/null and b/tools/designer/src/components/formeditor/images/mac/simplifyrichtext.png differ diff --git a/tools/designer/src/components/formeditor/images/win/simplifyrichtext.png b/tools/designer/src/components/formeditor/images/win/simplifyrichtext.png new file mode 100644 index 0000000..e251cf7 Binary files /dev/null and b/tools/designer/src/components/formeditor/images/win/simplifyrichtext.png differ diff --git a/tools/designer/src/lib/shared/richtexteditor.cpp b/tools/designer/src/lib/shared/richtexteditor.cpp index ec7c2e5..b5a2618 100644 --- a/tools/designer/src/lib/shared/richtexteditor.cpp +++ b/tools/designer/src/lib/shared/richtexteditor.cpp @@ -52,6 +52,9 @@ #include #include #include +#include +#include +#include #include #include @@ -74,28 +77,129 @@ QT_BEGIN_NAMESPACE -static const char *RichTextDialogC = "RichTextDialog"; -static const char *Geometry = "Geometry"; +static const char RichTextDialogGroupC[] = "RichTextDialog"; +static const char GeometryKeyC[] = "Geometry"; +static const char TabKeyC[] = "Tab"; + +const bool simplifyRichTextDefault = true; namespace qdesigner_internal { +// Richtext simplification filter helpers: Elements to be discarded +static inline bool filterElement(const QStringRef &name) +{ + return name != QLatin1String("meta") && name != QLatin1String("style"); +} + +// Richtext simplification filter helpers: Filter attributes of elements +static inline void filterAttributes(const QStringRef &name, + QXmlStreamAttributes *atts, + bool *paragraphAlignmentFound) +{ + typedef QXmlStreamAttributes::iterator AttributeIt; + + if (atts->isEmpty()) + return; + + // No style attributes for + if (name == QLatin1String("body")) { + atts->clear(); + return; + } + + // Clean out everything except 'align' for 'p' + if (name == QLatin1String("p")) { + for (AttributeIt it = atts->begin(); it != atts->end(); ) { + if (it->name() == QLatin1String("align")) { + ++it; + *paragraphAlignmentFound = true; + } else { + it = atts->erase(it); + } + } + return; + } +} + +// Richtext simplification filter helpers: Check for blank QStringRef. +static inline bool isWhiteSpace(const QStringRef &in) +{ + const int count = in.size(); + for (int i = 0; i < count; i++) + if (!in.at(i).isSpace()) + return false; + return true; +} + +// Richtext simplification filter: Remove hard-coded font settings, +//