1 | /* |
2 | This file is part of KDE. |
3 | SPDX-FileCopyrightText: 2001, 2002, 2003 Cornelius Schumacher <schumacher@kde.org> |
4 | SPDX-FileCopyrightText: 2003 Waldo Bastian <bastian@kde.org> |
5 | |
6 | SPDX-License-Identifier: LGPL-2.0-or-later |
7 | */ |
8 | |
9 | #ifndef KCONFIGSKELETON_H |
10 | #define KCONFIGSKELETON_H |
11 | |
12 | #include <kconfiggui_export.h> |
13 | |
14 | #include <kcoreconfigskeleton.h> |
15 | |
16 | #include <QColor> |
17 | #include <QFont> |
18 | |
19 | /** |
20 | * @class KConfigSkeleton kconfigskeleton.h <KConfigSkeleton> |
21 | * |
22 | * @short Class for handling preferences settings for an application. |
23 | * @author Cornelius Schumacher |
24 | * |
25 | * This class extends KCoreConfigSkeleton by support for GUI types. |
26 | */ |
27 | class KCONFIGGUI_EXPORT KConfigSkeleton : public KCoreConfigSkeleton |
28 | { |
29 | Q_OBJECT |
30 | public: |
31 | /** |
32 | * Class for handling a color preferences item. |
33 | */ |
34 | class KCONFIGGUI_EXPORT ItemColor : public KConfigSkeletonGenericItem<QColor> |
35 | { |
36 | public: |
37 | /** @copydoc KConfigSkeletonGenericItem::KConfigSkeletonGenericItem */ |
38 | ItemColor(const QString &_group, const QString &_key, QColor &reference, const QColor &defaultValue = QColor(128, 128, 128)); |
39 | |
40 | /** @copydoc KConfigSkeletonItem::readConfig(KConfig*) */ |
41 | void readConfig(KConfig *config) override; |
42 | |
43 | /** @copydoc KConfigSkeletonItem::setProperty(const QVariant&) */ |
44 | void setProperty(const QVariant &p) override; |
45 | |
46 | /** @copydoc KConfigSkeletonItem::isEqual(const QVariant &) */ |
47 | bool isEqual(const QVariant &p) const override; |
48 | |
49 | /** @copydoc KConfigSkeletonItem::property() */ |
50 | QVariant property() const override; |
51 | }; |
52 | |
53 | /** |
54 | * Class for handling a font preferences item. |
55 | */ |
56 | class KCONFIGGUI_EXPORT ItemFont : public KConfigSkeletonGenericItem<QFont> |
57 | { |
58 | public: |
59 | /** @copydoc KConfigSkeletonGenericItem::KConfigSkeletonGenericItem */ |
60 | ItemFont(const QString &_group, const QString &_key, QFont &reference, const QFont &defaultValue = QFont()); |
61 | |
62 | /** @copydoc KConfigSkeletonItem::readConfig(KConfig*) */ |
63 | void readConfig(KConfig *config) override; |
64 | |
65 | /** @copydoc KConfigSkeletonItem::setProperty(const QVariant&) */ |
66 | void setProperty(const QVariant &p) override; |
67 | |
68 | /** @copydoc KConfigSkeletonItem::isEqual(const QVariant &) */ |
69 | bool isEqual(const QVariant &p) const override; |
70 | |
71 | /** @copydoc KConfigSkeletonItem::property() */ |
72 | QVariant property() const override; |
73 | }; |
74 | |
75 | public: |
76 | /** |
77 | * Constructor. |
78 | * |
79 | * @param configname name of config file. If no name is given, the default |
80 | * config file as returned by KSharedConfig::openConfig() is used. |
81 | */ |
82 | explicit KConfigSkeleton(const QString &configname = QString(), QObject *parent = nullptr); |
83 | |
84 | /** |
85 | * Constructor. |
86 | * |
87 | * @param config configuration object to use. |
88 | */ |
89 | explicit KConfigSkeleton(KSharedConfig::Ptr config, QObject *parent = nullptr); |
90 | |
91 | /** |
92 | * Register an item of type QColor. |
93 | * |
94 | * @param name Name used to identify this setting. Names must be unique. |
95 | * @param reference Pointer to the variable, which is set by read() |
96 | * calls and read by save() calls. |
97 | * @param defaultValue Default value, which is used when the config file |
98 | * does not yet contain the key of this item. |
99 | * @param key Key used in config file. If @p key is a null string, @p name is used as key. |
100 | * @return The created item |
101 | */ |
102 | ItemColor *addItemColor(const QString &name, QColor &reference, const QColor &defaultValue = QColor(128, 128, 128), const QString &key = QString()); |
103 | |
104 | /** |
105 | * Register an item of type QFont. |
106 | * |
107 | * @param name Name used to identify this setting. Names must be unique. |
108 | * @param reference Pointer to the variable, which is set by read() |
109 | * calls and read by save() calls. |
110 | * @param defaultValue Default value, which is used when the config file |
111 | * does not yet contain the key of this item. |
112 | * @param key Key used in config file. If @p key is a null string, @p name is used as key. |
113 | * @return The created item |
114 | */ |
115 | ItemFont *addItemFont(const QString &name, QFont &reference, const QFont &defaultValue = QFont(), const QString &key = QString()); |
116 | }; |
117 | |
118 | #endif |
119 | |