-rw-r--r-- | microkde/kdecore/kprefs.cpp | 50 | ||||
-rw-r--r-- | microkde/kdecore/kprefs.h | 15 |
2 files changed, 64 insertions, 1 deletions
diff --git a/microkde/kdecore/kprefs.cpp b/microkde/kdecore/kprefs.cpp index f5e5e5a..71050e7 100644 --- a/microkde/kdecore/kprefs.cpp +++ b/microkde/kdecore/kprefs.cpp @@ -73,6 +73,21 @@ class KPrefsItemColor : public KPrefsItem { QColor mDefault; }; +class KPrefsItemSize : public KPrefsItem { + public: + KPrefsItemSize(const QString &group,const QString &name,QSize *, + const QSize &defaultValue=QSize()); + ~KPrefsItemSize() {} + + void setDefault(); + void readConfig(KConfig *); + void writeConfig(KConfig *); + + private: + QSize *mReference; + QSize mDefault; +}; + class KPrefsItemFont : public KPrefsItem { public: @@ -219,6 +234,33 @@ void KPrefsItemColor::readConfig(KConfig *config) } +KPrefsItemSize::KPrefsItemSize(const QString &group,const QString &name, + QSize *reference,const QSize &defaultValue) : + KPrefsItem(group,name) +{ + mReference = reference; + mDefault = defaultValue; +} + +void KPrefsItemSize::setDefault() +{ + *mReference = mDefault; +} + +void KPrefsItemSize::writeConfig(KConfig *config) +{ + config->setGroup(mGroup); + config->writeEntry(mName,*mReference); +} + +void KPrefsItemSize::readConfig(KConfig *config) +{ + config->setGroup(mGroup); + *mReference = config->readSizeEntry(mName,&mDefault); + +} + + KPrefsItemFont::KPrefsItemFont(const QString &group,const QString &name, QFont *reference,const QFont &defaultValue) : KPrefsItem(group,name) @@ -400,6 +442,7 @@ void KPrefs::readConfig() } usrReadConfig(); + //qDebug("KPrefs::readConfig: %s", mConfig->getFileName().latin1()); } void KPrefs::writeConfig() @@ -410,7 +453,7 @@ void KPrefs::writeConfig() } usrWriteConfig(); - + //qDebug("KPrefs::WriteConfig: %s", mConfig->getFileName().latin1()); mConfig->sync(); } @@ -440,6 +483,11 @@ void KPrefs::addItemFont(const QString &key,QFont *reference,const QFont &defaul addItem(new KPrefsItemFont(*mCurrentGroup,key,reference,defaultValue)); } +void KPrefs::addItemSize(const QString &key,QSize *reference,const QSize &defaultValue) +{ + addItem(new KPrefsItemSize(*mCurrentGroup,key,reference,defaultValue)); +} + void KPrefs::addItemString(const QString &key,QString *reference,const QString &defaultValue) { addItem(new KPrefsItemString(*mCurrentGroup,key,reference,defaultValue,false)); diff --git a/microkde/kdecore/kprefs.h b/microkde/kdecore/kprefs.h index 7014bb8..95d2724 100644 --- a/microkde/kdecore/kprefs.h +++ b/microkde/kdecore/kprefs.h @@ -24,6 +24,7 @@ #include <qptrlist.h> #include <qcolor.h> #include <qfont.h> +#include <qsize.h> #include <qstringlist.h> class KConfig; @@ -207,6 +208,20 @@ class KPrefs { */ void addItemColor(const QString &key,QColor *reference, const QColor &defaultValue=QColor(128,128,128)); + + /** + Register an item of type QSize. + + @param key Key used in config file. + @param reference Pointer to the variable, which is set by readConfig() + and setDefaults() calls and read by writeConfig() calls. + @param defaultValue Default value, which is used by setDefaults() and + when the config file does not yet contain the key of + this item. + */ + void addItemSize(const QString &key,QSize *reference, + const QSize &defaultValue=QSize()); + /** Register an item of type QFont. |