mirror of
				https://github.com/Swordfish90/cool-retro-term.git
				synced 2025-10-30 22:54:21 +00:00 
			
		
		
		
	Added initial files taken from yat declarative
This commit is contained in:
		
							
								
								
									
										21
									
								
								cool-old-term.pro
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										21
									
								
								cool-old-term.pro
									
									
									
									
									
										Normal file
									
								
							| @@ -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 | ||||||
							
								
								
									
										20
									
								
								main.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										20
									
								
								main.cpp
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,20 @@ | |||||||
|  | #include <QGuiApplication> | ||||||
|  | #include <QQmlApplicationEngine> | ||||||
|  | #include <QQuickWindow> | ||||||
|  |  | ||||||
|  | #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(); | ||||||
|  | } | ||||||
							
								
								
									
										75
									
								
								qml/cool-old-term/HighlightArea.qml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										75
									
								
								qml/cool-old-term/HighlightArea.qml
									
									
									
									
									
										Normal file
									
								
							| @@ -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; | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  |  | ||||||
|  | } | ||||||
							
								
								
									
										34
									
								
								qml/cool-old-term/TerminalLine.qml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										34
									
								
								qml/cool-old-term/TerminalLine.qml
									
									
									
									
									
										Normal file
									
								
							| @@ -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, | ||||||
|  |                 }) | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
|  |  | ||||||
							
								
								
									
										194
									
								
								qml/cool-old-term/TerminalScreen.qml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										194
									
								
								qml/cool-old-term/TerminalScreen.qml
									
									
									
									
									
										Normal file
									
								
							| @@ -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)); | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
							
								
								
									
										78
									
								
								qml/cool-old-term/TerminalText.qml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										78
									
								
								qml/cool-old-term/TerminalText.qml
									
									
									
									
									
										Normal file
									
								
							| @@ -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 | ||||||
|  |     //} | ||||||
|  | } | ||||||
							
								
								
									
										43
									
								
								qml/cool-old-term/main.qml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										43
									
								
								qml/cool-old-term/main.qml
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,43 @@ | |||||||
|  | /**************************************************************************** | ||||||
|  |  * This file is part of Terminal. | ||||||
|  |  * | ||||||
|  |  * Copyright (C) 2013 Pier Luigi Fiorini <pierluigi.fiorini@gmail.com> | ||||||
|  |  * | ||||||
|  |  * 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 <http://www.gnu.org/licenses/>. | ||||||
|  |  * | ||||||
|  |  * $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 | ||||||
|  |     } | ||||||
|  | } | ||||||
		Reference in New Issue
	
	Block a user