File indexing completed on 2024-05-12 16:15:57

0001 /*
0002    SPDX-FileCopyrightText: 2023 Laurent Montel <montel@kde.org>
0003 
0004    SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include "texttospeechcontainergui.h"
0008 #include "texttospeechcontainerwidget.h"
0009 #include <KLocalizedString>
0010 #include <QAction>
0011 #include <QApplication>
0012 #include <QCommandLineParser>
0013 #include <QDebug>
0014 #include <QMenu>
0015 #include <QMenuBar>
0016 #include <QStandardPaths>
0017 #include <QTextEdit>
0018 #include <QVBoxLayout>
0019 
0020 TextToSpeechGui::TextToSpeechGui(QWidget *parent)
0021     : QMainWindow(parent)
0022 {
0023     setWindowTitle(QStringLiteral("text to speech window"));
0024     auto mainWidget = new QWidget;
0025     auto mainLayout = new QVBoxLayout(mainWidget);
0026     mEdit = new QTextEdit;
0027     mContainerWidget = new TextEditTextToSpeech::TextToSpeechContainerWidget(this);
0028     mainLayout->addWidget(mContainerWidget);
0029     mainLayout->addWidget(mEdit);
0030 
0031     setCentralWidget(mainWidget);
0032 
0033     QMenu *editMenu = menuBar()->addMenu(QStringLiteral("Edit"));
0034 
0035     auto act = new QAction(i18n("Speech text"), this);
0036     connect(act, &QAction::triggered, this, &TextToSpeechGui::slotTextToSpeech);
0037     editMenu->addAction(act);
0038     // qDebug() << " isReady ? " << TextEditTextToSpeech::TextToSpeech::self()->isReady();
0039 }
0040 
0041 TextToSpeechGui::~TextToSpeechGui() = default;
0042 
0043 void TextToSpeechGui::slotTextToSpeech()
0044 {
0045     QString text;
0046     if (mEdit->textCursor().hasSelection()) {
0047         text = mEdit->textCursor().selectedText();
0048     } else {
0049         text = mEdit->toPlainText();
0050     }
0051     if (!text.isEmpty()) {
0052         mContainerWidget->say(text);
0053     }
0054 }
0055 
0056 int main(int argc, char **argv)
0057 {
0058     QApplication app(argc, argv);
0059     QStandardPaths::setTestModeEnabled(true);
0060     QCommandLineParser parser;
0061     parser.addVersionOption();
0062     parser.addHelpOption();
0063     parser.process(app);
0064 
0065     auto w = new TextToSpeechGui;
0066 
0067     w->show();
0068     app.exec();
0069     delete w;
0070     return 0;
0071 }
0072 
0073 #include "moc_texttospeechcontainergui.cpp"