mirror of
				https://github.com/Swordfish90/cool-retro-term.git
				synced 2025-10-31 15:12:28 +00:00 
			
		
		
		
	Settings window seems to work nicely.
This commit is contained in:
		| @@ -10,28 +10,38 @@ Tab{ | |||||||
|             Layout.fillWidth: true |             Layout.fillWidth: true | ||||||
|             ComboBox { |             ComboBox { | ||||||
|                 id: rasterizationBox |                 id: rasterizationBox | ||||||
|  |                 property string selectedElement: model[currentIndex] | ||||||
|                 anchors.fill: parent |                 anchors.fill: parent | ||||||
|                 model: [qsTr("Default"), qsTr("Scanlines"), qsTr("Pixels")] |                 model: [qsTr("Default"), qsTr("Scanlines"), qsTr("Pixels")] | ||||||
|                 currentIndex: shadersettings.rasterization |                 currentIndex: shadersettings.rasterization | ||||||
|                 onCurrentIndexChanged: shadersettings.rasterization = currentIndex |                 onCurrentIndexChanged: { | ||||||
|  |                     scalingChanger.enabled = false; | ||||||
|  |                     shadersettings.rasterization = currentIndex | ||||||
|  |                     fontChanger.updateIndex(); | ||||||
|  |                     scalingChanger.updateIndex(); | ||||||
|  |                     scalingChanger.enabled = true; | ||||||
|  |                 } | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|         GroupBox{ |         GroupBox{ | ||||||
|             title: qsTr("Font") |             title: qsTr("Font") + " (" + rasterizationBox.selectedElement + ")" | ||||||
|             Layout.fillWidth: true |             Layout.fillWidth: true | ||||||
|             GridLayout{ |             GridLayout{ | ||||||
|                 anchors.fill: parent |                 anchors.fill: parent | ||||||
|                 columns: 2 |                 columns: 2 | ||||||
|                 Text{ text: qsTr("Name") } |                 Text{ text: qsTr("Name") } | ||||||
|                 ComboBox{ |                 ComboBox{ | ||||||
|                     id: fontChanged |                     id: fontChanger | ||||||
|                     Layout.fillWidth: true |                     Layout.fillWidth: true | ||||||
|                     model: shadersettings.fontlist |                     model: shadersettings.fontlist | ||||||
|                     currentIndex: shadersettings.fontIndexes[shadersettings.rasterization] |                     currentIndex: updateIndex() | ||||||
|                     onCurrentIndexChanged: { |                     onActivated: { | ||||||
|                         shadersettings.fontIndexes[shadersettings.rasterization] = currentIndex; |                         shadersettings.fontIndexes[shadersettings.rasterization] = index; | ||||||
|                         shadersettings.handleFontChanged(); |                         shadersettings.handleFontChanged(); | ||||||
|                     } |                     } | ||||||
|  |                     function updateIndex(){ | ||||||
|  |                         currentIndex = shadersettings.fontIndexes[shadersettings.rasterization]; | ||||||
|  |                     } | ||||||
|                 } |                 } | ||||||
|                 Text{ text: qsTr("Scaling") } |                 Text{ text: qsTr("Scaling") } | ||||||
|                 RowLayout{ |                 RowLayout{ | ||||||
| @@ -42,12 +52,16 @@ Tab{ | |||||||
|                         minimumValue: 0 |                         minimumValue: 0 | ||||||
|                         maximumValue: shadersettings.fontScalingList.length - 1 |                         maximumValue: shadersettings.fontScalingList.length - 1 | ||||||
|                         stepSize: 1 |                         stepSize: 1 | ||||||
|                         value: shadersettings.fontScalingIndexes[shadersettings.rasterization] |                         tickmarksEnabled: true | ||||||
|  |                         value: updateIndex() | ||||||
|                         onValueChanged: { |                         onValueChanged: { | ||||||
|  |                             if(!enabled) return; //Ugly and hacky solution. Look for a better solution. | ||||||
|                             shadersettings.fontScalingIndexes[shadersettings.rasterization] = value; |                             shadersettings.fontScalingIndexes[shadersettings.rasterization] = value; | ||||||
|                             console.log(shadersettings.fontScalingIndexes); |  | ||||||
|                             shadersettings.handleFontChanged(); |                             shadersettings.handleFontChanged(); | ||||||
|                         } |                         } | ||||||
|  |                         function updateIndex(){ | ||||||
|  |                             value = shadersettings.fontScalingIndexes[shadersettings.rasterization]; | ||||||
|  |                         } | ||||||
|                     } |                     } | ||||||
|                     Text{ |                     Text{ | ||||||
|                         text: shadersettings.fontScalingList[scalingChanger.value].toFixed(2) |                         text: shadersettings.fontScalingList[scalingChanger.value].toFixed(2) | ||||||
|   | |||||||
| @@ -70,17 +70,23 @@ Item{ | |||||||
|     readonly property int pixel_rasterization: 2 |     readonly property int pixel_rasterization: 2 | ||||||
|  |  | ||||||
|     property int rasterization: no_rasterization |     property int rasterization: no_rasterization | ||||||
|     onRasterizationChanged: handleFontChanged() |  | ||||||
|  |     ListModel{ | ||||||
|  |         id: framelist | ||||||
|  |         ListElement{text: "No frame"; source: "./frames/NoFrame.qml"; reflections: false} | ||||||
|  |         ListElement{text: "Simple white frame"; source: "./frames/WhiteSimpleFrame.qml"; reflections: true} | ||||||
|  |         ListElement{text: "Rough black frame"; source: "./frames/BlackRoughFrame.qml"; reflections: true} | ||||||
|  |     } | ||||||
|  |  | ||||||
|     property string frame_source: frames_list.get(frames_index).source |     property string frame_source: frames_list.get(frames_index).source | ||||||
|     property int frames_index: 1 |     property int frames_index: 1 | ||||||
|     property var frames_list: framelist |     property var frames_list: framelist | ||||||
|  |  | ||||||
|     signal terminalFontChanged |  | ||||||
|  |     signal terminalFontChanged(string fontSource, int pixelSize, int lineSpacing, size virtualCharSize) | ||||||
|  |  | ||||||
|     Loader{ |     Loader{ | ||||||
|         id: fontManager |         id: fontManager | ||||||
|         onSourceChanged: console.log(source) |  | ||||||
|  |  | ||||||
|         states: [ |         states: [ | ||||||
|             State { when: rasterization == no_rasterization |             State { when: rasterization == no_rasterization | ||||||
| @@ -94,38 +100,23 @@ Item{ | |||||||
|         onLoaded: handleFontChanged() |         onLoaded: handleFontChanged() | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     Text{id: fontMetrics; text: "B"; visible: false} |  | ||||||
|  |  | ||||||
|     FontLoader{ |  | ||||||
|         property int pixelSize |  | ||||||
|         property real lineSpacing |  | ||||||
|         property size paintedSize |  | ||||||
|         property size virtualCharSize |  | ||||||
|         id: currentfont |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     property var fontlist: fontManager.item.fontlist |     property var fontlist: fontManager.item.fontlist | ||||||
|     property var fontScalingList: fontManager.item.fontScalingList |     property var fontScalingList: fontManager.item.fontScalingList | ||||||
|     property alias font: currentfont |  | ||||||
|  |  | ||||||
|     property var fontIndexes: [0,1,1] |     property var fontIndexes: [1,1,1] | ||||||
|     property var fontScalingIndexes: [5,1,1] |     property var fontScalingIndexes: [5,1,1] | ||||||
|  |  | ||||||
|     function handleFontChanged(){ |     function handleFontChanged(){ | ||||||
|         if(!fontManager.item) return; |         if(!fontManager.item) return; | ||||||
|         fontManager.item.selectedFontIndex = fontIndexes[rasterization]; |         fontManager.item.selectedFontIndex = fontIndexes[rasterization]; | ||||||
|         fontManager.item.selectedScalingIndex = fontScalingIndexes[rasterization]; |         fontManager.item.selectedScalingIndex = fontScalingIndexes[rasterization]; | ||||||
|         currentfont.source = fontManager.item.source; |  | ||||||
|         currentfont.pixelSize = fontManager.item.pixelSize; |         var fontSource = fontManager.item.source; | ||||||
|         currentfont.lineSpacing = fontManager.item.lineSpacing; |         var pixelSize = fontManager.item.pixelSize; | ||||||
|         fontMetrics.font = currentfont.name; |         var lineSpacing = fontManager.item.lineSpacing; | ||||||
|         fontMetrics.font.pixelSize = currentfont.pixelSize; |         var virtualCharSize = fontManager.item.virtualCharSize; | ||||||
|         currentfont.paintedSize = Qt.size(fontMetrics.paintedWidth, fontMetrics.paintedHeight) |  | ||||||
|         currentfont.virtualCharSize = fontManager.item.virtualCharSize !== undefined ? |         terminalFontChanged(fontSource, pixelSize, lineSpacing, virtualCharSize); | ||||||
|                     fontManager.item.virtualCharSize : |  | ||||||
|                     Qt.size(currentfont.paintedSize.width * 0.5, |  | ||||||
|                             currentfont.paintedSize.height * 0.5); |  | ||||||
|         terminalFontChanged(); |  | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     property bool frame_reflections: true |     property bool frame_reflections: true | ||||||
| @@ -134,13 +125,6 @@ Item{ | |||||||
|     property alias profiles_list: profileslist |     property alias profiles_list: profileslist | ||||||
|     property int profiles_index: 0 |     property int profiles_index: 0 | ||||||
|  |  | ||||||
|     ListModel{ |  | ||||||
|         id: framelist |  | ||||||
|         ListElement{text: "No frame"; source: "./frames/NoFrame.qml"; reflections: false} |  | ||||||
|         ListElement{text: "Simple white frame"; source: "./frames/WhiteSimpleFrame.qml"; reflections: true} |  | ||||||
|         ListElement{text: "Rough black frame"; source: "./frames/BlackRoughFrame.qml"; reflections: true} |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     Storage{id: storage} |     Storage{id: storage} | ||||||
|  |  | ||||||
|     function composeSettingsString(){ |     function composeSettingsString(){ | ||||||
| @@ -151,7 +135,8 @@ Item{ | |||||||
|             brightness: brightness, |             brightness: brightness, | ||||||
|             contrast: contrast, |             contrast: contrast, | ||||||
|             ambient_light: ambient_light, |             ambient_light: ambient_light, | ||||||
|             font_scaling_index: font_scaling_index, |             fontScalingIndexes: fontScalingIndexes, | ||||||
|  |             fontIndexes: fontIndexes | ||||||
|         } |         } | ||||||
|         return JSON.stringify(settings); |         return JSON.stringify(settings); | ||||||
|     } |     } | ||||||
| @@ -166,11 +151,11 @@ Item{ | |||||||
|             screen_distortion: screen_distortion, |             screen_distortion: screen_distortion, | ||||||
|             glowing_line_strength: glowing_line_strength, |             glowing_line_strength: glowing_line_strength, | ||||||
|             frames_index: frames_index, |             frames_index: frames_index, | ||||||
|             font_index: font_index, |  | ||||||
|             motion_blur: motion_blur, |             motion_blur: motion_blur, | ||||||
|             bloom_strength: bloom_strength, |             bloom_strength: bloom_strength, | ||||||
|             rasterization: rasterization, |             rasterization: rasterization, | ||||||
|             jitter: jitter |             jitter: jitter, | ||||||
|  |             fontIndex: fontIndexes[rasterization] | ||||||
|         } |         } | ||||||
|         return JSON.stringify(settings); |         return JSON.stringify(settings); | ||||||
|     } |     } | ||||||
| @@ -211,7 +196,8 @@ Item{ | |||||||
|         fps = settings.fps !== undefined ? settings.fps: fps |         fps = settings.fps !== undefined ? settings.fps: fps | ||||||
|         window_scaling = settings.window_scaling ? settings.window_scaling : window_scaling |         window_scaling = settings.window_scaling ? settings.window_scaling : window_scaling | ||||||
|  |  | ||||||
|         //font_scaling_index = settings.font_scaling_index !== undefined ? settings.font_scaling_index: font_scaling_index; |         fontIndexes = settings.fontIndexes ? settings.fontIndexes : fontIndexes | ||||||
|  |         fontScalingIndexes = settings.fontScalingIndexes ? settings.fontScalingIndexes : fontScalingIndexes | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     function loadProfileString(profileString){ |     function loadProfileString(profileString){ | ||||||
| @@ -231,11 +217,11 @@ Item{ | |||||||
|  |  | ||||||
|         frames_index = settings.frames_index !== undefined ? settings.frames_index : frames_index; |         frames_index = settings.frames_index !== undefined ? settings.frames_index : frames_index; | ||||||
|  |  | ||||||
|         //font_index = settings.font_index !== undefined ? settings.font_index : font_index; |  | ||||||
|  |  | ||||||
|         rasterization = settings.rasterization !== undefined ? settings.rasterization : rasterization; |         rasterization = settings.rasterization !== undefined ? settings.rasterization : rasterization; | ||||||
|  |  | ||||||
|         jitter = settings.jitter !== undefined ? settings.jitter : jitter |         jitter = settings.jitter !== undefined ? settings.jitter : jitter; | ||||||
|  |  | ||||||
|  |         fontIndexes[rasterization] = settings.fontIndex ? settings.fontIndex : fontIndexes[rasterization]; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     function storeCustomProfiles(){ |     function storeCustomProfiles(){ | ||||||
|   | |||||||
| @@ -56,8 +56,6 @@ Item{ | |||||||
|     property size terminalSize: kterminal.terminalSize |     property size terminalSize: kterminal.terminalSize | ||||||
|     property size paintedTextSize |     property size paintedTextSize | ||||||
|  |  | ||||||
|     onPaintedTextSizeChanged: console.log(paintedTextSize) |  | ||||||
|  |  | ||||||
|     //Force reload of the blursource when settings change |     //Force reload of the blursource when settings change | ||||||
|     onMBlurChanged: restartBlurredSource() |     onMBlurChanged: restartBlurredSource() | ||||||
|  |  | ||||||
| @@ -76,8 +74,6 @@ Item{ | |||||||
|     KTerminal { |     KTerminal { | ||||||
|         id: kterminal |         id: kterminal | ||||||
|         anchors.fill: parent |         anchors.fill: parent | ||||||
|         font.pixelSize: shadersettings.font.pixelSize |  | ||||||
|         font.family: shadersettings.font.name |  | ||||||
|  |  | ||||||
|         colorScheme: "MyWhiteOnBlack" |         colorScheme: "MyWhiteOnBlack" | ||||||
|  |  | ||||||
| @@ -90,33 +86,38 @@ Item{ | |||||||
|             } |             } | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         function handleFontChange(){ |         FontLoader{ id: fontLoader } | ||||||
|             var newFont = shadersettings.font; |         Text{id: fontMetrics; text: "B"; visible: false} | ||||||
|             var font_size = newFont.pixelSize * shadersettings.window_scaling; |  | ||||||
|             font.pixelSize = font_size; |  | ||||||
|             font.family = newFont.name; |  | ||||||
|  |  | ||||||
|             var virtualCharSize = newFont.virtualCharSize; |         function getPaintedSize(pixelSize){ | ||||||
|             var virtualPxSize = Qt.size(newFont.paintedSize.width  / virtualCharSize.width, |             fontMetrics.font.family = fontLoader.name; | ||||||
|                                         newFont.paintedSize.height / virtualCharSize.height) |             fontMetrics.font.pixelSize = pixelSize; | ||||||
|  |             return Qt.size(fontMetrics.paintedWidth, fontMetrics.paintedHeight); | ||||||
|  |         } | ||||||
|  |         function isValid(size){ | ||||||
|  |             return size.width >= 0 && size.height >= 0; | ||||||
|  |         } | ||||||
|  |  | ||||||
|             var scanline_spacing = shadersettings.font.lineSpacing; |         function handleFontChange(fontSource, pixelSize, lineSpacing, virtualCharSize){ | ||||||
|             var line_spacing = Math.round(scanline_spacing); |             fontLoader.source = fontSource; | ||||||
|  |             font.pixelSize = pixelSize * shadersettings.window_scaling; | ||||||
|  |             font.family = fontLoader.name; | ||||||
|  |  | ||||||
|             console.log(kterminal.paintedFontSize) |             var paintedSize = getPaintedSize(pixelSize); | ||||||
|  |             var charSize = isValid(virtualCharSize) | ||||||
|  |                     ? virtualCharSize | ||||||
|  |                     : Qt.size(paintedSize.width / 2, paintedSize.height / 2); | ||||||
|  |  | ||||||
|             //            console.log("Font height: " + fontMetrics.paintedHeight) |             var virtualPxSize = Qt.size(paintedSize.width  / charSize.width, | ||||||
|             //            console.log("Scanline Height: " + scanline_height) |                                         paintedSize.height / charSize.height) | ||||||
|             //            console.log("Line Spacing: " + line_spacing) |  | ||||||
|  |  | ||||||
|             terminalContainer.virtualPxSize = virtualPxSize; |             terminalContainer.virtualPxSize = virtualPxSize; | ||||||
|  |  | ||||||
|             setLineSpacing(newFont.lineSpacing); |             setLineSpacing(lineSpacing); | ||||||
|             restartBlurredSource(); |             restartBlurredSource(); | ||||||
|         } |         } | ||||||
|         Component.onCompleted: { |         Component.onCompleted: { | ||||||
|             shadersettings.terminalFontChanged.connect(handleFontChange); |             shadersettings.terminalFontChanged.connect(handleFontChange); | ||||||
|             handleFontChange(); |  | ||||||
|             forceActiveFocus(); |             forceActiveFocus(); | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|   | |||||||
| @@ -1,6 +1,6 @@ | |||||||
| <?xml version="1.0" encoding="UTF-8"?> | <?xml version="1.0" encoding="UTF-8"?> | ||||||
| <!DOCTYPE QtCreatorProject> | <!DOCTYPE QtCreatorProject> | ||||||
| <!-- Written by QtCreator 3.0.1, 2014-06-24T10:46:32. --> | <!-- Written by QtCreator 3.0.1, 2014-06-25T13:18:19. --> | ||||||
| <qtcreator> | <qtcreator> | ||||||
|  <data> |  <data> | ||||||
|   <variable>ProjectExplorer.Project.ActiveTarget</variable> |   <variable>ProjectExplorer.Project.ActiveTarget</variable> | ||||||
|   | |||||||
| @@ -159,4 +159,5 @@ ApplicationWindow{ | |||||||
|             terminalSize: terminal.terminalSize |             terminalSize: terminal.terminalSize | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |     Component.onCompleted: shadersettings.handleFontChanged(); | ||||||
| } | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user