1
0
mirror of https://github.com/Swordfish90/cool-retro-term.git synced 2025-01-31 02:01:19 +00:00

Moved to new version of yat. Yat is no longer a submodule but is now integrated.

This commit is contained in:
Filippo Scognamiglio 2013-12-27 00:31:43 +01:00
parent bd39a63a64
commit ce1017ce96
7 changed files with 302 additions and 124 deletions

4
.gitmodules vendored
View File

@ -1,4 +0,0 @@
[submodule "yat"]
path = yat
url = https://github.com/Swordifish90/yat
branch = stable

View File

@ -1,4 +1,4 @@
QT += widgets quick
QT += widgets quick core-private gui-private qml-private quick quick-private
include(yat/yat_declarative/yat_declarative.pro)

View File

@ -1,3 +1,26 @@
/*******************************************************************************
* Copyright (c) 2013 Jørgen Lind
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*******************************************************************************/
import QtQuick 2.0
Item {
@ -5,15 +28,19 @@ Item {
property real characterWidth: 0
property real characterHeight: 0
property int screenWidth: width / characterWidth
property int screenWidth: 0
property point start
property point end
property int startX
property int startY
property int endX
property int endY
property color color: "grey"
y: startY * characterHeight
width: parent.width
height: parent.height
height: (endY - startY + 1) * characterHeight
opacity: 0.8
@ -48,27 +75,29 @@ Item {
onCharacterHeightChanged: calculateRectangles();
onScreenWidthChanged: calculateRectangles();
onStartChanged: calculateRectangles();
onEndChanged: calculateRectangles();
onStartXChanged: calculateRectangles();
onStartYChanged: calculateRectangles();
onEndXChanged: calculateRectangles();
onEndYChanged: calculateRectangles();
function calculateRectangles() {
highlightArea.y = start.y * characterHeight;
begginning_rectangle.x = start.x * characterWidth;
if (start.y === end.y) {
highlightArea.y = startY * characterHeight;
begginning_rectangle.x = startX * characterWidth;
if (startY === endY) {
middle_rectangle.visible = false;
end_rectangle.visible = false
begginning_rectangle.width = (end.x - start.x) * characterWidth;
begginning_rectangle.width = (endX - startX) * characterWidth;
} else {
begginning_rectangle.width = (screenWidth - start.x) * characterWidth;
if (start.y === end.y - 1) {
begginning_rectangle.width = (screenWidth - startX) * characterWidth;
if (startY === endY - 1) {
middle_rectangle.height = 0;
middle_rectangle.visible = false;
}else {
middle_rectangle.visible = true;
middle_rectangle.height = (end.y - start.y - 1) * characterHeight;
middle_rectangle.height = (endY - startY - 1) * characterHeight;
}
end_rectangle.visible = true;
end_rectangle.width = end.x * characterWidth;
end_rectangle.width = endX * characterWidth;
}
}

View File

@ -0,0 +1,66 @@
/*******************************************************************************
* Copyright (c) 2013 Jørgen Lind
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*******************************************************************************/
import QtQuick 2.0
import org.yat 1.0
ObjectDestructItem {
id: cursor
property real fontHeight
property real fontWidth
height: fontHeight
width: fontWidth
x: objectHandle.x * fontWidth
y: objectHandle.y * fontHeight
z: 1.1
visible: objectHandle.visible
ShaderEffect {
anchors.fill: parent
property variant source: fragmentSource
fragmentShader:
"uniform lowp float qt_Opacity;" +
"uniform sampler2D source;" +
"varying highp vec2 qt_TexCoord0;" +
"void main() {" +
" lowp vec4 color = texture2D(source, qt_TexCoord0 ) * qt_Opacity;" +
" gl_FragColor = vec4(1.0 - color.r, 1.0 - color.g, 1.0 - color.b, color.a);" +
"}"
ShaderEffectSource {
id: fragmentSource
sourceItem: background
live: true
sourceRect: Qt.rect(cursor.x,cursor.y,cursor.width,cursor.height);
}
}
}

View File

@ -1,4 +1,28 @@
/*******************************************************************************
* Copyright (c) 2013 Jørgen Lind
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*******************************************************************************/
import QtQuick 2.0
import QtQuick.Controls 1.1
import org.yat 1.0
@ -10,10 +34,35 @@ TerminalScreen {
property real fontHeight: fontMetricText.paintedHeight
property var lineComponent : Qt.createComponent("TerminalLine.qml")
property var textComponent : Qt.createComponent("TerminalText.qml")
property var cursorComponent : Qt.createComponent("TerminalCursor.qml")
font.family: "Pet Me"
font.pointSize: 14
//font.bold: true
font.pixelSize: 20
focus: true
Action {
id: copyAction
shortcut: "Ctrl+Shift+C"
onTriggered: screen.selection.sendToClipboard()
}
Action {
id: paseAction
shortcut: "Ctrl+Shift+V"
onTriggered: screen.selection.pasteFromClipboard()
}
onActiveFocusChanged: {
if (activeFocus) {
Qt.inputMethod.show();
}
}
Keys.onPressed: {
if (event.text === "?") {
terminal.screen.printScreen()
}
}
Text {
id: fontMetricText
@ -23,10 +72,47 @@ TerminalScreen {
textFormat: Text.PlainText
}
Rectangle {
id: background
anchors.fill: parent
color: "black"
Flickable {
id: flickable
anchors.top: parent.top
anchors.left: parent.left
contentWidth: width
contentHeight: textContainer.height
interactive: true
flickableDirection: Flickable.VerticalFlick
contentY: ((screen.contentHeight - screen.height) * screenItem.fontHeight)
Item {
id: textContainer
width: parent.width
height: screen.contentHeight * screenItem.fontHeight
Rectangle {
id: background
anchors.fill: parent
color: terminal.screen.defaultBackgroundColor
}
HighlightArea {
characterHeight: fontHeight
characterWidth: fontWidth
screenWidth: terminalWindow.width
startX: screen.selection.startX
startY: screen.selection.startY
endX: screen.selection.endX
endY: screen.selection.endY
visible: screen.selection.enable
}
}
onContentYChanged: {
if (!atYEnd) {
var top_line = Math.floor(Math.max(contentY,0) / screenItem.fontHeight);
screen.ensureVisiblePages(top_line);
}
}
}
Connections {
@ -38,24 +124,44 @@ TerminalScreen {
flashAnimation.start()
}
onCursorPositionChanged: {
cursor.x = x * fontWidth;
cursor.y = y * fontHeight;
}
onReset: {
resetScreenItems();
}
onLineCreated: {
var lineVariable = lineComponent.createObject(screenItem,
onTextCreated: {
var textSegment = textComponent.createObject(screenItem,
{
"objectHandle" : line,
"font": screenItem.font,
"parent" : background,
"objectHandle" : text,
"font" : screenItem.font,
"fontWidth" : screenItem.fontWidth,
"fontHeight" : screenItem.fontHeight,
})
}
onCursorCreated: {
if (cursorComponent.status != Component.Ready) {
console.log(cursorComponent.errorString());
return;
}
var cursorVariable = cursorComponent.createObject(screenItem,
{
"parent" : textContainer,
"objectHandle" : cursor,
"fontWidth" : screenItem.fontWidth,
"fontHeight" : screenItem.fontHeight,
})
}
onRequestHeightChange: {
terminalWindow.height = newHeight * screenItem.fontHeight;
terminalWindow.contentItem.height = newHeight * screenItem.fontHeight;
}
onRequestWidthChange: {
terminalWindow.width = newWidth * screenItem.fontWidth;
terminalWindow.contentItem.width = newWidth * screenItem.fontWidth;
}
}
onFontChanged: {
@ -77,6 +183,7 @@ TerminalScreen {
function setTerminalWidth() {
if (fontWidth > 0) {
var pty_width = Math.floor(width / fontWidth);
flickable.width = pty_width * fontWidth;
screen.width = pty_width;
}
}
@ -84,50 +191,16 @@ TerminalScreen {
function setTerminalHeight() {
if (fontHeight > 0) {
var pty_height = Math.floor(height / fontHeight);
flickable.height = pty_height * fontHeight;
screen.height = pty_height;
}
}
Item {
id: keyHandler
focus: true
Keys.onPressed: {
terminal.screen.sendKey(event.text, event.key, event.modifiers);
if (event.text === "?") {
terminal.screen.printScreen()
}
}
}
HighlightArea {
characterHeight: fontHeight
characterWidth: fontWidth
start: screen.selectionAreaStart
end: screen.selectionAreaEnd
visible: screen.selectionEnabled
}
Rectangle {
id: cursor
width: fontWidth
height: fontHeight
x: 0
y: 0
color: "white"
// SequentialAnimation on opacity{
// NumberAnimation{from: 0; to: 1; duration: 500}
// NumberAnimation{from: 1; to: 0; duration: 500}
// loops: Animation.Infinite
// }
}
Rectangle {
id: flash
z: 1.2
anchors.fill: parent
color: "white"
color: "grey"
opacity: 0
SequentialAnimation {
id: flashAnimation
@ -149,39 +222,49 @@ TerminalScreen {
MouseArea {
id:mousArea
property point drag_start
property int drag_start_x
property int drag_start_y
anchors.fill: parent
acceptedButtons: Qt.LeftButton | Qt.MiddleButton
onPressed: {
if (mouse.button == Qt.LeftButton) {
hoverEnabled = true;
var character = Math.floor((mouse.x / screen.charWidth));
var line = Math.floor(mouse.y / screen.lineHeight);
var transformed_mouse = mapToItem(textContainer, mouse.x, mouse.y);
var character = Math.floor((transformed_mouse.x / fontWidth));
var line = Math.floor(transformed_mouse.y / fontHeight);
var start = Qt.point(character,line);
drag_start = start;
screen.selectionAreaStart = start;
screen.selectionAreaEnd = start;
drag_start_x = character;
drag_start_y = line;
screen.selection.startX = character;
screen.selection.startY = line;
screen.selection.endX = character;
screen.selection.endY = line;
}
}
onPositionChanged: {
var character = Math.floor(mouse.x / screen.charWidth);
var line = Math.floor(mouse.y / screen.lineHeight);
var transformed_mouse = mapToItem(textContainer, mouse.x, mouse.y);
var character = Math.floor(transformed_mouse.x / fontWidth);
var line = Math.floor(transformed_mouse.y / fontHeight);
var current_pos = Qt.point(character,line);
if (line < drag_start.y || (line === drag_start.y && character < drag_start.x)) {
screen.selectionAreaStart = current_pos;
screen.selectionAreaEnd = drag_start;
if (line < drag_start_y || (line === drag_start_y && character < drag_start_x)) {
screen.selection.startX = character;
screen.selection.startY = line;
screen.selection.endX = drag_start_x;
screen.selection.endY = drag_start_y;
}else {
screen.selectionAreaEnd = current_pos;
screen.selectionAreaStart = drag_start;
screen.selection.startX = drag_start_x;
screen.selection.startY = drag_start_y;
screen.selection.endX = character;
screen.selection.endY = line;
}
}
onReleased: {
if (mouse.button == Qt.LeftButton) {
hoverEnabled = false;
screen.sendSelectionToSelection();
screen.selection.sendToSelection();
}
}
@ -190,10 +273,12 @@ TerminalScreen {
screen.pasteFromSelection();
}
}
onDoubleClicked: {
if (mouse.button == Qt.LeftButton) {
var character = Math.floor(mouse.x / screen.charWidth);
var line = Math.floor(mouse.y / screen.lineHeight);
var transformed_mouse = mapToItem(textContainer, mouse.x, mouse.y);
var character = Math.floor(transformed_mouse.x / fontWidth);
var line = Math.floor(transformed_mouse.y / fontHeight);
screen.doubleClicked(Qt.point(character,line));
}
}

View File

@ -29,9 +29,10 @@ ObjectDestructItem {
id: textItem
property font font
property real fontWidth
property real fontHeight
y: 0
x: 0
y: objectHandle.line * fontHeight;
x: objectHandle.index * fontWidth;
width: textElement.paintedWidth
height: textElement.paintedHeight
@ -40,39 +41,41 @@ ObjectDestructItem {
Rectangle {
anchors.fill: parent
color: textItem.objectHandle.backgroundColor
}
color: "black" //objectHandle.backgroundColor
MonoText {
id: textElement
anchors.fill: parent
text: objectHandle.text
color: "white" //objectHandle.foregroundColor
font.family: textItem.font.family
font.pixelSize: textItem.font.pixelSize
font.pointSize: textItem.font.pointSize
font.bold: objectHandle.bold
font.underline: objectHandle.underline
latin: objectHandle.latin
Text {
id: textElement
anchors.fill: parent
text: objectHandle.text
color: "white"
font: textItem.font
textFormat: Text.PlainText
}
Connections {
target: objectHandle
onIndexChanged: {
textItem.x = objectHandle.index * textItem.fontWidth;
SequentialAnimation {
running: objectHandle.blinking
loops: Animation.Infinite
onRunningChanged: {
if (running === false)
textElement.opacity = 1
}
NumberAnimation {
target: textElement
property: "opacity"
to: 0
duration: 250
}
NumberAnimation {
target: textElement
property: "opacity"
to: 1
duration: 250
}
}
}
}
//Component.onCompleted: {
// //color = randomBg();
//}
//function randomBg()
//{
// var hex1=new Array("0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F")
// var hex2=new Array("0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F")
// var hex3=new Array("0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F")
// var hex4=new Array("0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F")
// var hex5=new Array("0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F")
// var hex6=new Array("0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F")
// var bg="#"+hex1[Math.floor(Math.random()*hex1.length)]+hex2[Math.floor(Math.random()*hex2.length)]+hex3[Math.floor(Math.random()*hex3.length)]+hex4[Math.floor(Math.random()*hex4.length)]+hex5[Math.floor(Math.random()*hex5.length)]+hex6[Math.floor(Math.random()*hex6.length)]
// return bg
//}
}

View File

@ -229,13 +229,12 @@ ApplicationWindow{
TerminalScreen {
id: terminal
anchors.centerIn: parent
width: mainwindow.width
height: mainwindow.height
visible: false
anchors.fill: parent
//FIXME: Ugly forced clear terminal at the beginning
Component.onCompleted: terminal.screen.sendKey("l", 76, 67108864);
Component.onCompleted: {
terminal.screen.sendKey("l", 76, 67108864);
}
}
RadialGradient{