not quite so much needs to be delayed to the init() function
[personal-kdebase.git] / workspace / kcontrol / fonts / kxftconfig.h
blob95763b471bf42545642fc623a3aaa543bfbfd17f
1 #ifndef __KXFTCONFIG_H__
2 #define __KXFTCONFIG_H__
4 /*
5 Copyright (c) 2002 Craig Drummond <craig@kde.org>
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Library General Public
9 License as published by the Free Software Foundation; either
10 version 2 of the License, or (at your option) any later version.
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Library General Public License for more details.
17 You should have received a copy of the GNU Library General Public License
18 along with this library; see the file COPYING.LIB. If not, write to
19 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 Boston, MA 02110-1301, USA.
23 #include <config-workspace.h>
25 #ifdef HAVE_FONTCONFIG
27 #include <QStringList>
28 #include <stdio.h>
29 #include <fstream>
30 #include <time.h>
31 #include <QtXml/QtXml>
33 class KXftConfig
35 public:
37 enum RequiredData
39 Dirs = 0x01,
40 SubPixelType = 0x02,
41 ExcludeRange = 0x04,
42 AntiAlias = 0x08,
43 HintStyle = 0x10
46 static const int constStyleSettings=SubPixelType|ExcludeRange|AntiAlias|HintStyle;
48 struct Item
50 Item(QDomNode &n) : node(n), toBeRemoved(false) {}
51 Item() : toBeRemoved(false) {}
52 virtual void reset() { node.clear(); toBeRemoved=false; }
53 bool added() { return node.isNull(); }
55 QDomNode node;
57 virtual ~Item() {}
58 bool toBeRemoved;
61 struct ListItem : public Item
63 ListItem(const QString &st, QDomNode &n) : Item(n), str(st) {}
64 ListItem(const QString &st) : str(st) {}
66 QString str;
69 struct SubPixel : public Item
71 enum Type
73 None,
74 Rgb,
75 Bgr,
76 Vrgb,
77 Vbgr
80 SubPixel(Type t, QDomNode &n) : Item(n), type(t) {}
81 SubPixel(Type t=None) : type(t) {}
83 void reset() { Item::reset(); type=None; }
85 Type type;
88 struct Exclude : public Item
90 Exclude(double f, double t, QDomNode &n) : Item(n), from(f), to(t) {}
91 Exclude(double f=0, double t=0) : from(f), to(t) {}
93 void reset() { Item::reset(); from=to=0; }
95 double from,
96 to;
99 struct Hint : public Item
101 enum Style
103 NotSet,
104 None,
105 Slight,
106 Medium,
107 Full
110 Hint(Style s, QDomNode &n) : Item(n), style(s) {}
111 Hint(Style s=NotSet) : style(s) {}
113 void reset() { Item::reset(); style=NotSet; }
115 Style style;
118 struct Hinting : public Item
120 Hinting(bool s, QDomNode &n) : Item(n), set(s) {}
121 Hinting(bool s=true) : set(s) {}
123 void reset() { Item::reset(); set=true; }
125 bool set;
128 struct AntiAliasing : public Item
130 AntiAliasing(bool s, QDomNode &n) : Item(n), set(s) {}
131 AntiAliasing(bool s=true) : set(s) {}
133 void reset() { Item::reset(); set=true; }
135 bool set;
138 public:
140 static QString contractHome(QString path);
141 static QString expandHome(QString path);
144 // Constructor
145 // required - This should be a bitmask of 'RequiredData', and indicates the data to be
146 // read/written to the config file. It is intended that the 'fonts' KControl
147 // module will use KXftConfig::SubPixelType|KXftConfig::ExcludeRange, and the
148 // font installer will use KXftConfig::Dirs
150 // system - Indicates if the system-wide config file, or the users ~/.xftconfig file
151 // should be used. Only the font-installer should access the system file (and then
152 // only if run as root.
153 explicit KXftConfig(int required, bool system=false);
155 virtual ~KXftConfig();
157 bool reset();
158 bool apply();
159 bool getSubPixelType(SubPixel::Type &type);
160 void setSubPixelType(SubPixel::Type type); // SubPixel::None => turn off sub-pixel rendering
161 bool getExcludeRange(double &from, double &to);
162 void setExcludeRange(double from, double to); // from:0, to:0 => turn off exclude range
163 void addDir(const QString &d);
164 void removeDir(const QString &d);
165 bool getHintStyle(Hint::Style &style);
166 void setHintStyle(Hint::Style style);
167 void setAntiAliasing(bool set);
168 bool getAntiAliasing() const;
169 bool changed() { return m_madeChanges; }
170 static QString description(SubPixel::Type t);
171 static const char * toStr(SubPixel::Type t);
172 static QString description(Hint::Style s);
173 static const char * toStr(Hint::Style s);
174 bool hasDir(const QString &d);
176 private:
178 QStringList getDirList();
179 void readContents();
180 void applyDirs();
181 void applySubPixelType();
182 void applyHintStyle();
183 void applyAntiAliasing();
184 void setHinting(bool set);
185 void applyHinting();
186 void applyExcludeRange(bool pixel);
187 void removeDirs();
189 private:
191 SubPixel m_subPixel;
192 Exclude m_excludeRange,
193 m_excludePixelRange;
194 Hint m_hint;
195 Hinting m_hinting;
196 AntiAliasing m_antiAliasing;
197 bool aliasingEnabled();
198 QDomDocument m_doc;
199 QList<ListItem> m_dirs;
200 QString m_file;
201 int m_required;
202 bool m_madeChanges,
203 m_system;
204 time_t m_time;
207 #endif
209 #endif