File indexing completed on 2024-11-24 04:16:54
0001 /* 0002 SPDX-FileCopyrightText: 2023-2024 Laurent Montel <montel.org> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include "begamotenginedialog.h" 0008 #include "bergamotenginewidget.h" 0009 #include <KConfigGroup> 0010 #include <KLocalizedString> 0011 #include <KSharedConfig> 0012 #include <KWindowConfig> 0013 #include <QDialogButtonBox> 0014 #include <QVBoxLayout> 0015 #include <QWindow> 0016 namespace 0017 { 0018 static const char myConfigGroupName[] = "BegamotEngineDialog"; 0019 } 0020 BegamotEngineDialog::BegamotEngineDialog(QWidget *parent) 0021 : QDialog(parent) 0022 , mBergamotEngineWidget(new BergamotEngineWidget(this)) 0023 { 0024 setWindowTitle(i18nc("@title:window", "Bergamot Plugin Settings")); 0025 auto mainLayout = new QVBoxLayout(this); 0026 mainLayout->setObjectName(QStringLiteral("mainLayout")); 0027 0028 mBergamotEngineWidget->setObjectName(QStringLiteral("mBergamotEngineWidget")); 0029 mainLayout->addWidget(mBergamotEngineWidget); 0030 0031 auto buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this); 0032 buttonBox->setObjectName(QStringLiteral("buttonBox")); 0033 mainLayout->addWidget(buttonBox); 0034 connect(buttonBox, &QDialogButtonBox::accepted, this, &BegamotEngineDialog::accept); 0035 connect(buttonBox, &QDialogButtonBox::rejected, this, &BegamotEngineDialog::reject); 0036 readConfig(); 0037 } 0038 0039 BegamotEngineDialog::~BegamotEngineDialog() 0040 { 0041 writeConfig(); 0042 } 0043 0044 void BegamotEngineDialog::writeConfig() 0045 { 0046 KConfigGroup group(KSharedConfig::openStateConfig(), QLatin1String(myConfigGroupName)); 0047 KWindowConfig::saveWindowSize(windowHandle(), group); 0048 } 0049 0050 void BegamotEngineDialog::readConfig() 0051 { 0052 create(); // ensure a window is created 0053 windowHandle()->resize(QSize(500, 300)); 0054 KConfigGroup group(KSharedConfig::openStateConfig(), QLatin1String(myConfigGroupName)); 0055 KWindowConfig::restoreWindowSize(windowHandle(), group); 0056 resize(windowHandle()->size()); // workaround for QTBUG-40584 0057 } 0058 0059 void BegamotEngineDialog::setSettingsInfo(const BergamotEngineUtils::SettingsInfo &info) 0060 { 0061 mBergamotEngineWidget->setSettingsInfo(info); 0062 } 0063 0064 BergamotEngineUtils::SettingsInfo BegamotEngineDialog::settingsInfo() const 0065 { 0066 return mBergamotEngineWidget->settingsInfo(); 0067 } 0068 0069 #include "moc_begamotenginedialog.cpp"