1 #ifndef WINDOW_DEFINITION_LIST_WIDGET_H
2 #define WINDOW_DEFINITION_LIST_WIDGET_H
3 /* SPDX-FileCopyrightText: 2009 Michael Jansen <kde@michael-jansen.biz>
4 
5    SPDX-License-Identifier: LGPL-2.0-or-later
6 */
7 
8 #include "hotkeys_widget_iface.h"
9 
10 #include "ui_window_definition_list_widget.h"
11 #include "windows_helper/window_selection_list.h"
12 #include <QDialog>
13 #include <QDialogButtonBox>
14 #include <QVBoxLayout>
15 
16 /**
17  * @author Michael Jansen <kde@michael-jansen.biz>
18  */
19 class WindowDefinitionListWidget : public HotkeysWidgetIFace
20 {
21     Q_OBJECT
22 
23 public:
24     /**
25      * Default constructor
26      */
27     WindowDefinitionListWidget(KHotKeys::Windowdef_list *windowdef_list, QWidget *parent = nullptr);
28 
29     WindowDefinitionListWidget(QWidget *parent);
30 
31     /**
32      * Destructor
33      */
34     virtual ~WindowDefinitionListWidget();
35 
36     void setWindowDefinitions(KHotKeys::Windowdef_list *windowdef_list);
37 
38     bool isChanged() const Q_DECL_OVERRIDE;
39 
40 private:
41     void emitChanged(bool);
42 
43 private Q_SLOTS:
44 
45     void slotDelete(bool);
46     void slotDuplicate(bool);
47     void slotEdit(bool);
48     void slotNew(bool);
49 
50 protected:
51     void doCopyFromObject() Q_DECL_OVERRIDE;
52     void doCopyToObject() Q_DECL_OVERRIDE;
53 
54 private:
55     // The Windowdefinition list
56     KHotKeys::Windowdef_list *_windowdefs;
57     KHotKeys::Windowdef_list *_working;
58 
59     // The User Interface
60     Ui::WindowDefinitionListWidget ui;
61 
62     // Unsaved changes?
63     bool _changed;
64 };
65 
66 class WindowDefinitionListDialog : public QDialog
67 {
68     Q_OBJECT
69 
70 public:
71     WindowDefinitionListDialog(KHotKeys::Windowdef_list *list, QWidget *parent = nullptr)
QDialog(parent)72         : QDialog(parent)
73         , def(nullptr)
74     {
75         setLayout(new QVBoxLayout);
76 
77         def = new WindowDefinitionListWidget(list, this);
78         def->copyFromObject();
79 
80         layout()->addWidget(def);
81 
82         QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
83 
84         layout()->addWidget(buttonBox);
85 
86         connect(buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept);
87         connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
88     }
89 
~WindowDefinitionListDialog()90     ~WindowDefinitionListDialog()
91     {
92         def = nullptr;
93     }
94 
accept()95     void accept() Q_DECL_OVERRIDE
96     {
97         def->copyToObject();
98         QDialog::accept();
99     }
100 
101 private:
102     WindowDefinitionListWidget *def;
103 };
104 
105 #endif /* #ifndef WINDOW_DEFINITION_LIST_WIDGET_H */
106