articleviewerwebenginewidgetng.cpp 3.39 KB
Newer Older
Laurent Montel's avatar
Laurent Montel committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
/*
  Copyright (c) 2016 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 "articleviewerwebenginewidgetng.h"

#include <KActionCollection>
#include <KLocalizedString>
#include <QVBoxLayout>
#include <QAction>
Laurent Montel's avatar
Laurent Montel committed
24
#include <viewerplugintoolmanager.h>
Laurent Montel's avatar
Laurent Montel committed
25 26 27 28 29

#include <KPIMTextEdit/kpimtextedit/texttospeechwidget.h>

#include <kpimtextedit/slidecontainer.h>

Laurent Montel's avatar
Laurent Montel committed
30 31
#include <MessageViewer/FindBarWebEngineView>

Laurent Montel's avatar
Laurent Montel committed
32 33
using namespace Akregator;

Laurent Montel's avatar
Laurent Montel committed
34
ArticleViewerWebEngineWidgetNg::ArticleViewerWebEngineWidgetNg(ArticleViewerWebEngine *customViewer, KActionCollection *ac, QWidget *parent)
Laurent Montel's avatar
Laurent Montel committed
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
    : QWidget(parent)
{
    mArticleViewerNg = customViewer;
    initializeLayout(ac);
}

ArticleViewerWebEngineWidgetNg::ArticleViewerWebEngineWidgetNg(KActionCollection *ac, QWidget *parent)
    : QWidget(parent),
      mArticleViewerNg(Q_NULLPTR)
{
    initializeLayout(ac);
}

void ArticleViewerWebEngineWidgetNg::initializeLayout(KActionCollection *ac)
{
    QVBoxLayout *layout = new QVBoxLayout;
    layout->setMargin(0);
    setLayout(layout);

    mTextToSpeechWidget = new KPIMTextEdit::TextToSpeechWidget(this);
    mTextToSpeechWidget->setObjectName(QStringLiteral("texttospeechwidget"));
    layout->addWidget(mTextToSpeechWidget);

    if (!mArticleViewerNg) {
Laurent Montel's avatar
Laurent Montel committed
59
        mArticleViewerNg = new ArticleViewerWebEngine(ac, this);
Laurent Montel's avatar
Laurent Montel committed
60 61 62 63
    }
    mArticleViewerNg->setObjectName(QStringLiteral("articleviewerng"));
    layout->addWidget(mArticleViewerNg);

64
    mArticleViewerNg->createViewerPluginToolManager(ac, this);
Laurent Montel's avatar
Laurent Montel committed
65

Laurent Montel's avatar
Laurent Montel committed
66 67
    mSliderContainer = new KPIMTextEdit::SlideContainer(this);
    mSliderContainer->setObjectName(QStringLiteral("slidercontainer"));
Laurent Montel's avatar
Laurent Montel committed
68
    mFindBarWebView = new MessageViewer::FindBarWebEngineView(mArticleViewerNg, this);
Laurent Montel's avatar
Laurent Montel committed
69 70 71 72
    mFindBarWebView->setObjectName(QStringLiteral("findbarwebview"));
    connect(mFindBarWebView, &MessageViewer::FindBarBase::hideFindBar, mSliderContainer, &KPIMTextEdit::SlideContainer::slideOut);
    mSliderContainer->setContent(mFindBarWebView);
    layout->addWidget(mSliderContainer);
Laurent Montel's avatar
Laurent Montel committed
73 74
    connect(articleViewerNg(), &ArticleViewerWebEngine::textToSpeech, this, &ArticleViewerWebEngineWidgetNg::slotSpeakText);
    connect(articleViewerNg(), &ArticleViewerWebEngine::findTextInHtml, this, &ArticleViewerWebEngineWidgetNg::slotFind);
Laurent Montel's avatar
Laurent Montel committed
75 76 77 78 79 80 81
}

ArticleViewerWebEngineWidgetNg::~ArticleViewerWebEngineWidgetNg()
{

}

Laurent Montel's avatar
Laurent Montel committed
82
ArticleViewerWebEngine *ArticleViewerWebEngineWidgetNg::articleViewerNg() const
Laurent Montel's avatar
Laurent Montel committed
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
{
    return mArticleViewerNg;
}

void ArticleViewerWebEngineWidgetNg::slotFind()
{
    if (mArticleViewerNg->hasSelection()) {
        mFindBarWebView->setText(mArticleViewerNg->selectedText());
    }
    mSliderContainer->slideIn();
    mFindBarWebView->focusAndSetCursor();
}

void ArticleViewerWebEngineWidgetNg::slotSpeakText()
{
    const QString text = mArticleViewerNg->selectedText();
    mTextToSpeechWidget->say(text);
}