File indexing completed on 2025-01-05 04:54:20
0001 /* 0002 SPDX-FileCopyrightText: 2013-2024 Laurent Montel <montel@kde.org> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 #include "knoteskeydialog.h" 0007 0008 #include <KConfigGroup> 0009 #include <KLocalizedString> 0010 #include <KSharedConfig> 0011 #include <KShortcutsEditor> 0012 #include <KWindowConfig> 0013 #include <QDialogButtonBox> 0014 #include <QPushButton> 0015 #include <QVBoxLayout> 0016 #include <QWindow> 0017 0018 KNotesKeyDialog::KNotesKeyDialog(KActionCollection *globals, QWidget *parent) 0019 : QDialog(parent) 0020 { 0021 setWindowTitle(i18nc("@title:window", "Configure Shortcuts")); 0022 auto mainLayout = new QVBoxLayout(this); 0023 m_keyChooser = new KShortcutsEditor(globals, this); 0024 0025 auto buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel | QDialogButtonBox::RestoreDefaults, this); 0026 QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok); 0027 okButton->setDefault(true); 0028 okButton->setShortcut(Qt::CTRL | Qt::Key_Return); 0029 connect(buttonBox, &QDialogButtonBox::accepted, this, &KNotesKeyDialog::accept); 0030 connect(buttonBox, &QDialogButtonBox::rejected, this, &KNotesKeyDialog::reject); 0031 connect(buttonBox->button(QDialogButtonBox::RestoreDefaults), &QPushButton::clicked, m_keyChooser, &KShortcutsEditor::allDefault); 0032 0033 mainLayout->addWidget(m_keyChooser); 0034 mainLayout->addWidget(buttonBox); 0035 readConfig(); 0036 } 0037 0038 KNotesKeyDialog::~KNotesKeyDialog() 0039 { 0040 writeConfig(); 0041 } 0042 0043 namespace 0044 { 0045 static const char myKNotesKeyDialogName[] = "KNotesKeyDialog"; 0046 } 0047 void KNotesKeyDialog::readConfig() 0048 { 0049 create(); // ensure a window is created 0050 windowHandle()->resize(QSize(300, 200)); 0051 KConfigGroup group(KSharedConfig::openStateConfig(), QLatin1StringView(myKNotesKeyDialogName)); 0052 KWindowConfig::restoreWindowSize(windowHandle(), group); 0053 resize(windowHandle()->size()); // workaround for QTBUG-40584 0054 } 0055 0056 void KNotesKeyDialog::writeConfig() 0057 { 0058 KConfigGroup group(KSharedConfig::openStateConfig(), QLatin1StringView(myKNotesKeyDialogName)); 0059 KWindowConfig::saveWindowSize(windowHandle(), group); 0060 group.sync(); 0061 } 0062 0063 void KNotesKeyDialog::insert(KActionCollection *actions) 0064 { 0065 m_keyChooser->addCollection(actions, i18n("Note Actions")); 0066 } 0067 0068 void KNotesKeyDialog::save() 0069 { 0070 m_keyChooser->save(); 0071 }