KTextAddons

texttospeechconfigdialog.cpp
1/*
2 SPDX-FileCopyrightText: 2014-2024 Laurent Montel <montel@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#include "texttospeechconfigdialog.h"
8#include "texttospeechconfigwidget.h"
9#include <KLocalizedString>
10
11#include <KConfigGroup>
12#include <KSharedConfig>
13#include <KWindowConfig>
14#include <QDialogButtonBox>
15#include <QPushButton>
16#include <QVBoxLayout>
17#include <QWindow>
18namespace
19{
20static const char myTextToSpeechConfigDialogConfigGroupName[] = "TextToSpeechConfigDialog";
21}
22using namespace TextEditTextToSpeech;
23
24TextToSpeechConfigDialog::TextToSpeechConfigDialog(QWidget *parent)
25 : QDialog(parent)
26 , mTextToSpeechConfigWidget(new TextToSpeechConfigWidget(parent))
27{
28 setWindowTitle(i18nc("@title:window", "Configure Text-To-Speech"));
29 auto mainLayout = new QVBoxLayout(this);
30 mainLayout->addWidget(mTextToSpeechConfigWidget);
31
33 QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok);
34 okButton->setDefault(true);
36 connect(buttonBox, &QDialogButtonBox::accepted, this, &TextToSpeechConfigDialog::slotAccepted);
37 connect(buttonBox, &QDialogButtonBox::rejected, this, &TextToSpeechConfigDialog::reject);
38 connect(buttonBox->button(QDialogButtonBox::RestoreDefaults), &QPushButton::clicked, this, &TextToSpeechConfigDialog::slotRestoreDefaults);
39 mainLayout->addWidget(buttonBox);
40 readConfig();
41}
42
43TextToSpeechConfigDialog::~TextToSpeechConfigDialog()
44{
45 writeConfig();
46}
47
48void TextToSpeechConfigDialog::slotRestoreDefaults()
49{
50 mTextToSpeechConfigWidget->restoreDefaults();
51}
52
53void TextToSpeechConfigDialog::readConfig()
54{
55 create(); // ensure a window is created
56 windowHandle()->resize(QSize(300, 200));
57 KConfigGroup group(KSharedConfig::openStateConfig(), QLatin1StringView(myTextToSpeechConfigDialogConfigGroupName));
59 resize(windowHandle()->size()); // workaround for QTBUG-40584
60 mTextToSpeechConfigWidget->initializeSettings();
61}
62
63void TextToSpeechConfigDialog::writeConfig()
64{
65 KConfigGroup group(KSharedConfig::openStateConfig(), QLatin1StringView(myTextToSpeechConfigDialogConfigGroupName));
67}
68
69void TextToSpeechConfigDialog::slotAccepted()
70{
71 mTextToSpeechConfigWidget->writeConfig();
72 accept();
73}
74
75#include "moc_texttospeechconfigdialog.cpp"
static KSharedConfig::Ptr openStateConfig(const QString &fileName=QString())
QString i18nc(const char *context, const char *text, const TYPE &arg...)
KCONFIGGUI_EXPORT void saveWindowSize(const QWindow *window, KConfigGroup &config, KConfigGroup::WriteConfigFlags options=KConfigGroup::Normal)
KCONFIGGUI_EXPORT void restoreWindowSize(QWindow *window, const KConfigGroup &config)
void clicked(bool checked)
void setShortcut(const QKeySequence &key)
virtual void accept()
void setDefault(bool)
Key_Return
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
void create(WId window, bool initializeWindow, bool destroyOldWindow)
void resize(const QSize &)
QWindow * windowHandle() const const
void resize(const QSize &newSize)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Jul 26 2024 11:51:28 by doxygen 1.11.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.