KCMUtils

kcmultidialog.h
1 /*
2  SPDX-FileCopyrightText: 2000 Matthias Elter <[email protected]>
3  SPDX-FileCopyrightText: 2003 Daniel Molkentin <[email protected]>
4  SPDX-FileCopyrightText: 2003, 2006 Matthias Kretz <[email protected]>
5  SPDX-FileCopyrightText: 2021 Alexander Lohnau <[email protected]>
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 <kcmoduleinfo.h>
18 
19 class KCMultiDialogPrivate;
20 
21 /**
22  * @short A class that offers a KPageDialog containing arbitrary
23  * KControl Modules.
24  *
25  * @author Matthias Elter <[email protected]>, Daniel Molkentin <[email protected]>
26  */
27 class KCMUTILS_EXPORT KCMultiDialog : public KPageDialog
28 {
29  Q_OBJECT
30  Q_DECLARE_PRIVATE(KCMultiDialog)
31 
32 public:
33  /**
34  * Constructs a new KCMultiDialog
35  *
36  * @param parent The parent widget
37  **/
38  explicit KCMultiDialog(QWidget *parent = nullptr);
39 
40  /**
41  * Destructor
42  **/
43  ~KCMultiDialog() override;
44 
45 #if KCMUTILS_ENABLE_DEPRECATED_SINCE(5, 85)
46  /**
47  * Add a module.
48  *
49  * The module is added according to its KCModuleInfo::weight(). The weight determines where in the list
50  * the module will appear. Lighter modules on top, heavier modules at the bottom.
51  *
52  * @param module Specify the name of the module that is to be added
53  * to the list of modules the dialog will show.
54  *
55  * @param args The arguments that should be given to the KCModule when it is created
56  *
57  * @returns The @see KPageWidgetItem associated with the new dialog page.
58  * @deprecated Since 5.85, use @p addModule(const KPluginMetaData &metaData) instead
59  **/
60  KCMUTILS_DEPRECATED_VERSION(5, 85, "use addModule(const KPluginMetaData &metaData) instead")
61  KPageWidgetItem *addModule(const QString &module, const QStringList &args = QStringList());
62 #endif
63 
64  /**
65  * @since 5.84
66  * @overload
67  */
68  KPageWidgetItem *addModule(const KPluginMetaData &metaData);
69 
70  /**
71  * Add a module to the dialog. Its position will be determined based on the @c X-KDE-Weight value.
72  * @param metaData KPluginMetaData that will be used to load the plugin
73  * @param args The arguments that should be given to the KCModule when it is created
74  * @since 5.85
75  */
76  KPageWidgetItem *addModule(const KPluginMetaData &metaData, const QStringList &args); // TODO KF6 merge with overload
77 
78 #if KCMUTILS_ENABLE_DEPRECATED_SINCE(5, 85)
79  /**
80  * Add a module.
81  *
82  * The module is added according to its KCModuleInfo::weight(). The weight determines where in the list
83  * the module will appear. Lighter modules on top, heavier modules at the bottom.
84  *
85  * @param moduleinfo Pass a KCModuleInfo object which will be
86  * used for creating the module. It will be added
87  * to the list of modules the dialog will show.
88  *
89  * @param parent The @see KPageWidgetItem that should appear as parents
90  * in the tree view or a 0 pointer if there is no parent.
91  *
92  * @param args The arguments that should be given to the KCModule when it is created
93  * @deprecated Since 5.85, use @p addModule(const KPluginMetaData &metaData) instead
94  **/
95  KCMUTILS_DEPRECATED_VERSION(5, 85, "use addModule(const KPluginMetaData &metaData) instead")
96  KPageWidgetItem *addModule(const KCModuleInfo &moduleinfo, KPageWidgetItem *parent = nullptr, const QStringList &args = QStringList());
97 #endif
98 
99  /**
100  * Removes all modules from the dialog.
101  */
102  void clear();
103 
104 Q_SIGNALS:
105  /**
106  * Emitted after all KCModules have been told to save their configuration.
107  *
108  * The applyClicked and okClicked signals are emitted before the
109  * configuration is saved.
110  */
111  void configCommitted();
112 
113 #if KCMUTILS_ENABLE_DEPRECATED_SINCE(5, 85)
114  /**
115  * Emitted after the KCModules have been told to save their configuration.
116  * It is emitted once for every instance the KCMs that were changed belong
117  * to.
118  *
119  * You can make use of this if you have more than one component in your
120  * application. componentName tells you the instance that has to reload its
121  * configuration.
122  *
123  * The applyClicked and okClicked signals are emitted before the
124  * configuration is saved.
125  *
126  * @param componentName The name of the instance that needs to reload its
127  * configuration.
128  * @deprecated Since 5.85, use @p KCMultiDialog::configCommitted() instead
129  */
130  KCMUTILS_DEPRECATED_VERSION(5, 85, "use KCMultiDialog::configCommitted() instead")
131  void configCommitted(const QByteArray &componentName);
132 #endif
133 
134 protected:
135  /**
136  * This constructor can be used by subclasses to provide a custom KPageWidget.
137  */
138  KCMultiDialog(KPageWidget *pageWidget, QWidget *parent, Qt::WindowFlags flags = Qt::WindowFlags());
139  KCMultiDialog(KCMultiDialogPrivate &dd, KPageWidget *pageWidget, QWidget *parent, Qt::WindowFlags flags = Qt::WindowFlags());
140 
141  KCMultiDialogPrivate *const d_ptr;
142 
143  void closeEvent(QCloseEvent *event) override;
144  void showEvent(QShowEvent *event) override;
145 
146 protected Q_SLOTS:
147  /**
148  * This slot is called when the user presses the "Default" Button.
149  * You can reimplement it if needed.
150  *
151  * @note Make sure you call the original implementation.
152  **/
153  void slotDefaultClicked();
154 
155  /**
156  * This slot is called when the user presses the "Reset" Button.
157  * You can reimplement it if needed.
158  *
159  * @note Make sure you call the original implementation.
160  */
161  void slotUser1Clicked();
162 
163  /**
164  * This slot is called when the user presses the "Apply" Button.
165  * You can reimplement it if needed.
166  *
167  * @note Make sure you call the original implementation.
168  **/
169  void slotApplyClicked();
170 
171  /**
172  * This slot is called when the user presses the "OK" Button.
173  * You can reimplement it if needed.
174  *
175  * @note Make sure you call the original implementation.
176  **/
177  void slotOkClicked();
178 
179  /**
180  * This slot is called when the user presses the "Help" Button.
181  * It reads the X-DocPath field of the currently selected KControl
182  * module's .desktop file to find the path to the documentation,
183  * which it then attempts to load.
184  *
185  * You can reimplement this slot if needed.
186  *
187  * @note Make sure you call the original implementation.
188  **/
189  void slotHelpClicked();
190 
191 private:
192  Q_PRIVATE_SLOT(d_func(), void _k_slotCurrentPageChanged(KPageWidgetItem *, KPageWidgetItem *))
193  Q_PRIVATE_SLOT(d_func(), void _k_clientChanged())
194  Q_PRIVATE_SLOT(d_func(), void _k_updateHeader(bool use, const QString &message))
195 };
196 
197 /**
198  * @brief Custom QScrollArea class that doesn't limit its size hint
199  *
200  * See original QScrollArea::sizeHint() function,
201  * where the size hint is bound by 36*24 font heights
202  *
203  * Workaround for https://bugreports.qt.io/browse/QTBUG-10459
204  */
205 
207 {
208  Q_OBJECT
209 public:
210  QSize sizeHint() const override
211  {
212  if (widget()) {
213  // Try to avoid horizontal scrollbar, which just scrolls a scrollbar width.
214  // We always need to reserve space for the vertical scroll bar,
215  // because we can’t know here whether vertical scrolling will be used.
216  QSize withScrollbar = widget()->sizeHint();
217  withScrollbar.rwidth() += verticalScrollBar()->sizeHint().width() + 4;
218  return withScrollbar;
219  } else {
220  return QScrollArea::sizeHint();
221  }
222  }
223 
225  : QScrollArea(w)
226  {
227  }
228  ~UnboundScrollArea() override = default;
229 };
230 
231 #endif
virtual void closeEvent(QCloseEvent *e) override
virtual QSize sizeHint() const const override
int & rwidth()
Custom QScrollArea class that doesn&#39;t limit its size hint.
A class that provides information about a KCModule.
Definition: kcmoduleinfo.h:36
virtual void showEvent(QShowEvent *event) override
A class that offers a KPageDialog containing arbitrary KControl Modules.
Definition: kcmultidialog.h:27
typedef WindowFlags
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Sat Dec 4 2021 22:47:25 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.