File indexing completed on 2025-01-05 04:49:29
0001 /* 0002 SPDX-FileCopyrightText: 2019-2024 Laurent Montel <montel@kde.org> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 #include "quicktextconfiguredialog.h" 0007 #include "quicktextconfigurewidget.h" 0008 0009 #include <KConfigGroup> 0010 #include <KLocalizedString> 0011 #include <KSharedConfig> 0012 #include <KWindowConfig> 0013 #include <QCloseEvent> 0014 #include <QDialogButtonBox> 0015 #include <QPushButton> 0016 #include <QVBoxLayout> 0017 #include <QWindow> 0018 0019 namespace 0020 { 0021 static const char myConfigGroupName[] = "QuickTextConfigureDialog"; 0022 } 0023 QuickTextConfigureDialog::QuickTextConfigureDialog(QWidget *parent) 0024 : QDialog(parent) 0025 , mQuickTextConfigureWidget(new QuickTextConfigureWidget(this)) 0026 { 0027 setWindowTitle(i18nc("@title:window", "Configure quick text")); 0028 auto mainLayout = new QVBoxLayout(this); 0029 mainLayout->setObjectName(QLatin1StringView("mainlayout")); 0030 mQuickTextConfigureWidget->setObjectName(QLatin1StringView("quicktextconfigurewidget")); 0031 mainLayout->addWidget(mQuickTextConfigureWidget); 0032 0033 auto buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this); 0034 buttonBox->setObjectName(QLatin1StringView("buttonbox")); 0035 connect(buttonBox, &QDialogButtonBox::accepted, this, &QuickTextConfigureDialog::slotAccepted); 0036 connect(buttonBox, &QDialogButtonBox::rejected, this, &QuickTextConfigureDialog::reject); 0037 0038 auto importButton = new QPushButton(i18n("Import..."), this); 0039 buttonBox->addButton(importButton, QDialogButtonBox::ActionRole); 0040 connect(importButton, &QPushButton::clicked, this, &QuickTextConfigureDialog::slotImport); 0041 auto exportButton = new QPushButton(i18n("Export..."), this); 0042 buttonBox->addButton(exportButton, QDialogButtonBox::ActionRole); 0043 connect(exportButton, &QPushButton::clicked, this, &QuickTextConfigureDialog::slotExport); 0044 0045 mainLayout->addWidget(buttonBox); 0046 writeConfig(); 0047 } 0048 0049 QuickTextConfigureDialog::~QuickTextConfigureDialog() 0050 { 0051 readConfig(); 0052 } 0053 0054 void QuickTextConfigureDialog::writeConfig() 0055 { 0056 KConfigGroup group(KSharedConfig::openStateConfig(), QLatin1StringView(myConfigGroupName)); 0057 KWindowConfig::saveWindowSize(windowHandle(), group); 0058 } 0059 0060 void QuickTextConfigureDialog::readConfig() 0061 { 0062 create(); // ensure a window is created 0063 windowHandle()->resize(QSize(300, 350)); 0064 KConfigGroup group(KSharedConfig::openStateConfig(), QLatin1StringView(myConfigGroupName)); 0065 KWindowConfig::restoreWindowSize(windowHandle(), group); 0066 resize(windowHandle()->size()); // workaround for QTBUG-40584 0067 } 0068 0069 void QuickTextConfigureDialog::slotImport() 0070 { 0071 mQuickTextConfigureWidget->importQuickText(); 0072 } 0073 0074 void QuickTextConfigureDialog::slotExport() 0075 { 0076 mQuickTextConfigureWidget->exportQuickText(); 0077 } 0078 0079 void QuickTextConfigureDialog::closeEvent(QCloseEvent *e) 0080 { 0081 mQuickTextConfigureWidget->save(); 0082 e->accept(); 0083 } 0084 0085 void QuickTextConfigureDialog::slotAccepted() 0086 { 0087 mQuickTextConfigureWidget->save(); 0088 QDialog::accept(); 0089 } 0090 0091 #include "moc_quicktextconfiguredialog.cpp"