Commit 89403ebf authored by Laurent Montel's avatar Laurent Montel 😁

To avoid cyclic dependancy I move composereditorwebengine here as it used just by blogilo

If a day we decided to use in other we can create an own git repository
parent 3d661592
......@@ -105,7 +105,6 @@ set(LIBKSIEVE_LIB_VERSION_LIB "5.2.40")
if (QTWEBENGINE_SUPPORT_OPTION)
set(QT_REQUIRED_MINIMUM_WEBENGINE_VERSION "5.6")
find_package(Qt5 ${QT_REQUIRED_MINIMUM_WEBENGINE_VERSION} CONFIG REQUIRED WebEngine WebEngineWidgets)
find_package(KF5ComposerEditorWebEngine ${KDEPIM_APPS_LIB_VERSION_LIB} CONFIG REQUIRED)
set(WEBENGINE_TYPE "QtWebEngine")
else()
find_package(Qt5 ${QT_REQUIRED_VERSION} CONFIG REQUIRED WebKitWidgets)
......
......@@ -2,6 +2,10 @@ project(blogilo)
add_definitions( -DQT_NO_CAST_FROM_ASCII )
add_definitions( -DQT_NO_CAST_TO_ASCII )
if (QTWEBENGINE_SUPPORT_OPTION)
add_subdirectory(composereditorwebengine)
endif()
add_subdirectory( src )
add_subdirectory( icons )
add_subdirectory(kconf_update)
project(composereditorwebengine)
add_definitions("-DQT_NO_CAST_FROM_ASCII -DQT_NO_CAST_TO_ASCII")
add_subdirectory(src)
if (BUILD_TESTING)
add_subdirectory(tests)
add_subdirectory(autotests)
endif()
/*
Copyright (c) 2016 Montel Laurent <montel@kde.org>
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 "composerwebenginewidgettest.h"
#include "composerwebenginewidget.h"
#include <QTest>
ComposerWebEngineWidgetTest::ComposerWebEngineWidgetTest(QObject *parent)
: QObject(parent)
{
}
ComposerWebEngineWidgetTest::~ComposerWebEngineWidgetTest()
{
}
QTEST_MAIN(ComposerWebEngineWidgetTest)
/*
Copyright (c) 2016 Montel Laurent <montel@kde.org>
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 COMPOSERWEBENGINEWIDGETTEST_H
#define COMPOSERWEBENGINEWIDGETTEST_H
#include <QObject>
class ComposerWebEngineWidgetTest : public QObject
{
Q_OBJECT
public:
explicit ComposerWebEngineWidgetTest(QObject *parent = Q_NULLPTR);
~ComposerWebEngineWidgetTest();
};
#endif // COMPOSERWEBENGINEWIDGETTEST_H
add_definitions(-DTRANSLATION_DOMAIN=\"libcomposereditorwebengine\")
set(libcomposereditor_webengine_SRCS
composerwebengine.cpp
private/composerwebengine_p.cpp
table/composertabledialog.cpp
link/composeranchordialog.cpp
link/composerlinkdialog.cpp
utils/composereditorutils.cpp
image/composerimagedialog.cpp
image/composerimageresizetooltip.cpp
#image/composerimageresizewidget.cpp
widgets/findreplacebar.cpp
composerwebenginewidget.cpp
)
ecm_qt_declare_logging_category(libcomposereditor_webengine_SRCS HEADER composereditorwebengine_debug.h IDENTIFIER COMPOSEREDITORWEBENGINE_LOG CATEGORY_NAME log_composereditorwebengine)
kconfig_add_kcfg_files(libcomposereditor_webengine_SRCS
globalsetting_composereditorwebengine.kcfgc
)
add_library(composereditorwebengineprivate ${libcomposereditor_webengine_SRCS})
generate_export_header(composereditorwebengineprivate BASE_NAME composereditorwebengine)
target_link_libraries(composereditorwebengineprivate
PRIVATE
KF5::PimTextEdit
KF5::SonnetCore
KF5::PimCommon
KF5::KIOWidgets
KF5::XmlGui
KF5::Completion
Qt5::WebEngine
Qt5::WebEngineWidgets
Qt5::PrintSupport
KF5::MessageViewer
)
target_include_directories(composereditorwebengineprivate PUBLIC "$<BUILD_INTERFACE:${composereditorwebengine_SOURCE_DIR}/src;${composereditorwebengine_BINARY_DIR}/src>")
set_target_properties(composereditorwebengineprivate PROPERTIES
VERSION ${KDEPIM_LIB_VERSION} SOVERSION ${KDEPIM_LIB_SOVERSION}
)
install(TARGETS composereditorwebengineprivate ${KDE_INSTALL_TARGETS_DEFAULT_ARGS} LIBRARY NAMELINK_SKIP)
install( FILES data/composereditorinitialhtml DESTINATION ${KDE_INSTALL_DATADIR}/composereditorwebengine )
#! /bin/sh
$EXTRACTRC `find . -name '*.ui' -o -name '*.kcfg'` >> rc.cpp || exit 11
$XGETTEXT `find . -name '*.h' -o -name '*.cpp' | grep -v '/tests/'` -o $podir/libcomposereditorwebengine.pot
rm -f rc.cpp
/*
Copyright (c) 2013-2016 Montel Laurent <montel@kde.org>
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 "composereditorscript.h"
using namespace ComposerEditorWebEngine;
ComposerEditorScript::ComposerEditorScript()
{
}
/*
Copyright (c) 2013-2016 Montel Laurent <montel@kde.org>
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 COMPOSEREDITORSCRIPT_H
#define COMPOSEREDITORSCRIPT_H
namespace ComposerEditorWebEngine
{
class ComposerEditorScript
{
public:
ComposerEditorScript();
};
}
#endif // COMPOSEREDITORSCRIPT_H
<?xml version="1.0" encoding="utf-8"?>
<kcfg xmlns="http://www.kde.org/standards/kcfg/1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.kde.org/standards/kcfg/1.0 http://www.kde.org/standards/kcfg/1.0/kcfg.xsd">
<kcfgfile name="composereditorwebenginerc" />
<group name="General">
<entry name="AutoSpellChecking" type="Bool" key="auto-spell-checking">
<label></label>
<default>false</default>
</entry>
</group>
</kcfg>
This diff is collapsed.
/*
Copyright (c) 2016 Montel Laurent <montel@kde.org>
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 COMPOSERWEBENGINE_H
#define COMPOSERWEBENGINE_H
#include <QWebEngineView>
#include <MessageViewer/WebEngineView>
#include "composereditorwebengine_export.h"
class KActionCollection;
class KToolBar;
namespace MessageViewer
{
class WebHitTestResult;
}
namespace ComposerEditorWebEngine
{
class ComposerEditorWebEnginePrivate;
class COMPOSEREDITORWEBENGINE_EXPORT ComposerWebEngine : public MessageViewer::WebEngineView
{
Q_OBJECT
public:
explicit ComposerWebEngine(QWidget *parent = Q_NULLPTR);
~ComposerWebEngine();
/**
* @brief initialHtml
* @return initial html file. Needs to initialize view
*/
virtual QString initialHtml();
enum ComposerWebEngineAction {
//Separator
Separator,
//Real Actions
Bold,
Italic,
Underline,
StrikeOut,
AlignLeft,
AlignCenter,
AlignRight,
AlignJustify,
DirectionLtr,
DirectionRtl,
SubScript,
SuperScript,
HorizontalRule,
ListIndent,
ListDedent,
OrderedList,
UnorderedList,
FormatType,
FontSize,
FontFamily,
Emoticon,
InsertHtml,
InsertImage,
InsertTable,
InsertLink,
InsertSpecialChar,
TextForegroundColor,
TextBackgroundColor,
FormatReset,
SpellCheck,
Find,
Replace,
PageColor,
BlockQuote,
SaveAs,
Print,
PrintPreview,
PasteWithoutFormatting,
InsertAnchor,
//Keep at end
LastType
};
virtual void addCreatedActionsToActionCollection(KActionCollection *actionCollection);
virtual void addExtraAction(QMenu *menu);
void createActions(const QList<ComposerWebEngineAction> &);
void createAllActions();
void createToolBar(const QList<ComposerWebEngineAction> &lstAction, KToolBar *toolbar);
void setActionsEnabled(bool enabled);
void setHtmlContent(const QString &html);
QAction *action(ComposerWebEngineAction actionType) const;
/**
* @brief evaluateJavascript
* @param javascript evaluate javascript function.
*/
void evaluateJavascript(const QString &javascript);
QMap<QString, QString> localImages() const;
protected:
void contextMenuEvent(QContextMenuEvent *event) Q_DECL_OVERRIDE;
void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
void keyPressEvent(QKeyEvent *event) Q_DECL_OVERRIDE;
void wheelEvent(QWheelEvent *event) Q_DECL_OVERRIDE;
void mouseDoubleClickEvent(QMouseEvent *) Q_DECL_OVERRIDE;
Q_SIGNALS:
void showFindBar();
void openLink(const QUrl &);
private Q_SLOTS:
void slotWebHitFinished(const MessageViewer::WebHitTestResult &result);
private:
friend class ComposerEditorWebEnginePrivate;
ComposerEditorWebEnginePrivate *const d;
Q_PRIVATE_SLOT(d, void _k_slotSpeakText())
Q_PRIVATE_SLOT(d, void _k_slotAdjustActions())
Q_PRIVATE_SLOT(d, void _k_setFormatType(QAction *))
Q_PRIVATE_SLOT(d, void _k_slotAddEmoticon(const QString &))
Q_PRIVATE_SLOT(d, void _k_slotInsertHtml())
Q_PRIVATE_SLOT(d, void _k_slotAddImage())
Q_PRIVATE_SLOT(d, void _k_slotInsertTable())
Q_PRIVATE_SLOT(d, void _k_setTextForegroundColor())
Q_PRIVATE_SLOT(d, void _k_setTextBackgroundColor())
Q_PRIVATE_SLOT(d, void _k_slotInsertHorizontalRule())
Q_PRIVATE_SLOT(d, void _k_insertLink())
Q_PRIVATE_SLOT(d, void _k_setFontSize(int))
Q_PRIVATE_SLOT(d, void _k_setFontFamily(const QString &))
Q_PRIVATE_SLOT(d, void _k_slotSpellCheck())
Q_PRIVATE_SLOT(d, void _k_spellCheckerCorrected(const QString &original, int pos, const QString &replacement))
Q_PRIVATE_SLOT(d, void _k_spellCheckerMisspelling(const QString &, int))
Q_PRIVATE_SLOT(d, void _k_slotSpellCheckDone(const QString &))
Q_PRIVATE_SLOT(d, void _k_slotFind())
Q_PRIVATE_SLOT(d, void _k_slotReplace())
Q_PRIVATE_SLOT(d, void _k_slotDeleteText())
Q_PRIVATE_SLOT(d, void _k_slotChangePageColorAndBackground())
Q_PRIVATE_SLOT(d, void _k_slotEditLink())
Q_PRIVATE_SLOT(d, void _k_slotOpenLink())
Q_PRIVATE_SLOT(d, void _k_slotToggleBlockQuote())
Q_PRIVATE_SLOT(d, void _k_slotEditImage())
Q_PRIVATE_SLOT(d, void _k_slotSaveAs())
Q_PRIVATE_SLOT(d, void _k_slotPrint())
Q_PRIVATE_SLOT(d, void _k_slotPrintPreview())
Q_PRIVATE_SLOT(d, void _k_changeAutoSpellChecking(bool))
Q_PRIVATE_SLOT(d, void _k_slotEditList())
Q_PRIVATE_SLOT(d, void _k_slotPasteWithoutFormatting())
Q_PRIVATE_SLOT(d, void _k_slotInsertSpecialChar())
Q_PRIVATE_SLOT(d, void _k_slotInsertAnchor())
Q_PRIVATE_SLOT(d, void _k_slotBold(bool))
Q_PRIVATE_SLOT(d, void _k_slotItalic(bool))
Q_PRIVATE_SLOT(d, void _k_slotUnderline(bool b))
Q_PRIVATE_SLOT(d, void _k_slotStrikeout(bool))
Q_PRIVATE_SLOT(d, void _k_slotSuperscript(bool b))
Q_PRIVATE_SLOT(d, void _k_slotJustifyLeft(bool b))
Q_PRIVATE_SLOT(d, void _k_slotJustifyCenter(bool b))
Q_PRIVATE_SLOT(d, void _k_slotJustifyRight(bool b))
Q_PRIVATE_SLOT(d, void _k_slotJustifyFull(bool b))
Q_PRIVATE_SLOT(d, void _k_slotSubscript(bool b))
Q_PRIVATE_SLOT(d, void _k_slotListIndent())
Q_PRIVATE_SLOT(d, void _k_slotListDedent())
Q_PRIVATE_SLOT(d, void _k_slotOrderedList(bool b))
Q_PRIVATE_SLOT(d, void _k_slotUnOrderedList(bool b))
Q_PRIVATE_SLOT(d, void _k_slotResetFormat())
Q_PRIVATE_SLOT(d, void _k_slotDirectionLtr())
Q_PRIVATE_SLOT(d, void _k_slotDirectionRtl())
};
}
#endif // COMPOSERWEBENGINE_H
/*
Copyright (c) 2016 Montel Laurent <montel@kde.org>
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 "composerwebenginewidget.h"
#include "composerwebengine.h"
#include "widgets/findreplacebar.h"
#include <KToolBar>
#include <QVBoxLayout>
using namespace ComposerEditorWebEngine;
class ComposerEditorWebEngine::ComposerWebEngineWidgetPrivate
{
public:
ComposerWebEngineWidgetPrivate(ComposerWebEngineWidget *qq)
: toolBarLayout(Q_NULLPTR),
webEngine(Q_NULLPTR),
q(qq),
richTextEnabled(true)
{
}
void initialize();
KToolBar *createToolBar(const QList<ComposerWebEngine::ComposerWebEngineAction> &lstActions);
void showToolBars(bool visible);
QList<KToolBar *> listToolBar;
QVBoxLayout *toolBarLayout;
FindReplaceBar *findReplace;
ComposerWebEngine *webEngine;
ComposerWebEngineWidget *q;
bool richTextEnabled;
};
void ComposerWebEngineWidgetPrivate::initialize()
{
QVBoxLayout *vbox = new QVBoxLayout(q);
toolBarLayout = new QVBoxLayout;
toolBarLayout->setMargin(0);
vbox->addLayout(toolBarLayout);
vbox->setMargin(0);
if (!webEngine) {
webEngine = new ComposerWebEngine(q);
}
webEngine->setObjectName(QStringLiteral("webengine"));
vbox->addWidget(webEngine);
findReplace = new FindReplaceBar(webEngine);
findReplace->setObjectName(QStringLiteral("findbar"));
vbox->addWidget(findReplace);
q->connect(webEngine, &ComposerWebEngine::showFindBar, findReplace, &FindReplaceBar::showAndFocus);
#if 0
q->connect(view, &ComposerView::openLink, q, &ComposerEditor::openLink);
q->connect(view->page(), &QWebPage::contentsChanged, q, &ComposerEditor::textChanged);
#endif
}
KToolBar *ComposerWebEngineWidgetPrivate::createToolBar(const QList<ComposerWebEngine::ComposerWebEngineAction> &lstActions)
{
KToolBar *toolbar = new KToolBar(q);
toolbar->setIconSize(QSize(22, 22));
toolbar->setToolButtonStyle(Qt::ToolButtonIconOnly);
toolBarLayout->addWidget(toolbar);
webEngine->createToolBar(lstActions, toolbar);
listToolBar.append(toolbar);
return toolbar;
}
void ComposerWebEngineWidgetPrivate::showToolBars(bool visible)
{
Q_FOREACH (KToolBar *toolBar, listToolBar) {
toolBar->setVisible(visible);
}
}
ComposerWebEngineWidget::ComposerWebEngineWidget(QWidget *parent)
: QWidget(parent),
d(new ComposerEditorWebEngine::ComposerWebEngineWidgetPrivate(this))
{
d->initialize();
}
ComposerWebEngineWidget::ComposerWebEngineWidget(ComposerWebEngine *view, QWidget *parent)
: QWidget(parent), d(new ComposerEditorWebEngine::ComposerWebEngineWidgetPrivate(this))
{
d->webEngine = view;
d->initialize();
}
ComposerWebEngineWidget::~ComposerWebEngineWidget()
{
delete d;
}
void ComposerWebEngineWidget::addCreatedActionsToActionCollection(KActionCollection *actionCollection)
{
d->webEngine->addCreatedActionsToActionCollection(actionCollection);
}
QString ComposerWebEngineWidget::plainTextContent() const
{
return {}; // FIXME d->webEngine->page()->mainFrame()->toPlainText();
}
void ComposerWebEngineWidget::setEnableRichText(bool richTextEnabled)
{
if (d->richTextEnabled != richTextEnabled) {
d->richTextEnabled = richTextEnabled;
d->webEngine->setActionsEnabled(d->richTextEnabled);
d->showToolBars(d->richTextEnabled);
}
}
bool ComposerWebEngineWidget::enableRichText() const
{
return d->richTextEnabled;
}
bool ComposerWebEngineWidget::isModified() const
{
return true; //FIXME d->webEngine->page()->isModified();
}
void ComposerWebEngineWidget::paste()
{
d->webEngine->page()->triggerAction(QWebEnginePage::Paste);
}
void ComposerWebEngineWidget::cut()
{
d->webEngine->page()->triggerAction(QWebEnginePage::Cut);
}
void ComposerWebEngineWidget::copy()
{
d->webEngine->page()->triggerAction(QWebEnginePage::Copy);
}
void ComposerWebEngineWidget::undo()
{
d->webEngine->page()->triggerAction(QWebEnginePage::Undo);
}
void ComposerWebEngineWidget::redo()
{
d->webEngine->page()->triggerAction(QWebEnginePage::Redo);
}
QAction *ComposerWebEngineWidget::action(ComposerWebEngine::ComposerWebEngineAction action) const
{
return {};//TODO d->webEngine->page()->action(action);
}
ComposerWebEngine *ComposerWebEngineWidget::view() const
{
return d->webEngine;
}
void ComposerWebEngineWidget::setHtmlContent(const QString &html)