2014-03-31 22:23:48 +02:00
|
|
|
/*******************************************************************************
|
2021-06-30 22:49:03 +02:00
|
|
|
* Copyright (c) 2013-2021 "Filippo Scognamiglio"
|
2014-09-03 22:19:34 +02:00
|
|
|
* https://github.com/Swordfish90/cool-retro-term
|
2014-03-31 22:23:48 +02:00
|
|
|
*
|
2014-09-03 22:19:34 +02:00
|
|
|
* This file is part of cool-retro-term.
|
2014-03-31 22:23:48 +02:00
|
|
|
*
|
2014-09-03 22:19:34 +02:00
|
|
|
* cool-retro-term is free software: you can redistribute it and/or modify
|
2014-03-31 22:23:48 +02:00
|
|
|
* 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
|
2021-06-30 08:33:31 +02:00
|
|
|
import QtQuick.Controls 2.0
|
2014-03-20 16:19:11 +01:00
|
|
|
|
2014-11-09 01:38:22 +01:00
|
|
|
import QMLTermWidget 1.0
|
2014-03-20 16:19:11 +01:00
|
|
|
|
2021-06-30 08:33:31 +02:00
|
|
|
import "menus"
|
2015-01-06 01:35:35 +01:00
|
|
|
import "utils.js" as Utils
|
|
|
|
|
2014-03-22 11:11:27 +01:00
|
|
|
Item{
|
|
|
|
id: terminalContainer
|
2014-09-14 02:43:48 +02:00
|
|
|
|
2018-12-16 22:30:03 +01:00
|
|
|
property size virtualResolution: Qt.size(kterminal.totalWidth, kterminal.totalHeight)
|
2014-12-11 10:40:14 +01:00
|
|
|
property alias mainTerminal: kterminal
|
2014-12-11 10:07:53 +01:00
|
|
|
|
2018-11-07 22:36:51 +01:00
|
|
|
property ShaderEffectSource mainSource: kterminalSource
|
|
|
|
property BurnInEffect burnInEffect: burnInEffect
|
2014-12-17 01:37:48 +01:00
|
|
|
property real fontWidth: 1.0
|
|
|
|
property real screenScaling: 1.0
|
2014-12-12 00:59:23 +01:00
|
|
|
property real scaleTexture: 1.0
|
2014-10-27 09:28:27 +02:00
|
|
|
property alias title: ksession.title
|
2014-06-07 11:33:37 +02:00
|
|
|
property alias kterminal: kterminal
|
|
|
|
|
2014-06-07 02:19:37 +02:00
|
|
|
property size terminalSize: kterminal.terminalSize
|
2014-12-13 01:44:26 +01:00
|
|
|
property size fontMetrics: kterminal.fontMetrics
|
2014-06-06 23:55:33 +02:00
|
|
|
|
2014-10-13 22:53:26 +02:00
|
|
|
// Manage copy and paste
|
2022-01-03 18:43:07 +01:00
|
|
|
Connections {
|
2014-10-13 22:53:26 +02:00
|
|
|
target: copyAction
|
2022-01-03 18:43:07 +01:00
|
|
|
|
|
|
|
function onTriggered() {
|
|
|
|
kterminal.copyClipboard()
|
|
|
|
}
|
2014-10-13 22:53:26 +02:00
|
|
|
}
|
2022-01-03 18:43:07 +01:00
|
|
|
Connections {
|
2014-10-13 22:53:26 +02:00
|
|
|
target: pasteAction
|
2022-01-03 18:43:07 +01:00
|
|
|
|
|
|
|
function onTriggered() {
|
|
|
|
kterminal.pasteClipboard()
|
|
|
|
}
|
2014-10-13 22:53:26 +02:00
|
|
|
}
|
|
|
|
|
2014-09-30 00:10:14 +02:00
|
|
|
//When settings are updated sources need to be redrawn.
|
2022-01-03 18:43:07 +01:00
|
|
|
Connections {
|
2014-12-11 12:08:15 +01:00
|
|
|
target: appSettings
|
2022-01-03 18:43:07 +01:00
|
|
|
|
|
|
|
function onFontScalingChanged() {
|
|
|
|
terminalContainer.updateSources()
|
|
|
|
}
|
|
|
|
|
|
|
|
function onFontWidthChanged() {
|
|
|
|
terminalContainer.updateSources()
|
|
|
|
}
|
2014-09-30 00:10:14 +02:00
|
|
|
}
|
2022-01-03 18:43:07 +01:00
|
|
|
Connections {
|
2014-09-30 00:10:14 +02:00
|
|
|
target: terminalContainer
|
2022-01-03 18:43:07 +01:00
|
|
|
|
|
|
|
function onWidthChanged() {
|
|
|
|
terminalContainer.updateSources()
|
|
|
|
}
|
|
|
|
|
|
|
|
function onHeightChanged() {
|
|
|
|
terminalContainer.updateSources()
|
|
|
|
}
|
2014-09-30 00:10:14 +02:00
|
|
|
}
|
2022-01-03 18:43:07 +01:00
|
|
|
Connections {
|
|
|
|
target: terminalWindow
|
|
|
|
|
|
|
|
function onActiveChanged() {
|
|
|
|
kterminal.forceActiveFocus()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-30 00:10:14 +02:00
|
|
|
function updateSources() {
|
2022-01-03 18:43:07 +01:00
|
|
|
kterminal.update()
|
2014-09-30 00:10:14 +02:00
|
|
|
}
|
|
|
|
|
2014-11-09 01:38:22 +01:00
|
|
|
QMLTermWidget {
|
2014-03-22 11:11:27 +01:00
|
|
|
id: kterminal
|
2018-12-16 22:30:03 +01:00
|
|
|
|
2019-01-09 19:26:02 +01:00
|
|
|
property int textureResolutionScale: appSettings.lowResolutionFont ? devicePixelRatio : 1
|
2021-07-15 23:20:42 +02:00
|
|
|
property int margin: appSettings.totalMargin / screenScaling
|
2018-12-17 19:09:19 +01:00
|
|
|
property int totalWidth: Math.floor(parent.width / (screenScaling * fontWidth))
|
|
|
|
property int totalHeight: Math.floor(parent.height / screenScaling)
|
2018-12-16 22:30:03 +01:00
|
|
|
|
2019-01-09 19:26:02 +01:00
|
|
|
property int rawWidth: totalWidth - 2 * margin
|
|
|
|
property int rawHeight: totalHeight - 2 * margin
|
|
|
|
|
|
|
|
textureSize: Qt.size(width / textureResolutionScale, height / textureResolutionScale)
|
|
|
|
|
|
|
|
width: ensureMultiple(rawWidth, devicePixelRatio)
|
|
|
|
height: ensureMultiple(rawHeight, devicePixelRatio)
|
|
|
|
|
|
|
|
/** Ensure size is a multiple of factor. This is needed for pixel perfect scaling on highdpi screens. */
|
|
|
|
function ensureMultiple(size, factor) {
|
|
|
|
return Math.round(size / factor) * factor;
|
|
|
|
}
|
2014-03-31 14:13:51 +02:00
|
|
|
|
2014-09-03 22:19:34 +02:00
|
|
|
colorScheme: "cool-retro-term"
|
2014-03-20 16:19:11 +01:00
|
|
|
|
2014-12-31 13:46:03 +01:00
|
|
|
smooth: !appSettings.lowResolutionFont
|
2014-11-12 23:14:48 +01:00
|
|
|
enableBold: false
|
2014-12-12 02:20:11 +01:00
|
|
|
fullCursorHeight: true
|
2019-07-08 15:21:17 +02:00
|
|
|
blinkingCursor: appSettings.blinkingCursor
|
2014-09-29 21:26:41 +02:00
|
|
|
|
2014-11-09 01:38:22 +01:00
|
|
|
session: QMLTermSession {
|
2014-06-07 02:19:37 +02:00
|
|
|
id: ksession
|
2014-04-17 13:27:41 +02:00
|
|
|
|
2014-06-07 02:19:37 +02:00
|
|
|
onFinished: {
|
|
|
|
Qt.quit()
|
2014-03-22 11:11:27 +01:00
|
|
|
}
|
2014-06-07 02:19:37 +02:00
|
|
|
}
|
2014-03-20 16:19:11 +01:00
|
|
|
|
2014-11-12 23:14:48 +01:00
|
|
|
QMLTermScrollbar {
|
2014-12-11 13:50:52 +01:00
|
|
|
id: kterminalScrollbar
|
2014-11-12 23:14:48 +01:00
|
|
|
terminal: kterminal
|
|
|
|
anchors.margins: width * 0.5
|
|
|
|
width: terminal.fontMetrics.width * 0.75
|
|
|
|
Rectangle {
|
|
|
|
anchors.fill: parent
|
2014-12-17 01:18:28 +01:00
|
|
|
anchors.topMargin: 1
|
|
|
|
anchors.bottomMargin: 1
|
2014-11-12 23:14:48 +01:00
|
|
|
color: "white"
|
|
|
|
radius: width * 0.25
|
|
|
|
opacity: 0.7
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-22 00:04:31 +02:00
|
|
|
function handleFontChanged(fontFamily, pixelSize, lineSpacing, screenScaling, fontWidth) {
|
2014-12-31 13:46:03 +01:00
|
|
|
kterminal.antialiasText = !appSettings.lowResolutionFont;
|
2014-09-10 00:59:53 +02:00
|
|
|
font.pixelSize = pixelSize;
|
2018-10-22 00:04:31 +02:00
|
|
|
font.family = fontFamily;
|
2014-06-23 16:25:41 +02:00
|
|
|
|
2014-12-17 01:37:48 +01:00
|
|
|
terminalContainer.fontWidth = fontWidth;
|
2015-01-02 12:09:25 +01:00
|
|
|
terminalContainer.screenScaling = screenScaling;
|
|
|
|
scaleTexture = Math.max(1.0, Math.floor(screenScaling * appSettings.windowScaling));
|
2014-09-29 21:26:41 +02:00
|
|
|
|
2014-11-09 01:38:22 +01:00
|
|
|
kterminal.lineSpacing = lineSpacing;
|
2014-06-07 02:19:37 +02:00
|
|
|
}
|
2018-10-22 00:04:31 +02:00
|
|
|
|
2016-03-21 12:55:09 -07:00
|
|
|
function startSession() {
|
|
|
|
appSettings.initializedSettings.disconnect(startSession);
|
2014-10-04 16:21:17 +02:00
|
|
|
|
|
|
|
// Retrieve the variable set in main.cpp if arguments are passed.
|
2014-12-23 17:07:10 +01:00
|
|
|
if (defaultCmd) {
|
|
|
|
ksession.setShellProgram(defaultCmd);
|
|
|
|
ksession.setArgs(defaultCmdArgs);
|
2016-03-21 12:55:09 -07:00
|
|
|
} else if (appSettings.useCustomCommand) {
|
|
|
|
var args = Utils.tokenizeCommandLine(appSettings.customCommand);
|
|
|
|
ksession.setShellProgram(args[0]);
|
|
|
|
ksession.setArgs(args.slice(1));
|
2022-01-03 18:43:07 +01:00
|
|
|
} else if (!defaultCmd && appSettings.isMacOS) {
|
2014-12-21 16:19:23 +01:00
|
|
|
// OSX Requires the following default parameters for auto login.
|
|
|
|
ksession.setArgs(["-i", "-l"]);
|
|
|
|
}
|
|
|
|
|
2014-10-04 16:21:17 +02:00
|
|
|
if (workdir)
|
|
|
|
ksession.initialWorkingDirectory = workdir;
|
|
|
|
|
2014-10-04 15:01:50 +02:00
|
|
|
ksession.startShellProgram();
|
2014-06-07 02:19:37 +02:00
|
|
|
forceActiveFocus();
|
2014-03-22 11:11:27 +01:00
|
|
|
}
|
2016-03-21 12:55:09 -07:00
|
|
|
Component.onCompleted: {
|
2018-10-22 00:04:31 +02:00
|
|
|
appSettings.terminalFontChanged.connect(handleFontChanged);
|
2016-03-21 12:55:09 -07:00
|
|
|
appSettings.initializedSettings.connect(startSession);
|
2021-06-30 08:33:31 +02:00
|
|
|
appSettings.handleFontChanged()
|
2016-03-21 12:55:09 -07:00
|
|
|
}
|
2014-03-20 16:19:11 +01:00
|
|
|
}
|
2021-06-30 08:33:31 +02:00
|
|
|
|
2014-12-22 21:44:45 +01:00
|
|
|
Component {
|
2021-06-30 08:33:31 +02:00
|
|
|
id: shortContextMenu
|
|
|
|
ShortContextMenu { }
|
2014-12-22 21:44:45 +01:00
|
|
|
}
|
2021-06-30 08:33:31 +02:00
|
|
|
|
2014-12-22 21:44:45 +01:00
|
|
|
Component {
|
2021-06-30 08:33:31 +02:00
|
|
|
id: fullContextMenu
|
|
|
|
FullContextMenu { }
|
2014-04-16 19:18:14 +02:00
|
|
|
}
|
2021-06-30 08:33:31 +02:00
|
|
|
|
2014-12-22 21:44:45 +01:00
|
|
|
Loader {
|
|
|
|
id: menuLoader
|
2022-01-03 18:43:07 +01:00
|
|
|
sourceComponent: (appSettings.isMacOS || appSettings.showMenubar ? shortContextMenu : fullContextMenu)
|
2014-12-22 21:44:45 +01:00
|
|
|
}
|
|
|
|
property alias contextmenu: menuLoader.item
|
|
|
|
|
2021-07-15 23:20:42 +02:00
|
|
|
MouseArea {
|
|
|
|
property real margin: appSettings.totalMargin
|
2018-12-16 22:30:03 +01:00
|
|
|
|
2014-04-16 19:18:14 +02:00
|
|
|
acceptedButtons: Qt.LeftButton | Qt.MiddleButton | Qt.RightButton
|
2014-12-11 11:31:23 +01:00
|
|
|
anchors.fill: parent
|
2015-01-19 18:20:23 +01:00
|
|
|
cursorShape: kterminal.terminalUsesMouse ? Qt.ArrowCursor : Qt.IBeamCursor
|
2014-07-02 02:38:28 +02:00
|
|
|
onWheel:{
|
2014-08-28 00:43:50 +02:00
|
|
|
if(wheel.modifiers & Qt.ControlModifier){
|
2014-10-11 01:24:20 +02:00
|
|
|
wheel.angleDelta.y > 0 ? zoomIn.trigger() : zoomOut.trigger();
|
2014-08-28 00:43:50 +02:00
|
|
|
} else {
|
|
|
|
var coord = correctDistortion(wheel.x, wheel.y);
|
2014-11-09 01:38:22 +01:00
|
|
|
kterminal.simulateWheel(coord.x, coord.y, wheel.buttons, wheel.modifiers, wheel.angleDelta);
|
2014-08-28 00:43:50 +02:00
|
|
|
}
|
2014-07-02 02:38:28 +02:00
|
|
|
}
|
2014-04-16 19:18:14 +02:00
|
|
|
onDoubleClicked: {
|
2014-08-27 18:36:08 +02:00
|
|
|
var coord = correctDistortion(mouse.x, mouse.y);
|
2014-11-09 01:38:22 +01:00
|
|
|
kterminal.simulateMouseDoubleClick(coord.x, coord.y, mouse.button, mouse.buttons, mouse.modifiers);
|
2014-04-16 19:18:14 +02:00
|
|
|
}
|
|
|
|
onPressed: {
|
2014-11-09 01:38:22 +01:00
|
|
|
if((!kterminal.terminalUsesMouse || mouse.modifiers & Qt.ShiftModifier) && mouse.button == Qt.RightButton) {
|
2014-08-28 00:43:50 +02:00
|
|
|
contextmenu.popup();
|
|
|
|
} else {
|
|
|
|
var coord = correctDistortion(mouse.x, mouse.y);
|
2014-11-09 01:38:22 +01:00
|
|
|
kterminal.simulateMousePress(coord.x, coord.y, mouse.button, mouse.buttons, mouse.modifiers)
|
2014-08-28 00:43:50 +02:00
|
|
|
}
|
2014-04-16 19:18:14 +02:00
|
|
|
}
|
|
|
|
onReleased: {
|
2014-08-27 18:36:08 +02:00
|
|
|
var coord = correctDistortion(mouse.x, mouse.y);
|
2014-11-09 01:38:22 +01:00
|
|
|
kterminal.simulateMouseRelease(coord.x, coord.y, mouse.button, mouse.buttons, mouse.modifiers);
|
2014-04-16 19:18:14 +02:00
|
|
|
}
|
2014-09-10 00:59:53 +02:00
|
|
|
onPositionChanged: {
|
|
|
|
var coord = correctDistortion(mouse.x, mouse.y);
|
2014-11-09 01:38:22 +01:00
|
|
|
kterminal.simulateMouseMove(coord.x, coord.y, mouse.button, mouse.buttons, mouse.modifiers);
|
2014-09-10 00:59:53 +02:00
|
|
|
}
|
2014-04-16 19:18:14 +02:00
|
|
|
|
2014-06-07 12:03:34 +02:00
|
|
|
function correctDistortion(x, y){
|
2018-12-16 22:30:03 +01:00
|
|
|
x = (x - margin) / width;
|
|
|
|
y = (y - margin) / height;
|
2014-04-16 19:18:14 +02:00
|
|
|
|
|
|
|
var cc = Qt.size(0.5 - x, 0.5 - y);
|
2018-11-23 22:35:48 +01:00
|
|
|
var distortion = (cc.height * cc.height + cc.width * cc.width) * appSettings.screenCurvature * appSettings.screenCurvatureSize;
|
2014-04-16 19:18:14 +02:00
|
|
|
|
2021-07-15 23:20:42 +02:00
|
|
|
return Qt.point((x - cc.width * (1+distortion) * distortion) * (kterminal.totalWidth),
|
|
|
|
(y - cc.height * (1+distortion) * distortion) * (kterminal.totalHeight))
|
2014-04-16 19:18:14 +02:00
|
|
|
}
|
2014-03-30 22:29:15 +02:00
|
|
|
}
|
2014-03-23 18:29:19 +01:00
|
|
|
ShaderEffectSource{
|
2014-09-13 22:18:11 +02:00
|
|
|
id: kterminalSource
|
2014-03-23 18:29:19 +01:00
|
|
|
sourceItem: kterminal
|
|
|
|
hideSource: true
|
2018-11-30 00:57:59 +01:00
|
|
|
wrapMode: ShaderEffectSource.Repeat
|
2014-12-11 00:52:09 +01:00
|
|
|
visible: false
|
2018-12-16 22:30:03 +01:00
|
|
|
textureSize: Qt.size(kterminal.totalWidth * scaleTexture, kterminal.totalHeight * scaleTexture)
|
|
|
|
sourceRect: Qt.rect(-kterminal.margin, -kterminal.margin, kterminal.totalWidth, kterminal.totalHeight)
|
2014-03-23 18:29:19 +01:00
|
|
|
}
|
2014-09-13 23:19:00 +02:00
|
|
|
|
2019-01-09 19:01:11 +01:00
|
|
|
Item {
|
|
|
|
id: burnInContainer
|
|
|
|
|
|
|
|
property int burnInScaling: scaleTexture * appSettings.burnInQuality
|
|
|
|
|
|
|
|
width: Math.round(appSettings.lowResolutionFont
|
|
|
|
? kterminal.totalWidth * Math.max(1, burnInScaling)
|
|
|
|
: kterminal.totalWidth * scaleTexture * appSettings.burnInQuality)
|
|
|
|
|
|
|
|
height: Math.round(appSettings.lowResolutionFont
|
|
|
|
? kterminal.totalHeight * Math.max(1, burnInScaling)
|
|
|
|
: kterminal.totalHeight * scaleTexture * appSettings.burnInQuality)
|
|
|
|
|
|
|
|
|
|
|
|
BurnInEffect {
|
|
|
|
id: burnInEffect
|
|
|
|
}
|
2014-03-23 18:29:19 +01:00
|
|
|
}
|
2014-03-20 16:19:11 +01:00
|
|
|
}
|