KConfig XT: kcalc.kcfg, an example
Waldo Bastian
bastian at kde.org
Thu Oct 2 12:29:44 BST 2003
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
I will use kdeutils/kcalc to give a quick rundown of things:
kdeutils/kcalc/kcalc.kcfg describes all the kcalc specific settings:
<kcfgfile name="kcalcrc"/>
To say that kcalcrc is the configuration file that we are describing.
<include>kapplication.h</include>
<include>kglobalsettings.h</include>
<include>config.h</include>
Include files needed to be able to compile expressions for default-values.
Note that one of the default values actually depends on HAVE_LONG_DOUBLE.
<group name="Colors">
This starts the description of the [Colors] group in kcalcrc
<entry name="ForeColor" type="QColor">
<desc>The foreground color of the display.</desc>
<default>#000000</default>
</entry>
This describes the ForeColor=... configuration entry. The default is specified
here as the literal value "#000000" aka black.
<entry name="NumberButtonsColor" type="QColor">
<desc>The color of number buttons.</desc>
<code>QColor defaultButtonColor = kapp->palette().active().background();</
code>
<default code="true">defaultButtonColor</default>
</entry>
This describes the NumberButtonsColor=... configuration entry. The default is
specified here using the C++ code "defaultButtonColor". The code="true" part
indicates that "defaultButtonColor" is to interpreted as C++ code and not as
the name of a color. The code inside <code>...</code> will be copied as-is
into the settings class. Since defaultButtonColor is used as default by
several configuration entries
<group name="Precision">
This starts the description of the [Precision] group in kcalcrc
<entry name="FixedPrecision" type="int" key="fixedprecision">
<desc>Number of fixed decimal places.</desc>
<default>2</default>
</entry>
This describes the fixedprecision=... configuration entry. This entry will be
known as "FixedPrecision" though. The default is the literal value 2.
Now have a look at the kcalc_settings.kcfg-codegen file:
# Code generation options for kconfig_compiler
ClassName=KCalcSettings
Singleton=true
# Inherits=KConfigSkeleton
# IncludeFiles=libkdepim/kpimprefs.h
# MemberVariables=public
It generates a singleton-style KCalcSettings class. Using this class the
fixedprecision configuration entry can be accessed with KCalcSettings::
fixedPrecision(). It can also be changed with KCalcSettings::
setFixedPrecision(). The "FixedPrecision" name is used as basis for these
mutator and accessor functions.
This is used in kdeutils/kcalc/dlabel.cpp as follows:
setFont(KCalcSettings::font());
setPrecision(KCalcSettings::precision());
if(KCalcSettings::fixed() == false)
setFixedPrecision(-1);
else
setFixedPrecision(KCalcSettings::fixedPrecision());
Note that kcalc sets the precicion in the KCalcDisplay object. It would
probably be even easier to just use KCalcSettings::fixed() and
KCalcSettings::fixedPrecision() in the the KCalcDisplay object directly. That
would make the way free for "instant-apply" style dialogs at some future date
(KDE 4.0?)
Cheers,
Waldo
- --
bastian at kde.org -=|[ SUSE, The Linux Desktop Experts ]|=- bastian at suse.com
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org
iD8DBQE/fAwoN4pvrENfboIRAmsGAJ9k3lLQQNed0D5nSlrmx9cETkNdoQCeIcnM
egUJ4brUqXpEfvVjh8queWw=
=QekF
-----END PGP SIGNATURE-----
More information about the kde-core-devel
mailing list