Commit 08d85959 authored by Laurent Montel's avatar Laurent Montel 😁

Merge remote-tracking branch 'origin/Applications/17.04'

parents f7afde8b f9762412
......@@ -96,17 +96,6 @@ void RichTextComposerControlerTest::shouldHaveDefaultValue()
QVERIFY(!controler.richTextComposer()->acceptRichText());
}
void RichTextComposerControlerTest::shouldAddQuote()
{
#if 0
KPIMTextEdit::RichTextComposer composer;
KActionCollection *actionCollection = new KActionCollection(&composer);
composer.createActions(actionCollection);
KPIMTextEdit::RichTextComposerControler controler(&composer);
controler.alignLeft();
#endif
}
void RichTextComposerControlerTest::shouldBoldText()
{
......@@ -237,6 +226,12 @@ void RichTextComposerControlerTest::shouldRemoveQuote_data()
//Bug David, new line with quote
QTest::newRow("removequotewithnewline") << QStringLiteral(">foo\n>\n>bla\n>blo\n") << QStringLiteral("foo\n\nbla\nblo\n");
QTest::newRow("removequote2") << QStringLiteral(">foo\n\nbla\n>blo\nbli") << QStringLiteral("foo\n\nbla\nblo\nbli");
QTest::newRow("twoquotes") << QStringLiteral(">>foo\n\nbla\n>blo\nbli") << QStringLiteral(">foo\n\nbla\nblo\nbli");
QTest::newRow("quoteintext") << QStringLiteral("foo>>\n\nbla\n>blo\nbli") << QStringLiteral("foo>>\n\nbla\nblo\nbli");
QTest::newRow("emptyline") << QStringLiteral("foo>>\n\n\nbla\n>blo\nbli") << QStringLiteral("foo>>\n\n\nbla\nblo\nbli");
}
void RichTextComposerControlerTest::shouldRemoveQuote()
......@@ -255,5 +250,66 @@ void RichTextComposerControlerTest::shouldRemoveQuote()
QCOMPARE(composer.toPlainText(), output);
}
void RichTextComposerControlerTest::shouldRemoveQuoteWithSpecificQuote_data()
{
QTest::addColumn<QString>("input");
QTest::addColumn<QString>("output");
QTest::addColumn<QString>("quote");
QTest::newRow("empty") << QString() << QString() << QString();
QTest::newRow("empty1") << QString() << QString() << QStringLiteral("QT");
QTest::newRow("removequote1") << QStringLiteral(">foo\n>bla\n>blo\n") << QStringLiteral(">foo\n>bla\n>blo\n") << QStringLiteral("QT");
QTest::newRow("removequote2") << QStringLiteral("QTfoo\nQTbla\n>blo\n") << QStringLiteral("foo\nbla\n>blo\n") << QStringLiteral("QT");
QTest::newRow("removequote3") << QStringLiteral("|foo\n|bla\n>blo\n") << QStringLiteral("foo\nbla\n>blo\n") << QStringLiteral("|");
}
void RichTextComposerControlerTest::shouldRemoveQuoteWithSpecificQuote()
{
QFETCH(QString, input);
QFETCH(QString, output);
QFETCH(QString, quote);
KPIMTextEdit::RichTextComposer composer;
composer.setQuotePrefixName(quote);
KActionCollection *actionCollection = new KActionCollection(&composer);
composer.createActions(actionCollection);
KPIMTextEdit::RichTextComposerControler controler(&composer);
composer.show();
QTest::qWaitForWindowExposed(&composer);
composer.setPlainText(input);
controler.slotRemoveQuotes();
QCOMPARE(composer.toPlainText(), output);
}
void RichTextComposerControlerTest::shouldAddQuote_data()
{
// QTest::addColumn<QString>("input");
// QTest::addColumn<QString>("output");
// QTest::addColumn<QString>("quote");
// QTest::newRow("empty") << QString() << QString() << QString();
// QTest::newRow("empty1") << QString() << QString() << QStringLiteral("QT");
// QTest::newRow("removequote1") << QStringLiteral(">foo\n>bla\n>blo\n") << QStringLiteral("QT>foo\nQT>bla\nQT>blo\n") << QStringLiteral("QT");
// QTest::newRow("removequote2") << QStringLiteral("QTfoo\nQTbla\n>blo\n") << QStringLiteral("QTQTfoo\nQTQTbla\n>QTblo\n") << QStringLiteral("QT");
// QTest::newRow("removequote3") << QStringLiteral("|foo\n|bla\n>blo\n") << QStringLiteral("||foo\n||bla\n|>blo\n") << QStringLiteral("|");
}
void RichTextComposerControlerTest::shouldAddQuote()
{
// QFETCH(QString, input);
// QFETCH(QString, output);
// QFETCH(QString, quote);
// KPIMTextEdit::RichTextComposer composer;
// composer.setQuotePrefixName(quote);
// KActionCollection *actionCollection = new KActionCollection(&composer);
// composer.createActions(actionCollection);
// KPIMTextEdit::RichTextComposerControler controler(&composer);
// composer.show();
// QTest::qWaitForWindowExposed(&composer);
// composer.setPlainText(input);
// controler.slotAddQuotes();
// QCOMPARE(composer.toPlainText(), QString(output + QChar::ParagraphSeparator));
}
QTEST_MAIN(RichTextComposerControlerTest)
......@@ -35,7 +35,6 @@ private Q_SLOTS:
void shouldAlignRight();
void shouldAlignJustify();
void shouldHaveDefaultValue();
void shouldAddQuote();
void shouldBoldText();
void shouldItalicText();
void shouldTextUnderline();
......@@ -49,6 +48,12 @@ private Q_SLOTS:
void shouldRemoveQuote_data();
void shouldRemoveQuote();
void shouldRemoveQuoteWithSpecificQuote_data();
void shouldRemoveQuoteWithSpecificQuote();
void shouldAddQuote_data();
void shouldAddQuote();
};
#endif // RICHTEXTCOMPOSERCONTROLERTEST_H
......@@ -461,6 +461,7 @@ int RichTextComposer::quoteLength(const QString &line) const
for (int i = 0; i < lineLength; ++i) {
if (line[i] == QLatin1Char('>') || line[i] == QLatin1Char('|')) {
quoteFound = true;
break;
} else if (line[i] != QLatin1Char(' ')) {
startOfText = i;
break;
......
......@@ -827,7 +827,7 @@ void RichTextComposerControler::slotRemoveQuotes()
int selectionEnd = cursor.selectionEnd();
while (block.isValid() && block.position() <= selectionEnd) {
cursor.setPosition(block.position());
int length = richTextComposer()->isLineQuoted(block.text());
int length = richTextComposer()->quoteLength(block.text());
if (length > 0) {
cursor.movePosition(QTextCursor::NextCharacter, QTextCursor::KeepAnchor, length);
cursor.removeSelectedText();
......
......@@ -19,6 +19,7 @@
#include "richtextcomposeremailquotehighlighter.h"
#include "richtextcomposer.h"
#include <QRegularExpression>
using namespace KPIMTextEdit;
class Q_DECL_HIDDEN KPIMTextEdit::RichTextComposerEmailQuoteHighlighter::RichTextComposerEmailQuoteHighlighterPrivate
......@@ -77,7 +78,7 @@ void RichTextComposerEmailQuoteHighlighter::toggleSpellHighlighting(bool on)
void RichTextComposerEmailQuoteHighlighter::highlightBlock(const QString &text)
{
QString simplified = text;
simplified = simplified.remove(QRegExp(QLatin1String("\\s"))).
simplified = simplified.remove(QRegularExpression(QStringLiteral("\\s"))).
replace(QLatin1Char('|'), QLatin1Char('>'));
while (simplified.startsWith(QStringLiteral(">>>>"))) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment