diff --git a/app/InsertNameDialog.qml b/app/InsertNameDialog.qml new file mode 100644 index 0000000..08fd980 --- /dev/null +++ b/app/InsertNameDialog.qml @@ -0,0 +1,42 @@ +import QtQuick 2.1 +import QtQuick.Window 2.0 +import QtQuick.Controls 1.1 +import QtQuick.Layouts 1.1 + +Window{ + id: insertnamedialog + width: 400 + height: 100 + modality: Qt.ApplicationModal + title: qsTr("Save current profile") + + signal nameSelected(string name) + + ColumnLayout{ + anchors.margins: 10 + anchors.fill: parent + RowLayout{ + Label{text: qsTr("Name")} + TextField{ + id: namefield + Layout.fillWidth: true + Component.onCompleted: forceActiveFocus() + } + } + RowLayout{ + anchors.right: parent.right + anchors.bottom: parent.bottom + Button{ + text: qsTr("OK") + onClicked: { + nameSelected(namefield.text); + close(); + } + } + Button{ + text: qsTr("Cancel") + onClicked: close() + } + } + } +} diff --git a/app/SettingsWindow.qml b/app/SettingsWindow.qml index f63c76f..dca0daf 100644 --- a/app/SettingsWindow.qml +++ b/app/SettingsWindow.qml @@ -47,11 +47,34 @@ Window { anchors.right: parent.right Layout.columnSpan: 2 title: qsTr("Profile") - ComboBox{ + RowLayout{ anchors.fill: parent - model: shadersettings.profiles_list - onCurrentIndexChanged: shadersettings.profiles_index = currentIndex - currentIndex: shadersettings.profiles_index + ComboBox{ + id: profilesbox + Layout.fillWidth: true + model: shadersettings.profiles_list + currentIndex: shadersettings.profiles_index + } + Button{ + text: "Load" + onClicked: shadersettings.profiles_index = profilesbox.currentIndex + } + Button{ + text: "Add" + onClicked: insertname.show() + } + Button{ + text: "Remove" + enabled: !shadersettings.profiles_list.get(profilesbox.currentIndex).builtin + onClicked: { + shadersettings.profiles_list.remove(profilesbox.currentIndex) + profilesbox.currentIndex = profilesbox.currentIndex - 1 + } + } + InsertNameDialog{ + id: insertname + onNameSelected: shadersettings.addNewCustomProfile(name) + } } } diff --git a/app/ShaderSettings.qml b/app/ShaderSettings.qml index 885c9c0..a9b22f4 100644 --- a/app/ShaderSettings.qml +++ b/app/ShaderSettings.qml @@ -82,9 +82,9 @@ Item{ property bool frame_reflections: true property real frame_reflection_strength: ((frame_reflections && framelist.get(frames_index).reflections) ? 1.0 : 0.0) * 0.15 - property var profiles_list: profileslist + property alias profiles_list: profileslist property int profiles_index: 0 - onProfiles_indexChanged: loadProfile(profiles_list.get(profiles_index).obj_name); + onProfiles_indexChanged: loadProfile(profiles_index); onFont_indexChanged: handleFontChanged(); onFont_scalingChanged: handleFontChanged(); @@ -159,21 +159,80 @@ Item{ Storage{id: storage} - function loadProfile(profilename){ - var settings = storage.getSetting(profilename); - if(!settings) return; - console.log(profilename + settings); - settings = JSON.parse(settings); + function composeSettingsString(){ + var settings = { + fps: fps, + window_scaling: window_scaling, + show_terminal_size: show_terminal_size, + brightness: brightness, + contrast: contrast, + ambient_light: ambient_light, + font_scaling: font_scaling, + } + return JSON.stringify(settings); + } + + function composeProfileString(){ + var settings = { + background_color: _background_color, + font_color: _font_color, + brightness_flickering: brightness_flickering, + horizontal_sincronization: horizontal_sincronization, + noise_strength: noise_strength, + screen_distortion: screen_distortion, + glowing_line_strength: glowing_line_strength, + frames_index: frames_index, + font_index: font_index, + motion_blur: motion_blur, + bloom_strength: bloom_strength, + rasterization_strength: rasterization_strength, + rasterization: rasterization + } + return JSON.stringify(settings); + } + + function loadSettings(){ + var settingsString = storage.getSetting("_CURRENT_SETTINGS"); + var profileString = storage.getSetting("_CURRENT_PROFILE"); + + if(!settingsString) return; + if(!profileString) return; + + loadSettingsString(settingsString); + loadProfileString(profileString); + + console.log("Loading settings: " + settingsString + profileString); + } + + function storeSettings(){ + var settingsString = composeSettingsString(); + var profileString = composeProfileString(); + + storage.setSetting("_CURRENT_SETTINGS", settingsString); + storage.setSetting("_CURRENT_PROFILE", profileString); + + console.log("Storing settings :" + settingsString + profileString); + } + + function loadSettingsString(settingsString){ + var settings = JSON.parse(settingsString); + + ambient_light = settings.ambient_light !== undefined ? settings.ambient_light : ambient_light; + + contrast = settings.contrast !== undefined ? settings.contrast : contrast; + brightness = settings.brightness !== undefined ? settings.brightness : brightness show_terminal_size = settings.show_terminal_size ? settings.show_terminal_size : show_terminal_size fps = settings.fps !== undefined ? settings.fps: fps window_scaling = settings.window_scaling ? settings.window_scaling : window_scaling - contrast = settings.contrast !== undefined ? settings.contrast : contrast; - brightness = settings.brightness !== undefined ? settings.brightness : brightness + font_scaling = settings.font_scaling !== undefined ? settings.font_scaling: font_scaling; + } + + function loadProfileString(profileString){ + var settings = JSON.parse(profileString); - ambient_light = settings.ambient_light !== undefined ? settings.ambient_light : ambient_light; _background_color = settings.background_color !== undefined ? settings.background_color : _background_color; _font_color = settings.font_color !== undefined ? settings.font_color : _font_color; @@ -189,71 +248,76 @@ Item{ frames_index = settings.frames_index !== undefined ? settings.frames_index : frames_index; font_index = settings.font_index !== undefined ? settings.font_index : font_index; - font_scaling = settings.font_scaling !== undefined ? settings.font_scaling: font_scaling; rasterization_strength = settings.rasterization_strength !== undefined ? settings.rasterization_strength : rasterization_strength; rasterization = settings.rasterization !== undefined ? settings.rasterization : rasterization; } - function storeCurrentSettings(){ - var settings = { - fps: fps, - window_scaling: window_scaling, - show_terminal_size: show_terminal_size, - ambient_light: ambient_light, - brightness: brightness, - contrast: contrast, - background_color: _background_color, - font_color: _font_color, - brightness_flickering: brightness_flickering, - horizontal_sincronization: horizontal_sincronization, - noise_strength: noise_strength, - screen_distortion: screen_distortion, - glowing_line_strength: glowing_line_strength, - frames_index: frames_index, - font_index: font_index, - font_scaling: font_scaling, - motion_blur: motion_blur, - bloom_strength: bloom_strength, - rasterization_strength: rasterization_strength, - rasterization: rasterization - } + function storeCustomProfiles(){ + storage.setSetting("_CUSTOM_PROFILES", composeCustomProfilesString()); + } - console.log(JSON.stringify(settings)); - storage.setSetting("CURRENT_SETTINGS", JSON.stringify(settings)); + function loadCustomProfiles(){ + var customProfileString = storage.getSetting("_CUSTOM_PROFILES"); + if(customProfileString === undefined) customProfileString = "[]"; + loadCustomProfilesString(customProfileString); + } + + function loadCustomProfilesString(customProfilesString){ + var customProfiles = JSON.parse(customProfilesString); + for (var i=0; i - + ProjectExplorer.Project.ActiveTarget