diff --git a/kmail/editorconvertertextplugins/markdown/autotests/markdowncreateimagewidgettest.cpp b/kmail/editorconvertertextplugins/markdown/autotests/markdowncreateimagewidgettest.cpp index b130e51e..a181eb0f 100644 --- a/kmail/editorconvertertextplugins/markdown/autotests/markdowncreateimagewidgettest.cpp +++ b/kmail/editorconvertertextplugins/markdown/autotests/markdowncreateimagewidgettest.cpp @@ -1,59 +1,67 @@ /* Copyright (C) 2019 Laurent Montel 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 "markdowncreateimagewidgettest.h" #include "markdowncreateimagewidget.h" #include "kdepimtest_layout.h" #include #include #include QTEST_MAIN(MarkdownCreateImageWidgetTest) MarkdownCreateImageWidgetTest::MarkdownCreateImageWidgetTest(QObject *parent) : QObject(parent) { } void MarkdownCreateImageWidgetTest::shouldHaveDefaultValue() { MarkdownCreateImageWidget w; QFormLayout *mainLayout = w.findChild(QStringLiteral("mainlayout")); QVERIFY(mainLayout); KdepimTestLayout::checkContentsMargins(0, mainLayout); mainLayout->setContentsMargins(0, 0, 0, 0); QLineEdit *mTitle = w.findChild(QStringLiteral("title")); QVERIFY(mTitle); QVERIFY(mTitle->text().isEmpty()); QLineEdit *mLink = w.findChild(QStringLiteral("image")); QVERIFY(mLink); QVERIFY(mLink->text().isEmpty()); + + QLineEdit *mAlternateText = w.findChild(QStringLiteral("alternatetext")); + QVERIFY(mAlternateText); + QVERIFY(mAlternateText->text().isEmpty()); } void MarkdownCreateImageWidgetTest::shouldGenerateLink() { MarkdownCreateImageWidget w; QLineEdit *mTitle = w.findChild(QStringLiteral("title")); QLineEdit *mLink = w.findChild(QStringLiteral("image")); + QLineEdit *mAlternateText = w.findChild(QStringLiteral("alternatetext")); mLink->setText(QStringLiteral("http://www.kde.org")); mTitle->setText(QStringLiteral("TITLE")); QCOMPARE(w.linkStr(), QStringLiteral("![TITLE](http://www.kde.org)")); + + mAlternateText->setText(QStringLiteral("alternate")); + QCOMPARE(w.linkStr(), QStringLiteral("![TITLE](http://www.kde.org \"alternate\")")); } diff --git a/kmail/editorconvertertextplugins/markdown/markdowncreateimagewidget.cpp b/kmail/editorconvertertextplugins/markdown/markdowncreateimagewidget.cpp index c68458e6..6cf5b7fc 100644 --- a/kmail/editorconvertertextplugins/markdown/markdowncreateimagewidget.cpp +++ b/kmail/editorconvertertextplugins/markdown/markdowncreateimagewidget.cpp @@ -1,52 +1,61 @@ /* Copyright (C) 2019 Laurent Montel 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 "markdowncreateimagewidget.h" #include #include #include #include MarkdownCreateImageWidget::MarkdownCreateImageWidget(QWidget *parent) : QWidget(parent) { QFormLayout *mainLayout = new QFormLayout(this); mainLayout->setObjectName(QStringLiteral("mainlayout")); mainLayout->setContentsMargins(0, 0, 0, 0); mTitle = new QLineEdit(this); mTitle->setObjectName(QStringLiteral("title")); mImageUrl = new QLineEdit(this); mImageUrl->setObjectName(QStringLiteral("image")); + mAlternateText = new QLineEdit(this); + mAlternateText->setObjectName(QStringLiteral("alternatetext")); + + mainLayout->addRow(i18n("Title:"), mTitle); mainLayout->addRow(i18n("Image Link:"), mImageUrl); + mainLayout->addRow(i18n("Alternate text:"), mAlternateText); } MarkdownCreateImageWidget::~MarkdownCreateImageWidget() { } QString MarkdownCreateImageWidget::linkStr() const { - if (mTitle->text().isEmpty() && mImageUrl->text().isEmpty()) { + if (mTitle->text().trimmed().isEmpty() && mImageUrl->text().trimmed().isEmpty()) { return {}; } - return QStringLiteral("![%1](%2)").arg(mTitle->text(), mImageUrl->text()); + if (!mAlternateText->text().trimmed().isEmpty()) { + return QStringLiteral("![%1](%2 \"%3\")").arg(mTitle->text(), mImageUrl->text(), mAlternateText->text()); + } else { + return QStringLiteral("![%1](%2)").arg(mTitle->text(), mImageUrl->text()); + } } diff --git a/kmail/editorconvertertextplugins/markdown/markdowncreateimagewidget.h b/kmail/editorconvertertextplugins/markdown/markdowncreateimagewidget.h index e5f7e9a2..14e72b72 100644 --- a/kmail/editorconvertertextplugins/markdown/markdowncreateimagewidget.h +++ b/kmail/editorconvertertextplugins/markdown/markdowncreateimagewidget.h @@ -1,38 +1,39 @@ /* Copyright (C) 2019 Laurent Montel 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 MARKDOWNCREATEIMAGEWIDGET_H #define MARKDOWNCREATEIMAGEWIDGET_H #include class QLineEdit; class MarkdownCreateImageWidget : public QWidget { Q_OBJECT public: explicit MarkdownCreateImageWidget(QWidget *parent = nullptr); ~MarkdownCreateImageWidget(); QString linkStr() const; private: QLineEdit *mTitle = nullptr; QLineEdit *mImageUrl = nullptr; + QLineEdit *mAlternateText = nullptr; }; #endif // MARKDOWNCREATEIMAGEWIDGET_H