File indexing completed on 2025-01-05 04:54:24
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 #pragma once 0011 0012 #include <QScrollArea> 0013 #include <QScrollBar> 0014 0015 #include <KPageDialog> 0016 #include <KPluginMetaData> 0017 0018 class KontactKCMultiDialogPrivate; 0019 0020 /** 0021 * @short A class that offers a KPageDialog containing arbitrary 0022 * KControl Modules. 0023 * 0024 * @author Matthias Elter <elter@kde.org>, Daniel Molkentin <molkentin@kde.org> 0025 */ 0026 class KontactKCMultiDialog : public KPageDialog 0027 { 0028 Q_OBJECT 0029 Q_DECLARE_PRIVATE(KontactKCMultiDialog) 0030 0031 public: 0032 explicit KontactKCMultiDialog(QWidget *parent = nullptr); 0033 ~KontactKCMultiDialog() override; 0034 0035 /** 0036 * Add a module to the dialog. Its position will be determined based on the @c X-KDE-Weight value. 0037 * @param metaData KPluginMetaData that will be used to load the plugin 0038 * @since 5.84 0039 */ 0040 KPageWidgetItem *addModule(const KPluginMetaData &metaData, KPageWidgetItem *parent = nullptr); 0041 0042 Q_SIGNALS: 0043 /** 0044 * Emitted after the KCModules have been told to save their configuration. 0045 * It is emitted once for every instance the KCMs that were changed belong 0046 * to. 0047 * 0048 * You can make use of this if you have more than one component in your 0049 * application. componentName tells you the instance that has to reload its 0050 * configuration. 0051 * 0052 * The applyClicked and okClicked signals are emitted before the 0053 * configuration is saved. 0054 * 0055 * @param componentName The name of the instance that needs to reload its 0056 * configuration. 0057 */ 0058 void configCommitted(const QByteArray &componentName); 0059 0060 protected: 0061 /** 0062 * This constructor can be used by subclasses to provide a custom KPageWidget. 0063 */ 0064 KontactKCMultiDialog(KontactKCMultiDialogPrivate &dd, KPageWidget *pageWidget, QWidget *parent, Qt::WindowFlags flags = Qt::WindowFlags()); 0065 0066 KontactKCMultiDialogPrivate *const d_ptr; 0067 0068 void closeEvent(QCloseEvent *event) override; 0069 void showEvent(QShowEvent *event) override; 0070 0071 protected Q_SLOTS: 0072 /** 0073 * This slot is called when the user presses the "Default" Button. 0074 * You can reimplement it if needed. 0075 * 0076 * @note Make sure you call the original implementation. 0077 **/ 0078 void slotDefaultClicked(); 0079 0080 /** 0081 * This slot is called when the user presses the "Reset" Button. 0082 * You can reimplement it if needed. 0083 * 0084 * @note Make sure you call the original implementation. 0085 */ 0086 void slotUser1Clicked(); 0087 0088 /** 0089 * This slot is called when the user presses the "Apply" Button. 0090 * You can reimplement it if needed. 0091 * 0092 * @note Make sure you call the original implementation. 0093 **/ 0094 void slotApplyClicked(); 0095 0096 /** 0097 * This slot is called when the user presses the "OK" Button. 0098 * You can reimplement it if needed. 0099 * 0100 * @note Make sure you call the original implementation. 0101 **/ 0102 void slotOkClicked(); 0103 0104 /** 0105 * This slot is called when the user presses the "Help" Button. 0106 * It reads the X-DocPath field of the currently selected KControl 0107 * module's .desktop file to find the path to the documentation, 0108 * which it then attempts to load. 0109 * 0110 * You can reimplement this slot if needed. 0111 * 0112 * @note Make sure you call the original implementation. 0113 **/ 0114 void slotHelpClicked(); 0115 0116 private: 0117 Q_PRIVATE_SLOT(d_func(), void _k_slotCurrentPageChanged(KPageWidgetItem *, KPageWidgetItem *)) 0118 Q_PRIVATE_SLOT(d_func(), void _k_clientChanged()) 0119 }; 0120 0121 /** 0122 * @brief Custom QScrollArea class that doesn't limit its size hint 0123 * 0124 * See original QScrollArea::sizeHint() function, 0125 * where the size hint is bound by 36*24 font heights 0126 * 0127 * Workaround for https://bugreports.qt.io/browse/QTBUG-10459 0128 */ 0129 0130 class UnboundScrollArea : public QScrollArea 0131 { 0132 Q_OBJECT 0133 public: 0134 QSize sizeHint() const override 0135 { 0136 if (widget()) { 0137 // Try to avoid horizontal scrollbar, which just scrolls a scrollbar width. 0138 // We always need to reserve space for the vertical scroll bar, 0139 // because we can’t know here whether vertical scrolling will be used. 0140 QSize withScrollbar = widget()->sizeHint(); 0141 withScrollbar.rwidth() += verticalScrollBar()->sizeHint().width() + 4; 0142 return withScrollbar; 0143 } else { 0144 return QScrollArea::sizeHint(); 0145 } 0146 } 0147 0148 explicit UnboundScrollArea(QWidget *w) 0149 : QScrollArea(w) 0150 { 0151 } 0152 ~UnboundScrollArea() override = default; 0153 };