Libksieve

sievescriptdescriptiondialog.cpp
1/*
2 SPDX-FileCopyrightText: 2013-2024 Laurent Montel <montel@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#include "sievescriptdescriptiondialog.h"
8#include <TextCustomEditor/PlainTextEditorWidget>
9
10#include <KConfigGroup>
11#include <KLocalizedString>
12#include <KSharedConfig>
13#include <KWindowConfig>
14#include <QDialogButtonBox>
15#include <QPushButton>
16#include <QVBoxLayout>
17#include <QWindow>
18
19using namespace KSieveUi;
20namespace
21{
22static const char mySieveScriptDescriptionDialogGroupName[] = "SieveScriptDescriptionDialog";
23}
24SieveScriptDescriptionDialog::SieveScriptDescriptionDialog(QWidget *parent)
25 : QDialog(parent)
26 , mEdit(new TextCustomEditor::PlainTextEditorWidget(this))
27{
28 setWindowTitle(i18nc("@title:window", "Description"));
29 auto mainLayout = new QVBoxLayout(this);
30
32 QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok);
33 okButton->setDefault(true);
35 connect(buttonBox, &QDialogButtonBox::accepted, this, &SieveScriptDescriptionDialog::accept);
36 connect(buttonBox, &QDialogButtonBox::rejected, this, &SieveScriptDescriptionDialog::reject);
37 mainLayout->addWidget(mEdit);
38 mainLayout->addWidget(buttonBox);
39
40 readConfig();
41 mEdit->setFocus();
42}
43
44SieveScriptDescriptionDialog::~SieveScriptDescriptionDialog()
45{
46 writeConfig();
47}
48
49void SieveScriptDescriptionDialog::setDescription(const QString &desc)
50{
51 mEdit->setPlainText(desc);
52}
53
54QString SieveScriptDescriptionDialog::description() const
55{
56 return mEdit->toPlainText();
57}
58
59void SieveScriptDescriptionDialog::readConfig()
60{
61 create(); // ensure a window is created
62 windowHandle()->resize(QSize(800, 600));
63 KConfigGroup group(KSharedConfig::openStateConfig(), QLatin1StringView(mySieveScriptDescriptionDialogGroupName));
65 resize(windowHandle()->size()); // workaround for QTBUG-40584
66}
67
68void SieveScriptDescriptionDialog::writeConfig()
69{
70 KConfigGroup group(KSharedConfig::openStateConfig(), QLatin1StringView(mySieveScriptDescriptionDialogGroupName));
72 group.sync();
73}
74
75#include "moc_sievescriptdescriptiondialog.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 setShortcut(const QKeySequence &key)
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 Mon Nov 18 2024 12:14:30 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.