File indexing completed on 2024-05-12 03:54:28
0001 /* 0002 This file is part of KDE. 0003 SPDX-FileCopyrightText: 2001, 2002, 2003 Cornelius Schumacher <schumacher@kde.org> 0004 SPDX-FileCopyrightText: 2003 Waldo Bastian <bastian@kde.org> 0005 0006 SPDX-License-Identifier: LGPL-2.0-or-later 0007 */ 0008 0009 #ifndef KCONFIGSKELETON_H 0010 #define KCONFIGSKELETON_H 0011 0012 #include <kconfiggui_export.h> 0013 0014 #include <kcoreconfigskeleton.h> 0015 0016 #include <QColor> 0017 #include <QFont> 0018 0019 /** 0020 * @class KConfigSkeleton kconfigskeleton.h <KConfigSkeleton> 0021 * 0022 * @short Class for handling preferences settings for an application. 0023 * @author Cornelius Schumacher 0024 * 0025 * This class extends KCoreConfigSkeleton by support for GUI types. 0026 */ 0027 class KCONFIGGUI_EXPORT KConfigSkeleton : public KCoreConfigSkeleton 0028 { 0029 Q_OBJECT 0030 public: 0031 /** 0032 * Class for handling a color preferences item. 0033 */ 0034 class KCONFIGGUI_EXPORT ItemColor : public KConfigSkeletonGenericItem<QColor> 0035 { 0036 public: 0037 /** @copydoc KConfigSkeletonGenericItem::KConfigSkeletonGenericItem */ 0038 ItemColor(const QString &_group, const QString &_key, QColor &reference, const QColor &defaultValue = QColor(128, 128, 128)); 0039 0040 /** @copydoc KConfigSkeletonItem::readConfig(KConfig*) */ 0041 void readConfig(KConfig *config) override; 0042 0043 /** @copydoc KConfigSkeletonItem::setProperty(const QVariant&) */ 0044 void setProperty(const QVariant &p) override; 0045 0046 /** @copydoc KConfigSkeletonItem::isEqual(const QVariant &) */ 0047 bool isEqual(const QVariant &p) const override; 0048 0049 /** @copydoc KConfigSkeletonItem::property() */ 0050 QVariant property() const override; 0051 }; 0052 0053 /** 0054 * Class for handling a font preferences item. 0055 */ 0056 class KCONFIGGUI_EXPORT ItemFont : public KConfigSkeletonGenericItem<QFont> 0057 { 0058 public: 0059 /** @copydoc KConfigSkeletonGenericItem::KConfigSkeletonGenericItem */ 0060 ItemFont(const QString &_group, const QString &_key, QFont &reference, const QFont &defaultValue = QFont()); 0061 0062 /** @copydoc KConfigSkeletonItem::readConfig(KConfig*) */ 0063 void readConfig(KConfig *config) override; 0064 0065 /** @copydoc KConfigSkeletonItem::setProperty(const QVariant&) */ 0066 void setProperty(const QVariant &p) override; 0067 0068 /** @copydoc KConfigSkeletonItem::isEqual(const QVariant &) */ 0069 bool isEqual(const QVariant &p) const override; 0070 0071 /** @copydoc KConfigSkeletonItem::property() */ 0072 QVariant property() const override; 0073 }; 0074 0075 public: 0076 /** 0077 * Constructor. 0078 * 0079 * @param configname name of config file. If no name is given, the default 0080 * config file as returned by KSharedConfig::openConfig() is used. 0081 */ 0082 explicit KConfigSkeleton(const QString &configname = QString(), QObject *parent = nullptr); 0083 0084 /** 0085 * Constructor. 0086 * 0087 * @param config configuration object to use. 0088 */ 0089 explicit KConfigSkeleton(KSharedConfig::Ptr config, QObject *parent = nullptr); 0090 0091 /** 0092 * Register an item of type QColor. 0093 * 0094 * @param name Name used to identify this setting. Names must be unique. 0095 * @param reference Pointer to the variable, which is set by read() 0096 * calls and read by save() calls. 0097 * @param defaultValue Default value, which is used when the config file 0098 * does not yet contain the key of this item. 0099 * @param key Key used in config file. If @p key is a null string, @p name is used as key. 0100 * @return The created item 0101 */ 0102 ItemColor *addItemColor(const QString &name, QColor &reference, const QColor &defaultValue = QColor(128, 128, 128), const QString &key = QString()); 0103 0104 /** 0105 * Register an item of type QFont. 0106 * 0107 * @param name Name used to identify this setting. Names must be unique. 0108 * @param reference Pointer to the variable, which is set by read() 0109 * calls and read by save() calls. 0110 * @param defaultValue Default value, which is used when the config file 0111 * does not yet contain the key of this item. 0112 * @param key Key used in config file. If @p key is a null string, @p name is used as key. 0113 * @return The created item 0114 */ 0115 ItemFont *addItemFont(const QString &name, QFont &reference, const QFont &defaultValue = QFont(), const QString &key = QString()); 0116 }; 0117 0118 #endif