File indexing completed on 2024-12-29 04:54:45
0001 /* 0002 SPDX-FileCopyrightText: 2013-2024 Laurent Montel <montel@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "sievescriptdescriptiondialog.h" 0008 #include <TextCustomEditor/PlainTextEditorWidget> 0009 0010 #include <KConfigGroup> 0011 #include <KLocalizedString> 0012 #include <KSharedConfig> 0013 #include <KWindowConfig> 0014 #include <QDialogButtonBox> 0015 #include <QPushButton> 0016 #include <QVBoxLayout> 0017 #include <QWindow> 0018 0019 using namespace KSieveUi; 0020 namespace 0021 { 0022 static const char mySieveScriptDescriptionDialogGroupName[] = "SieveScriptDescriptionDialog"; 0023 } 0024 SieveScriptDescriptionDialog::SieveScriptDescriptionDialog(QWidget *parent) 0025 : QDialog(parent) 0026 , mEdit(new TextCustomEditor::PlainTextEditorWidget(this)) 0027 { 0028 setWindowTitle(i18nc("@title:window", "Description")); 0029 auto mainLayout = new QVBoxLayout(this); 0030 0031 auto buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this); 0032 QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok); 0033 okButton->setDefault(true); 0034 okButton->setShortcut(Qt::CTRL | Qt::Key_Return); 0035 connect(buttonBox, &QDialogButtonBox::accepted, this, &SieveScriptDescriptionDialog::accept); 0036 connect(buttonBox, &QDialogButtonBox::rejected, this, &SieveScriptDescriptionDialog::reject); 0037 mainLayout->addWidget(mEdit); 0038 mainLayout->addWidget(buttonBox); 0039 0040 readConfig(); 0041 mEdit->setFocus(); 0042 } 0043 0044 SieveScriptDescriptionDialog::~SieveScriptDescriptionDialog() 0045 { 0046 writeConfig(); 0047 } 0048 0049 void SieveScriptDescriptionDialog::setDescription(const QString &desc) 0050 { 0051 mEdit->setPlainText(desc); 0052 } 0053 0054 QString SieveScriptDescriptionDialog::description() const 0055 { 0056 return mEdit->toPlainText(); 0057 } 0058 0059 void SieveScriptDescriptionDialog::readConfig() 0060 { 0061 create(); // ensure a window is created 0062 windowHandle()->resize(QSize(800, 600)); 0063 KConfigGroup group(KSharedConfig::openStateConfig(), QLatin1StringView(mySieveScriptDescriptionDialogGroupName)); 0064 KWindowConfig::restoreWindowSize(windowHandle(), group); 0065 resize(windowHandle()->size()); // workaround for QTBUG-40584 0066 } 0067 0068 void SieveScriptDescriptionDialog::writeConfig() 0069 { 0070 KConfigGroup group(KSharedConfig::openStateConfig(), QLatin1StringView(mySieveScriptDescriptionDialogGroupName)); 0071 KWindowConfig::saveWindowSize(windowHandle(), group); 0072 group.sync(); 0073 } 0074 0075 #include "moc_sievescriptdescriptiondialog.cpp"