Commit c6abf2c0 authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Move composer-ng here to replace old texteditor and remove duplicate code

parent 394fd87b
......@@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12)
project(KPimTextEdit)
# ECM setup
find_package(ECM 5.12.0 CONFIG REQUIRED)
find_package(ECM 5.16.0 CONFIG REQUIRED)
set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH})
include(GenerateExportHeader)
......@@ -15,10 +15,10 @@ include(FeatureSummary)
include(KDEInstallDirs)
include(KDECMakeSettings)
include(KDEFrameworkCompilerSettings)
include(ECMAddTests)
set(KF5_VERSION "5.12.0")
set(KPIMTEXTEDIT_LIB_VERSION "4.84.0")
set(KF5_VERSION "5.16.0")
set(KPIMTEXTEDIT_LIB_VERSION "4.85.0")
ecm_setup_version(${KPIMTEXTEDIT_LIB_VERSION} VARIABLE_PREFIX KPIMTEXTEDIT
VERSION_HEADER "${CMAKE_CURRENT_BINARY_DIR}/kpimtextedit_version.h"
......@@ -26,6 +26,10 @@ ecm_setup_version(${KPIMTEXTEDIT_LIB_VERSION} VARIABLE_PREFIX KPIMTEXTEDIT
SOVERSION 5
)
set(QT_REQUIRED_VERSION "5.2.0")
find_package(Qt5 ${QT_REQUIRED_VERSION} CONFIG REQUIRED COMPONENTS Test Widgets DBus)
find_package(Grantlee5 "5.0" CONFIG REQUIRED)
########### Find packages ###########
find_package(KF5CoreAddons ${KF5_VERSION} CONFIG REQUIRED)
find_package(KF5Emoticons ${KF5_VERSION} CONFIG REQUIRED)
......@@ -35,10 +39,28 @@ find_package(KF5WidgetsAddons ${KF5_VERSION} CONFIG REQUIRED)
find_package(KF5KIO ${KF5_VERSION} CONFIG REQUIRED)
find_package(KF5Codecs ${KF5_VERSION} CONFIG REQUIRED)
find_package(KF5IconThemes ${KF5_VERSION} CONFIG REQUIRED)
find_package(KF5ConfigWidgets ${KF5_VERSION} CONFIG REQUIRED)
find_package(KF5IconThemes ${KF5_VERSION} CONFIG REQUIRED)
find_package(KF5XmlGui ${KF5_VERSION} CONFIG REQUIRED)
add_definitions(-DTRANSLATION_DOMAIN=\"libkpimtextedit\")
add_definitions("-DQT_NO_CAST_FROM_ASCII -DQT_NO_CAST_TO_ASCII")
option(KPIMTEXTEDIT_NO_TEXTTOSPEECH "Do not use TextToSpeech in the kdepim applications" FALSE)
if (NOT KPIMTEXTEDIT_NO_TEXTTOSPEECH)
find_package(Qt5 OPTIONAL_COMPONENTS TextToSpeech)
endif()
if (KPIMTEXTEDIT_NO_TEXTTOSPEECH)
set(KPIMTEXTEDIT_HAVE_TEXTTOSPEECH FALSE)
else()
if (${Qt5TextToSpeech_FOUND})
set(KPIMTEXTEDIT_HAVE_TEXTTOSPEECH TRUE)
endif()
endif()
########### Targets ###########
add_subdirectory(src)
......
......@@ -4,3 +4,8 @@ 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_test(slidecontainertest.cpp
# TEST_NAME slidecontainertest
# NAME_PREFIX pimcommon-widget
# LINK_LIBRARIES Qt5::Test Qt5::Gui KF5::PimCommon
# )
/*
Gwenview: an image viewer
Copyright 2011 Aurélien Gâteau <agateau@kde.org>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Cambridge, MA 02110-1301, USA.
*/
// Self
#include "slidecontainertest.h"
// Local
#include "kpimtextedit/slidecontainer.h"
#include <qtest.h>
#include <QTextEdit>
#include <QVBoxLayout>
#include <QSignalSpy>
using namespace PimCommon;
struct TestWindow : public QWidget {
explicit TestWindow(QWidget *parent = Q_NULLPTR)
: QWidget(parent)
, mContainer(new SlideContainer)
, mContent(Q_NULLPTR)
{
createContent();
mMainWidget = new QTextEdit();
QVBoxLayout *layout = new QVBoxLayout(this);
layout->setSpacing(0);
layout->setMargin(0);
layout->addWidget(mMainWidget);
layout->addWidget(mContainer);
}
void createContent()
{
mContent = new QTextEdit;
mContent->setFixedSize(100, 40);
mContainer->setContent(mContent);
}
SlideContainer *mContainer;
QWidget *mMainWidget;
QWidget *mContent;
};
void SlideContainerAutoTest::testInit()
{
// Even with content, a SlideContainer should be invisible until slideIn()
// is called
TestWindow window;
window.show();
QTest::qWait(500);
QCOMPARE(window.mMainWidget->height(), window.height());
}
void SlideContainerAutoTest::testSlideIn()
{
TestWindow window;
QSignalSpy inSpy(window.mContainer, SIGNAL(slidedIn()));
QSignalSpy outSpy(window.mContainer, SIGNAL(slidedOut()));
window.show();
window.mContainer->slideIn();
while (window.mContainer->slideHeight() != window.mContent->height()) {
QTest::qWait(100);
}
QCOMPARE(window.mContainer->height(), window.mContent->height());
QCOMPARE(inSpy.count(), 1);
QCOMPARE(outSpy.count(), 0);
}
void SlideContainerAutoTest::testSlideOut()
{
TestWindow window;
window.show();
window.mContainer->slideIn();
while (window.mContainer->slideHeight() != window.mContent->height()) {
QTest::qWait(100);
}
QSignalSpy inSpy(window.mContainer, SIGNAL(slidedIn()));
QSignalSpy outSpy(window.mContainer, SIGNAL(slidedOut()));
window.mContainer->slideOut();
while (window.mContainer->slideHeight() != 0) {
QTest::qWait(100);
}
QCOMPARE(window.mContainer->height(), 0);
QCOMPARE(inSpy.count(), 0);
QCOMPARE(outSpy.count(), 1);
}
void SlideContainerAutoTest::testSlideInDeleteSlideOut()
{
// If content is deleted while visible, slideOut() should still produce an
// animation
TestWindow window;
window.show();
window.mContainer->slideIn();
while (window.mContainer->slideHeight() != window.mContent->height()) {
QTest::qWait(100);
}
window.mContent->deleteLater();
window.mContainer->slideOut();
while (window.mContainer->slideHeight() != 0) {
QTest::qWait(100);
}
QCOMPARE(window.mContainer->height(), 0);
}
void SlideContainerAutoTest::testHiddenContentResize()
{
// Resizing content should not trigger a slide if it is not visible.
TestWindow window;
window.show();
QTest::qWaitForWindowExposed(&window);
window.mContent->show();
window.mContent->setFixedSize(150, 80);
QTest::qWait(500);
QCOMPARE(window.mContainer->height(), 0);
}
QTEST_MAIN(SlideContainerAutoTest)
/*
Gwenview: an image viewer
Copyright 2011 Aurélien Gâteau <agateau@kde.org>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Cambridge, MA 02110-1301, USA.
*/
#ifndef SLIDECONTAINERAUTOTEST_H
#define SLIDECONTAINERAUTOTEST_H
// Local
// KDE
// Qt
#include <QObject>
class SlideContainerAutoTest : public QObject
{
Q_OBJECT
private Q_SLOTS:
void testInit();
void testSlideIn();
void testSlideOut();
void testSlideInDeleteSlideOut();
void testHiddenContentResize();
};
#endif /* SLIDECONTAINERAUTOTEST_H */
add_definitions(-DQT_DISABLE_DEPRECATED_BEFORE=0)
configure_file(config-kpimtextedit.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config-kpimtextedit.h )
set(kpimtextedit_texteditor_SRCS
texteditor/plaintexteditor/plaintexteditfindbar.cpp
texteditor/plaintexteditor/plaintexteditor.cpp
texteditor/plaintexteditor/plaintexteditorwidget.cpp
texteditor/plaintexteditor/plaintextsyntaxspellcheckinghighlighter.cpp
texteditor/commonwidget/textfindreplacewidget.cpp
texteditor/commonwidget/texteditfindbarbase.cpp
texteditor/commonwidget/textgotolinewidget.cpp
texteditor/commonwidget/textmessageindicator.cpp
texteditor/richtexteditor/richtexteditor.cpp
texteditor/richtexteditor/richtexteditfindbar.cpp
texteditor/richtexteditor/richtexteditorwidget.cpp
)
# set(kpimtextedit_composerng_SRCS
# composer-ng/richtextcomposer.cpp
# composer-ng/richtextcomposercontroler.cpp
# composer-ng/richtextcomposeractions.cpp
# composer-ng/klinkdialog.cpp
# composer-ng/nestedlisthelper.cpp
# composer-ng/richtextexternalcomposer.cpp
# composer-ng/richtextcomposerimages.cpp
# composer-ng/richtextcomposeremailquotedecorator.cpp
# composer-ng/richtextcomposeremailquotehighlighter.cpp
# )
set(kpimtextedit_texttospeech_SRCS
texttospeech/texttospeech.cpp
texttospeech/texttospeechwidget.cpp
texttospeech/texttospeechconfigwidget.cpp
texttospeech/texttospeechinterface.cpp
texttospeech/abstracttexttospeechinterface.cpp
texttospeech/abstracttexttospeechconfiginterface.cpp
texttospeech/texttospeechconfiginterface.cpp
texttospeech/texttospeechconfigdialog.cpp
texttospeech/texttospeechlanguagecombobox.cpp
texttospeech/texttospeechactions.cpp
)
set(kpimtextedit_SRCS
emailquotehighlighter.cpp
emoticontexteditaction.cpp
......@@ -17,15 +61,16 @@ set(kpimtextedit_SRCS
emailquotedecorator.cpp
syntaxhighlighterbase.cpp
texteditorcompleter.cpp
slidecontainer.cpp
)
add_library(KF5PimTextEdit ${kpimtextedit_SRCS})
add_library(KF5PimTextEdit ${kpimtextedit_SRCS} ${kpimtextedit_texteditor_SRCS} ${kpimtextedit_texttospeech_SRCS} )#${kpimtextedit_composerng_SRCS})
generate_export_header(KF5PimTextEdit BASE_NAME kpimtextedit)
add_library(KF5::PimTextEdit ALIAS KF5PimTextEdit)
target_include_directories(KF5PimTextEdit INTERFACE "$<INSTALL_INTERFACE:${KDE_INSTALL_INCLUDEDIR_KF5}/KPIMTextEdit>")
target_include_directories(KF5PimTextEdit INTERFACE "$<INSTALL_INTERFACE:${KDE_INSTALL_INCLUDEDIR_KF5}/KPIMTextEdit;>")
target_include_directories(KF5PimTextEdit PUBLIC "$<BUILD_INTERFACE:${KPimTextEdit_SOURCE_DIR}/src;${KPimTextEdit_BINARY_DIR}/src>")
......@@ -36,8 +81,14 @@ PRIVATE
KF5::Emoticons
KF5::Codecs
KF5::SonnetUi
KF5::SonnetCore
KF5::WidgetsAddons
KF5::KIOWidgets
KF5::ConfigWidgets
KF5::IconThemes
Qt5::DBus
Grantlee5::TextDocument
KF5::XmlGui
)
set_target_properties(KF5PimTextEdit PROPERTIES
......@@ -62,6 +113,7 @@ ecm_generate_headers(KPimTextEdit_CamelCase_HEADERS
InsertTableWidget
SelectSpecialCharDialog
SyntaxHighlighterBase
SlideContainer
TableCellFormatDialog
TableFormatDialog
TableActionMenu
......@@ -73,20 +125,100 @@ ecm_generate_headers(KPimTextEdit_CamelCase_HEADERS
REQUIRED_HEADERS kpimtextedit_HEADERS
)
ecm_generate_headers(PimCommon_CamelCasetextrichtexteditor_HEADERS
HEADER_NAMES
RichTextEditorWidget
RichTextEditor
REQUIRED_HEADERS PimCommon_richtexteditor_HEADERS
PREFIX KPIMTextEdit
RELATIVE texteditor/richtexteditor
)
ecm_generate_headers(PimCommon_CamelCaseplaintexteditor_HEADERS
HEADER_NAMES
PlainTextEditor
PlainTextEditorWidget
PlainTextEditFindBar
PlainTextSyntaxSpellCheckingHighlighter
REQUIRED_HEADERS PimCommon_plaintexteditor_HEADERS
PREFIX KPIMTextEdit
RELATIVE texteditor/plaintexteditor
)
ecm_generate_headers(PimCommon_CamelCasetexteditor_commonwidget_HEADERS
HEADER_NAMES
TextGotoLineWidget
TextEditFindBarBase
REQUIRED_HEADERS PimCommon_texteditor_commonwidget_HEADERS
PREFIX KPIMTextEdit
RELATIVE texteditor/commonwidget
)
ecm_generate_headers(KPimTextEdit_CamelCasetexttospeechs_HEADERS
HEADER_NAMES
TextToSpeech
TextToSpeechActions
TextToSpeechInterface
TextToSpeechWidget
AbstractTextToSpeechInterface
REQUIRED_HEADERS KPimTextEdit_texttospeechs_HEADERS
PREFIX KPIMTextEdit
RELATIVE texttospeech
)
# ecm_generate_headers(KPimTextEdit_Camelcasecomposerng_HEADERS
# HEADER_NAMES
# RichTextComposer
# RichTextComposerControler
# RichTextComposerImages
# RichTextExternalComposer
# RichTextComposerActions
# RichTextComposerEmailQuoteHighlighter
# REQUIRED_HEADERS KPimTextEdit_composerng_HEADERS
# PREFIX KPIMTextEdit
# RELATIVE composer-ng
# )
########### install files ###############
install(FILES
${CMAKE_CURRENT_BINARY_DIR}/kpimtextedit_export.h
${kpimtextedit_HEADERS}
${KPimTextEdit_texttospeechs_HEADERS}
${PimCommon_richtexteditor_HEADERS}
${PimCommon_texteditor_commonwidget_HEADERS}
${PimCommon_plaintexteditor_HEADERS}
# ${KPimTextEdit_composerng_HEADERS}
DESTINATION ${KDE_INSTALL_INCLUDEDIR_KF5}/KPIMTextEdit/kpimtextedit
COMPONENT Devel
)
install(FILES
${KPimTextEdit_CamelCase_HEADERS}
${PimCommon_CamelCasetextrichtexteditor_HEADERS}
${KPimTextEdit_CamelCasetexttospeechs_HEADERS}
${PimCommon_CamelCasetexteditor_commonwidget_HEADERS}
${PimCommon_CamelCasetexteditor_commonwidget_HEADERS}
# ${KPimTextEdit_Camelcasecomposerng_HEADERS}
DESTINATION ${KDE_INSTALL_INCLUDEDIR_KF5}/KPIMTextEdit/KPIMTextEdit/
COMPONENT Devel
)
ecm_generate_pri_file(BASE_NAME KPIMTextEdit LIB_NAME KF5PIMTextEdit DEPS "" FILENAME_VAR PRI_FILENAME INCLUDE_INSTALL_DIR ${KDE_INSTALL_INCLUDEDIR_KF5}/KPIMTextEdit/)
install(FILES ${PRI_FILENAME} DESTINATION ${ECM_MKSPECS_INSTALL_DIR})
if (BUILD_TESTING)
add_subdirectory(texteditor/plaintexteditor/autotests)
add_subdirectory(texteditor/richtexteditor/autotests)
add_subdirectory(texteditor/commonwidget/autotests)
add_subdirectory(texteditor/plaintexteditor/tests)
add_subdirectory(texteditor/richtexteditor/tests)
add_subdirectory(texttospeech/autotests)
add_subdirectory(texttospeech/tests)
# add_subdirectory(composer-ng/autotests)
# add_subdirectory(composer-ng/tests)
endif()
macro(add_composer_ng_test _source)
ecm_add_test(${_source}
NAME_PREFIX "kpimtextedit-composerng-"
LINK_LIBRARIES Qt5::Test KF5::PimTextEdit KF5::XmlGui
)
endmacro()
add_composer_ng_test(richtextcomposertest.cpp)
add_composer_ng_test(richtextcomposercontrolertest.cpp)
add_composer_ng_test(richtextcomposeractionstest.cpp)
add_composer_ng_test(richtextexternalcomposertest.cpp)
add_composer_ng_test(richtextcomposerimagestest.cpp)
/*
Copyright (c) 2015 Montel Laurent <montel@kde.org>
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
This program 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
General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "richtextcomposeractionstest.h"
#include "../richtextcomposercontroler.h"
#include "../richtextcomposeractions.h"
#include "../richtextcomposer.h"
#include <KActionCollection>
#include <QAction>
#include <qtest.h>
RichTextComposerActionsTest::RichTextComposerActionsTest(QObject *parent)
: QObject(parent)
{
}
RichTextComposerActionsTest::~RichTextComposerActionsTest()
{
}
void RichTextComposerActionsTest::shouldHaveDefaultValue()
{
KPIMTextEdit::RichTextComposer composer;
KPIMTextEdit::RichTextComposerControler controler(&composer);
KPIMTextEdit::RichTextComposerActions composerActions(&controler);
KActionCollection *actionCollection = new KActionCollection(&composerActions);
QVERIFY(actionCollection->actions().isEmpty());
composerActions.createActions(actionCollection);
QVERIFY(!actionCollection->actions().isEmpty());
QCOMPARE(composerActions.numberOfActions(), actionCollection->actions().count() - 4);
}
void RichTextComposerActionsTest::shouldHaveActions()
{
KPIMTextEdit::RichTextComposer composer;
KPIMTextEdit::RichTextComposerControler controler(&composer);
KPIMTextEdit::RichTextComposerActions composerActions(&controler);
KActionCollection *actionCollection = new KActionCollection(&composerActions);
composerActions.createActions(actionCollection);
QStringList lst;
lst << QStringLiteral("format_align_left")
<< QStringLiteral("format_align_center")
<< QStringLiteral("format_align_right")
<< QStringLiteral("format_align_justify")
<< QStringLiteral("direction_ltr")
<< QStringLiteral("direction_rtl")
<< QStringLiteral("format_text_subscript")
<< QStringLiteral("format_text_superscript")
<< QStringLiteral("format_text_bold")
<< QStringLiteral("format_text_italic")
<< QStringLiteral("format_text_underline")
<< QStringLiteral("format_text_strikeout")
<< QStringLiteral("format_font_family")
<< QStringLiteral("format_font_size")
<< QStringLiteral("insert_horizontal_rule")
<< QStringLiteral("format_text_foreground_color")
<< QStringLiteral("format_text_background_color")
<< QStringLiteral("manage_link")
<< QStringLiteral("format_list_indent_less")
<< QStringLiteral("format_list_indent_more")
<< QStringLiteral("format_list_style")
<< QStringLiteral("add_image")
<< QStringLiteral("add_emoticon")
<< QStringLiteral("insert_html")
<< QStringLiteral("insert_table")
<< QStringLiteral("delete_line")
<< QStringLiteral("format_reset")
<< QStringLiteral("format_painter");
QStringList actionNoRichText;
actionNoRichText << QStringLiteral("paste_quoted")
<< QStringLiteral("tools_quote")
<< QStringLiteral("tools_unquote")
<< QStringLiteral("paste_without_formatting");
QCOMPARE(lst.count(), composerActions.numberOfActions());
Q_FOREACH (QAction *act, actionCollection->actions()) {
const QString actionName = act->objectName();
if (!actionNoRichText.contains(actionName)) {
QVERIFY(lst.contains(actionName));
}
}
}
void RichTextComposerActionsTest::shouldChangeEnableState()
{
KPIMTextEdit::RichTextComposer composer;
KPIMTextEdit::RichTextComposerControler controler(&composer);
KPIMTextEdit::RichTextComposerActions composerActions(&controler);
KActionCollection *actionCollection = new KActionCollection(&composerActions);
composerActions.createActions(actionCollection);
QStringList actionNoRichText;
actionNoRichText << QStringLiteral("paste_quoted")
<< QStringLiteral("tools_quote")
<< QStringLiteral("tools_unquote")
<< QStringLiteral("paste_without_formatting");
composerActions.setActionsEnabled(false);
Q_FOREACH (QAction *act, actionCollection->actions()) {
if (!actionNoRichText.contains(act->objectName())) {
QVERIFY(!act->isEnabled());
}
}
composerActions.setActionsEnabled(true);
Q_FOREACH (QAction *act, actionCollection->actions()) {
if (!actionNoRichText.contains(act->objectName())) {
QVERIFY(act->isEnabled());
}
}
}
QTEST_MAIN(RichTextComposerActionsTest)
/*
Copyright (c) 2015 Montel Laurent <montel@kde.org>
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
This program 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
General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef RICHTEXTCOMPOSERACTIONSTEST_H
#define RICHTEXTCOMPOSERACTIONSTEST_H
#include <QObject>
class RichTextComposerActionsTest : public QObject
{
Q_OBJECT
public:
explicit RichTextComposerActionsTest(QObject *parent = Q_NULLPTR);