| 1 | /* |
| 2 | SPDX-FileCopyrightText: 2000 Matthias Elter <elter@kde.org> |
| 3 | SPDX-FileCopyrightText: 2003 Daniel Molkentin <molkentin@kde.org> |
| 4 | SPDX-FileCopyrightText: 2003, 2006 Matthias Kretz <kretz@kde.org> |
| 5 | SPDX-FileCopyrightText: 2021 Alexander Lohnau <alexander.lohnau@gmx.de> |
| 6 | |
| 7 | SPDX-License-Identifier: LGPL-2.0-or-later |
| 8 | */ |
| 9 | |
| 10 | #ifndef KCMULTIDIALOG_H |
| 11 | #define KCMULTIDIALOG_H |
| 12 | |
| 13 | #include <QScrollArea> |
| 14 | #include <QScrollBar> |
| 15 | |
| 16 | #include <KPageDialog> |
| 17 | #include <KPluginMetaData> |
| 18 | |
| 19 | #include "kcmutils_export.h" |
| 20 | |
| 21 | class KCMultiDialogPrivate; |
| 22 | |
| 23 | /*! |
| 24 | * \brief A class that offers a KPageDialog containing config modules. |
| 25 | * \inmodule KCMUtils |
| 26 | */ |
| 27 | class KCMUTILS_EXPORT KCMultiDialog : public KPageDialog |
| 28 | { |
| 29 | Q_OBJECT |
| 30 | |
| 31 | public: |
| 32 | /*! |
| 33 | * \brief Constructs a new KCMultiDialog. |
| 34 | * |
| 35 | * \a parent The parent widget. |
| 36 | **/ |
| 37 | explicit KCMultiDialog(QWidget *parent = nullptr); |
| 38 | |
| 39 | ~KCMultiDialog() override; |
| 40 | |
| 41 | /*! |
| 42 | * \brief Adds a module to the dialog. Its position will be determined based on the \c X-KDE-Weight value. |
| 43 | * |
| 44 | * \a metaData KPluginMetaData that will be used to load the plugin. |
| 45 | * |
| 46 | * \a args The arguments that should be given to the KCModule when it is created. |
| 47 | */ |
| 48 | KPageWidgetItem *addModule(const KPluginMetaData &metaData, const QVariantList &args = {}); |
| 49 | |
| 50 | /*! |
| 51 | * \brief Removes all modules from the dialog. |
| 52 | */ |
| 53 | void clear(); |
| 54 | |
| 55 | /*! |
| 56 | * \brief Whether to \a show or hide an indicator when settings have changed from their default value. |
| 57 | * |
| 58 | * \since 6.0 |
| 59 | */ |
| 60 | void setDefaultsIndicatorsVisible(bool show); |
| 61 | |
| 62 | Q_SIGNALS: |
| 63 | /*! |
| 64 | * \brief Emitted after all KCModules have been told to save their configuration. |
| 65 | * |
| 66 | * The applyClicked and okClicked signals are emitted before the |
| 67 | * configuration is saved. |
| 68 | */ |
| 69 | void configCommitted(); |
| 70 | |
| 71 | protected: |
| 72 | void closeEvent(QCloseEvent *event) override; |
| 73 | void showEvent(QShowEvent *event) override; |
| 74 | |
| 75 | protected Q_SLOTS: |
| 76 | /*! |
| 77 | * \brief This slot is called when the user presses the "Default" Button. |
| 78 | * |
| 79 | * You can reimplement it if needed. |
| 80 | * |
| 81 | * \note Make sure you call the original implementation. |
| 82 | **/ |
| 83 | void slotDefaultClicked(); |
| 84 | |
| 85 | /*! |
| 86 | * \brief This slot is called when the user presses the "Reset" Button. |
| 87 | * You can reimplement it if needed. |
| 88 | * |
| 89 | * \note Make sure you call the original implementation. |
| 90 | */ |
| 91 | void slotUser1Clicked(); |
| 92 | |
| 93 | /*! |
| 94 | * \brief This slot is called when the user presses the "Apply" Button. |
| 95 | * You can reimplement it if needed. |
| 96 | * |
| 97 | * \note Make sure you call the original implementation. |
| 98 | **/ |
| 99 | void slotApplyClicked(); |
| 100 | |
| 101 | /*! |
| 102 | * \brief This slot is called when the user presses the "OK" Button. |
| 103 | * You can reimplement it if needed. |
| 104 | * |
| 105 | * \note Make sure you call the original implementation. |
| 106 | **/ |
| 107 | void slotOkClicked(); |
| 108 | |
| 109 | /*! |
| 110 | * \brief This slot is called when the user presses the "Help" Button. |
| 111 | * |
| 112 | * It reads the X-DocPath field of the currently selected KControl |
| 113 | * module's .desktop file to find the path to the documentation, |
| 114 | * which it then attempts to load. |
| 115 | * |
| 116 | * You can reimplement this slot if needed. |
| 117 | * |
| 118 | * \note Make sure you call the original implementation. |
| 119 | **/ |
| 120 | void slotHelpClicked(); |
| 121 | |
| 122 | private: |
| 123 | friend KCMultiDialogPrivate; |
| 124 | const std::unique_ptr<KCMultiDialogPrivate> d; |
| 125 | bool eventFilter(QObject *watched, QEvent *event) override; |
| 126 | }; |
| 127 | |
| 128 | class UnboundScrollArea : public QScrollArea |
| 129 | { |
| 130 | Q_OBJECT |
| 131 | public: |
| 132 | QSize sizeHint() const override |
| 133 | { |
| 134 | if (widget()) { |
| 135 | // Try to avoid horizontal scrollbar, which just scrolls a scrollbar width. |
| 136 | // We always need to reserve space for the vertical scroll bar, |
| 137 | // because we can’t know here whether vertical scrolling will be used. |
| 138 | QSize withScrollbar = widget()->sizeHint(); |
| 139 | withScrollbar.rwidth() += verticalScrollBar()->sizeHint().width() + 4; |
| 140 | return withScrollbar; |
| 141 | } else { |
| 142 | return QScrollArea::sizeHint(); |
| 143 | } |
| 144 | } |
| 145 | |
| 146 | explicit UnboundScrollArea(QWidget *w) |
| 147 | : QScrollArea(w) |
| 148 | { |
| 149 | } |
| 150 | ~UnboundScrollArea() override = default; |
| 151 | }; |
| 152 | |
| 153 | #endif |
| 154 | |