1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
|
/*
SPDX-FileCopyrightText: 2002 George Russell <george.russell@clara.net>
SPDX-FileCopyrightText: 2003-2004 Olaf Schmidt <ojschmidt@kde.org>
SPDX-FileCopyrightText: 2015 Jeremy Whiting <jpwhiting@kde.org>
SPDX-License-Identifier: GPL-2.0-or-later
*/
// Own
#include "khtmltts.h"
#include "textextension.h"
// Qt
#include <QAction>
#include <QIcon>
#include <QTextToSpeech>
// KDE
#include <KActionCollection>
#include <KLocalizedString>
#include <KParts/ReadOnlyPart>
#include <kpluginfactory.h>
KHTMLPluginTTS::KHTMLPluginTTS(QObject *parent, const QVariantList &)
: KonqParts::Plugin(parent)
{
TextExtension *textExt = TextExtension::childObject(parent);
if (textExt && qobject_cast<KParts::ReadOnlyPart *>(parent)) {
m_tts = std::unique_ptr<QTextToSpeech>(new QTextToSpeech);
QAction *action = actionCollection()->addAction(QStringLiteral("tools_tts"));
action->setIcon(QIcon::fromTheme(QStringLiteral("text-speak")));
action->setText(i18n("&Speak Text"));
connect(action, SIGNAL(triggered(bool)), SLOT(slotReadOut()));
}
}
KHTMLPluginTTS::~KHTMLPluginTTS()
{
}
void KHTMLPluginTTS::slotReadOut()
{
TextExtension *textExt = TextExtension::childObject(parent());
QString query;
const TextExtension::Format format = TextExtension::PlainText;
if (textExt->hasSelection()) {
query = textExt->selectedText(format);
} else {
query = textExt->completeText(format);
}
m_tts->say(query);
}
K_PLUGIN_CLASS_WITH_JSON(KHTMLPluginTTS, "khtmltts.json")
#include "khtmltts.moc"
|