Libksieve

sievescriptdescriptiondialog.cpp
1 /*
2  SPDX-FileCopyrightText: 2013-2021 Laurent Montel <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 
7 #include "sievescriptdescriptiondialog.h"
8 #include <KPIMTextEdit/PlainTextEditorWidget>
9 
10 #include <KConfigGroup>
11 #include <KLocalizedString>
12 #include <KSharedConfig>
13 #include <QDialogButtonBox>
14 #include <QPushButton>
15 #include <QVBoxLayout>
16 
17 using namespace KSieveUi;
18 
19 SieveScriptDescriptionDialog::SieveScriptDescriptionDialog(QWidget *parent)
20  : QDialog(parent)
21 {
22  setWindowTitle(i18nc("@title:window", "Description"));
23  auto mainLayout = new QVBoxLayout(this);
24 
25  mEdit = new KPIMTextEdit::PlainTextEditorWidget(this);
26 
28  QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok);
29  okButton->setDefault(true);
30  okButton->setShortcut(Qt::CTRL | Qt::Key_Return);
31  connect(buttonBox, &QDialogButtonBox::accepted, this, &SieveScriptDescriptionDialog::accept);
32  connect(buttonBox, &QDialogButtonBox::rejected, this, &SieveScriptDescriptionDialog::reject);
33  mainLayout->addWidget(mEdit);
34  mainLayout->addWidget(buttonBox);
35 
36  readConfig();
37  mEdit->setFocus();
38 }
39 
40 SieveScriptDescriptionDialog::~SieveScriptDescriptionDialog()
41 {
42  writeConfig();
43 }
44 
45 void SieveScriptDescriptionDialog::setDescription(const QString &desc)
46 {
47  mEdit->setPlainText(desc);
48 }
49 
50 QString SieveScriptDescriptionDialog::description() const
51 {
52  return mEdit->toPlainText();
53 }
54 
55 void SieveScriptDescriptionDialog::readConfig()
56 {
57  KConfigGroup group(KSharedConfig::openStateConfig(), "SieveScriptDescriptionDialog");
58  const QSize sizeDialog = group.readEntry("Size", QSize(800, 600));
59  if (sizeDialog.isValid()) {
60  resize(sizeDialog);
61  }
62 }
63 
64 void SieveScriptDescriptionDialog::writeConfig()
65 {
66  KConfigGroup group(KSharedConfig::openStateConfig(), "SieveScriptDescriptionDialog");
67  group.writeEntry("Size", size());
68 }
void resize(int w, int h)
bool isValid() const const
QSize size() const const
static KSharedConfig::Ptr openStateConfig(const QString &fileName=QString())
QString i18nc(const char *context, const char *text, const TYPE &arg...)
void setShortcut(const QKeySequence &key)
void readConfig()
void setWindowTitle(const QString &)
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
void setDefault(bool)
Key_Return
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Fri Apr 16 2021 23:09:34 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.