2013-12-27 00:31:43 +01:00
|
|
|
/*******************************************************************************
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
*******************************************************************************/
|
|
|
|
|
2013-12-27 19:11:11 +01:00
|
|
|
import QtQuick 2.1
|
2013-11-22 14:17:24 +01:00
|
|
|
|
|
|
|
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")
|
2013-12-27 00:31:43 +01:00
|
|
|
property var textComponent : Qt.createComponent("TerminalText.qml")
|
|
|
|
property var cursorComponent : Qt.createComponent("TerminalCursor.qml")
|
2013-11-22 14:17:24 +01:00
|
|
|
|
2013-12-27 19:11:11 +01:00
|
|
|
font.family: shadersettings.font.name
|
|
|
|
font.pixelSize: shadersettings.fontSize
|
2013-12-27 00:31:43 +01:00
|
|
|
focus: true
|
|
|
|
|
|
|
|
onActiveFocusChanged: {
|
|
|
|
if (activeFocus) {
|
|
|
|
Qt.inputMethod.show();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Keys.onPressed: {
|
|
|
|
if (event.text === "?") {
|
|
|
|
terminal.screen.printScreen()
|
|
|
|
}
|
|
|
|
}
|
2013-11-22 14:17:24 +01:00
|
|
|
|
|
|
|
Text {
|
|
|
|
id: fontMetricText
|
|
|
|
text: "B"
|
|
|
|
font: parent.font
|
|
|
|
visible: false
|
|
|
|
textFormat: Text.PlainText
|
|
|
|
}
|
|
|
|
|
2013-12-27 00:31:43 +01:00
|
|
|
Flickable {
|
|
|
|
id: flickable
|
|
|
|
anchors.top: parent.top
|
|
|
|
anchors.left: parent.left
|
|
|
|
contentWidth: width
|
|
|
|
contentHeight: textContainer.height
|
2013-12-27 16:27:33 +01:00
|
|
|
interactive: false
|
2013-12-27 00:31:43 +01:00
|
|
|
flickableDirection: Flickable.VerticalFlick
|
|
|
|
contentY: ((screen.contentHeight - screen.height) * screenItem.fontHeight)
|
2013-12-27 16:27:33 +01:00
|
|
|
boundsBehavior: Flickable.StopAtBounds
|
2013-12-27 00:31:43 +01:00
|
|
|
|
|
|
|
Item {
|
|
|
|
id: textContainer
|
|
|
|
width: parent.width
|
|
|
|
height: screen.contentHeight * screenItem.fontHeight
|
|
|
|
Rectangle {
|
|
|
|
id: background
|
|
|
|
anchors.fill: parent
|
|
|
|
color: terminal.screen.defaultBackgroundColor
|
|
|
|
}
|
|
|
|
}
|
|
|
|
onContentYChanged: {
|
|
|
|
if (!atYEnd) {
|
|
|
|
var top_line = Math.floor(Math.max(contentY,0) / screenItem.fontHeight);
|
|
|
|
screen.ensureVisiblePages(top_line);
|
|
|
|
}
|
|
|
|
}
|
2013-11-22 14:17:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Connections {
|
|
|
|
id: connections
|
|
|
|
|
|
|
|
target: terminal.screen
|
|
|
|
|
|
|
|
onFlash: {
|
|
|
|
flashAnimation.start()
|
|
|
|
}
|
|
|
|
|
|
|
|
onReset: {
|
|
|
|
resetScreenItems();
|
|
|
|
}
|
|
|
|
|
2013-12-27 00:31:43 +01:00
|
|
|
onTextCreated: {
|
|
|
|
var textSegment = textComponent.createObject(screenItem,
|
2013-11-22 14:17:24 +01:00
|
|
|
{
|
2013-12-27 00:31:43 +01:00
|
|
|
"parent" : background,
|
|
|
|
"objectHandle" : text,
|
|
|
|
"font" : screenItem.font,
|
2013-11-22 14:17:24 +01:00
|
|
|
"fontWidth" : screenItem.fontWidth,
|
|
|
|
"fontHeight" : screenItem.fontHeight,
|
|
|
|
})
|
|
|
|
}
|
2013-12-27 00:31:43 +01:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
2013-11-22 14:17:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
onFontChanged: {
|
|
|
|
setTerminalHeight();
|
|
|
|
setTerminalWidth();
|
|
|
|
}
|
|
|
|
|
|
|
|
onWidthChanged: {
|
|
|
|
setTerminalWidth();
|
|
|
|
}
|
|
|
|
onHeightChanged: {
|
|
|
|
setTerminalHeight();
|
|
|
|
}
|
|
|
|
Component.onCompleted: {
|
|
|
|
setTerminalWidth();
|
|
|
|
setTerminalHeight();
|
|
|
|
}
|
|
|
|
|
|
|
|
function setTerminalWidth() {
|
|
|
|
if (fontWidth > 0) {
|
|
|
|
var pty_width = Math.floor(width / fontWidth);
|
2013-12-27 00:31:43 +01:00
|
|
|
flickable.width = pty_width * fontWidth;
|
2013-11-22 14:17:24 +01:00
|
|
|
screen.width = pty_width;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function setTerminalHeight() {
|
|
|
|
if (fontHeight > 0) {
|
|
|
|
var pty_height = Math.floor(height / fontHeight);
|
2013-12-27 00:31:43 +01:00
|
|
|
flickable.height = pty_height * fontHeight;
|
2013-11-22 14:17:24 +01:00
|
|
|
screen.height = pty_height;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-27 16:27:33 +01:00
|
|
|
HighlightArea {
|
|
|
|
characterHeight: fontHeight
|
|
|
|
characterWidth: fontWidth
|
|
|
|
|
|
|
|
start: screen.selectionAreaStart
|
|
|
|
end: screen.selectionAreaEnd
|
|
|
|
|
|
|
|
visible: screen.selectionEnabled
|
|
|
|
}
|
|
|
|
|
2013-11-22 14:17:24 +01:00
|
|
|
Rectangle {
|
|
|
|
id: flash
|
2013-12-27 00:31:43 +01:00
|
|
|
z: 1.2
|
2013-11-22 14:17:24 +01:00
|
|
|
anchors.fill: parent
|
2013-12-27 00:31:43 +01:00
|
|
|
color: "grey"
|
2013-11-22 14:17:24 +01:00
|
|
|
opacity: 0
|
|
|
|
SequentialAnimation {
|
|
|
|
id: flashAnimation
|
|
|
|
NumberAnimation {
|
|
|
|
target: flash
|
|
|
|
property: "opacity"
|
2013-12-25 19:11:00 +01:00
|
|
|
to: 0.5
|
2013-11-22 14:17:24 +01:00
|
|
|
duration: 75
|
|
|
|
}
|
|
|
|
NumberAnimation {
|
|
|
|
target: flash
|
|
|
|
property: "opacity"
|
|
|
|
to: 0
|
|
|
|
duration: 75
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
MouseArea {
|
|
|
|
id:mousArea
|
|
|
|
|
2013-12-27 16:27:33 +01:00
|
|
|
property point drag_start
|
2013-11-22 14:17:24 +01:00
|
|
|
|
|
|
|
anchors.fill: parent
|
|
|
|
acceptedButtons: Qt.LeftButton | Qt.MiddleButton
|
|
|
|
onPressed: {
|
|
|
|
if (mouse.button == Qt.LeftButton) {
|
|
|
|
hoverEnabled = true;
|
2013-12-27 16:27:33 +01:00
|
|
|
var character = Math.floor((mouse.x / screen.charWidth));
|
|
|
|
var line = Math.floor(mouse.y / screen.lineHeight);
|
2013-11-22 14:17:24 +01:00
|
|
|
var start = Qt.point(character,line);
|
2013-12-27 16:27:33 +01:00
|
|
|
drag_start = start;
|
|
|
|
screen.selectionAreaStart = start;
|
|
|
|
screen.selectionAreaEnd = start;
|
2013-11-22 14:17:24 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
onPositionChanged: {
|
2013-12-27 16:27:33 +01:00
|
|
|
var character = Math.floor(mouse.x / screen.charWidth);
|
|
|
|
var line = Math.floor(mouse.y / screen.lineHeight);
|
2013-11-22 14:17:24 +01:00
|
|
|
var current_pos = Qt.point(character,line);
|
2013-12-27 16:27:33 +01:00
|
|
|
if (line < drag_start.y || (line === drag_start.y && character < drag_start.x)) {
|
|
|
|
screen.selectionAreaStart = current_pos;
|
|
|
|
screen.selectionAreaEnd = drag_start;
|
2013-11-22 14:17:24 +01:00
|
|
|
}else {
|
2013-12-27 16:27:33 +01:00
|
|
|
screen.selectionAreaEnd = current_pos;
|
|
|
|
screen.selectionAreaStart = drag_start;
|
2013-11-22 14:17:24 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
onReleased: {
|
|
|
|
if (mouse.button == Qt.LeftButton) {
|
|
|
|
hoverEnabled = false;
|
2013-12-27 16:27:33 +01:00
|
|
|
screen.sendSelectionToSelection();
|
2013-11-22 14:17:24 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
onClicked: {
|
|
|
|
if (mouse.button == Qt.MiddleButton) {
|
|
|
|
screen.pasteFromSelection();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
onDoubleClicked: {
|
|
|
|
if (mouse.button == Qt.LeftButton) {
|
2013-12-27 16:27:33 +01:00
|
|
|
var character = Math.floor(mouse.x / screen.charWidth);
|
|
|
|
var line = Math.floor(mouse.y / screen.lineHeight);
|
2013-11-22 14:17:24 +01:00
|
|
|
screen.doubleClicked(Qt.point(character,line));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|