Setting scaling stepSize to 0.05 instead of 0.1. Refactored scaling handling.

This commit is contained in:
Filippo Scognamiglio 2014-09-29 22:38:33 +02:00
parent 2ff6c71c23
commit e815fe2787
3 changed files with 28 additions and 39 deletions

View File

@ -119,30 +119,29 @@ Item{
onLoaded: handleFontChanged() onLoaded: handleFontChanged()
} }
signal fontScalingChanged property real fontScaling: 1.0
property var fontScalingList: [0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2.0, 2.1, 2.2, 2.3, 2.4, 2.5] onFontScalingChanged: handleFontChanged();
property int fontScalingIndex: 5
property real fontWidth: 1.0 function incrementScaling(){
onFontWidthChanged: handleFontChanged(); fontScaling = Math.min(fontScaling + 0.05, 2.50);
function setScalingIndex(newScaling){
fontScalingIndex = newScaling;
fontScalingChanged();
handleFontChanged(); handleFontChanged();
} }
function getScalingIndex(){ function decrementScaling(){
return fontScalingIndex; fontScaling = Math.max(fontScaling - 0.05, 0.50);
handleFontChanged();
} }
property real fontWidth: 1.0
onFontWidthChanged: handleFontChanged();
property var fontIndexes: [0,0,0] property var fontIndexes: [0,0,0]
property var fontlist: fontManager.item.fontlist property var fontlist: fontManager.item.fontlist
function handleFontChanged(){ function handleFontChanged(){
if(!fontManager.item) return; if(!fontManager.item) return;
fontManager.item.selectedFontIndex = fontIndexes[rasterization]; fontManager.item.selectedFontIndex = fontIndexes[rasterization];
fontManager.item.scaling = fontScalingList[fontScalingIndex]; fontManager.item.scaling = fontScaling;
var fontSource = fontManager.item.source; var fontSource = fontManager.item.source;
var pixelSize = fontManager.item.pixelSize; var pixelSize = fontManager.item.pixelSize;
@ -170,7 +169,7 @@ Item{
fps: fps, fps: fps,
window_scaling: window_scaling, window_scaling: window_scaling,
show_terminal_size: show_terminal_size, show_terminal_size: show_terminal_size,
fontScalingIndex: fontScalingIndex, fontScaling: fontScaling,
fontIndexes: fontIndexes, fontIndexes: fontIndexes,
frameReflections: _frameReflections, frameReflections: _frameReflections,
showMenubar: showMenubar, showMenubar: showMenubar,
@ -239,7 +238,7 @@ Item{
window_scaling = settings.window_scaling !== undefined ? settings.window_scaling : window_scaling window_scaling = settings.window_scaling !== undefined ? settings.window_scaling : window_scaling
fontIndexes = settings.fontIndexes !== undefined ? settings.fontIndexes : fontIndexes fontIndexes = settings.fontIndexes !== undefined ? settings.fontIndexes : fontIndexes
fontScalingIndex = settings.fontScalingIndex !== undefined ? settings.fontScalingIndex : fontScalingIndex fontScaling = settings.fontScaling !== undefined ? settings.fontScaling : fontScaling
_frameReflections = settings.frameReflections !== undefined ? settings.frameReflections : _frameReflections; _frameReflections = settings.frameReflections !== undefined ? settings.frameReflections : _frameReflections;

View File

@ -35,11 +35,8 @@ Tab{
model: [qsTr("Default"), qsTr("Scanlines"), qsTr("Pixels")] model: [qsTr("Default"), qsTr("Scanlines"), qsTr("Pixels")]
currentIndex: shadersettings.rasterization currentIndex: shadersettings.rasterization
onCurrentIndexChanged: { onCurrentIndexChanged: {
scalingChanger.enabled = false;
shadersettings.rasterization = currentIndex shadersettings.rasterization = currentIndex
fontChanger.updateIndex(); fontChanger.updateIndex();
scalingChanger.updateIndex();
scalingChanger.enabled = true;
} }
} }
} }
@ -67,24 +64,24 @@ Tab{
RowLayout{ RowLayout{
Layout.fillWidth: true Layout.fillWidth: true
Slider{ Slider{
id: scalingChanger
Layout.fillWidth: true Layout.fillWidth: true
minimumValue: 0 id: fontScalingChanger
maximumValue: shadersettings.fontScalingList.length - 1 onValueChanged: if(enabled) shadersettings.fontScaling = value
stepSize: 1 stepSize: 0.05
tickmarksEnabled: true enabled: false // Another trick to fix initial bad behavior.
value: updateIndex() Component.onCompleted: {
onValueChanged: { minimumValue = 0.5;
if(!enabled) return; //Ugly and hacky solution. Look for a better solution. maximumValue = 2.5;
shadersettings.setScalingIndex(value); value = shadersettings.fontScaling;
enabled = true;
} }
function updateIndex(){ Connections{
value = shadersettings.getScalingIndex(); target: shadersettings
onFontScalingChanged: fontScalingChanger.value = shadersettings.fontScaling;
} }
Component.onCompleted: shadersettings.fontScalingChanged.connect(updateIndex);
} }
Text{ Text{
text: shadersettings.fontScalingList[scalingChanger.value].toFixed(2) text: Math.round(fontScalingChanger.value * 100) + "%"
} }
} }
Text{ text: qsTr("Font Width") } Text{ text: qsTr("Font Width") }

View File

@ -85,20 +85,13 @@ ApplicationWindow{
id: zoomIn id: zoomIn
text: qsTr("Zoom In") text: qsTr("Zoom In")
shortcut: "Ctrl++" shortcut: "Ctrl++"
onTriggered: { onTriggered: shadersettings.incrementScaling();
var oldScaling = shadersettings.fontScalingIndex;
var maxScalingIndex = shadersettings.fontScalingList.length - 1;
shadersettings.setScalingIndex(Math.min(oldScaling + 1, maxScalingIndex));
}
} }
Action{ Action{
id: zoomOut id: zoomOut
text: qsTr("Zoom Out") text: qsTr("Zoom Out")
shortcut: "Ctrl+-" shortcut: "Ctrl+-"
onTriggered: { onTriggered: shadersettings.decrementScaling();
var oldScaling = shadersettings.fontScalingIndex;
shadersettings.setScalingIndex(Math.max(oldScaling - 1, 0));
}
} }
Action{ Action{
id: showAboutAction id: showAboutAction