From bd0938610f14783a3cf9434254ab78ea056a5d09 Mon Sep 17 00:00:00 2001 From: Filippo Scognamiglio Date: Sat, 7 Jun 2014 02:19:37 +0200 Subject: [PATCH] Various riorganizations and fixes. --- app/ShaderSettings.qml | 2 +- app/Terminal.qml | 155 +++++++++++++++++++--------------------- app/app.qmlproject.user | 7 +- app/main.qml | 11 ++- 4 files changed, 83 insertions(+), 92 deletions(-) diff --git a/app/ShaderSettings.qml b/app/ShaderSettings.qml index 258799a..3908e53 100644 --- a/app/ShaderSettings.qml +++ b/app/ShaderSettings.qml @@ -127,7 +127,7 @@ Item{ ListElement{pixelSize: 18; virtualWidth: 0; virtualHeight: 6}, ListElement{pixelSize: 24; virtualWidth: 0; virtualHeight: 8}, ListElement{pixelSize: 35; virtualWidth: 5; virtualHeight: 12}, - ListElement{pixelSize: 47; virtualWidth: 6; virtualHeight: 11}, + ListElement{pixelSize: 43; virtualWidth: 6; virtualHeight: 11}, ListElement{pixelSize: 54; virtualWidth: 7; virtualHeight: 11}, ListElement{pixelSize: 64; virtualWidth: 8; virtualHeight: 11}, ListElement{pixelSize: 75; virtualWidth: 8; virtualHeight: 11}] diff --git a/app/Terminal.qml b/app/Terminal.qml index 9f844ff..fb6a7ad 100644 --- a/app/Terminal.qml +++ b/app/Terminal.qml @@ -47,7 +47,7 @@ Item{ property int mScanlines: shadersettings.rasterization onMScanlinesChanged: restartBlurredSource() - property size terminalSize + property size terminalSize: kterminal.terminalSize property size paintedTextSize onPaintedTextSizeChanged: console.log(paintedTextSize) @@ -60,79 +60,64 @@ Item{ blurredSource.live = true; livetimer.restart() } - function loadKTerminal(){ - kterminal.active = true; - } - function unloadKTerminal(){ - kterminal.active = false; - } function pasteClipboard(){ - kterminal.item.pasteClipboard(); + kterminal.pasteClipboard(); } function copyClipboard(){ - kterminal.item.copyClipboard(); + kterminal.copyClipboard(); } - Loader{ + + KTerminal { id: kterminal - active: false anchors.fill: parent + font.pixelSize: shadersettings.font.pixelSize + font.family: shadersettings.font.name - sourceComponent: KTerminal { - id: ktermitem - font.pixelSize: shadersettings.font.pixelSize - font.family: shadersettings.font.name + colorScheme: "MyWhiteOnBlack" - colorScheme: "MyWhiteOnBlack" + session: KSession { + id: ksession + kbScheme: "linux" - onTerminalSizeChanged: terminalContainer.terminalSize = ktermitem.terminalSize - - session: KSession { - id: ksession - kbScheme: "linux" - - onFinished: { - Qt.quit() - } + onFinished: { + Qt.quit() } + } - Text{id: fontMetrics; text: "B"; visible: false} + Text{id: fontMetrics; text: "B"; visible: false} - function handleFontChange(){ - var scaling_factor = shadersettings.window_scaling; - var font_size = shadersettings.font.pixelSize * scaling_factor; - font.pixelSize = font_size; - font.family = shadersettings.font.name; + function handleFontChange(){ + var scaling_factor = shadersettings.window_scaling; + var font_size = shadersettings.font.pixelSize * scaling_factor; + font.pixelSize = font_size; + font.family = shadersettings.font.name; - fontMetrics.font = font; + fontMetrics.font = font; - var vertical_density = shadersettings.font.virtualResolution.height; - var horizontal_density = shadersettings.font.virtualResolution.width; + var vertical_density = shadersettings.font.virtualResolution.height; + var horizontal_density = shadersettings.font.virtualResolution.width; - var scanline_height = fontMetrics.paintedHeight / vertical_density; - var scanline_width = fontMetrics.paintedWidth / horizontal_density; + var scanline_height = fontMetrics.paintedHeight / vertical_density; + var scanline_width = fontMetrics.paintedWidth / horizontal_density; - console.log("Font height: " + fontMetrics.paintedHeight) + var scanline_spacing = shadersettings.font.lineSpacing; + var line_spacing = Math.round(scanline_spacing * scanline_height); - var scanline_spacing = shadersettings.font.lineSpacing; - var line_spacing = Math.round(scanline_spacing * scanline_height); +// console.log("Font height: " + fontMetrics.paintedHeight) +// console.log("Scanline Height: " + scanline_height) +// console.log("Line Spacing: " + line_spacing) - console.log("Scanline Height: " + scanline_height) - console.log("Line Spacing: " + line_spacing) + terminalContainer.scanlineHeight = scanline_height; + terminalContainer.scanlineWidth = scanline_width; - terminalContainer.scanlineHeight = scanline_height; - terminalContainer.scanlineWidth = scanline_width; - - setLineSpacing(line_spacing); - restartBlurredSource(); - } - - onUpdatedImage: {blurredSource.live = true;livetimer.restart();} - Component.onCompleted: { - shadersettings.terminalFontChanged.connect(handleFontChange); - handleFontChange(); - forceActiveFocus(); - } + setLineSpacing(line_spacing); + restartBlurredSource(); + } + Component.onCompleted: { + shadersettings.terminalFontChanged.connect(handleFontChange); + handleFontChange(); + forceActiveFocus(); } } Menu{ @@ -146,33 +131,33 @@ Item{ acceptedButtons: Qt.LeftButton | Qt.MiddleButton | Qt.RightButton anchors.fill: parent onWheel: - wheel.angleDelta.y > 0 ? kterminal.item.scrollUp() : kterminal.item.scrollDown() + wheel.angleDelta.y > 0 ? kterminal.scrollUp() : kterminal.scrollDown() onClicked: { if (mouse.button == Qt.RightButton){ contextmenu.popup(); } else if (mouse.button == Qt.MiddleButton){ - kterminal.item.pasteSelection(); + kterminal.pasteSelection(); } } onDoubleClicked: { if (mouse.button == Qt.LeftButton){ var coord = correctDistortion(mouse.x, mouse.y); - kterminal.item.mouseDoubleClick(coord.width, coord.height); + kterminal.mouseDoubleClick(coord.width, coord.height); } } onPositionChanged: { var coord = correctDistortion(mouse.x, mouse.y); - kterminal.item.mouseMove(coord.width, coord.height); + kterminal.mouseMove(coord.width, coord.height); } onPressed: { if (mouse.button == Qt.LeftButton){ var coord = correctDistortion(mouse.x, mouse.y); - kterminal.item.mousePress(coord.width, coord.height); + kterminal.mousePress(coord.width, coord.height); } } onReleased: { if (mouse.button == Qt.LeftButton){ - kterminal.item.mouseRelease(mouse.x, mouse.y); + kterminal.mouseRelease(mouse.x, mouse.y); } } @@ -206,6 +191,12 @@ Item{ id: livetimer running: true onTriggered: parent.live = false; + + function updateImageHandler(){ + livetimer.restart(); + blurredSource.live = true; + } + Component.onCompleted: kterminal.updatedImage.connect(updateImageHandler); } } ShaderEffectSource{ @@ -220,7 +211,7 @@ Item{ property variant blurredSource: (mBlur !== 0) ? blurredSource : undefined property size virtual_resolution: parent.virtual_resolution property size delta: Qt.size((mScanlines == shadersettings.pixel_rasterization ? deltax : 0), - mScanlines != shadersettings.no_rasterization ? deltay : 0) + mScanlines != shadersettings.no_rasterization ? deltay : 0) z: 2 fragmentShader: @@ -232,28 +223,28 @@ Item{ uniform highp vec2 virtual_resolution;" + - (mBlur !== 0 ? - "uniform lowp sampler2D blurredSource;" - : "") + + (mBlur !== 0 ? + "uniform lowp sampler2D blurredSource;" + : "") + - "void main() {" + - "vec2 coords = qt_TexCoord0;" + - (mScanlines != shadersettings.no_rasterization ? " + "void main() {" + + "vec2 coords = qt_TexCoord0;" + + (mScanlines != shadersettings.no_rasterization ? " coords.y = floor(virtual_resolution.y * coords.y) / virtual_resolution.y;" + - (mScanlines == shadersettings.pixel_rasterization ? " + (mScanlines == shadersettings.pixel_rasterization ? " coords.x = floor(virtual_resolution.x * coords.x) / virtual_resolution.x;" : "") - : "") + + : "") + - "float color = texture2D(source, coords + delta).r * 256.0;" + - (mBlur !== 0 ? - "float blurredSourceColor = texture2D(blurredSource, qt_TexCoord0).r * 256.0;" + - "blurredSourceColor = blurredSourceColor - blurredSourceColor * " + (1.0 - motionBlurCoefficient) * fpsAttenuation+ ";" + - "color = step(1.0, color) * color + step(color, 1.0) * blurredSourceColor;" - : "") + + "float color = texture2D(source, coords + delta).r * 256.0;" + + (mBlur !== 0 ? + "float blurredSourceColor = texture2D(blurredSource, qt_TexCoord0).r * 256.0;" + + "blurredSourceColor = blurredSourceColor - blurredSourceColor * " + (1.0 - motionBlurCoefficient) * fpsAttenuation+ ";" + + "color = step(1.0, color) * color + step(color, 1.0) * blurredSourceColor;" + : "") + - "gl_FragColor = vec4(vec3(floor(color) / 256.0), 1.0);" + - "}" + "gl_FragColor = vec4(vec3(floor(color) / 256.0), 1.0);" + + "}" } ////////////////////////////////////////////////////////////////////// //EFFECTS @@ -296,14 +287,14 @@ Item{ float getScanlineIntensity(vec2 coords) { float result = abs(sin(coords.y * virtual_resolution.y * "+Math.PI+"));" + - (mScanlines == shadersettings.pixel_rasterization ? - "result *= abs(sin(coords.x * virtual_resolution.x * "+Math.PI+"));" : "") + " + (mScanlines == shadersettings.pixel_rasterization ? + "result *= abs(sin(coords.x * virtual_resolution.x * "+Math.PI+"));" : "") + " return result; }" + - "void main() {" + - "gl_FragColor = vec4(getScanlineIntensity(qt_TexCoord0));" + - "}" + "void main() {" + + "gl_FragColor = vec4(getScanlineIntensity(qt_TexCoord0));" + + "}" } } Loader{ diff --git a/app/app.qmlproject.user b/app/app.qmlproject.user index e686147..8ca1b8a 100644 --- a/app/app.qmlproject.user +++ b/app/app.qmlproject.user @@ -1,6 +1,6 @@ - + ProjectExplorer.Project.ActiveTarget @@ -74,7 +74,10 @@ 0 - + + QML_DISABLE_OPTIMIZER=1 + <VARIABLE>=<VALUE> + QML Scene QmlProjectManager.QmlRunConfiguration.QmlScene diff --git a/app/main.qml b/app/main.qml index 9f019ed..41d49d7 100644 --- a/app/main.qml +++ b/app/main.qml @@ -88,6 +88,10 @@ ApplicationWindow{ } } + ShaderSettings{ + id: shadersettings + } + Loader{ id: frame property rect sourceRect: Qt.rect(-item.rectX * shadersettings.window_scaling, @@ -142,9 +146,6 @@ ApplicationWindow{ z: 1.9 } } - ShaderSettings{ - id: shadersettings - } SettingsWindow{ id: settingswindow visible: false @@ -158,8 +159,4 @@ ApplicationWindow{ terminalSize: terminal.terminalSize } } - - Component.onCompleted: { - terminal.loadKTerminal(); - } }