2014-03-31 22:23:48 +02:00
|
|
|
/*******************************************************************************
|
|
|
|
* Copyright (c) 2013 "Filippo Scognamiglio"
|
|
|
|
* https://github.com/Swordifish90/cool-old-term
|
|
|
|
*
|
|
|
|
* This file is part of cool-old-term.
|
|
|
|
*
|
|
|
|
* cool-old-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/>.
|
|
|
|
*******************************************************************************/
|
|
|
|
|
2014-04-17 13:56:13 +02:00
|
|
|
import QtQuick 2.2
|
2014-03-23 18:29:19 +01:00
|
|
|
import QtGraphicalEffects 1.0
|
2014-04-17 13:56:13 +02:00
|
|
|
import QtQuick.Controls 1.1
|
2014-03-20 16:19:11 +01:00
|
|
|
|
|
|
|
import org.kde.konsole 0.1
|
|
|
|
|
2014-03-22 11:11:27 +01:00
|
|
|
Item{
|
|
|
|
id: terminalContainer
|
2014-04-03 18:44:23 +02:00
|
|
|
//The blur effect has to take into account the framerate
|
2014-05-15 23:41:12 +02:00
|
|
|
property real fpsAttenuation: 60 / shadersettings.fps
|
2014-03-23 18:29:19 +01:00
|
|
|
property real mBlur: shadersettings.motion_blur
|
2014-05-15 23:41:12 +02:00
|
|
|
property real motionBlurCoefficient: (_maxBlurCoefficient * mBlur + _minBlurCoefficient * (1 - mBlur))
|
|
|
|
property real _minBlurCoefficient: 0.75
|
|
|
|
property real _maxBlurCoefficient: 0.95
|
2014-03-23 18:29:19 +01:00
|
|
|
|
2014-04-03 18:44:23 +02:00
|
|
|
property real mBloom: shadersettings.bloom_strength
|
|
|
|
|
2014-04-17 13:27:41 +02:00
|
|
|
property size terminalSize
|
|
|
|
|
2014-03-31 16:57:51 +02:00
|
|
|
//Force reload of the blursource when settings change
|
|
|
|
onMBloomChanged: restartBlurredSource()
|
|
|
|
|
|
|
|
function restartBlurredSource(){
|
|
|
|
if(!blurredSource) return;
|
|
|
|
|
|
|
|
blurredSource.live = true;
|
|
|
|
livetimer.restart()
|
|
|
|
}
|
2014-03-30 22:29:15 +02:00
|
|
|
function loadKTerminal(){
|
|
|
|
kterminal.active = true;
|
2014-03-24 23:17:02 +01:00
|
|
|
}
|
2014-03-30 22:29:15 +02:00
|
|
|
function unloadKTerminal(){
|
|
|
|
kterminal.active = false;
|
2014-03-24 23:17:02 +01:00
|
|
|
}
|
2014-04-16 19:30:11 +02:00
|
|
|
function pasteClipboard(){
|
|
|
|
kterminal.item.pasteClipboard();
|
|
|
|
}
|
|
|
|
function copyClipboard(){
|
|
|
|
kterminal.item.copyClipboard();
|
|
|
|
}
|
2014-03-24 23:17:02 +01:00
|
|
|
|
2014-03-30 22:29:15 +02:00
|
|
|
Loader{
|
2014-03-22 11:11:27 +01:00
|
|
|
id: kterminal
|
2014-03-30 22:29:15 +02:00
|
|
|
active: false
|
|
|
|
anchors.fill: parent
|
2014-03-31 14:13:51 +02:00
|
|
|
|
2014-03-30 22:29:15 +02:00
|
|
|
sourceComponent: KTerminal {
|
2014-03-31 14:13:51 +02:00
|
|
|
id: ktermitem
|
2014-05-27 23:54:28 +02:00
|
|
|
font.pixelSize: shadersettings.fontSize
|
2014-03-30 22:29:15 +02:00
|
|
|
font.family: shadersettings.font.name
|
2014-03-20 16:19:11 +01:00
|
|
|
|
2014-03-30 22:29:15 +02:00
|
|
|
colorScheme: "MyWhiteOnBlack"
|
2014-03-20 16:19:11 +01:00
|
|
|
|
2014-04-17 13:27:41 +02:00
|
|
|
onTerminalSizeChanged: terminalContainer.terminalSize = ktermitem.terminalSize
|
|
|
|
|
2014-03-30 22:29:15 +02:00
|
|
|
session: KSession {
|
|
|
|
id: ksession
|
|
|
|
kbScheme: "linux"
|
2014-03-20 16:19:11 +01:00
|
|
|
|
2014-03-30 22:29:15 +02:00
|
|
|
onFinished: {
|
|
|
|
Qt.quit()
|
|
|
|
}
|
2014-03-22 11:11:27 +01:00
|
|
|
}
|
2014-03-20 16:19:11 +01:00
|
|
|
|
2014-03-30 22:29:15 +02:00
|
|
|
onUpdatedImage: {blurredSource.live = true;livetimer.restart();}
|
2014-03-30 18:30:35 +02:00
|
|
|
|
2014-03-30 22:29:15 +02:00
|
|
|
Component.onCompleted: {
|
2014-04-20 22:59:46 +02:00
|
|
|
var scaling_factor = shadersettings.font_scaling * shadersettings.window_scaling;
|
2014-05-08 21:59:46 +02:00
|
|
|
var font_size = shadersettings.font.pixelSize * scaling_factor;
|
|
|
|
var line_spacing = Math.round(shadersettings.font.lineSpacing * font_size);
|
2014-05-27 23:54:28 +02:00
|
|
|
font.pixelSize = font_size;
|
2014-03-30 22:29:15 +02:00
|
|
|
font.family = shadersettings.font.name;
|
2014-05-08 21:59:46 +02:00
|
|
|
setLineSpacing(line_spacing);
|
2014-03-30 22:29:15 +02:00
|
|
|
forceActiveFocus();
|
|
|
|
}
|
2014-03-22 11:11:27 +01:00
|
|
|
}
|
2014-03-20 16:19:11 +01:00
|
|
|
}
|
2014-04-16 19:18:14 +02:00
|
|
|
Menu{
|
|
|
|
id: contextmenu
|
2014-04-16 19:30:11 +02:00
|
|
|
MenuItem{action: copyAction}
|
|
|
|
MenuItem{action: pasteAction}
|
2014-04-17 13:56:13 +02:00
|
|
|
MenuSeparator{}
|
|
|
|
MenuItem{action: fullscreenAction}
|
2014-04-16 19:18:14 +02:00
|
|
|
}
|
2014-03-30 22:29:15 +02:00
|
|
|
MouseArea{
|
2014-04-16 19:18:14 +02:00
|
|
|
|
|
|
|
acceptedButtons: Qt.LeftButton | Qt.MiddleButton | Qt.RightButton
|
2014-03-30 22:29:15 +02:00
|
|
|
anchors.fill: parent
|
|
|
|
onWheel:
|
|
|
|
wheel.angleDelta.y > 0 ? kterminal.item.scrollUp() : kterminal.item.scrollDown()
|
2014-04-16 19:18:14 +02:00
|
|
|
onClicked: {
|
|
|
|
if (mouse.button == Qt.RightButton){
|
|
|
|
contextmenu.popup();
|
|
|
|
} else if (mouse.button == Qt.MiddleButton){
|
|
|
|
kterminal.item.pasteSelection();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
onDoubleClicked: {
|
|
|
|
if (mouse.button == Qt.LeftButton){
|
|
|
|
var coord = correctDistortion(mouse.x, mouse.y);
|
|
|
|
kterminal.item.mouseDoubleClick(coord.width, coord.height);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
onPositionChanged: {
|
|
|
|
var coord = correctDistortion(mouse.x, mouse.y);
|
|
|
|
kterminal.item.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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
onReleased: {
|
|
|
|
if (mouse.button == Qt.LeftButton){
|
|
|
|
kterminal.item.mouseRelease(mouse.x, mouse.y);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function correctDistortion(x, y){
|
|
|
|
x = x / width;
|
|
|
|
y = y / height;
|
|
|
|
|
|
|
|
var cc = Qt.size(0.5 - x, 0.5 - y);
|
|
|
|
var distortion = (cc.height * cc.height + cc.width * cc.width) * shadersettings.screen_distortion;
|
|
|
|
|
|
|
|
return Qt.size((x - cc.width * (1+distortion) * distortion) * width,
|
|
|
|
(y - cc.height * (1+distortion) * distortion) * height)
|
|
|
|
}
|
2014-03-30 22:29:15 +02:00
|
|
|
}
|
2014-03-23 18:29:19 +01:00
|
|
|
ShaderEffectSource{
|
|
|
|
id: source
|
|
|
|
sourceItem: kterminal
|
|
|
|
hideSource: true
|
|
|
|
}
|
|
|
|
Loader{
|
|
|
|
anchors.fill: parent
|
|
|
|
active: mBlur !== 0
|
|
|
|
ShaderEffectSource{
|
|
|
|
id: blurredSource
|
|
|
|
sourceItem: blurredterminal
|
|
|
|
recursive: true
|
|
|
|
live: true
|
2014-03-30 18:30:35 +02:00
|
|
|
|
2014-04-20 22:59:46 +02:00
|
|
|
smooth: false
|
|
|
|
antialiasing: false
|
|
|
|
|
2014-03-30 18:30:35 +02:00
|
|
|
Timer{
|
|
|
|
id: livetimer
|
|
|
|
running: true
|
|
|
|
onTriggered: parent.live = false;
|
|
|
|
}
|
2014-03-23 18:29:19 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
ShaderEffect {
|
|
|
|
id: blurredterminal
|
|
|
|
anchors.fill: parent
|
|
|
|
property variant source: source
|
|
|
|
property variant blurredSource: (mBlur !== 0) ? blurredSource : undefined
|
2014-03-31 16:57:51 +02:00
|
|
|
property size txt_size: Qt.size(width, height)
|
|
|
|
|
2014-03-23 18:29:19 +01:00
|
|
|
z: 2
|
2014-03-26 19:23:47 +01:00
|
|
|
|
2014-03-23 18:29:19 +01:00
|
|
|
fragmentShader:
|
|
|
|
"uniform lowp float qt_Opacity;" +
|
|
|
|
"uniform lowp sampler2D source;" +
|
2014-03-31 16:57:51 +02:00
|
|
|
"uniform lowp vec2 txt_size;" +
|
2014-03-23 18:29:19 +01:00
|
|
|
|
|
|
|
"varying highp vec2 qt_TexCoord0;" +
|
|
|
|
|
|
|
|
(mBlur !== 0 ?
|
2014-03-31 16:57:51 +02:00
|
|
|
"uniform lowp sampler2D blurredSource;"
|
|
|
|
: "") +
|
2014-03-23 18:29:19 +01:00
|
|
|
|
|
|
|
"void main() {" +
|
2014-05-15 23:41:12 +02:00
|
|
|
"float color = texture2D(source, qt_TexCoord0).r * 256.0;" +
|
2014-03-31 16:57:51 +02:00
|
|
|
|
|
|
|
(mBlur !== 0 ?
|
2014-05-15 23:41:12 +02:00
|
|
|
"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;"
|
2014-03-31 16:57:51 +02:00
|
|
|
: "") +
|
|
|
|
|
|
|
|
|
2014-05-15 23:41:12 +02:00
|
|
|
"gl_FragColor = vec4(vec3(floor(color) / 256.0), 1.0);" +
|
2014-03-23 18:29:19 +01:00
|
|
|
"}"
|
|
|
|
}
|
2014-03-20 16:19:11 +01:00
|
|
|
}
|