From c149f38f118d607e1cd0e2fbb62575e262355480 Mon Sep 17 00:00:00 2001 From: karliss Date: Fri, 7 Aug 2020 17:01:50 +0300 Subject: [PATCH] Output colors in rgb:nnnnnn format instead of #nnnnnn. (#2376) ec name #nnnnnn can get mixed up with comment. --- src/common/ColorThemeWorker.cpp | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/src/common/ColorThemeWorker.cpp b/src/common/ColorThemeWorker.cpp index f24947fa..c0484343 100644 --- a/src/common/ColorThemeWorker.cpp +++ b/src/common/ColorThemeWorker.cpp @@ -122,26 +122,27 @@ QString ColorThemeWorker::save(const QJsonDocument &theme, const QString &themeN } QJsonObject obj = theme.object(); - QString line; - QColor::NameFormat format; for (auto it = obj.constBegin(); it != obj.constEnd(); it++) { - if (cutterSpecificOptions.contains(it.key())) { - line = "#~%1 %2\n"; - format = QColor::HexArgb; - } else { - line = "ec %1 %2\n"; - format = QColor::HexRgb; - } + QJsonArray arr = it.value().toArray(); + QColor color; if (arr.isEmpty()) { - fOut.write(line.arg(it.key()) - .arg(it.value().toVariant().value().name(format)).toUtf8()); + color = it.value().toVariant().value(); } else if (arr.size() == 4) { - fOut.write(line.arg(it.key()) - .arg(QColor(arr[0].toInt(), arr[1].toInt(), arr[2].toInt(), arr[3].toInt()).name(format)).toUtf8()); + color = QColor(arr[0].toInt(), arr[1].toInt(), arr[2].toInt(), arr[3].toInt()); } else if (arr.size() == 3) { - fOut.write(line.arg(it.key()) - .arg(QColor(arr[0].toInt(), arr[1].toInt(), arr[2].toInt()).name(format)).toUtf8()); + color = QColor(arr[0].toInt(), arr[1].toInt(), arr[2].toInt()); + } else { + continue; + } + if (cutterSpecificOptions.contains(it.key())) { + fOut.write(QString("#~%1 rgb:%2\n") + .arg(it.key(), color.name(QColor::HexArgb).remove('#')) + .toUtf8()); + } else { + fOut.write(QString("ec %1 rgb:%2\n") + .arg(it.key(), color.name(QColor::HexRgb).remove('#')) + .toUtf8()); } }