-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 @@ -64,24 +64,39 @@ class KPrefsItemColor : public KPrefsItem { const QColor &defaultValue=QColor(128,128,128)); virtual ~KPrefsItemColor() {} void setDefault(); void readConfig(KConfig *); void writeConfig(KConfig *); private: QColor *mReference; 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: KPrefsItemFont(const QString &group,const QString &name,QFont *, const QFont &defaultValue=QFont("helvetica",12)); virtual ~KPrefsItemFont() {} void setDefault(); void readConfig(KConfig *); void writeConfig(KConfig *); private: @@ -210,24 +225,51 @@ void KPrefsItemColor::writeConfig(KConfig *config) config->setGroup(mGroup); config->writeEntry(mName,*mReference); } void KPrefsItemColor::readConfig(KConfig *config) { config->setGroup(mGroup); *mReference = config->readColorEntry(mName,&mDefault); } +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) { mReference = reference; mDefault = defaultValue; } void KPrefsItemFont::setDefault() { *mReference = mDefault; } @@ -391,35 +433,36 @@ void KPrefs::setDefaults() usrSetDefaults(); } void KPrefs::readConfig() { KPrefsItem *item; for(item = mItems.first();item;item = mItems.next()) { item->readConfig(mConfig); } usrReadConfig(); + //qDebug("KPrefs::readConfig: %s", mConfig->getFileName().latin1()); } void KPrefs::writeConfig() { KPrefsItem *item; for(item = mItems.first();item;item = mItems.next()) { item->writeConfig(mConfig); } usrWriteConfig(); - + //qDebug("KPrefs::WriteConfig: %s", mConfig->getFileName().latin1()); mConfig->sync(); } void KPrefs::addItem(KPrefsItem *item) { mItems.append(item); } void KPrefs::addItemBool(const QString &key,bool *reference,bool defaultValue) { addItem(new KPrefsItemBool(*mCurrentGroup,key,reference,defaultValue)); @@ -431,24 +474,29 @@ void KPrefs::addItemInt(const QString &key,int *reference,int defaultValue) } void KPrefs::addItemColor(const QString &key,QColor *reference,const QColor &defaultValue) { addItem(new KPrefsItemColor(*mCurrentGroup,key,reference,defaultValue)); } void KPrefs::addItemFont(const QString &key,QFont *reference,const QFont &defaultValue) { 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)); } void KPrefs::addItemPassword(const QString &key,QString *reference,const QString &defaultValue) { addItem(new KPrefsItemString(*mCurrentGroup,key,reference,defaultValue,true)); } void KPrefs::addItemStringList(const QString &key,QStringList *reference, const QStringList &defaultValue) 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 @@ -15,24 +15,25 @@ You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #ifndef _KPREFS_H #define _KPREFS_H // $Id$ #include <qptrlist.h> #include <qcolor.h> #include <qfont.h> +#include <qsize.h> #include <qstringlist.h> class KConfig; /** @short Class for storing a preferences setting @author Cornelius Schumacher @see KPref This class represents one preferences setting as used by @ref KPrefs. Subclasses of KPrefsItem implement storage functions for a certain type of setting. Normally you don't have to use this class directly. Use the special @@ -198,24 +199,38 @@ class KPrefs { /** Register an item of type QColor. @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 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. @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 addItemFont(const QString &key,QFont *reference, const QFont &defaultValue=QFont("helvetica",12)); |