149 QJsonObject paletteObject;
150 for (
auto paletteIterator = map.constBegin(); paletteIterator != map.constEnd();
153 QFlatMap<QPalette::ColorRole, QGtk3Storage::BrushMap> brushMaps;
154 for (
auto brushIterator = bm.constBegin(); brushIterator != bm.constEnd();
156 const QPalette::ColorRole role = brushIterator.key().colorRole;
157 if (brushMaps.contains(role)) {
158 brushMaps[role].insert(brushIterator.key(), brushIterator.value());
161 newMap.insert(brushIterator.key(), brushIterator.value());
162 brushMaps.insert(role, newMap);
166 QJsonObject brushArrayObject;
167 for (
auto brushMapIterator = brushMaps.constBegin();
168 brushMapIterator != brushMaps.constEnd(); ++brushMapIterator) {
170 QJsonArray brushArray;
173 for (
auto brushIterator = bm.constBegin(); brushIterator != bm.constEnd();
175 QJsonObject brushObject;
178 brushObject.insert(ceColorGroup, fromColorGroup(tb.colorGroup));
179 brushObject.insert(ceColorScheme, fromColorScheme(tb.colorScheme));
180 brushObject.insert(ceSourceType, fromSourceType(s.sourceType));
182 QJsonObject sourceObject;
185 sourceObject.insert(ceGtkWidget, fromWidgetType(s.gtk3.gtkWidgetType));
186 sourceObject.insert(ceGdkSource, fromGdkSource(s.gtk3.source));
187 sourceObject.insert(ceGtkState, fromGtkState(s.gtk3.state));
188 sourceObject.insert(ceWidth, s.gtk3.width);
189 sourceObject.insert(ceHeight, s.gtk3.height);
194 QJsonObject fixedObject;
195 fixedObject.insert(ceColor, s.fix.fixedBrush.color().name());
196 fixedObject.insert(ceWidth, s.fix.fixedBrush.texture().width());
197 fixedObject.insert(ceHeight, s.fix.fixedBrush.texture().height());
198 sourceObject.insert(ceBrush, fixedObject);
203 sourceObject.insert(ceColorGroup, fromColorGroup(s.rec.colorGroup));
204 sourceObject.insert(ceColorRole, fromColorRole(s.rec.colorRole));
205 sourceObject.insert(ceColorScheme, fromColorScheme(s.rec.colorScheme));
206 sourceObject.insert(ceRed, s.rec.deltaRed);
207 sourceObject.insert(ceGreen, s.rec.deltaGreen);
208 sourceObject.insert(ceBlue, s.rec.deltaBlue);
209 sourceObject.insert(ceWidth, s.rec.width);
210 sourceObject.insert(ceHeight, s.rec.height);
211 sourceObject.insert(ceLighter, s.rec.lighter);
216 sourceObject.insert(ceColorGroup, fromColorGroup(s.mix.sourceGroup));
217 QJsonArray colorRoles;
218 colorRoles << fromColorRole(s.mix.colorRole1)
219 << fromColorRole(s.mix.colorRole2);
220 sourceObject.insert(ceColorRole, colorRoles);
228 brushObject.insert(ceData, sourceObject);
229 brushArray.insert(brushIndex, brushObject);
232 brushArrayObject.insert(fromColorRole(brushMapIterator.key()), brushArray);
234 paletteObject.insert(fromPalette(paletteIterator.key()), brushArrayObject);
238 top.insert(cePalettes, paletteObject);
239 return paletteObject.keys().isEmpty() ? QJsonDocument() : QJsonDocument(top);
269#define GETSTR(obj, key)
270 if (!obj.contains(key)) {
271 qCInfo(lcQGtk3Interface) << key << "missing for palette" << paletteName
272 << ", Brush" << colorRoleName;
275 value = obj[key].toString()
277#define GETINT(obj, key, var) GETSTR(obj, key);
278 if (!obj[key].isDouble()) {
279 qCInfo(lcQGtk3Interface) << key << "type mismatch" << value
280 << "is not an integer!"
281 << "(Palette" << paletteName << "), Brush" << colorRoleName;
284 const int var = obj[key].toInt()
287 const QJsonObject top(doc.object());
288 if (doc.isEmpty() || top.isEmpty() || !top.contains(cePalettes)) {
289 qCInfo(lcQGtk3Interface) <<
"Document does not contain Palettes.";
293 const QStringList &paletteList = top[cePalettes].toObject().keys();
294 for (
const QString &paletteName : paletteList) {
296 const int intVal = QMetaEnum::fromType<QPlatformTheme::Palette>().keyToValue(paletteName
297 .toLatin1().constData(), &ok);
299 qCInfo(lcQGtk3Interface) <<
"Invalid Palette name:" << paletteName;
302 const QJsonObject &paletteObject = top[cePalettes][paletteName].toObject();
303 const QStringList &brushList = paletteObject.keys();
304 if (brushList.isEmpty()) {
305 qCInfo(lcQGtk3Interface) <<
"Palette" << paletteName <<
"does not contain brushes";
309 const QPlatformTheme::Palette paletteType =
static_cast<QPlatformTheme::Palette>(intVal);
310 QGtk3Storage::BrushMap brushes;
311 const QStringList &colorRoles = paletteObject.keys();
312 for (
const QString &colorRoleName : colorRoles) {
313 const int intVal = QMetaEnum::fromType<QPalette::ColorRole>().keyToValue(colorRoleName
314 .toLatin1().constData(), &ok);
316 qCInfo(lcQGtk3Interface) <<
"Palette" << paletteName
317 <<
"contains invalid color role" << colorRoleName;
320 const QPalette::ColorRole colorRole =
static_cast<QPalette::ColorRole>(intVal);
321 const QJsonArray &brushArray = paletteObject[colorRoleName].toArray();
322 for (
int brushIndex = 0; brushIndex < brushArray.size(); ++brushIndex) {
323 const QJsonObject brushObject = brushArray.at(brushIndex).toObject();
324 if (brushObject.isEmpty()) {
325 qCInfo(lcQGtk3Interface) <<
"Brush specification missing at for palette"
326 << paletteName <<
", Brush" << colorRoleName;
331 GETSTR(brushObject, ceSourceType);
332 const QGtk3Storage::SourceType sourceType = toSourceType(value);
333 GETSTR(brushObject, ceColorGroup);
334 const QPalette::ColorGroup colorGroup = toColorGroup(value);
335 GETSTR(brushObject, ceColorScheme);
336 const Qt::ColorScheme colorScheme = toColorScheme(value);
337 QGtk3Storage::TargetBrush tb(colorGroup, colorRole, colorScheme);
338 QGtk3Storage::Source s;
340 if (!brushObject.contains(ceData) || !brushObject[ceData].isObject()) {
341 qCInfo(lcQGtk3Interface) <<
"Source specification missing for palette" << paletteName
342 <<
"Brush" << colorRoleName;
345 const QJsonObject &sourceObject = brushObject[ceData].toObject();
347 switch (sourceType) {
348 case QGtk3Storage::SourceType::Gtk: {
349 GETSTR(sourceObject, ceGdkSource);
350 const QGtk3Interface::QGtkColorSource gtkSource = toGdkSource(value);
351 GETSTR(sourceObject, ceGtkState);
352 const GtkStateFlags gtkState = toGtkState(value);
353 GETSTR(sourceObject, ceGtkWidget);
354 const QGtk3Interface::QGtkWidget widgetType = toWidgetType(value);
355 GETINT(sourceObject, ceHeight, height);
356 GETINT(sourceObject, ceWidth, width);
357 s = QGtk3Storage::Source(widgetType, gtkSource, gtkState, width, height);
361 case QGtk3Storage::SourceType::Fixed: {
362 if (!sourceObject.contains(ceBrush)) {
363 qCInfo(lcQGtk3Interface) <<
"Fixed brush specification missing for palette" << paletteName
364 <<
"Brush" << colorRoleName;
367 const QJsonObject &fixedSource = sourceObject[ceBrush].toObject();
368 GETINT(fixedSource, ceWidth, width);
369 GETINT(fixedSource, ceHeight, height);
370 GETSTR(fixedSource, ceColor);
371 const QColor color(value);
372 if (!color.isValid()) {
373 qCInfo(lcQGtk3Interface) <<
"Color" << value <<
"can't be parsed for:" << paletteName
374 <<
"Brush" << colorRoleName;
377 const QBrush fixedBrush = (width < 0 && height < 0)
378 ? QBrush(color, QPixmap(width, height))
380 s = QGtk3Storage::Source(fixedBrush);
384 case QGtk3Storage::SourceType::Modified: {
385 GETSTR(sourceObject, ceColorGroup);
386 const QPalette::ColorGroup colorGroup = toColorGroup(value);
387 GETSTR(sourceObject, ceColorRole);
388 const QPalette::ColorRole colorRole = toColorRole(value);
389 GETSTR(sourceObject, ceColorScheme);
390 const Qt::ColorScheme colorScheme = toColorScheme(value);
391 GETINT(sourceObject, ceLighter, lighter);
392 GETINT(sourceObject, ceRed, red);
393 GETINT(sourceObject, ceBlue, blue);
394 GETINT(sourceObject, ceGreen, green);
395 s = QGtk3Storage::Source(colorGroup, colorRole, colorScheme,
396 lighter, red, green, blue);
400 case QGtk3Storage::SourceType::Mixed: {
401 if (!sourceObject[ceColorRole].isArray()) {
402 qCInfo(lcQGtk3Interface) <<
"Mixed brush missing the array of color roles for palette:" << paletteName
403 <<
"Brush" << colorRoleName;
406 QJsonArray colorRoles = sourceObject[ceColorRole].toArray();
407 if (colorRoles.size() < 2) {
408 qCInfo(lcQGtk3Interface) <<
"Mixed brush missing enough color roles for palette" << paletteName
409 <<
"Brush" << colorRoleName;
412 const QPalette::ColorRole colorRole1 = toColorRole(colorRoles[0].toString());
413 const QPalette::ColorRole colorRole2 = toColorRole(colorRoles[1].toString());
414 GETSTR(sourceObject, ceColorGroup);
415 const QPalette::ColorGroup sourceGroup = toColorGroup(value);
416 s = QGtk3Storage::Source(sourceGroup, colorRole1, colorRole2);
420 case QGtk3Storage::SourceType::Invalid:
421 qCInfo(lcQGtk3Interface) <<
"Invalid source type for palette" << paletteName
422 <<
"Brush." << colorRoleName;
425 brushes.insert(tb, s);
428 map.insert(paletteType, brushes);