File indexing completed on 2024-04-28 16:44:48

0001 #ifndef WINDOW_DEFINITION_LIST_WIDGET_H
0002 #define WINDOW_DEFINITION_LIST_WIDGET_H
0003 /* SPDX-FileCopyrightText: 2009 Michael Jansen <kde@michael-jansen.biz>
0004 
0005    SPDX-License-Identifier: LGPL-2.0-or-later
0006 */
0007 
0008 #include "hotkeys_widget_iface.h"
0009 
0010 #include "ui_window_definition_list_widget.h"
0011 #include "windows_helper/window_selection_list.h"
0012 #include <QDialog>
0013 #include <QDialogButtonBox>
0014 #include <QVBoxLayout>
0015 
0016 /**
0017  * @author Michael Jansen <kde@michael-jansen.biz>
0018  */
0019 class WindowDefinitionListWidget : public HotkeysWidgetIFace
0020 {
0021     Q_OBJECT
0022 
0023 public:
0024     /**
0025      * Default constructor
0026      */
0027     WindowDefinitionListWidget(KHotKeys::Windowdef_list *windowdef_list, QWidget *parent = nullptr);
0028 
0029     WindowDefinitionListWidget(QWidget *parent);
0030 
0031     /**
0032      * Destructor
0033      */
0034     ~WindowDefinitionListWidget() override;
0035 
0036     void setWindowDefinitions(KHotKeys::Windowdef_list *windowdef_list);
0037 
0038     bool isChanged() const override;
0039 
0040 private:
0041     void emitChanged(bool);
0042 
0043 private Q_SLOTS:
0044 
0045     void slotDelete(bool);
0046     void slotDuplicate(bool);
0047     void slotEdit(bool);
0048     void slotNew(bool);
0049 
0050 protected:
0051     void doCopyFromObject() override;
0052     void doCopyToObject() override;
0053 
0054 private:
0055     // The Windowdefinition list
0056     KHotKeys::Windowdef_list *_windowdefs;
0057     KHotKeys::Windowdef_list *_working;
0058 
0059     // The User Interface
0060     Ui::WindowDefinitionListWidget ui;
0061 
0062     // Unsaved changes?
0063     bool _changed;
0064 };
0065 
0066 class WindowDefinitionListDialog : public QDialog
0067 {
0068     Q_OBJECT
0069 
0070 public:
0071     WindowDefinitionListDialog(KHotKeys::Windowdef_list *list, QWidget *parent = nullptr)
0072         : QDialog(parent)
0073         , def(nullptr)
0074     {
0075         setLayout(new QVBoxLayout);
0076 
0077         def = new WindowDefinitionListWidget(list, this);
0078         def->copyFromObject();
0079 
0080         layout()->addWidget(def);
0081 
0082         QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
0083 
0084         layout()->addWidget(buttonBox);
0085 
0086         connect(buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept);
0087         connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
0088     }
0089 
0090     ~WindowDefinitionListDialog() override
0091     {
0092         def = nullptr;
0093     }
0094 
0095     void accept() override
0096     {
0097         def->copyToObject();
0098         QDialog::accept();
0099     }
0100 
0101 private:
0102     WindowDefinitionListWidget *def;
0103 };
0104 
0105 #endif /* #ifndef WINDOW_DEFINITION_LIST_WIDGET_H */