[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [juk/frameworks] /: Port the shortcut key dialog away from KDialog.
From:       Michael Pyne <null () kde ! org>
Date:       2017-09-30 21:33:48
Message-ID: E1dyPOO-0007iK-AT () code ! kde ! org
[Download RAW message or body]

Git commit 9b56415011e72cb22020cf612ee0c1a017aa77c0 by Michael Pyne.
Committed on 30/09/2017 at 19:49.
Pushed by mpyne into branch 'frameworks'.

Port the shortcut key dialog away from KDialog.

M  +1    -1    juk.cpp
M  +25   -26   keydialog.cpp
M  +15   -25   keydialog.h

https://commits.kde.org/juk/9b56415011e72cb22020cf612ee0c1a017aa77c0

diff --git a/juk.cpp b/juk.cpp
index 66797b6..295e0bc 100644
--- a/juk.cpp
+++ b/juk.cpp
@@ -552,7 +552,7 @@ void JuK::slotToggleSystemTray(bool enabled)
 
 void JuK::slotEditKeys()
 {
-    KeyDialog::configure(ActionCollection::actions(), this);
+    KeyDialog(ActionCollection::actions(), this).configure();
 }
 
 void JuK::slotConfigureTagGuesser()
diff --git a/keydialog.cpp b/keydialog.cpp
index 3a6efb8..90b9956 100644
--- a/keydialog.cpp
+++ b/keydialog.cpp
@@ -22,8 +22,6 @@
 #include <klocale.h>
 #include <kshortcutseditor.h>
 #include <kglobal.h>
-#include <QAction>
-#include <kvbox.h>
 #include <kconfiggroup.h>
 #include <KGlobalAccel>
 
@@ -31,9 +29,12 @@
 #include <QKeySequence>
 #include <QList>
 #include <QHBoxLayout>
+#include <QVBoxLayout>
 #include <QTimer>
+#include <QDialogButtonBox>
 #include <QButtonGroup>
 #include <QRadioButton>
+#include <QPushButton>
 #include <QGroupBox>
 #include <QString>
 
@@ -94,10 +95,10 @@ const KeyDialog::KeyInfo KeyDialog::keyInfo[] = {
 const uint KeyDialog::keyInfoCount = sizeof(KeyDialog::keyInfo) / sizeof(KeyDialog::keyInfo[0]);
 
 KeyDialog::KeyDialog(KActionCollection *actionCollection, QWidget *parent)
-    : KDialog(parent), m_actionCollection(actionCollection)
+  : QDialog(parent)
+  , m_actionCollection(actionCollection)
 {
-    setCaption(i18n("Configure Shortcuts"));
-    setButtons(Default | Ok | Cancel);
+    setWindowTitle(i18n("Configure Shortcuts"));
 
     // Read key group from configuration
 
@@ -106,17 +107,18 @@ KeyDialog::KeyDialog(KActionCollection *actionCollection, QWidget *parent)
 
     // Create widgets for key chooser
 
-    KVBox *vbox = new KVBox(this);
-    vbox->setSpacing(KDialog::spacingHint());
+    auto vboxLayout = new QVBoxLayout(this);
 
-    m_pKeyChooser = new KShortcutsEditor(actionCollection, vbox);
+    m_pKeyChooser = new KShortcutsEditor(actionCollection, this);
+    vboxLayout->addWidget(m_pKeyChooser);
 
     // Create buttons to select key group
 
-    QGroupBox *buttonBox = new QGroupBox(i18n("Global Shortcuts"), vbox);
+    QGroupBox *buttonBox = new QGroupBox(i18n("Global Shortcuts"), this);
+    vboxLayout->addWidget(buttonBox);
+
     m_group = new QButtonGroup(buttonBox);
-    QHBoxLayout *buttonLayout = new QHBoxLayout;
-    buttonBox->setLayout(buttonLayout);
+    QHBoxLayout *buttonLayout = new QHBoxLayout(buttonBox);
 
     QRadioButton *radioButton = new QRadioButton(i18n("&No keys"), buttonBox);
     m_group->addButton(radioButton, NoKeys);
@@ -130,19 +132,23 @@ KeyDialog::KeyDialog(KActionCollection *actionCollection, QWidget *parent)
     m_group->addButton(radioButton, MultimediaKeys);
     buttonLayout->addWidget(radioButton);
 
-    connect(m_group, SIGNAL(buttonClicked(int)), this, SLOT(slotKeys(int)));
+    connect(m_group, SIGNAL(buttonClicked(int)), SLOT(slotKeys(int)));
     buttonBox->setWhatsThis(
-	i18n("Here you can select the keys used as global shortcuts to control the player"));
+        i18n("Here you can select the keys used as global shortcuts to control the player"));
 
     m_group->button(selectedButton)->setChecked(true);
-    connect(this, SIGNAL(defaultClicked()), this, SLOT(slotDefault()));
 
-    setMainWidget(vbox);
-    resize(400, 500); // Make it bigger!
-}
+    auto dlgButtonBox = new QDialogButtonBox(
+            QDialogButtonBox::Ok | QDialogButtonBox::Cancel | QDialogButtonBox::RestoreDefaults,
+            this);
+    vboxLayout->addWidget(dlgButtonBox);
 
-KeyDialog::~KeyDialog()
-{
+    connect(dlgButtonBox, &QDialogButtonBox::accepted, this, &QDialog::accept);
+    connect(dlgButtonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
+    connect(dlgButtonBox->button(QDialogButtonBox::RestoreDefaults), &QAbstractButton::clicked,
+            this,                                                    &KeyDialog::slotDefault);
+
+    resize(400, 500); // TODO: Make it bigger!
 }
 
 int KeyDialog::configure()
@@ -200,13 +206,6 @@ void KeyDialog::slotDefault()
     m_pKeyChooser->allDefault();
 }
 
-int KeyDialog::configure(KActionCollection *actionCollection, QWidget *parent)
-{
-    // Create and show dialog - update connections if accepted
-
-    return KeyDialog(actionCollection, parent).configure();
-}
-
 void KeyDialog::setupActionShortcut(const QString &actionName)
 {
     // Find and insert a standard key
diff --git a/keydialog.h b/keydialog.h
index 317ac6d..6574a93 100644
--- a/keydialog.h
+++ b/keydialog.h
@@ -15,36 +15,25 @@
  * this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#ifndef KEYDIALOG_H
-#define KEYDIALOG_H
+#ifndef JUK_KEYDIALOG_H
+#define JUK_KEYDIALOG_H
 
-#include <KDialog>
+#include <QDialog>
 
 class QButtonGroup;
 
 class KActionCollection;
 class KShortcutsEditor;
 
-class KeyDialog : public KDialog
+/**
+ * For keyboard shortcut management.
+ */
+class KeyDialog : public QDialog
 {
     Q_OBJECT
 
 public:
-    /**
-     * Constructs a KeyDialog called @p name as a child of @p parent.
-     */
-    explicit KeyDialog(KActionCollection *actionCollection, QWidget *parent = 0);
-
-    /**
-     * Destructor. Deletes all resources used by a KeyDialog object.
-     */
-    virtual ~KeyDialog();
-
-    /**
-     * This is a member function, provided to allow inserting both global
-     * accelerators and actions.
-     */
-    static int configure(KActionCollection *actionCollection, QWidget *parent = 0);
+    explicit KeyDialog(KActionCollection *actionCollection, QWidget *parent = nullptr);
 
     /**
      * This is a member function, provided to create a global accelerator with
@@ -52,6 +41,9 @@ public:
      */
     static void setupActionShortcut(const QString &actionName);
 
+    // Does exec() and auto-saves any changed config
+    int configure();
+
 private:
 
     /**
@@ -61,16 +53,14 @@ private:
      */
     enum KeyGroup { NoKeys = 0, StandardKeys = 1, MultimediaKeys = 2 };
 
-    int configure();
-
 private slots:
     void slotKeys(int group);
     void slotDefault();
 
 private:
-    KActionCollection *m_actionCollection;
-    KShortcutsEditor  *m_pKeyChooser;
-    QButtonGroup      *m_group;
+    KActionCollection *m_actionCollection = nullptr;
+    KShortcutsEditor  *m_pKeyChooser      = nullptr;
+    QButtonGroup      *m_group            = nullptr;
 
     struct KeyInfo;
 
@@ -78,6 +68,6 @@ private:
     static const uint    keyInfoCount;
 };
 
-#endif // KEYDIALOG_H
+#endif // JUK_KEYDIALOG_H
 
 // vim: set et sw=4 tw=0 sta:

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic