Fixed save / load of fade effect configurations

This commit is contained in:
Olivier Prat 2018-02-06 17:57:04 +01:00
parent fc1d9319bd
commit 733d36df47
3 changed files with 58 additions and 78 deletions

View file

@ -297,19 +297,20 @@ float FadeConfig::getEdgeWidth() const {
return sqrtf(events[editedCategory].edgeWidth);
}
void FadeConfig::setEdgeInnerColorR(float value) {
events[editedCategory].edgeInnerColor.r = value;
void FadeConfig::setEdgeInnerColor(const QColor& value) {
events[editedCategory].edgeInnerColor.r = value.redF();
events[editedCategory].edgeInnerColor.g = value.greenF();
events[editedCategory].edgeInnerColor.b = value.blueF();
emit dirty();
}
void FadeConfig::setEdgeInnerColorG(float value) {
events[editedCategory].edgeInnerColor.g = value;
emit dirty();
}
void FadeConfig::setEdgeInnerColorB(float value) {
events[editedCategory].edgeInnerColor.b = value;
emit dirty();
QColor FadeConfig::getEdgeInnerColor() const {
QColor color;
color.setRedF(events[editedCategory].edgeInnerColor.r);
color.setGreenF(events[editedCategory].edgeInnerColor.g);
color.setBlueF(events[editedCategory].edgeInnerColor.b);
color.setAlphaF(1.0f);
return color;
}
void FadeConfig::setEdgeInnerIntensity(float value) {
@ -317,19 +318,20 @@ void FadeConfig::setEdgeInnerIntensity(float value) {
emit dirty();
}
void FadeConfig::setEdgeOuterColorR(float value) {
events[editedCategory].edgeOuterColor.r = value;
void FadeConfig::setEdgeOuterColor(const QColor& value) {
events[editedCategory].edgeOuterColor.r = value.redF();
events[editedCategory].edgeOuterColor.g = value.greenF();
events[editedCategory].edgeOuterColor.b = value.blueF();
emit dirty();
}
void FadeConfig::setEdgeOuterColorG(float value) {
events[editedCategory].edgeOuterColor.g = value;
emit dirty();
}
void FadeConfig::setEdgeOuterColorB(float value) {
events[editedCategory].edgeOuterColor.b = value;
emit dirty();
QColor FadeConfig::getEdgeOuterColor() const {
QColor color;
color.setRedF(events[editedCategory].edgeOuterColor.r);
color.setGreenF(events[editedCategory].edgeOuterColor.g);
color.setBlueF(events[editedCategory].edgeOuterColor.b);
color.setAlphaF(1.0f);
return color;
}
void FadeConfig::setEdgeOuterIntensity(float value) {
@ -352,13 +354,13 @@ QString FadeConfig::eventNames[FADE_CATEGORY_COUNT] = {
};
void FadeConfig::save() const {
// Save will only work if the HIFI_USE_SOURCE_TREE_RESOURCES environment variable is set
assert(editedCategory < FADE_CATEGORY_COUNT);
QJsonObject lProperties;
const QString configFile = "config/" + eventNames[editedCategory] + ".json";
QUrl path(PathUtils::resourcesPath() + configFile);
QFile file(path.toString());
const QString configFilePath = PathUtils::resourcesPath() + "config/" + eventNames[editedCategory] + ".json";
QFile file(configFilePath);
if (!file.open(QFile::WriteOnly | QFile::Text)) {
qWarning() << "Fade event configuration file " << path << " cannot be opened";
qWarning() << "Fade event configuration file " << configFilePath << " cannot be opened";
}
else {
const auto& event = events[editedCategory];
@ -381,15 +383,13 @@ void FadeConfig::save() const {
}
void FadeConfig::load() {
const QString configFile = "config/" + eventNames[editedCategory] + ".json";
QUrl path(PathUtils::resourcesPath() + configFile);
QFile file(path.toString());
const QString configFilePath = PathUtils::resourcesPath() + "config/" + eventNames[editedCategory] + ".json";
QFile file(configFilePath);
if (!file.exists()) {
qWarning() << "Fade event configuration file " << path << " does not exist";
qWarning() << "Fade event configuration file " << configFilePath << " does not exist";
}
else if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
qWarning() << "Fade event configuration file " << path << " cannot be opened";
qWarning() << "Fade event configuration file " << configFilePath << " cannot be opened";
}
else {
QString fileData = file.readAll();
@ -401,14 +401,14 @@ void FadeConfig::load() {
QJsonValue value;
auto& event = events[editedCategory];
qCDebug(renderlogging) << "Fade event configuration file" << path << "loaded";
qCDebug(renderlogging) << "Fade event configuration file" << configFilePath << "loaded";
value = jsonObject["edgeInnerColor"];
if (value.isArray()) {
QJsonArray data = value.toArray();
if (data.size() < 4) {
qWarning() << "Fade event configuration file " << path << " contains an invalid 'edgeInnerColor' field. Expected array of size 4";
qWarning() << "Fade event configuration file " << configFilePath << " contains an invalid 'edgeInnerColor' field. Expected array of size 4";
}
else {
event.edgeInnerColor.r = (float)data.at(0).toDouble();
@ -418,7 +418,7 @@ void FadeConfig::load() {
}
}
else {
qWarning() << "Fade event configuration file " << path << " contains an invalid 'edgeInnerColor' field. Expected array of size 4";
qWarning() << "Fade event configuration file " << configFilePath << " contains an invalid 'edgeInnerColor' field. Expected array of size 4";
}
value = jsonObject["edgeOuterColor"];
@ -426,7 +426,7 @@ void FadeConfig::load() {
QJsonArray data = value.toArray();
if (data.size() < 4) {
qWarning() << "Fade event configuration file " << path << " contains an invalid 'edgeOuterColor' field. Expected array of size 4";
qWarning() << "Fade event configuration file " << configFilePath << " contains an invalid 'edgeOuterColor' field. Expected array of size 4";
}
else {
event.edgeOuterColor.r = (float)data.at(0).toDouble();
@ -436,7 +436,7 @@ void FadeConfig::load() {
}
}
else {
qWarning() << "Fade event configuration file " << path << " contains an invalid 'edgeOuterColor' field. Expected array of size 4";
qWarning() << "Fade event configuration file " << configFilePath << " contains an invalid 'edgeOuterColor' field. Expected array of size 4";
}
value = jsonObject["noiseSize"];
@ -444,7 +444,7 @@ void FadeConfig::load() {
QJsonArray data = value.toArray();
if (data.size() < 3) {
qWarning() << "Fade event configuration file " << path << " contains an invalid 'noiseSize' field. Expected array of size 3";
qWarning() << "Fade event configuration file " << configFilePath << " contains an invalid 'noiseSize' field. Expected array of size 3";
}
else {
event.noiseSize.x = (float)data.at(0).toDouble();
@ -453,7 +453,7 @@ void FadeConfig::load() {
}
}
else {
qWarning() << "Fade event configuration file " << path << " contains an invalid 'noiseSize' field. Expected array of size 3";
qWarning() << "Fade event configuration file " << configFilePath << " contains an invalid 'noiseSize' field. Expected array of size 3";
}
value = jsonObject["noiseSpeed"];
@ -461,7 +461,7 @@ void FadeConfig::load() {
QJsonArray data = value.toArray();
if (data.size() < 3) {
qWarning() << "Fade event configuration file " << path << " contains an invalid 'noiseSpeed' field. Expected array of size 3";
qWarning() << "Fade event configuration file " << configFilePath << " contains an invalid 'noiseSpeed' field. Expected array of size 3";
}
else {
event.noiseSpeed.x = (float)data.at(0).toDouble();
@ -470,7 +470,7 @@ void FadeConfig::load() {
}
}
else {
qWarning() << "Fade event configuration file " << path << " contains an invalid 'noiseSpeed' field. Expected array of size 3";
qWarning() << "Fade event configuration file " << configFilePath << " contains an invalid 'noiseSpeed' field. Expected array of size 3";
}
value = jsonObject["baseSize"];
@ -478,7 +478,7 @@ void FadeConfig::load() {
QJsonArray data = value.toArray();
if (data.size() < 3) {
qWarning() << "Fade event configuration file " << path << " contains an invalid 'baseSize' field. Expected array of size 3";
qWarning() << "Fade event configuration file " << configFilePath << " contains an invalid 'baseSize' field. Expected array of size 3";
}
else {
event.baseSize.x = (float)data.at(0).toDouble();
@ -487,7 +487,7 @@ void FadeConfig::load() {
}
}
else {
qWarning() << "Fade event configuration file " << path << " contains an invalid 'baseSize' field. Expected array of size 3";
qWarning() << "Fade event configuration file " << configFilePath << " contains an invalid 'baseSize' field. Expected array of size 3";
}
value = jsonObject["noiseLevel"];
@ -495,7 +495,7 @@ void FadeConfig::load() {
event.noiseLevel = (float)value.toDouble();
}
else {
qWarning() << "Fade event configuration file " << path << " contains an invalid 'noiseLevel' field. Expected float value";
qWarning() << "Fade event configuration file " << configFilePath << " contains an invalid 'noiseLevel' field. Expected float value";
}
value = jsonObject["baseLevel"];
@ -503,7 +503,7 @@ void FadeConfig::load() {
event.baseLevel = (float)value.toDouble();
}
else {
qWarning() << "Fade event configuration file " << path << " contains an invalid 'baseLevel' field. Expected float value";
qWarning() << "Fade event configuration file " << configFilePath << " contains an invalid 'baseLevel' field. Expected float value";
}
value = jsonObject["duration"];
@ -511,7 +511,7 @@ void FadeConfig::load() {
event.duration = (float)value.toDouble();
}
else {
qWarning() << "Fade event configuration file " << path << " contains an invalid 'duration' field. Expected float value";
qWarning() << "Fade event configuration file " << configFilePath << " contains an invalid 'duration' field. Expected float value";
}
value = jsonObject["edgeWidth"];
@ -519,7 +519,7 @@ void FadeConfig::load() {
event.edgeWidth = std::min(1.f, std::max(0.f, (float)value.toDouble()));
}
else {
qWarning() << "Fade event configuration file " << path << " contains an invalid 'edgeWidth' field. Expected float value";
qWarning() << "Fade event configuration file " << configFilePath << " contains an invalid 'edgeWidth' field. Expected float value";
}
value = jsonObject["timing"];
@ -527,7 +527,7 @@ void FadeConfig::load() {
event.timing = std::max(0, std::min(TIMING_COUNT - 1, value.toInt()));
}
else {
qWarning() << "Fade event configuration file " << path << " contains an invalid 'timing' field. Expected integer value";
qWarning() << "Fade event configuration file " << configFilePath << " contains an invalid 'timing' field. Expected integer value";
}
value = jsonObject["isInverted"];
@ -535,13 +535,13 @@ void FadeConfig::load() {
event.isInverted = value.toBool();
}
else {
qWarning() << "Fade event configuration file " << path << " contains an invalid 'isInverted' field. Expected boolean value";
qWarning() << "Fade event configuration file " << configFilePath << " contains an invalid 'isInverted' field. Expected boolean value";
}
emit dirty();
}
else {
qWarning() << "Fade event configuration file" << path << "failed to load:" <<
qWarning() << "Fade event configuration file" << configFilePath << "failed to load:" <<
error.errorString() << "at offset" << error.offset;
}
}

View file

@ -56,13 +56,9 @@ class FadeConfig : public render::Job::Config {
Q_PROPERTY(float noiseSizeZ READ getNoiseSizeZ WRITE setNoiseSizeZ NOTIFY dirty)
Q_PROPERTY(float noiseLevel READ getNoiseLevel WRITE setNoiseLevel NOTIFY dirty)
Q_PROPERTY(float edgeWidth READ getEdgeWidth WRITE setEdgeWidth NOTIFY dirty)
Q_PROPERTY(float edgeInnerColorR READ getEdgeInnerColorR WRITE setEdgeInnerColorR NOTIFY dirty)
Q_PROPERTY(float edgeInnerColorG READ getEdgeInnerColorG WRITE setEdgeInnerColorG NOTIFY dirty)
Q_PROPERTY(float edgeInnerColorB READ getEdgeInnerColorB WRITE setEdgeInnerColorB NOTIFY dirty)
Q_PROPERTY(QColor edgeInnerColor READ getEdgeInnerColor WRITE setEdgeInnerColor NOTIFY dirty)
Q_PROPERTY(float edgeInnerIntensity READ getEdgeInnerIntensity WRITE setEdgeInnerIntensity NOTIFY dirty)
Q_PROPERTY(float edgeOuterColorR READ getEdgeOuterColorR WRITE setEdgeOuterColorR NOTIFY dirty)
Q_PROPERTY(float edgeOuterColorG READ getEdgeOuterColorG WRITE setEdgeOuterColorG NOTIFY dirty)
Q_PROPERTY(float edgeOuterColorB READ getEdgeOuterColorB WRITE setEdgeOuterColorB NOTIFY dirty)
Q_PROPERTY(QColor edgeOuterColor READ getEdgeOuterColor WRITE setEdgeOuterColor NOTIFY dirty)
Q_PROPERTY(float edgeOuterIntensity READ getEdgeOuterIntensity WRITE setEdgeOuterIntensity NOTIFY dirty)
Q_PROPERTY(int timing READ getTiming WRITE setTiming NOTIFY dirty)
Q_PROPERTY(float noiseSpeedX READ getNoiseSpeedX WRITE setNoiseSpeedX NOTIFY dirty)
@ -129,26 +125,14 @@ public:
void setEdgeWidth(float value);
float getEdgeWidth() const;
void setEdgeInnerColorR(float value);
float getEdgeInnerColorR() const { return events[editedCategory].edgeInnerColor.r; }
void setEdgeInnerColorG(float value);
float getEdgeInnerColorG() const { return events[editedCategory].edgeInnerColor.g; }
void setEdgeInnerColorB(float value);
float getEdgeInnerColorB() const { return events[editedCategory].edgeInnerColor.b; }
void setEdgeInnerColor(const QColor& value);
QColor getEdgeInnerColor() const;
void setEdgeInnerIntensity(float value);
float getEdgeInnerIntensity() const { return events[editedCategory].edgeInnerColor.a; }
void setEdgeOuterColorR(float value);
float getEdgeOuterColorR() const { return events[editedCategory].edgeOuterColor.r; }
void setEdgeOuterColorG(float value);
float getEdgeOuterColorG() const { return events[editedCategory].edgeOuterColor.g; }
void setEdgeOuterColorB(float value);
float getEdgeOuterColorB() const { return events[editedCategory].edgeOuterColor.b; }
void setEdgeOuterColor(const QColor& value);
QColor getEdgeOuterColor() const;
void setEdgeOuterIntensity(float value);
float getEdgeOuterIntensity() const { return events[editedCategory].edgeOuterColor.a; }

View file

@ -221,11 +221,9 @@ Rectangle {
height: 30
anchors.left: parent.left
anchors.right: parent.right
_color: Qt.rgba(root.config.edgeInnerColorR, root.config.edgeInnerColorG, root.config.edgeInnerColorB, 1.0)
_color: root.config.edgeInnerColor
onNewColor: {
root.config.edgeInnerColorR = _color.red
root.config.edgeInnerColorG = _color.green
root.config.edgeInnerColorB = _color.blue
root.config.edgeInnerColor = _color
}
}
ConfigSlider {
@ -251,11 +249,9 @@ Rectangle {
height: 30
anchors.left: parent.left
anchors.right: parent.right
_color: Qt.rgba(root.config.edgeOuterColorR, root.config.edgeOuterColorG, root.config.edgeOuterColorB, 1.0)
_color: root.config.edgeOuterColor
onNewColor: {
root.config.edgeOuterColorR = _color.red
root.config.edgeOuterColorG = _color.green
root.config.edgeOuterColorB = _color.blue
root.config.edgeOuterColor = _color
}
}
ConfigSlider {