mirror of
				https://github.com/Swordfish90/cool-retro-term.git
				synced 2025-10-31 15:12:28 +00:00 
			
		
		
		
	Improve profiles management, redesign a bit the settings window.
This commit is contained in:
		| @@ -356,8 +356,7 @@ QtObject{ | |||||||
|         loadProfileString(profile.obj_string); |         loadProfileString(profile.obj_string); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     function addNewCustomProfile(name){ |     function appendCustomProfile(name, profileString) { | ||||||
|         var profileString = composeProfileString(); |  | ||||||
|         profilesList.append({text: name, obj_string: profileString, builtin: false}); |         profilesList.append({text: name, obj_string: profileString, builtin: false}); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -31,6 +31,7 @@ Window{ | |||||||
|     modality: Qt.ApplicationModal |     modality: Qt.ApplicationModal | ||||||
|     title: qsTr("Save new profile") |     title: qsTr("Save new profile") | ||||||
|  |  | ||||||
|  |     property alias profileName: namefield.text | ||||||
|     signal nameSelected(string name) |     signal nameSelected(string name) | ||||||
|  |  | ||||||
|     MessageDialog { |     MessageDialog { | ||||||
|   | |||||||
| @@ -28,6 +28,7 @@ Tab{ | |||||||
|         anchors.fill: parent |         anchors.fill: parent | ||||||
|         ColumnLayout{ |         ColumnLayout{ | ||||||
|             anchors.fill: parent |             anchors.fill: parent | ||||||
|  |             spacing: 2 | ||||||
|             CheckableSlider{ |             CheckableSlider{ | ||||||
|                 name: qsTr("Bloom") |                 name: qsTr("Bloom") | ||||||
|                 onNewValue: appSettings.bloom = newValue |                 onNewValue: appSettings.bloom = newValue | ||||||
|   | |||||||
| @@ -51,6 +51,14 @@ Tab{ | |||||||
|                 ColumnLayout { |                 ColumnLayout { | ||||||
|                     anchors { top: parent.top; bottom: parent.bottom } |                     anchors { top: parent.top; bottom: parent.bottom } | ||||||
|                     Layout.fillWidth: false |                     Layout.fillWidth: false | ||||||
|  |                     Button{ | ||||||
|  |                         Layout.fillWidth: true | ||||||
|  |                         text: qsTr("New") | ||||||
|  |                         onClicked: { | ||||||
|  |                             insertname.profileName = ""; | ||||||
|  |                             insertname.show() | ||||||
|  |                         } | ||||||
|  |                     } | ||||||
|                     Button{ |                     Button{ | ||||||
|                         Layout.fillWidth: true |                         Layout.fillWidth: true | ||||||
|                         property alias currentIndex: profilesView.currentRow |                         property alias currentIndex: profilesView.currentRow | ||||||
| @@ -62,11 +70,6 @@ Tab{ | |||||||
|                                 appSettings.loadProfile(index); |                                 appSettings.loadProfile(index); | ||||||
|                         } |                         } | ||||||
|                     } |                     } | ||||||
|                     Button{ |  | ||||||
|                         Layout.fillWidth: true |  | ||||||
|                         text: qsTr("New") |  | ||||||
|                         onClicked: insertname.show() |  | ||||||
|                     } |  | ||||||
|                     Button{ |                     Button{ | ||||||
|                         Layout.fillWidth: true |                         Layout.fillWidth: true | ||||||
|                         text: qsTr("Remove") |                         text: qsTr("Remove") | ||||||
| @@ -74,11 +77,12 @@ Tab{ | |||||||
|  |  | ||||||
|                         enabled: currentIndex >= 0 && !appSettings.profilesList.get(currentIndex).builtin |                         enabled: currentIndex >= 0 && !appSettings.profilesList.get(currentIndex).builtin | ||||||
|                         onClicked: { |                         onClicked: { | ||||||
|                             appSettings.profilesList.remove(profilesView.currentRow); |                             appSettings.profilesList.remove(currentIndex); | ||||||
|                             profilesView.activated(currentIndex); |                             currentIndex = -1; // Unselect the profile. | ||||||
|                         } |                         } | ||||||
|                     } |                     } | ||||||
|                     Button{ |                     Button{ | ||||||
|  |                         Layout.fillWidth: true | ||||||
|                         text: qsTr("Import") |                         text: qsTr("Import") | ||||||
|                         onClicked: { |                         onClicked: { | ||||||
|                             fileDialog.selectExisting = true; |                             fileDialog.selectExisting = true; | ||||||
| @@ -86,105 +90,103 @@ Tab{ | |||||||
|                             fileDialog.open(); |                             fileDialog.open(); | ||||||
|                         } |                         } | ||||||
|                         function loadFile(url) { |                         function loadFile(url) { | ||||||
|                             if (true) |                             try { | ||||||
|                                 console.log("Loading file: " + url); |                                 if (appSettings.verbose) | ||||||
|                             var profileStirng = fileIO.read(url); |                                     console.log("Loading file: " + url); | ||||||
|                             appSettings.loadProfileString(profileStirng); |  | ||||||
|  |                                 var profileObject = JSON.parse(fileIO.read(url)); | ||||||
|  |                                 var name = profileObject.name; | ||||||
|  |  | ||||||
|  |                                 if (!name) | ||||||
|  |                                     throw "Profile doesn't have a name"; | ||||||
|  |  | ||||||
|  |                                 delete profileObject.name; | ||||||
|  |  | ||||||
|  |                                 appSettings.appendCustomProfile(name, JSON.stringify(profileObject)); | ||||||
|  |                             } catch (err) { | ||||||
|  |                                 console.log(err); | ||||||
|  |                                 messageDialog.text = qsTr("There has been an error reading the file.") | ||||||
|  |                                 messageDialog.open(); | ||||||
|  |                             } | ||||||
|                         } |                         } | ||||||
|                     } |                     } | ||||||
|                     Button{ |                     Button{ | ||||||
|  |                         property alias currentIndex: profilesView.currentRow | ||||||
|  |  | ||||||
|  |                         Layout.fillWidth: true | ||||||
|  |  | ||||||
|                         text: qsTr("Export") |                         text: qsTr("Export") | ||||||
|  |                         enabled: currentIndex >= 0 && !appSettings.profilesList.get(currentIndex).builtin | ||||||
|                         onClicked: { |                         onClicked: { | ||||||
|                             fileDialog.selectExisting = false; |                             fileDialog.selectExisting = false; | ||||||
|                             fileDialog.callBack = function (url) {storeFile(url);}; |                             fileDialog.callBack = function (url) {storeFile(url);}; | ||||||
|                             fileDialog.open(); |                             fileDialog.open(); | ||||||
|                         } |                         } | ||||||
|                         function storeFile(url) { |                         function storeFile(url) { | ||||||
|                             if (true) |                             try { | ||||||
|                                 console.log("Storing file: " + url); |                                 var urlString = url.toString(); | ||||||
|                             var profileObject = appSettings.composeProfileObject(); |  | ||||||
|                             fileIO.write(url, JSON.stringify(profileObject, undefined, 2)); |  | ||||||
|                         } |  | ||||||
|                     } |  | ||||||
|                     InsertNameDialog{ |  | ||||||
|                         id: insertname |  | ||||||
|                         onNameSelected: appSettings.addNewCustomProfile(name) |  | ||||||
|                     } |  | ||||||
|                     Loader { |  | ||||||
|                         property var callBack |  | ||||||
|                         property bool selectExisting: false |  | ||||||
|                         id: fileDialog |  | ||||||
|  |  | ||||||
|                         sourceComponent: FileDialog{ |                                 // Fix the extension if it's missing. | ||||||
|                             nameFilters: ["Json files (*.json)"] |                                 var extension = urlString.substring(urlString.length - 5, urlString.length); | ||||||
|                             selectMultiple: false |                                 var urlTail = (extension === ".json" ? "" : ".json"); | ||||||
|                             selectFolder: false |                                 url += urlTail; | ||||||
|                             selectExisting: fileDialog.selectExisting |  | ||||||
|                             onAccepted: callBack(fileUrl); |  | ||||||
|                         } |  | ||||||
|  |  | ||||||
|                         onSelectExistingChanged: reload() |                                 if (true) | ||||||
|  |                                     console.log("Storing file: " + url); | ||||||
|  |  | ||||||
|                         function open() { |                                 var profileObject = appSettings.profilesList.get(currentIndex); | ||||||
|                             item.open(); |                                 var profileSettings = JSON.parse(profileObject.obj_string); | ||||||
|                         } |                                 profileSettings["name"] = profileObject.text; | ||||||
|  |  | ||||||
|                         function reload() { |                                 var result = fileIO.write(url, JSON.stringify(profileSettings, undefined, 2)); | ||||||
|                             active = false; |                                 if (!result) | ||||||
|                             active = true; |                                     throw "The file could not be written."; | ||||||
|  |                             } catch (err) { | ||||||
|  |                                 console.log(err); | ||||||
|  |                                 messageDialog.text = qsTr("There has been an error storing the file.") | ||||||
|  |                                 messageDialog.open(); | ||||||
|  |                             } | ||||||
|                         } |                         } | ||||||
|                     } |                     } | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|         GroupBox{ |         // DIALOGS //////////////////////////////////////////////////////////////// | ||||||
|             title: qsTr("Lights") |         InsertNameDialog{ | ||||||
|             Layout.fillWidth: true |             id: insertname | ||||||
|             GridLayout{ |             onNameSelected: { | ||||||
|                 anchors.fill: parent |                 appSettings.appendCustomProfile(name, appSettings.composeProfileString()); | ||||||
|                 columns: 2 |  | ||||||
|                 Text{ text: qsTr("Brightness") } |  | ||||||
|                 SimpleSlider{ |  | ||||||
|                     onValueChanged: appSettings.brightness = value |  | ||||||
|                     value: appSettings.brightness |  | ||||||
|                 } |  | ||||||
|                 Text{ text: qsTr("Contrast") } |  | ||||||
|                 SimpleSlider{ |  | ||||||
|                     onValueChanged: appSettings.contrast = value |  | ||||||
|                     value: appSettings.contrast |  | ||||||
|                 } |  | ||||||
|                 Text{ text: qsTr("Opacity") } |  | ||||||
|                 SimpleSlider{ |  | ||||||
|                     onValueChanged: appSettings.windowOpacity = value |  | ||||||
|                     value: appSettings.windowOpacity |  | ||||||
|                 } |  | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|         GroupBox{ |         MessageDialog { | ||||||
|             title: qsTr("Frame") |             id: messageDialog | ||||||
|             Layout.fillWidth: true |             title: qsTr("File Error") | ||||||
|             RowLayout{ |             onAccepted: { | ||||||
|                 anchors.fill: parent |                 messageDialog.close(); | ||||||
|                 ComboBox{ |             } | ||||||
|                     id: framescombobox |         } | ||||||
|                     Layout.fillWidth: true |         Loader { | ||||||
|                     model: appSettings.framesList |             property var callBack | ||||||
|                     currentIndex: appSettings.framesIndex |             property bool selectExisting: false | ||||||
|                     onActivated: { |             id: fileDialog | ||||||
|                         appSettings.frameName = appSettings.framesList.get(index).name; |  | ||||||
|                     } |             sourceComponent: FileDialog{ | ||||||
|                     function updateIndex(){ |                 nameFilters: ["Json files (*.json)"] | ||||||
|                         var name = appSettings.frameName; |                 selectMultiple: false | ||||||
|                         var index = appSettings.getFrameIndexByName(name); |                 selectFolder: false | ||||||
|                         if (index !== undefined) |                 selectExisting: fileDialog.selectExisting | ||||||
|                             currentIndex = index; |                 onAccepted: callBack(fileUrl); | ||||||
|                     } |             } | ||||||
|                     Component.onCompleted: updateIndex(); |  | ||||||
|                     Connections { |             onSelectExistingChanged: reload() | ||||||
|                         target: appSettings |  | ||||||
|                         onFrameNameChanged: framescombobox.updateIndex(); |             function open() { | ||||||
|                     } |                 item.open(); | ||||||
|                 } |             } | ||||||
|  |  | ||||||
|  |             function reload() { | ||||||
|  |                 active = false; | ||||||
|  |                 active = true; | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|   | |||||||
							
								
								
									
										94
									
								
								app/qml/SettingsScreenTab.qml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										94
									
								
								app/qml/SettingsScreenTab.qml
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,94 @@ | |||||||
|  | /******************************************************************************* | ||||||
|  | * Copyright (c) 2013 "Filippo Scognamiglio" | ||||||
|  | * https://github.com/Swordfish90/cool-retro-term | ||||||
|  | * | ||||||
|  | * This file is part of cool-retro-term. | ||||||
|  | * | ||||||
|  | * cool-retro-term is free software: you can redistribute it and/or modify | ||||||
|  | * it under the terms of the GNU General Public License as published by | ||||||
|  | * the Free Software Foundation, either version 3 of the License, or | ||||||
|  | * (at your option) any later version. | ||||||
|  | * | ||||||
|  | * This program is distributed in the hope that it will be useful, | ||||||
|  | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||||
|  | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||||
|  | * GNU General Public License for more details. | ||||||
|  | * | ||||||
|  | * You should have received a copy of the GNU General Public License | ||||||
|  | * along with this program.  If not, see <http://www.gnu.org/licenses/>. | ||||||
|  | *******************************************************************************/ | ||||||
|  |  | ||||||
|  | import QtQuick 2.2 | ||||||
|  | import QtQuick.Controls 1.1 | ||||||
|  | import QtQuick.Layouts 1.1 | ||||||
|  | import QtQuick.Dialogs 1.1 | ||||||
|  |  | ||||||
|  | Tab{ | ||||||
|  |     ColumnLayout{ | ||||||
|  |         anchors.fill: parent | ||||||
|  |         GroupBox{ | ||||||
|  |             title: qsTr("Rasterization Mode") | ||||||
|  |             Layout.fillWidth: true | ||||||
|  |             ComboBox { | ||||||
|  |                 id: rasterizationBox | ||||||
|  |                 property string selectedElement: model[currentIndex] | ||||||
|  |                 anchors.fill: parent | ||||||
|  |                 model: [qsTr("Default"), qsTr("Scanlines"), qsTr("Pixels")] | ||||||
|  |                 currentIndex: appSettings.rasterization | ||||||
|  |                 onCurrentIndexChanged: { | ||||||
|  |                     appSettings.rasterization = currentIndex | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |         GroupBox{ | ||||||
|  |             title: qsTr("Lights") | ||||||
|  |             Layout.fillWidth: true | ||||||
|  |             GridLayout{ | ||||||
|  |                 anchors.fill: parent | ||||||
|  |                 columns: 2 | ||||||
|  |                 Text{ text: qsTr("Brightness") } | ||||||
|  |                 SimpleSlider{ | ||||||
|  |                     onValueChanged: appSettings.brightness = value | ||||||
|  |                     value: appSettings.brightness | ||||||
|  |                 } | ||||||
|  |                 Text{ text: qsTr("Contrast") } | ||||||
|  |                 SimpleSlider{ | ||||||
|  |                     onValueChanged: appSettings.contrast = value | ||||||
|  |                     value: appSettings.contrast | ||||||
|  |                 } | ||||||
|  |                 Text{ text: qsTr("Opacity") } | ||||||
|  |                 SimpleSlider{ | ||||||
|  |                     onValueChanged: appSettings.windowOpacity = value | ||||||
|  |                     value: appSettings.windowOpacity | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |         GroupBox{ | ||||||
|  |             title: qsTr("Frame") | ||||||
|  |             Layout.fillWidth: true | ||||||
|  |             RowLayout{ | ||||||
|  |                 anchors.fill: parent | ||||||
|  |                 ComboBox{ | ||||||
|  |                     id: framescombobox | ||||||
|  |                     Layout.fillWidth: true | ||||||
|  |                     model: appSettings.framesList | ||||||
|  |                     currentIndex: appSettings.framesIndex | ||||||
|  |                     onActivated: { | ||||||
|  |                         appSettings.frameName = appSettings.framesList.get(index).name; | ||||||
|  |                     } | ||||||
|  |                     function updateIndex(){ | ||||||
|  |                         var name = appSettings.frameName; | ||||||
|  |                         var index = appSettings.getFrameIndexByName(name); | ||||||
|  |                         if (index !== undefined) | ||||||
|  |                             currentIndex = index; | ||||||
|  |                     } | ||||||
|  |                     Component.onCompleted: updateIndex(); | ||||||
|  |                     Connections { | ||||||
|  |                         target: appSettings | ||||||
|  |                         onFrameNameChanged: framescombobox.updateIndex(); | ||||||
|  |                     } | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
| @@ -26,21 +26,8 @@ Tab{ | |||||||
|     ColumnLayout{ |     ColumnLayout{ | ||||||
|         anchors.fill: parent |         anchors.fill: parent | ||||||
|         GroupBox{ |         GroupBox{ | ||||||
|             title: qsTr("Rasterization Mode") |             property var rasterization: [qsTr("Default"), qsTr("Scanlines"), qsTr("Pixels")][appSettings.rasterization] | ||||||
|             Layout.fillWidth: true |             title: qsTr("Font" + "(" + rasterization + ")") | ||||||
|             ComboBox { |  | ||||||
|                 id: rasterizationBox |  | ||||||
|                 property string selectedElement: model[currentIndex] |  | ||||||
|                 anchors.fill: parent |  | ||||||
|                 model: [qsTr("Default"), qsTr("Scanlines"), qsTr("Pixels")] |  | ||||||
|                 currentIndex: appSettings.rasterization |  | ||||||
|                 onCurrentIndexChanged: { |  | ||||||
|                     appSettings.rasterization = currentIndex |  | ||||||
|                 } |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|         GroupBox{ |  | ||||||
|             title: qsTr("Font") + " (" + rasterizationBox.selectedElement + ")" |  | ||||||
|             Layout.fillWidth: true |             Layout.fillWidth: true | ||||||
|             GridLayout{ |             GridLayout{ | ||||||
|                 anchors.fill: parent |                 anchors.fill: parent | ||||||
|   | |||||||
| @@ -42,6 +42,12 @@ Window { | |||||||
|             anchors.fill: parent |             anchors.fill: parent | ||||||
|             anchors.margins: tabmargins |             anchors.margins: tabmargins | ||||||
|         } |         } | ||||||
|  |         SettingsScreenTab{ | ||||||
|  |             id: screenTab | ||||||
|  |             title: qsTr("Screen") | ||||||
|  |             anchors.fill: parent | ||||||
|  |             anchors.margins: tabmargins | ||||||
|  |         } | ||||||
|         SettingsTerminalTab{ |         SettingsTerminalTab{ | ||||||
|             id: terminalTab |             id: terminalTab | ||||||
|             title: qsTr("Terminal") |             title: qsTr("Terminal") | ||||||
|   | |||||||
| @@ -49,5 +49,6 @@ | |||||||
|         <file>fonts/modern-hermit/Hermit-medium.otf</file> |         <file>fonts/modern-hermit/Hermit-medium.otf</file> | ||||||
|         <file>fonts/modern-envy-code-r/Envy Code R.ttf</file> |         <file>fonts/modern-envy-code-r/Envy Code R.ttf</file> | ||||||
|         <file>fonts/modern-inconsolata/Inconsolata.otf</file> |         <file>fonts/modern-inconsolata/Inconsolata.otf</file> | ||||||
|  |         <file>SettingsScreenTab.qml</file> | ||||||
|     </qresource> |     </qresource> | ||||||
| </RCC> | </RCC> | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user