summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMontel Laurent <[email protected]>2015-10-18 09:11:57 +0200
committerMontel Laurent <[email protected]>2015-10-18 09:12:31 +0200
commit3a70a04305f505dc5c817709a6b5e6ae31c5941e (patch)
tree32da28576d86a8e8eca41f89b56d1beccabf0c87
parent84ce438f31fb2582c75bbd4107de44a07471d823 (diff)
Remove unused code
-rw-r--r--autotests/CMakeLists.txt3
-rw-r--r--src/CMakeLists.txt6
-rw-r--r--src/emailquotedecorator.cpp53
-rw-r--r--src/emailquotedecorator.h43
-rw-r--r--src/emailquotehighlighter.cpp166
-rw-r--r--src/emailquotehighlighter.h133
-rw-r--r--src/textedit.cpp878
-rw-r--r--src/textedit.h365
-rw-r--r--tests/CMakeLists.txt4
9 files changed, 4 insertions, 1647 deletions
diff --git a/autotests/CMakeLists.txt b/autotests/CMakeLists.txt
index 86773b6..4fed2c4 100644
--- a/autotests/CMakeLists.txt
+++ b/autotests/CMakeLists.txt
@@ -3,7 +3,8 @@ include(ECMAddTests)
set(QT_REQUIRED_VERSION "5.2.0")
find_package(Qt5 ${QT_REQUIRED_VERSION} CONFIG REQUIRED COMPONENTS Test Widgets)
-ecm_add_tests( textedittest.cpp textutilstest.cpp NAME_PREFIX "kpimtextedit-" LINK_LIBRARIES Qt5::Test Qt5::Widgets KF5::Codecs KF5PimTextEdit KF5::IconThemes KF5::TextWidgets)
+ecm_add_tests( textutilstest.cpp NAME_PREFIX "kpimtextedit-" LINK_LIBRARIES Qt5::Test Qt5::Widgets KF5::Codecs KF5PimTextEdit KF5::IconThemes KF5::TextWidgets)
+#textedittest.cpp
ecm_add_test(slidecontainertest.cpp
TEST_NAME slidecontainertest
NAME_PREFIX kpimtextedit-widget
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index efc11ce..3ece3c2 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -43,7 +43,6 @@ set(kpimtextedit_texttospeech_SRCS
set(kpimtextedit_SRCS
- emailquotehighlighter.cpp
emoticontexteditaction.cpp
emoticontexteditselector.cpp
htmlhighlighter.cpp
@@ -55,10 +54,8 @@ set(kpimtextedit_SRCS
tableactionmenu.cpp
tablecellformatdialog.cpp
tableformatdialog.cpp
- textedit.cpp
textutils.cpp
inserttablewidget.cpp
- emailquotedecorator.cpp
syntaxhighlighterbase.cpp
texteditorcompleter.cpp
slidecontainer.cpp
@@ -106,8 +103,6 @@ install(TARGETS KF5PimTextEdit EXPORT KF5PimTextEditTargets ${KF5_INSTALL_TARGET
########### Generate Headers ###############
ecm_generate_headers(KPimTextEdit_CamelCase_HEADERS
HEADER_NAMES
- EMailQuoteHighlighter
- EmailQuoteDecorator
EmoticonTextEditAction
HtmlHighlighter
InsertHtmlDialog
@@ -121,7 +116,6 @@ ecm_generate_headers(KPimTextEdit_CamelCase_HEADERS
TableCellFormatDialog
TableFormatDialog
TableActionMenu
- TextEdit
TextEditorCompleter
TextUtils
diff --git a/src/emailquotedecorator.cpp b/src/emailquotedecorator.cpp
deleted file mode 100644
index 6448867..0000000
--- a/src/emailquotedecorator.cpp
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * Copyright (C) 2015 Laurent Montel <[email protected]>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA
- */
-
-#include "emailquotedecorator.h"
-#include <KTextEdit>
-
-using namespace KPIMTextEdit;
-
-class EmailQuoteDecorator::EmailQuoteDecoratorPrivate
-{
-public:
- EmailQuoteDecoratorPrivate(KTextEdit *edit)
- : textEdit(edit)
- {
-
- }
-
- KTextEdit *textEdit;
-};
-
-EmailQuoteDecorator::EmailQuoteDecorator(KTextEdit *textEdit)
- : Sonnet::SpellCheckDecorator(textEdit),
- d(new EmailQuoteDecoratorPrivate(textEdit))
-{
-
-}
-
-EmailQuoteDecorator::~EmailQuoteDecorator()
-{
- delete d;
-}
-
-bool EmailQuoteDecorator::isSpellCheckingEnabledForBlock(const QString &blockText) const
-{
- return d->textEdit->shouldBlockBeSpellChecked(blockText);
-}
-
diff --git a/src/emailquotedecorator.h b/src/emailquotedecorator.h
deleted file mode 100644
index 9fecf3b..0000000
--- a/src/emailquotedecorator.h
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * Copyright (C) 2015 Laurent Montel <[email protected]>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA
- */
-
-#ifndef EMAILQUOTEDECORATOR_H
-#define EMAILQUOTEDECORATOR_H
-
-#include <sonnet/spellcheckdecorator.h>
-#include "kpimtextedit_export.h"
-
-class KTextEdit;
-
-namespace KPIMTextEdit
-{
-class KPIMTEXTEDIT_EXPORT EmailQuoteDecorator : public Sonnet::SpellCheckDecorator
-{
-public:
- explicit EmailQuoteDecorator(KTextEdit *textEdit);
- ~EmailQuoteDecorator();
-
-protected:
- bool isSpellCheckingEnabledForBlock(const QString &blockText) const Q_DECL_OVERRIDE;
-private:
- class EmailQuoteDecoratorPrivate;
- EmailQuoteDecoratorPrivate *const d;
-};
-}
-#endif // EMAILQUOTEDECORATOR_H
diff --git a/src/emailquotehighlighter.cpp b/src/emailquotehighlighter.cpp
deleted file mode 100644
index ca971fc..0000000
--- a/src/emailquotehighlighter.cpp
+++ /dev/null
@@ -1,166 +0,0 @@
-/**
- * Copyright (C) 2006 Laurent Montel <[email protected]>
- * Copyright (C) 2008 Thomas McGuire <[email protected]>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA
- */
-
-#include "emailquotehighlighter.h"
-
-#include "textedit.h"
-
-namespace KPIMTextEdit
-{
-
-class EMailQuoteHighlighter::EMailQuoteHighlighterPrivate
-{
-public:
- QColor col1, col2, col3, misspelledColor;
- bool spellCheckingEnabled;
- TextEdit *parent;
-};
-
-EMailQuoteHighlighter::EMailQuoteHighlighter(TextEdit *textEdit,
- const QColor &normalColor,
- const QColor &quoteDepth1,
- const QColor &quoteDepth2,
- const QColor &quoteDepth3,
- const QColor &misspelledColor)
- : Highlighter(textEdit, textEdit->configFile()),
- d(new EMailQuoteHighlighterPrivate())
-{
- Q_UNUSED(normalColor);
- // Don't automatically disable the spell checker, for example because there
- // are too many misspelled words. That would also disable quote highlighting.
- // FIXME: disable this spell checking!
- setAutomatic(false);
-
- setActive(true);
- d->col1 = quoteDepth1;
- d->col2 = quoteDepth2;
- d->col3 = quoteDepth3;
- d->misspelledColor = misspelledColor;
- d->spellCheckingEnabled = false;
- d->parent = textEdit;
-}
-
-EMailQuoteHighlighter::~EMailQuoteHighlighter()
-{
-}
-
-QString EMailQuoteHighlighter::highlightText(const QString &text,
- const QColor &quoteDepth1,
- const QColor &quoteDepth2,
- const QColor &quoteDepth3)
-{
- const QStringList splitList = text.split(QLatin1Char('\n'));
- QString result;
- QStringList::const_iterator it = splitList.constBegin();
- QStringList::const_iterator end = splitList.constEnd();
- while (it != end) {
- result.append(highlightParagraph((*it) + QLatin1Char('\n'),
- quoteDepth1, quoteDepth2, quoteDepth3));
- ++it;
- }
- return result;
-}
-
-QString EMailQuoteHighlighter::highlightParagraph(const QString &text,
- const QColor &quoteDepth1,
- const QColor &quoteDepth2,
- const QColor &quoteDepth3)
-{
- QString simplified = text;
- simplified = simplified.remove(QRegExp(QStringLiteral("\\s"))).
- replace(QLatin1Char('|'), QLatin1Char('>')).
- replace(QStringLiteral("&gt;"), QStringLiteral(">"));
-
- while (simplified.startsWith(QStringLiteral(">>>>"))) {
- simplified = simplified.mid(3);
- }
-
- QString result(QStringLiteral("<font color=\"%1\">%2</font>"));
- if (simplified.startsWith(QStringLiteral(">>>"))) {
- return result.arg(quoteDepth3.name(), text);
- } else if (simplified.startsWith(QStringLiteral(">>"))) {
- return result.arg(quoteDepth2.name(), text);
- } else if (simplified.startsWith(QStringLiteral(">"))) {
- return result.arg(quoteDepth1.name(), text);
- }
-
- return text;
-}
-
-void EMailQuoteHighlighter::setQuoteColor(const QColor &normalColor,
- const QColor &quoteDepth1,
- const QColor &quoteDepth2,
- const QColor &quoteDepth3,
- const QColor &misspelledColor)
-{
- Q_UNUSED(normalColor);
- d->col1 = quoteDepth1;
- d->col2 = quoteDepth2;
- d->col3 = quoteDepth3;
- d->misspelledColor = misspelledColor;
-}
-
-void EMailQuoteHighlighter::toggleSpellHighlighting(bool on)
-{
- if (on != d->spellCheckingEnabled) {
- d->spellCheckingEnabled = on;
- rehighlight();
- }
-}
-
-void EMailQuoteHighlighter::highlightBlock(const QString &text)
-{
- QString simplified = text;
- simplified = simplified.remove(QRegExp(QStringLiteral("\\s"))).
- replace(QLatin1Char('|'), QLatin1Char('>'));
-
- while (simplified.startsWith(QLatin1String(">>>>"))) {
- simplified = simplified.mid(3);
- }
-
- if (simplified.startsWith(QLatin1String(">>>"))) {
- setFormat(0, text.length(), d->col3);
- } else if (simplified.startsWith(QLatin1String(">>"))) {
- setFormat(0, text.length(), d->col2);
- } else if (simplified.startsWith(QLatin1String(">"))) {
- setFormat(0, text.length(), d->col1);
- } else if (d->parent->isLineQuoted(text)) {
- setFormat(0, text.length(), d->col1); // FIXME: custom quote prefix
- // can't handle multiple levels
- } else if (d->spellCheckingEnabled) {
- Highlighter::highlightBlock(text);
- return; //setCurrentBlockState already done in Highlighter::highlightBlock
- }
- setCurrentBlockState(0);
-}
-
-void EMailQuoteHighlighter::unsetMisspelled(int start, int count)
-{
- Q_UNUSED(start);
- Q_UNUSED(count);
-}
-
-void EMailQuoteHighlighter::setMisspelled(int start, int count)
-{
- setMisspelledColor(d->misspelledColor);
- Sonnet::Highlighter::setMisspelled(start, count);
-}
-
-}
diff --git a/src/emailquotehighlighter.h b/src/emailquotehighlighter.h
deleted file mode 100644
index 77e30c4..0000000
--- a/src/emailquotehighlighter.h
+++ /dev/null
@@ -1,133 +0,0 @@
-/**
- * Copyright (C) 2006 Laurent Montel <[email protected]>
- * Copyright (C) 2008 Thomas McGuire <[email protected]>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA
- */
-#ifndef KPIMTEXTEDIT_EMAILQUOTEHIGHLIGHTER_H
-#define KPIMTEXTEDIT_EMAILQUOTEHIGHLIGHTER_H
-
-#include "kpimtextedit_export.h"
-
-#include <sonnet/highlighter.h>
-
-#include <memory>
-
-namespace KPIMTextEdit
-{
-
-class TextEdit;
-
-/**
- * This highlighter highlights spelling mistakes and also highlightes
- * quotes.
- *
- * Spelling mistakes inside quotes will not be highlighted.
- * The quote highlighting color is configurable.
- *
- * Spell highlighting is disabled by default but can be toggled.
- *
- * @since 4.3
- */
-class KPIMTEXTEDIT_EXPORT EMailQuoteHighlighter : public Sonnet::Highlighter
-{
-public:
-
- /**
- * Constructor. See setQuoteColor() for the parameters.
- * FIXME: Default colors don't obey color scheme
- */
- explicit EMailQuoteHighlighter(TextEdit *textEdit,
- const QColor &normalColor = Qt::black,
- const QColor &quoteDepth1 = QColor(0x00, 0x80, 0x00),
- const QColor &quoteDepth2 = QColor(0x00, 0x80, 0x00),
- const QColor &quoteDepth3 = QColor(0x00, 0x80, 0x00),
- const QColor &misspelledColor = Qt::red);
-
- ~EMailQuoteHighlighter();
-
- /**
- * Sets the colors used for highlighting quoted text and spelling mistakes.
- *
- * @param quoteDepth1 color for text quoted 1 level deep
- * @param quoteDepth2 color for text quoted 2 level deep
- * @param quoteDepth3 color for text quoted 3 level deep
- * @param misspelledColor color in which misspelled words will be underlined
- * @param normalColor will be ignored, only provided for KNode
- * compatibility.
- */
- void setQuoteColor(const QColor &normalColor,
- const QColor &quoteDepth1,
- const QColor &quoteDepth2,
- const QColor &quoteDepth3,
- const QColor &misspelledColor = Qt::red);
-
- /**
- * Turns spellcheck highlighting on or off.
- *
- * @param on if true, spelling mistakes will be highlighted
- */
- void toggleSpellHighlighting(bool on);
-
- /**
- * Reimplemented to highlight quote blocks.
- */
- void highlightBlock(const QString &text) Q_DECL_OVERRIDE;
-
- /**
- * Use this static method to get a text consisting of multiple lines
- * highligted.
- * @since 4.4
- */
- static QString highlightText(const QString &text,
- const QColor &quoteDepth1 = QColor(0x00, 0x80, 0x00),
- const QColor &quoteDepth2 = QColor(0x00, 0x80, 0x00),
- const QColor &quoteDepth3 = QColor(0x00, 0x80, 0x00));
-
- /**
- * Use this static method to get proper highlighting for a single line.
- * @since 4.4
- */
- static QString highlightParagraph(const QString &text,
- const QColor &quoteDepth1 = QColor(0x00, 0x80, 0x00),
- const QColor &quoteDepth2 = QColor(0x00, 0x80, 0x00),
- const QColor &quoteDepth3 = QColor(0x00, 0x80, 0x00));
-
-protected:
-
- /**
- * Reimplemented, the base version sets the text color to black, which
- * is not what we want. We do nothing, the format is already reset by
- * Qt.
- * @param start the beginning of text
- * @param count the amount of characters to set
- */
- void unsetMisspelled(int start, int count) Q_DECL_OVERRIDE;
-
- /**
- * Reimplemented to set the color of the misspelled word to a color
- * defined by setQuoteColor().
- */
- void setMisspelled(int start, int count) Q_DECL_OVERRIDE;
-
-private:
- class EMailQuoteHighlighterPrivate;
- std::unique_ptr<EMailQuoteHighlighterPrivate> d;
-};
-
-}
-
-#endif
diff --git a/src/textedit.cpp b/src/textedit.cpp
deleted file mode 100644
index 136cd72..0000000
--- a/src/textedit.cpp
+++ /dev/null
@@ -1,878 +0,0 @@
-/*
- Copyright (c) 2009 Thomas McGuire <[email protected]>
-
- Based on KMail and libkdepim code by:
- Copyright 2007 - 2012 Laurent Montel <[email protected]>
-
- This library is free software; you can redistribute it and/or modify it
- under the terms of the GNU Library General Public License as published by
- the Free Software Foundation; either version 2 of the License, or (at your
- option) any later version.
-
- This library is distributed in the hope that it will be useful, but WITHOUT
- ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
- License for more details.
-
- You should have received a copy of the GNU Library General Public License
- along with this library; see the file COPYING.LIB. If not, write to the
- Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- 02110-1301, USA.
-*/
-#include "textedit.h"
-
-#include "emailquotedecorator.h"
-#include "emailquotehighlighter.h"
-#include "emoticontexteditaction.h"
-#include "inserthtmldialog.h"
-#include "tableactionmenu.h"
-#include "insertimagedialog.h"
-
-#include <KCodecs/KCodecs>
-
-#include <QAction>
-#include <KCursor>
-#include <KLocalizedString>
-#include <KMessageBox>
-
-#include <QtCore/QBuffer>
-#include <QtCore/QDateTime>
-#include <QtCore/QMimeData>
-#include <QtCore/QFileInfo>
-#include <QtCore/QPointer>
-#include <QKeyEvent>
-#include <QTextLayout>
-#include <QUrl>
-
-#include "textutils.h"
-
-namespace KPIMTextEdit
-{
-
-class TextEditPrivate
-{
-public:
-
- TextEditPrivate(TextEdit *parent)
- : actionAddImage(0),
- actionDeleteLine(0),
- actionAddEmoticon(0),
- actionInsertHtml(0),
- actionTable(0),
- actionFormatReset(0),
- q(parent),
- imageSupportEnabled(false),
- emoticonSupportEnabled(false),
- insertHtmlSupportEnabled(false),
- insertTableSupportEnabled(false),
- spellCheckingEnabled(false)
- {
- }
-
- /**
- * Helper function for addImage(), which does the actual work of adding the QImage as a
- * resource to the document, pasting it and adding it to the image name list.
- *
- * @param imageName the desired image name. If it is already taken, a number will
- * be appended to it
- * @param image the actual image to add
- */
- void addImageHelper(const QString &imageName, const QImage &image,
- int width = -1, int height = -1);
-
- /**
- * Helper function to get the list of all QTextImageFormats in the document.
- */
- QList<QTextImageFormat> embeddedImageFormats() const;
-
- /**
- * Removes embedded image markers, converts non-breaking spaces to normal spaces
- * and other fixes for strings that came from toPlainText()/toHtml().
- */
- void fixupTextEditString(QString &text) const;
-
- /**
- * Does the constructor work
- */
- void init();
-
- /**
- * Opens a file dialog to let the user choose an image and then pastes that
- * image to the editor
- */
- void _k_slotAddImage();
-
- void _k_slotDeleteLine();
-
- void _k_slotAddEmoticon(const QString &);
-
- void _k_slotInsertHtml();
-
- void _k_slotFormatReset();
-
- void _k_slotTextModeChanged(KRichTextEdit::Mode);
-
- /// The action that triggers _k_slotAddImage()
- QAction *actionAddImage;
-
- /// The action that triggers _k_slotDeleteLine()
- QAction *actionDeleteLine;
-
- EmoticonTextEditAction *actionAddEmoticon;
-
- QAction *actionInsertHtml;
-
- TableActionMenu *actionTable;
-
- QAction *actionFormatReset;
-
- /// The parent class
- TextEdit *q;
-
- /**
- * The names of embedded images.
- * Used to easily obtain the names of the images.
- * New images are compared to the list and not added as resource if already present.
- */
- QStringList mImageNames;
-
- QString configFile;
- QFont saveFont;
-
- /// Whether or not adding or pasting images is supported
- bool imageSupportEnabled;
-
- bool emoticonSupportEnabled;
-
- bool insertHtmlSupportEnabled;
-
- bool insertTableSupportEnabled;
-
- /**
- * Although KTextEdit keeps track of the spell checking state, we override
- * it here, because we have a highlighter which does quote highlighting.
- * And since disabling spellchecking in KTextEdit simply would turn off our
- * quote highlighter, we never actually deactivate spell checking in the
- * base class, but only tell our own email highlighter to not highlight
- * spelling mistakes.
- * For this, we use the KTextEditSpellInterface, which is basically a hack
- * that makes it possible to have our own enabled/disabled state in a binary
- * compatible way.
- */
- bool spellCheckingEnabled;
-};
-
-} // namespace
-
-using namespace KPIMTextEdit;
-
-void TextEditPrivate::fixupTextEditString(QString &text) const
-{
- // Remove line separators. Normal \n chars are still there, so no linebreaks get lost here
- text.remove(QChar::LineSeparator);
-
- // Get rid of embedded images, see QTextImageFormat documentation:
- // "Inline images are represented by an object replacement character (0xFFFC in Unicode) "
- text.remove(0xFFFC);
-
- // In plaintext mode, each space is non-breaking.
- text.replace(QChar::Nbsp, QChar::fromLatin1(' '));
-}
-
-TextEdit::TextEdit(const QString &text, QWidget *parent)
- : KRichTextWidget(text, parent),
- d(new TextEditPrivate(this))
-{
- d->init();
-}
-
-TextEdit::TextEdit(QWidget *parent, const QString &configFile)
- : KRichTextWidget(parent),
- d(new TextEditPrivate(this))
-{
- d->init();
- d->configFile = configFile;
-}
-
-TextEdit::~TextEdit()
-{
-}
-
-bool TextEdit::eventFilter(QObject *o, QEvent *e)
-{
-#ifndef QT_NO_CURSOR
- if (o == this) {
- KCursor::autoHideEventFilter(o, e);
- }
-#endif
- return KRichTextWidget::eventFilter(o, e);
-}
-
-void TextEditPrivate::init()
-{
- q->connect(q, SIGNAL(textModeChanged(KRichTextEdit::Mode)), q, SLOT(_k_slotTextModeChanged(KRichTextEdit::Mode)));
-
- // We tell the KRichTextWidget to enable spell checking, because only then it will
- // call createHighlighter() which will create our own highlighter which also
- // does quote highlighting.
- // However, *our* spellchecking is still disabled. Our own highlighter only
- // cares about our spellcheck status, it will not highlight missspelled words
- // if our spellchecking is disabled.
- // See also KEMailQuotingHighlighter::highlightBlock().
- spellCheckingEnabled = false;
- q->setCheckSpellingEnabled(true);
-
-#ifndef QT_NO_CURSOR
- KCursor::setAutoHideCursor(q, true, true);
-#endif
- q->installEventFilter(q);
-}
-
-QString TextEdit::configFile() const
-{
- return d->configFile;
-}
-
-void TextEdit::keyPressEvent(QKeyEvent *e)
-{
- if (e->key() == Qt::Key_Return) {
- QTextCursor cursor = textCursor();
- int oldPos = cursor.position();
- int blockPos = cursor.block().position();
-
- //selection all the line.
- cursor.movePosition(QTextCursor::StartOfBlock);
- cursor.movePosition(QTextCursor::EndOfBlock, QTextCursor::KeepAnchor);
- QString lineText = cursor.selectedText();
- if (((oldPos - blockPos) > 0) &&
- ((oldPos - blockPos) < int(lineText.length()))) {
- bool isQuotedLine = false;
- int bot = 0; // bot = begin of text after quote indicators
- while (bot < lineText.length()) {
- if ((lineText[bot] == QChar::fromLatin1('>')) ||
- (lineText[bot] == QChar::fromLatin1('|'))) {
- isQuotedLine = true;
- ++bot;
- } else if (lineText[bot].isSpace()) {
- ++bot;
- } else {
- break;
- }
- }
- KRichTextWidget::keyPressEvent(e);
- // duplicate quote indicators of the previous line before the new
- // line if the line actually contained text (apart from the quote
- // indicators) and the cursor is behind the quote indicators
- if (isQuotedLine &&
- (bot != lineText.length()) &&
- ((oldPos - blockPos) >= int(bot))) {
- // The cursor position might have changed unpredictably if there was selected
- // text which got replaced by a new line, so we query it again:
- cursor.movePosition(QTextCursor::StartOfBlock);
- cursor.movePosition(QTextCursor::EndOfBlock, QTextCursor::KeepAnchor);
- QString newLine = cursor.selectedText();
-
- // remove leading white space from the new line and instead
- // add the quote indicators of the previous line
- int leadingWhiteSpaceCount = 0;
- while ((leadingWhiteSpaceCount < newLine.length()) &&
- newLine[leadingWhiteSpaceCount].isSpace()) {
- ++leadingWhiteSpaceCount;
- }
- newLine = newLine.replace(0, leadingWhiteSpaceCount, lineText.left(bot));
- cursor.insertText(newLine);
- //cursor.setPosition( cursor.position() + 2 );
- cursor.movePosition(QTextCursor::StartOfBlock);
- setTextCursor(cursor);
- }
- } else {
- KRichTextWidget::keyPressEvent(e);
- }
- } else {
- KRichTextWidget::keyPressEvent(e);
- }
-}
-
-bool TextEdit::checkSpellingEnabled() const
-{
- return d->spellCheckingEnabled;
-}
-
-void TextEdit::setCheckSpellingEnabled(bool check)
-{
- EMailQuoteHighlighter *hlighter = dynamic_cast<EMailQuoteHighlighter *>(highlighter());
- if (hlighter) {
- hlighter->toggleSpellHighlighting(check);
- }
- d->spellCheckingEnabled = check;
- KTextEdit::setCheckSpellingEnabled(check);
-#if 0
- if (d->spellCheckingEnabled == check) {
- return;
- }
-
- d->spellCheckingEnabled = check;
- if (check) {
- if (hasFocus()) {
- createHighlighter();
- if (!spellCheckingLanguage().isEmpty()) {
- setSpellCheckingLanguage(spellCheckingLanguage());
- }
- }
- } else {
- clearDecorator();
- }
-
- emit checkSpellingChanged(check);
-#endif
-}
-
-bool TextEdit::shouldBlockBeSpellChecked(const QString &block) const
-{
- return !isLineQuoted(block);
-}
-
-bool KPIMTextEdit::TextEdit::isLineQuoted(const QString &line) const
-{
- return quoteLength(line) > 0;
-}
-
-int KPIMTextEdit::TextEdit::quoteLength(const QString &line) const
-{
- bool quoteFound = false;
- int startOfText = -1;
- const int lineLength(line.length());
- for (int i = 0; i < lineLength; ++i) {
- if (line[i] == QLatin1Char('>') || line[i] == QLatin1Char('|')) {
- quoteFound = true;
- } else if (line[i] != QLatin1Char(' ')) {
- startOfText = i;
- break;
- }
- }
- if (quoteFound) {
- if (startOfText == -1) {
- startOfText = line.length() - 1;
- }
- return startOfText;
- } else {
- return 0;
- }
-}
-
-const QString KPIMTextEdit::TextEdit::defaultQuoteSign() const
-{
- return QStringLiteral("> ");
-}
-
-void TextEdit::createHighlighter()
-{
- EMailQuoteHighlighter *emailHighLighter = new EMailQuoteHighlighter(this);
-
- setHighlighterColors(emailHighLighter);
-
- EmailQuoteDecorator *decorator = new EmailQuoteDecorator(this);
- decorator->setHighlighter(emailHighLighter);
-
- //KTextEdit used to take ownership of the highlighter, Sonnet::SpellCheckDecorator does not.
- //so we reparent the highlighter so it will be deleted when the decorator is destroyed
- emailHighLighter->setParent(decorator);
- addTextDecorator(decorator);
-
- if (!spellCheckingLanguage().isEmpty()) {
- setSpellCheckingLanguage(spellCheckingLanguage());
- }
-}
-
-void TextEdit::setHighlighterColors(EMailQuoteHighlighter *highlighter)
-{
- Q_UNUSED(highlighter);
-}
-
-QString TextEdit::toWrappedPlainText() const
-{
- QTextDocument *doc = document();
- return toWrappedPlainText(doc);
-}
-
-QString TextEdit::toWrappedPlainText(QTextDocument *doc) const
-{
- QString temp;
- QRegExp rx(QStringLiteral("(http|ftp|ldap)s?\\S+-$"));
- QTextBlock block = doc->begin();
- while (block.isValid()) {
- QTextLayout *layout = block.layout();
- const int numberOfLine(layout->lineCount());
- bool urlStart = false;
- for (int i = 0; i < numberOfLine; ++i) {
- QTextLine line = layout->lineAt(i);
- QString lineText = block.text().mid(line.textStart(), line.textLength());
-
- if (lineText.contains(rx) ||
- (urlStart && !lineText.contains(QLatin1Char(' ')) &&
- lineText.endsWith(QLatin1Char('-')))) {
- // don't insert line break in URL
- temp += lineText;
- urlStart = true;
- } else {
- temp += lineText + QLatin1Char('\n');
- }
- }
- block = block.next();
- }
-
- // Remove the last superfluous newline added above
- if (temp.endsWith(QLatin1Char('\n'))) {
- temp.chop(1);
- }
-
- d->fixupTextEditString(temp);
- return temp;
-}
-
-QString TextEdit::toCleanPlainText(const QString &plainText) const
-{
- QString temp = plainText.isEmpty() ? toPlainText() : plainText;
- d->fixupTextEditString(temp);
- return temp;
-}
-
-QList<QAction *> TextEdit::createActions()
-{
- QList<QAction *> listAction = KRichTextWidget::createActions();
-
- if (d->imageSupportEnabled) {
- d->actionAddImage = new QAction(QIcon::fromTheme(QStringLiteral("insert-image")),
- i18n("Add Image"), this);
- d->actionAddImage->setObjectName(QStringLiteral("add_image"));
- connect(d->actionAddImage, SIGNAL(triggered(bool)), SLOT(_k_slotAddImage()));
- listAction << d->actionAddImage;
- }
- if (d->emoticonSupportEnabled) {
- d->actionAddEmoticon = new EmoticonTextEditAction(this);
- d->actionAddEmoticon->setObjectName(QStringLiteral("add_emoticon"));
- connect(d->actionAddEmoticon, SIGNAL(emoticonActivated(QString)),
- SLOT(_k_slotAddEmoticon(QString)));
- listAction << d->actionAddEmoticon;
- }
-
- if (d->insertHtmlSupportEnabled) {
- d->actionInsertHtml = new QAction(i18n("Insert HTML"), this);
- d->actionInsertHtml->setObjectName(QStringLiteral("insert_html"));
- connect(d->actionInsertHtml, SIGNAL(triggered(bool)), SLOT(_k_slotInsertHtml()));
- listAction << d->actionInsertHtml;
- }
-
- if (d->insertTableSupportEnabled) {
- d->actionTable = new TableActionMenu(this);
- d->actionTable->setIcon(QIcon::fromTheme(QStringLiteral("insert-table")));
- d->actionTable->setText(i18n("Table"));
- d->actionTable->setDelayed(false);
- d->actionTable->setObjectName(QStringLiteral("insert_table"));
- listAction << d->actionTable->listAction();
- listAction << d->actionTable;
- }
- d->actionDeleteLine = new QAction(i18n("Delete Line"), this);
- d->actionDeleteLine->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_K));
- d->actionDeleteLine->setObjectName(QStringLiteral("delete_line"));
- connect(d->actionDeleteLine, SIGNAL(triggered(bool)), SLOT(_k_slotDeleteLine()));
- listAction << d->actionDeleteLine;
-
- d->actionFormatReset =
- new QAction(QIcon::fromTheme(QStringLiteral("draw-eraser")), i18n("Reset Font Settings"), this);
- d->actionFormatReset->setIconText(i18n("Reset Font"));
- d->actionFormatReset->setObjectName(QStringLiteral("format_reset"));
- connect(d->actionFormatReset, SIGNAL(triggered(bool)), SLOT(_k_slotFormatReset()));
- listAction << d->actionFormatReset;
- return listAction;
-}
-
-void TextEdit::addImage(const QUrl &url, int width, int height)
-{
- addImageHelper(url, width, height);
-}
-
-void TextEdit::addImageHelper(const QUrl &url, int width, int height)
-{
- QImage image;
- if (!image.load(url.path())) {
- KMessageBox::error(
- this,
- xi18nc("@info",
- "Unable to load image <filename>%1</filename>.",
- url.path()));
- return;
- }
- QFileInfo fi(url.path());
- QString imageName =
- fi.baseName().isEmpty() ?
- QStringLiteral("image.png") :
- QString(fi.baseName() + QLatin1String(".png"));
- d->addImageHelper(imageName, image, width, height);
-}
-
-void TextEdit::loadImage(const QImage &image, const QString &matchName,
- const QString &resourceName)
-{
- QSet<int> cursorPositionsToSkip;
- QTextBlock currentBlock = document()->begin();
- QTextBlock::iterator it;
- while (currentBlock.isValid()) {
- for (it = currentBlock.begin(); !it.atEnd(); ++it) {
- QTextFragment fragment = it.fragment();
- if (fragment.isValid()) {
- QTextImageFormat imageFormat = fragment.charFormat().toImageFormat();
- if (imageFormat.isValid() && imageFormat.name() == matchName) {
- int pos = fragment.position();
- if (!cursorPositionsToSkip.contains(pos)) {
- QTextCursor cursor(document());
- cursor.setPosition(pos);
- cursor.setPosition(pos + 1, QTextCursor::KeepAnchor);
- cursor.removeSelectedText();
- document()->addResource(QTextDocument::ImageResource,
- QUrl(resourceName), QVariant(image));
- QTextImageFormat format;
- format.setName(resourceName);
- if ((imageFormat.width() != 0) && (imageFormat.height() != 0)) {
- format.setWidth(imageFormat.width());
- format.setHeight(imageFormat.height());
- }
- cursor.insertImage(format);
-
- // The textfragment iterator is now invalid, restart from the beginning
- // Take care not to replace the same fragment again, or we would be in
- // an infinite loop.
- cursorPositionsToSkip.insert(pos);
- it = currentBlock.begin();
- }
- }
- }
- }
- currentBlock = currentBlock.next();
- }
-}
-
-void TextEditPrivate::addImageHelper(const QString &imageName, const QImage &image,
- int width, int height)
-{
- QString imageNameToAdd = imageName;
- QTextDocument *document = q->document();
-
- // determine the imageNameToAdd
- int imageNumber = 1;
- while (mImageNames.contains(imageNameToAdd)) {
- QVariant qv = document->resource(QTextDocument::ImageResource, QUrl(imageNameToAdd));
- if (qv == image) {
- // use the same name
- break;
- }
- int firstDot = imageName.indexOf(QLatin1Char('.'));
- if (firstDot == -1) {
- imageNameToAdd = imageName + QString::number(imageNumber++);
- } else {
- imageNameToAdd = imageName.left(firstDot) + QString::number(imageNumber++) +
- imageName.mid(firstDot);
- }
- }
-
- if (!mImageNames.contains(imageNameToAdd)) {
- document->addResource(QTextDocument::ImageResource, QUrl(imageNameToAdd), image);
- mImageNames << imageNameToAdd;
- }
- if (width != -1 && height != -1) {
- QTextImageFormat format;
- format.setName(imageNameToAdd);
- format.setWidth(width);
- format.setHeight(height);
- q->textCursor().insertImage(format);
- } else {
- q->textCursor().insertImage(imageNameToAdd);
- }
- q->enableRichTextMode();
-}
-
-ImageWithNameList TextEdit::imagesWithName() const
-{
- ImageWithNameList retImages;
- QStringList seenImageNames;
- QList<QTextImageFormat> imageFormats = d->embeddedImageFormats();
- foreach (const QTextImageFormat &imageFormat, imageFormats) {
- if (!seenImageNames.contains(imageFormat.name())) {
- QVariant resourceData = document()->resource(QTextDocument::ImageResource,
- QUrl(imageFormat.name()));
- QImage image = qvariant_cast<QImage>(resourceData);
- QString name = imageFormat.name();
- ImageWithNamePtr newImage(new ImageWithName);
- newImage->image = image;
- newImage->name = name;
- retImages.append(newImage);
- seenImageNames.append(imageFormat.name());
- }
- }
- return retImages;
-}
-
-QList< QSharedPointer<EmbeddedImage> > TextEdit::embeddedImages() const
-{
- ImageWithNameList normalImages = imagesWithName();
- QList< QSharedPointer<EmbeddedImage> > retImages;
- retImages.reserve(normalImages.count());
- foreach (const ImageWithNamePtr &normalImage, normalImages) {
- QBuffer buffer;
- buffer.open(QIODevice::WriteOnly);
- normalImage->image.save(&buffer, "PNG");
-
- qsrand(QDateTime::currentDateTime().toTime_t() + qHash(normalImage->name));
- QSharedPointer<EmbeddedImage> embeddedImage(new EmbeddedImage());
- retImages.append(embeddedImage);
- embeddedImage->image = KCodecs::Codec::codecForName("base64")->encode(buffer.buffer());
- embeddedImage->imageName = normalImage->name;
- embeddedImage->contentID = QStringLiteral("%[email protected]").arg(qrand());
- }
- return retImages;
-}
-
-QList<QTextImageFormat> TextEditPrivate::embeddedImageFormats() const
-{
- QTextDocument *doc = q->document();
- QList<QTextImageFormat> retList;
-
- QTextBlock currentBlock = doc->begin();
- while (currentBlock.isValid()) {
- QTextBlock::iterator it;
- for (it = currentBlock.begin(); !it.atEnd(); ++it) {
- QTextFragment fragment = it.fragment();
- if (fragment.isValid()) {
- QTextImageFormat imageFormat = fragment.charFormat().toImageFormat();
- if (imageFormat.isValid()) {
- //TODO: Replace with a way to see if an image is an embedded image or a remote
- QUrl url(imageFormat.name());
- if (!url.isValid() || !url.scheme().startsWith(QLatin1String("http"))) {
- retList.append(imageFormat);
- }
- }
- }
- }
- currentBlock = currentBlock.next();
- }
- return retList;
-}
-
-void TextEditPrivate::_k_slotAddEmoticon(const QString &text)
-{
- QTextCursor cursor = q->textCursor();
- cursor.insertText(text);
-}
-
-void TextEditPrivate::_k_slotInsertHtml()
-{
- if (q->textMode() == KRichTextEdit::Rich) {
- QPointer<InsertHtmlDialog> dialog = new InsertHtmlDialog(q);
- if (dialog->exec()) {
- const QString str = dialog->html();
- if (!str.isEmpty()) {
- QTextCursor cursor = q->textCursor();
- cursor.insertHtml(str);
- }
- }
- delete dialog;
- }
-}
-
-void TextEditPrivate::_k_slotAddImage()
-{
- QPointer<InsertImageDialog> dlg = new InsertImageDialog(q);
- if (dlg->exec() == QDialog::Accepted && dlg) {
- const QUrl url = dlg->imageUrl();
- int imageWidth = -1;
- int imageHeight = -1;
- if (!dlg->keepOriginalSize()) {
- imageWidth = dlg->imageWidth();
- imageHeight = dlg->imageHeight();
- }
- q->addImage(url, imageWidth, imageHeight);
- }
- delete dlg;
-}
-
-void TextEditPrivate::_k_slotTextModeChanged(KRichTextEdit::Mode mode)
-{
- const bool richTextMode = (mode == KRichTextEdit::Rich);
- if (richTextMode) {
- saveFont = q->currentFont();
- }
- if (actionTable) {
- actionTable->setRichTextMode(richTextMode);
- }
-}
-
-void TextEditPrivate::_k_slotFormatReset()
-{
- q->setTextBackgroundColor(q->palette().highlightedText().color());
- q->setTextForegroundColor(q->palette().text().color());
- q->setFont(saveFont);
-
-}
-
-void KPIMTextEdit::TextEdit::enableImageActions()
-{
- d->imageSupportEnabled = true;
-}
-
-bool KPIMTextEdit::TextEdit::isEnableImageActions() const
-{
- return d->imageSupportEnabled;
-}
-
-void KPIMTextEdit::TextEdit::enableEmoticonActions()
-{
- d->emoticonSupportEnabled = true;
-}
-
-bool KPIMTextEdit::TextEdit::isEnableEmoticonActions() const
-{
- return d->emoticonSupportEnabled;
-}
-
-void KPIMTextEdit::TextEdit::enableInsertHtmlActions()
-{
- d->insertHtmlSupportEnabled = true;
-}
-
-bool KPIMTextEdit::TextEdit::isEnableInsertHtmlActions() const
-{
- return d->insertHtmlSupportEnabled;
-}
-
-bool KPIMTextEdit::TextEdit::isEnableInsertTableActions() const
-{
- return d->insertTableSupportEnabled;
-}
-
-void KPIMTextEdit::TextEdit::enableInsertTableActions()
-{
- d->insertTableSupportEnabled = true;
-}
-
-QByteArray KPIMTextEdit::TextEdit::imageNamesToContentIds(
- const QByteArray &htmlBody, const KPIMTextEdit::ImageList &imageList)
-{
- QByteArray result = htmlBody;
- if (!imageList.isEmpty()) {
- foreach (const QSharedPointer<EmbeddedImage> &image, imageList) {
- const QString newImageName = QLatin1String("cid:") + image->contentID;
- QByteArray quote("\"");
- result.replace(QByteArray(quote + image->imageName.toLocal8Bit() + quote),
- QByteArray(quote + newImageName.toLocal8Bit() + quote));
- }
- }
- return result;
-}
-
-void TextEdit::insertImage(const QImage &image, const QFileInfo &fileInfo)
-{
- QString imageName = fileInfo.baseName().isEmpty() ?
- i18nc("Start of the filename for an image", "image") :
- fileInfo.baseName();
- d->addImageHelper(imageName, image);
-}
-
-void TextEdit::insertFromMimeData(const QMimeData *source)
-{
- // Add an image if that is on the clipboard
- if (textMode() == KRichTextEdit::Rich && source->hasImage() && d->imageSupportEnabled) {
- QImage image = qvariant_cast<QImage>(source->imageData());
- QFileInfo fi;
- insertImage(image, fi);
- return;
- }
-
- // Attempt to paste HTML contents into the text edit in plain text mode,
- // prevent this and prevent plain text instead.
- if (textMode() == KRichTextEdit::Plain && source->hasHtml()) {
- if (source->hasText()) {
- insertPlainText(source->text());
- return;
- }
- }
-
- KRichTextWidget::insertFromMimeData(source);
-}
-
-bool KPIMTextEdit::TextEdit::canInsertFromMimeData(const QMimeData *source) const
-{
- if (source->hasHtml() && textMode() == KRichTextEdit::Rich) {
- return true;
- }
-
- if (source->hasText()) {
- return true;
- }
-
- if (textMode() == KRichTextEdit::Rich && source->hasImage() && d->imageSupportEnabled) {
- return true;
- }
-
- return KRichTextWidget::canInsertFromMimeData(source);
-}
-
-bool TextEdit::isFormattingUsed() const
-{
- if (textMode() == Plain) {
- return false;
- }
-
- return TextUtils::containsFormatting(document());
-}
-
-void TextEditPrivate::_k_slotDeleteLine()
-{
- if (q->hasFocus()) {
- q->deleteCurrentLine();
- }
-}
-
-void TextEdit::deleteCurrentLine()
-{
- QTextCursor cursor = textCursor();
- QTextBlock block = cursor.block();
- const QTextLayout *layout = block.layout();
-
- // The current text block can have several lines due to word wrapping.
- // Search the line the cursor is in, and then delete it.
- for (int lineNumber = 0; lineNumber < layout->lineCount(); lineNumber++) {
- QTextLine line = layout->lineAt(lineNumber);
- const bool lastLineInBlock = (line.textStart() + line.textLength() == block.length() - 1);
- const bool oneLineBlock = (layout->lineCount() == 1);
- const int startOfLine = block.position() + line.textStart();
- int endOfLine = block.position() + line.textStart() + line.textLength();
- if (!lastLineInBlock) {
- endOfLine -= 1;
- }
-
- // Found the line where the cursor is in
- if (cursor.position() >= startOfLine && cursor.position() <= endOfLine) {
- int deleteStart = startOfLine;
- int deleteLength = line.textLength();
- if (oneLineBlock) {
- deleteLength++; // The trailing newline
- }
-
- // When deleting the last line in the document,
- // remove the newline of the line before the last line instead
- if (deleteStart + deleteLength >= document()->characterCount() &&
- deleteStart > 0) {
- deleteStart--;
- }
-
- cursor.beginEditBlock();
- cursor.setPosition(deleteStart);
- cursor.movePosition(QTextCursor::NextCharacter, QTextCursor::KeepAnchor, deleteLength);
- cursor.removeSelectedText();
- cursor.endEditBlock();
- return;
- }
- }
-}
-
-#include "moc_textedit.cpp"
diff --git a/src/textedit.h b/src/textedit.h
deleted file mode 100644
index 86d0c78..0000000
--- a/src/textedit.h
+++ /dev/null
@@ -1,365 +0,0 @@
-/*
- Copyright (c) 2009 Thomas McGuire <[email protected]>
-
- Based on KMail and libkdepim code by:
- Copyright 2007 - 2010 Laurent Montel <[email protected]>
-
- This library is free software; you can redistribute it and/or modify it
- under the terms of the GNU Library General Public License as published by
- the Free Software Foundation; either version 2 of the License, or (at your
- option) any later version.
-
- This library is distributed in the hope that it will be useful, but WITHOUT
- ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
- License for more details.
-
- You should have received a copy of the GNU Library General Public License
- along with this library; see the file COPYING.LIB. If not, write to the
- Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- 02110-1301, USA.
-*/
-#ifndef KPIMTEXTEDIT_TEXTEDIT_H
-#define KPIMTEXTEDIT_TEXTEDIT_H
-
-#include "kpimtextedit_export.h"
-
-#include <KRichTextWidget>
-
-#include <QtCore/QSharedPointer>
-
-#include <memory>
-
-class QUrl;
-class QFileInfo;
-
-namespace KPIMTextEdit
-{
-
-class TextEditPrivate;
-class EMailQuoteHighlighter;
-
-/**
- * Holds information about an embedded HTML image that will be useful for mail clients.
- * A list with all images can be retrieved with TextEdit::embeddedImages().
- */
-struct EmbeddedImage {
- QByteArray image; ///< The image, encoded as PNG with base64 encoding
- QString contentID; ///< The content id of the embedded image
- QString imageName; ///< Name of the image as it is available as a resource in the editor
-};
-
-/**
- * Holds information about an embedded HTML image that will be generally useful.
- * A list with all images can be retrieved with TextEdit::imagesWithName().
- *
- * @since 4.4
- */
-struct ImageWithName {
- QImage image; ///< The image
- QString name; ///< The name of the image as it is available as a resource in the editor
-};
-
-typedef QSharedPointer<ImageWithName> ImageWithNamePtr;
-typedef QList< ImageWithNamePtr > ImageWithNameList;
-typedef QList< QSharedPointer<EmbeddedImage> > ImageList;
-
-/**
- * Special textedit that provides additional features which are useful for PIM applications
- * like mail clients.
- * Additional features this class provides:
- * - Highlighting quoted text
- * - Handling of inline images
- * - Auto-Hiding the cursor
- * - Handling of pastes and drops of images
- *
- * @since 4.3
- */
-class KPIMTEXTEDIT_EXPORT TextEdit : public KRichTextWidget
-{
- Q_OBJECT
-
-public:
-
- /**
- * Constructs a TextEdit object
- * @param text the initial plain text of the text edit, interpreted as HTML
- * @param parent the parent widget
- */
- explicit TextEdit(const QString &text, QWidget *parent = Q_NULLPTR);
-
- /**
- * Constructs a TextEdit object
- * @param parent the parent widget
- * @param configFile the config file
- * @since 4.6
- */
- explicit TextEdit(QWidget *parent = Q_NULLPTR, const QString &configFile = QString());
-
- /**
- * Calling this allows createActions() to create the add image actions.
- * Call this method before calling createActions(), otherwise the action
- * will not be added.
- * Also, if image actions is enabled, the user can paste PNG images.
- *
- * Don't call this if you don't want to support adding images.
- */
- void enableImageActions();
- /**
- * Calling this allows createActions() to create the add emoticons actions.
- * Call this method before calling createActions(), otherwise the action
- * will not be added.
- * Don't call this if you don't want to support emoticons actions.
- */
- void enableEmoticonActions();
-
- void enableInsertHtmlActions();
-
- void enableInsertTableActions();
- /**
- * Destructor
- */
- ~TextEdit();
-
- /**
- * Reimplemented from KMEditor, to support more actions.
- *
- * @param actionCollection the collection to put the new actions into
- * The additional action XML names are:
- * - add_image
- * - delete_line
- *
- * The add_image actions is only added if enableImageActions() is called before.
- */
- QList<QAction *> createActions() Q_DECL_OVERRIDE;
-
- /**
- * Adds an image. The image is loaded from file and then pasted to the current
- * cursor position with the given @p width and @p height.
- *
- * @param url The URL of the file which contains the image
- * @param width The width the inserted image will have.
- * @param height The height the inserted image will have.
- *
- * @since 4.10
- */
- void addImage(const QUrl &url, int width = -1, int height = -1);
-
- /**
- * Loads an image into the textedit. The difference to addImage() is that this
- * function expects that the image tag is already present in the HTML source.
- *
- * @param image the image to load
- * @param matchName the name of tags to match image
- * @param resourceName the resource name of image
- * So what this message does is that it scans the HTML source for the image
- * tag that matches the @p matchName, and then inserts the @p image as a
- * resource, giving that resource the name @p resourceName.
- *
- * @since 4.4
- */
- void loadImage(const QImage &image, const QString &matchName, const QString &resourceName);
-
- /**
- * Deletes the line at the current cursor position.
- * @since 4.4
- */
- void deleteCurrentLine();
-
- /**
- * Get a list with all embedded HTML images.
- * If the same image is contained twice or more in the editor, it will have only
- * one entry in this list.
- *
- * @return a list of embedded HTML images of the editor.
- */
- ImageList embeddedImages() const;
-
- /**
- * Same as embeddedImages(), only that this returns a list of general purpose information,
- * whereas the embeddedImages() function returns a list with mail-specific information.
- *
- * @since 4.4
- */
- ImageWithNameList imagesWithName() const;
-
- /**
- * Returns the text of the editor as plain text, with linebreaks inserted
- * where word-wrapping occurred.
- */
- QString toWrappedPlainText() const;
-
- /**
- * @since 5.0
- */
- QString toWrappedPlainText(QTextDocument *document) const;
-
- /**
- * Same as toPlainText() from QTextEdit, only that it removes embedded
- * images and converts non-breaking space characters to normal spaces.
- * @since 4.10
- */
- QString toCleanPlainText(const QString &plainText = QString()) const;
-
- /**
- * This method is called after the highlighter is created.
- * If you use custom colors for highlighting, override this method and
- * set the colors to the highlighter in it.
- *
- * The default implementation does nothing, therefore the default colors of
- * the EMailQuoteHighlighter class will be used.
- *
- * @param highlighter the highlighter that was just created. You need to
- * set the colors of this highlighter.
- */
- virtual void setHighlighterColors(EMailQuoteHighlighter *highlighter);
-
- /**
- * Convenience method for qouteLength( line ) > 0
- */
- bool isLineQuoted(const QString &line) const;
-
- /**
- * This is called whenever the editor needs to find out the length of the quote,
- * i.e. the length of the quote prefix before the real text starts.
- * The default implementation counts the number of spaces, '>' and '|' chars in
- * front of the line.
- *
- * @param line the line of which the length of the quote prefix should be returned
- * @return 0 if the line is not quoted, the length of the quote prefix otherwise
- * FIXME: Not yet used in all places, e.g. keypressEvent() or the quote highlighter
- */
- virtual int quoteLength(const QString &line) const;
-
- /**
- * Returns the prefix that is added to a line that is quoted.
- * By default, this is "> ".
- */
- virtual const QString defaultQuoteSign() const;
-
- /**
- * For all given embedded images, this function replace the image name
- * in the <img> tag of the HTML body with cid:content-id, so that the
- * HTML references the image body parts, see RFC 2557.
- *
- * This is useful when building a MIME message with inline images.
- *
- * Note that this function works on encoded content already.
- *
- * @param htmlBody the HTML code in which the <img> tag will be modified.
- * The HTML code here could come from toHtml(), for example.
- *
- * @param imageList the list of images of which the <img> tag will be modified.
- * You can get such a list from the embeddedImages() function.
- *
- * @return a modified HTML code, where the <img> tags got replaced
- */
- static QByteArray imageNamesToContentIds(const QByteArray &htmlBody,
- const ImageList &imageList);
-
- /**
- * Checks if rich text formatting is used anywhere.
- * This is not the same as checking whether textMode() returns "Rich",
- * since that only tells that rich text mode is enabled, but not if any
- * special formatting is actually used.
- *
- * @return true if formatting is used anywhere
- */
- bool isFormattingUsed() const;
-
- /**
- * Return config file.
- * @since 4.5
- */
- QString configFile() const;
-
- /** Return true if richtext mode support image
- * @since 4.6
- */
- bool isEnableImageActions() const;
-
- /** Return true if emoticons actions supported
- * @since 4.9
- */
- bool isEnableEmoticonActions() const;
-
- /**
- * @param image the image to insert
- * @param info the info to supply with image
- * @since 4.6
- */
- void insertImage(const QImage &image, const QFileInfo &info);
-
- /**
- * @since 4.10
- */
- bool isEnableInsertHtmlActions() const;
-
- /**
- * @since 4.10
- */
- bool isEnableInsertTableActions() const;
- // For the explaination for these four methods, see the comment at the
- // spellCheckingEnabled variable of the private class.
-
- /**
- * Reimplemented from KTextEdit
- */
- bool checkSpellingEnabled() const Q_DECL_OVERRIDE;
-
- /**
- * Reimplemented from KTextEdit
- */
- void setCheckSpellingEnabled(bool check) Q_DECL_OVERRIDE;
-
-protected:
-
- /**
- * Reimplemented for inline image support
- */
- bool canInsertFromMimeData(const QMimeData *source) const Q_DECL_OVERRIDE;
-
- /**
- * Reimplemented for inline image support
- */
- void insertFromMimeData(const QMimeData *source) Q_DECL_OVERRIDE;
-
- /**
- * Reimplemented from KRichTextWidget to hide the mouse cursor when there
- * was no mouse movement for some time, using KCursor
- */
- bool eventFilter(QObject *o, QEvent *e) Q_DECL_OVERRIDE;
-
- /**
- * Reimplemented to add qoute signs when the user presses enter
- * on a quoted line.
- */
- void keyPressEvent(QKeyEvent *e) Q_DECL_OVERRIDE;
-
- /**
- * Reimplemented from KTextEdit, to avoid spellchecking
- * quoted text.
- */
- bool shouldBlockBeSpellChecked(const QString &block) const Q_DECL_OVERRIDE;
-
- /**
- * Reimplemented to create our own highlighter which does quote and
- * spellcheck highlighting
- */
- void createHighlighter() Q_DECL_OVERRIDE;
-
-private:
- void addImageHelper(const QUrl &url, int width = -1, int height = -1);
- std::unique_ptr<TextEditPrivate> const d;
- friend class TextEditPrivate;
- Q_PRIVATE_SLOT(d, void _k_slotAddImage())
- Q_PRIVATE_SLOT(d, void _k_slotDeleteLine())
- Q_PRIVATE_SLOT(d, void _k_slotAddEmoticon(const QString &))
- Q_PRIVATE_SLOT(d, void _k_slotInsertHtml())
- Q_PRIVATE_SLOT(d, void _k_slotFormatReset())
- Q_PRIVATE_SLOT(d, void _k_slotTextModeChanged(KRichTextEdit::Mode))
-};
-
-} // namespace
-
-#endif
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 441e410..e418d2f 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -1,6 +1,6 @@
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../src ${CMAKE_CURRENT_BINARY_DIR}/../src)
-add_executable(textedit_demo textedit_demo.cpp)
-target_link_libraries(textedit_demo KF5PimTextEdit)
+#add_executable(textedit_demo textedit_demo.cpp)
+#target_link_libraries(textedit_demo KF5PimTextEdit)
add_executable(inserthtmldialog_demo inserthtmldialog_demo.cpp)