File indexing completed on 2024-12-01 05:02:15

0001 /*
0002     SPDX-FileCopyrightText: 2020 Michail Vourlakos <mvourlakos@gmail.com>
0003     SPDX-License-Identifier: GPL-2.0-or-later
0004 */
0005 
0006 #ifndef SETTINGSGENERICHANDLER_H
0007 #define SETTINGSGENERICHANDLER_H
0008 
0009 //! Qt
0010 #include <QAction>
0011 #include <QObject>
0012 #include <QPushButton>
0013 
0014 // KDE
0015 #include <KMessageWidget>
0016 
0017 namespace Latte {
0018 namespace Settings {
0019 namespace Dialog {
0020 class GenericDialog;
0021 }
0022 }
0023 }
0024 
0025 
0026 namespace Latte {
0027 namespace Settings {
0028 namespace Handler {
0029 
0030 //! Handlers are objects to handle the UI elements that semantically associate with specific
0031 //! ui::tabs or different windows. They are responsible also to handle the user interaction
0032 //! between controllers and views
0033 
0034 class Generic : public QObject
0035 {
0036     Q_OBJECT
0037 public:
0038     static constexpr const char* TWINENABLED = "Enabled";
0039     static constexpr const char* TWINVISIBLE = "Visible";
0040     static constexpr const char* TWINCHECKED = "Checked";
0041 
0042     Generic(Dialog::GenericDialog *parent);
0043     Generic(Dialog::GenericDialog *parentDialog, QObject *parent);
0044 
0045     virtual bool hasChangedData() const = 0;
0046     virtual bool inDefaultValues() const = 0;
0047 
0048     void showInlineMessage(const QString &msg, const KMessageWidget::MessageType &type, const bool &isPersistent = false, QList<QAction *> actions = QList<QAction *>());
0049 
0050 public slots:
0051     virtual void reset() = 0;
0052     virtual void resetDefaults() = 0;
0053     virtual void save() = 0;
0054 
0055 signals:
0056     void dataChanged();
0057 
0058 protected:
0059     void setTwinProperty(QAction *action, const QString &property, QVariant value);
0060     void connectActionWithButton(QPushButton *button, QAction *action);
0061 
0062 private:
0063     //! Twin Actions bind QAction* behavior with QPushButton*
0064     //! for simplicity reasons
0065     QHash<QAction *, QPushButton *> m_twinActions;
0066 
0067     Dialog::GenericDialog *m_dialog;
0068 
0069 
0070 };
0071 
0072 }
0073 }
0074 }
0075 
0076 #endif