File indexing completed on 2024-04-28 03:53:01

0001 /*
0002     SPDX-FileCopyrightText: 2000 Matthias Elter <elter@kde.org>
0003     SPDX-FileCopyrightText: 2003 Daniel Molkentin <molkentin@kde.org>
0004     SPDX-FileCopyrightText: 2003, 2006 Matthias Kretz <kretz@kde.org>
0005     SPDX-FileCopyrightText: 2021 Alexander Lohnau <alexander.lohnau@gmx.de>
0006 
0007     SPDX-License-Identifier: LGPL-2.0-or-later
0008 */
0009 
0010 #ifndef KCMULTIDIALOG_H
0011 #define KCMULTIDIALOG_H
0012 
0013 #include <QScrollArea>
0014 #include <QScrollBar>
0015 
0016 #include <KPageDialog>
0017 #include <KPluginMetaData>
0018 
0019 #include "kcmutils_export.h"
0020 
0021 class KCMultiDialogPrivate;
0022 
0023 /**
0024  * @short A class that offers a KPageDialog containing config modules
0025  *
0026  * @author Matthias Elter <elter@kde.org>, Daniel Molkentin <molkentin@kde.org>
0027  */
0028 class KCMUTILS_EXPORT KCMultiDialog : public KPageDialog
0029 {
0030     Q_OBJECT
0031 
0032 public:
0033     /**
0034      * Constructs a new KCMultiDialog
0035      *
0036      * @param parent The parent widget
0037      **/
0038     explicit KCMultiDialog(QWidget *parent = nullptr);
0039 
0040     /**
0041      * Destructor
0042      **/
0043     ~KCMultiDialog() override;
0044 
0045     /**
0046      * Add a module to the dialog. Its position will be determined based on the @c X-KDE-Weight value.
0047      * @param metaData KPluginMetaData that will be used to load the plugin
0048      * @param args The arguments that should be given to the KCModule when it is created
0049      */
0050     KPageWidgetItem *addModule(const KPluginMetaData &metaData, const QVariantList &args = {});
0051 
0052     /**
0053      * Removes all modules from the dialog.
0054      */
0055     void clear();
0056 
0057     /**
0058      * Show or hide an indicator when settings have changed from their default value
0059      *
0060      * @since 6.0
0061      */
0062     void setDefaultsIndicatorsVisible(bool show);
0063 
0064 Q_SIGNALS:
0065     /**
0066      * Emitted after all KCModules have been told to save their configuration.
0067      *
0068      * The applyClicked and okClicked signals are emitted before the
0069      * configuration is saved.
0070      */
0071     void configCommitted();
0072 
0073 protected:
0074     void closeEvent(QCloseEvent *event) override;
0075     void showEvent(QShowEvent *event) override;
0076 
0077 protected Q_SLOTS:
0078     /**
0079      * This slot is called when the user presses the "Default" Button.
0080      * You can reimplement it if needed.
0081      *
0082      * @note Make sure you call the original implementation.
0083      **/
0084     void slotDefaultClicked();
0085 
0086     /**
0087      * This slot is called when the user presses the "Reset" Button.
0088      * You can reimplement it if needed.
0089      *
0090      * @note Make sure you call the original implementation.
0091      */
0092     void slotUser1Clicked();
0093 
0094     /**
0095      * This slot is called when the user presses the "Apply" Button.
0096      * You can reimplement it if needed.
0097      *
0098      * @note Make sure you call the original implementation.
0099      **/
0100     void slotApplyClicked();
0101 
0102     /**
0103      * This slot is called when the user presses the "OK" Button.
0104      * You can reimplement it if needed.
0105      *
0106      * @note Make sure you call the original implementation.
0107      **/
0108     void slotOkClicked();
0109 
0110     /**
0111      * This slot is called when the user presses the "Help" Button.
0112      * It reads the X-DocPath field of the currently selected KControl
0113      * module's .desktop file to find the path to the documentation,
0114      * which it then attempts to load.
0115      *
0116      * You can reimplement this slot if needed.
0117      *
0118      * @note Make sure you call the original implementation.
0119      **/
0120     void slotHelpClicked();
0121 
0122 private:
0123     friend KCMultiDialogPrivate;
0124     const std::unique_ptr<KCMultiDialogPrivate> d;
0125 };
0126 
0127 /**
0128  * @brief Custom QScrollArea class that doesn't limit its size hint
0129  *
0130  * See original QScrollArea::sizeHint() function,
0131  * where the size hint is bound by 36*24 font heights
0132  *
0133  * Workaround for https://bugreports.qt.io/browse/QTBUG-10459
0134  */
0135 
0136 class UnboundScrollArea : public QScrollArea
0137 {
0138     Q_OBJECT
0139 public:
0140     QSize sizeHint() const override
0141     {
0142         if (widget()) {
0143             // Try to avoid horizontal scrollbar, which just scrolls a scrollbar width.
0144             // We always need to reserve space for the vertical scroll bar,
0145             // because we can’t know here whether vertical scrolling will be used.
0146             QSize withScrollbar = widget()->sizeHint();
0147             withScrollbar.rwidth() += verticalScrollBar()->sizeHint().width() + 4;
0148             return withScrollbar;
0149         } else {
0150             return QScrollArea::sizeHint();
0151         }
0152     }
0153 
0154     explicit UnboundScrollArea(QWidget *w)
0155         : QScrollArea(w)
0156     {
0157     }
0158     ~UnboundScrollArea() override = default;
0159 };
0160 
0161 #endif