From ce4a44753a0d7cea468b9f188f6a796e4f751006 Mon Sep 17 00:00:00 2001 From: Filippo Scognamiglio Date: Fri, 22 Nov 2013 14:17:24 +0100 Subject: [PATCH] Added initial files taken from yat declarative --- cool-old-term.pro | 21 +++ main.cpp | 20 +++ qml/cool-old-term/HighlightArea.qml | 75 +++++++++++ qml/cool-old-term/TerminalLine.qml | 34 +++++ qml/cool-old-term/TerminalScreen.qml | 194 +++++++++++++++++++++++++++ qml/cool-old-term/TerminalText.qml | 78 +++++++++++ qml/cool-old-term/main.qml | 43 ++++++ 7 files changed, 465 insertions(+) create mode 100644 cool-old-term.pro create mode 100644 main.cpp create mode 100644 qml/cool-old-term/HighlightArea.qml create mode 100644 qml/cool-old-term/TerminalLine.qml create mode 100644 qml/cool-old-term/TerminalScreen.qml create mode 100644 qml/cool-old-term/TerminalText.qml create mode 100644 qml/cool-old-term/main.qml diff --git a/cool-old-term.pro b/cool-old-term.pro new file mode 100644 index 0000000..4a4771b --- /dev/null +++ b/cool-old-term.pro @@ -0,0 +1,21 @@ +QT += gui quick + +include(yat/yat_declarative/yat_declarative.pro) + +# If your application uses the Qt Mobility libraries, uncomment the following +# lines and add the respective components to the MOBILITY variable. +# CONFIG += mobility +# MOBILITY += + +# The .cpp file which was generated for your project. Feel free to hack it. +SOURCES += main.cpp + +# Installation path +# target.path = + +OTHER_FILES += \ + $$PWD/qml/cool-old-term/main.qml \ + $$PWD/qml/cool-old-term/TerminalLine.qml \ + $$PWD/qml/cool-old-term/TerminalScreen.qml \ + $$PWD/qml/cool-old-term/TerminalText.qml \ + $$PWD/qml/cool-old-term/HighlightArea.qml diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..e427fab --- /dev/null +++ b/main.cpp @@ -0,0 +1,20 @@ +#include +#include +#include + +#include "register_qml_types.h" +#include "terminal_screen.h" +#include "yat_pty.h" + +int main(int argc, char *argv[]) +{ + QGuiApplication app(argc, argv); + app.setApplicationName("cool-old-term"); + + register_qml_types(); + + QQmlApplicationEngine engine; + engine.load(QUrl("qml/cool-old-term/main.qml")); + + return app.exec(); +} diff --git a/qml/cool-old-term/HighlightArea.qml b/qml/cool-old-term/HighlightArea.qml new file mode 100644 index 0000000..bc40a1c --- /dev/null +++ b/qml/cool-old-term/HighlightArea.qml @@ -0,0 +1,75 @@ +import QtQuick 2.0 + +Item { + id: highlightArea + + property real characterWidth: 0 + property real characterHeight: 0 + property int screenWidth: width / characterWidth + + property point start + property point end + + property color color: "grey" + + width: parent.width + height: parent.height + + opacity: 0.8 + + Rectangle { + id: begginning_rectangle + color: parent.color + opacity: parent.opacity + y:0 + height: characterHeight + } + + Rectangle { + id: middle_rectangle + color: parent.color + opacity: parent.opacity + width: parent.width + x: 0 + anchors.top: begginning_rectangle.bottom + + } + + Rectangle { + id: end_rectangle + color: parent.color + opacity: parent.opacity + x: 0 + height: characterHeight + anchors.top: middle_rectangle.bottom + } + + onCharacterWidthChanged: calculateRectangles(); + onCharacterHeightChanged: calculateRectangles(); + onScreenWidthChanged: calculateRectangles(); + + onStartChanged: calculateRectangles(); + onEndChanged: calculateRectangles(); + + function calculateRectangles() { + highlightArea.y = start.y * characterHeight; + begginning_rectangle.x = start.x * characterWidth; + if (start.y === end.y) { + middle_rectangle.visible = false; + end_rectangle.visible = false + begginning_rectangle.width = (end.x - start.x) * characterWidth; + } else { + begginning_rectangle.width = (screenWidth - start.x) * characterWidth; + if (start.y === end.y - 1) { + middle_rectangle.height = 0; + middle_rectangle.visible = false; + }else { + middle_rectangle.visible = true; + middle_rectangle.height = (end.y - start.y - 1) * characterHeight; + } + end_rectangle.visible = true; + end_rectangle.width = end.x * characterWidth; + } + } + +} diff --git a/qml/cool-old-term/TerminalLine.qml b/qml/cool-old-term/TerminalLine.qml new file mode 100644 index 0000000..e1c7ab2 --- /dev/null +++ b/qml/cool-old-term/TerminalLine.qml @@ -0,0 +1,34 @@ +import QtQuick 2.0 + +import org.yat 1.0 + +ObjectDestructItem { + id: textLine + + property var textComponent : Qt.createComponent("TerminalText.qml") + property font font + property real fontHeight + property real fontWidth + + height: fontHeight + width: parent.width + visible: objectHandle.visible + + Connections { + target: objectHandle + + onIndexChanged: { + y = objectHandle.index * fontHeight; + } + + onTextCreated: { + var textSegment = textComponent.createObject(textLine, + { + "objectHandle" : text, + "font" : textLine.font, + "fontWidth" : textLine.fontWidth, + }) + } + } +} + diff --git a/qml/cool-old-term/TerminalScreen.qml b/qml/cool-old-term/TerminalScreen.qml new file mode 100644 index 0000000..12f5bc2 --- /dev/null +++ b/qml/cool-old-term/TerminalScreen.qml @@ -0,0 +1,194 @@ +import QtQuick 2.0 + +import org.yat 1.0 + +TerminalScreen { + id: screenItem + + property font font + property real fontWidth: fontMetricText.paintedWidth + property real fontHeight: fontMetricText.paintedHeight + + property var lineComponent : Qt.createComponent("TerminalLine.qml") + + font.family: "courier" + + Text { + id: fontMetricText + text: "B" + font: parent.font + visible: false + textFormat: Text.PlainText + } + + Rectangle { + id: background + anchors.fill: parent + color: "black" + } + + Connections { + id: connections + + target: terminal.screen + + onFlash: { + flashAnimation.start() + } + + onCursorPositionChanged: { + cursor.x = x * fontWidth; + cursor.y = y * fontHeight; + } + + onReset: { + resetScreenItems(); + } + + onLineCreated: { + var lineVariable = lineComponent.createObject(screenItem, + { + "objectHandle" : line, + "font": screenItem.font, + "fontWidth" : screenItem.fontWidth, + "fontHeight" : screenItem.fontHeight, + }) + } + } + + onFontChanged: { + setTerminalHeight(); + setTerminalWidth(); + } + + onWidthChanged: { + setTerminalWidth(); + } + onHeightChanged: { + setTerminalHeight(); + } + Component.onCompleted: { + setTerminalWidth(); + setTerminalHeight(); + } + + function setTerminalWidth() { + if (fontWidth > 0) { + var pty_width = Math.floor(width / fontWidth); + screen.width = pty_width; + } + } + + function setTerminalHeight() { + if (fontHeight > 0) { + var pty_height = Math.floor(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" + } + + Rectangle { + id: flash + anchors.fill: parent + color: "grey" + opacity: 0 + SequentialAnimation { + id: flashAnimation + NumberAnimation { + target: flash + property: "opacity" + to: 1 + duration: 75 + } + NumberAnimation { + target: flash + property: "opacity" + to: 0 + duration: 75 + } + } + } + + MouseArea { + id:mousArea + + property point drag_start + + 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 start = Qt.point(character,line); + drag_start = start; + screen.selectionAreaStart = start; + screen.selectionAreaEnd = start; + } + } + + onPositionChanged: { + var character = Math.floor(mouse.x / screen.charWidth); + var line = Math.floor(mouse.y / screen.lineHeight); + 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; + }else { + screen.selectionAreaEnd = current_pos; + screen.selectionAreaStart = drag_start; + } + } + + onReleased: { + if (mouse.button == Qt.LeftButton) { + hoverEnabled = false; + screen.sendSelectionToSelection(); + } + } + + onClicked: { + if (mouse.button == Qt.MiddleButton) { + screen.pasteFromSelection(); + } + } + onDoubleClicked: { + if (mouse.button == Qt.LeftButton) { + var character = Math.floor(mouse.x / screen.charWidth); + var line = Math.floor(mouse.y / screen.lineHeight); + screen.doubleClicked(Qt.point(character,line)); + } + } + } +} diff --git a/qml/cool-old-term/TerminalText.qml b/qml/cool-old-term/TerminalText.qml new file mode 100644 index 0000000..8b805d6 --- /dev/null +++ b/qml/cool-old-term/TerminalText.qml @@ -0,0 +1,78 @@ +/******************************************************************************* +* 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: textItem + property font font + property real fontWidth + + y: 0 + x: 0 + + width: textElement.paintedWidth + height: textElement.paintedHeight + + visible: objectHandle.visible + + Rectangle { + anchors.fill: parent + color: textItem.objectHandle.backgroundColor + } + + + Text { + id: textElement + anchors.fill: parent + text: objectHandle.text + color: objectHandle.foregroundColor + font: textItem.font + textFormat: Text.PlainText + } + + Connections { + target: objectHandle + + onIndexChanged: { + textItem.x = objectHandle.index * textItem.fontWidth; + } + } + + //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 + //} +} diff --git a/qml/cool-old-term/main.qml b/qml/cool-old-term/main.qml new file mode 100644 index 0000000..09675ae --- /dev/null +++ b/qml/cool-old-term/main.qml @@ -0,0 +1,43 @@ +/**************************************************************************** + * This file is part of Terminal. + * + * Copyright (C) 2013 Pier Luigi Fiorini + * + * Author(s): + * Pier Luigi Fiorini + * + * $BEGIN_LICENSE:GPL2+$ + * + * This program 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 2 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 . + * + * $END_LICENSE$ + ***************************************************************************/ + +import QtQuick 2.1 +import QtQuick.Window 2.1 +import QtQuick.Controls 1.0 + +ApplicationWindow{ + id: mainwindow + width: 640 + height: 480 + + visible: true + + TerminalScreen { + id: terminal + width: mainwindow.width + height: mainwindow.height + } +}