23 #include <QtCore/QMutableStringListIterator>
24 #include <QtGui/QColor>
25 #include <QtGui/QFont>
41 const QString errString = QString::fromLatin1(
"\"%1\" - conversion from \"%3\" to %2 failed")
43 .arg(QVariant::typeToName(input.type()))
44 .arg(data.constData());
45 const QString formatError = QString::fromLatin1(
" (wrong format: expected '%1' items, read '%2')");
50 switch (input.type()) {
51 case QVariant::Color: {
52 if (data.isEmpty() || data ==
"invalid") {
55 }
else if (data.at(0) ==
'#') {
57 col.setNamedColor(QString::fromUtf8(data.constData(), data.length()));
60 }
else if (!data.contains(
',')) {
62 col.setNamedColor(QString::fromUtf8(data.constData(), data.length()));
64 kError() << qPrintable(errString);
69 const int count = list.count();
71 if (count != 3 && count != 4) {
72 kError() << qPrintable(errString) << qPrintable(formatError.arg(
"3' or '4").arg(count));
78 for(
int i = 0; i < count; i++) {
80 const int j = temp[i] = list.at(i).toInt(&ok);
82 kError() << qPrintable(errString) <<
" (integer conversion failed)";
85 if (j < 0 || j > 255) {
86 static const char *
const components[6] = {
87 "red",
"green",
"blue",
"alpha"
89 const QString boundsError = QLatin1String(
" (bounds error: %1 component %2)");
90 kError() << qPrintable(errString)
91 << qPrintable(boundsError.arg(components[i]).arg(j < 0?
"< 0":
"> 255"));
95 QColor aColor(temp[0], temp[1], temp[2]);
97 aColor.setAlpha(temp[3]);
102 kError() << qPrintable(errString);
107 case QVariant::Font: {
108 QVariant tmp = QString::fromUtf8(data.constData(), data.length());
109 if (tmp.convert(QVariant::Font))
112 kError() << qPrintable(errString);
115 case QVariant::Pixmap:
116 case QVariant::Image:
117 case QVariant::Brush:
118 case QVariant::Palette:
120 case QVariant::Region:
121 case QVariant::Bitmap:
122 case QVariant::Cursor:
123 case QVariant::SizePolicy:
141 KConfigGroup::WriteConfigFlags pFlags)
143 switch (prop.type()) {
144 case QVariant::Color: {
147 if (!rColor.isValid()) {
153 list.insert(0, rColor.red());
154 list.insert(1, rColor.green());
155 list.insert(2, rColor.blue());
156 if (rColor.alpha() != 255)
157 list.insert(3, rColor.alpha());
163 cg->
writeEntry( key, prop.toString().toUtf8(), pFlags );
166 case QVariant::Pixmap:
167 case QVariant::Image:
168 case QVariant::Brush:
169 case QVariant::Palette:
171 case QVariant::Region:
172 case QVariant::Bitmap:
173 case QVariant::Cursor:
174 case QVariant::SizePolicy:
193 #ifdef Q_CONSTRUCTOR_FUNCTION
kWriteEntryGui writeEntryGui
static int initKConfigGroupGui()
static QDebug kError(bool cond, int area=KDE_DEFAULT_DEBUG_AREA)
static int dummyKConfigGroupGui
void writeEntry(const QString &key, const QVariant &value, WriteConfigFlags pFlags=Normal)
static bool writeEntryGui(KConfigGroup *cg, const char *key, const QVariant &prop, KConfigGroup::WriteConfigFlags pFlags)
Try to write a GUI type prop to config group cg at key key.
kReadEntryGui readEntryGui
static bool readEntryGui(const QByteArray &data, const char *key, const QVariant &input, QVariant &output)
Try to read a GUI type from config group cg at key key.
KGuiItem ok()
Returns the 'Ok' gui item.
KConfigGroupGui _kde_internal_KConfigGroupGui