1
0
mirror of https://github.com/Swordfish90/cool-retro-term.git synced 2026-02-08 00:32:27 +00:00

Add multiple windows handling.

This commit is contained in:
Filippo Scognamiglio
2026-01-04 23:03:20 +01:00
parent 11ad932965
commit 267b39bc9d
10 changed files with 219 additions and 168 deletions

View File

@@ -28,8 +28,6 @@ ApplicationWindow {
width: 600
height: 400
modality: Qt.ApplicationModal
ColumnLayout {
anchors.fill: parent
anchors.margins: 15

View File

@@ -813,7 +813,6 @@ QtObject {
wintitle = args[args.indexOf("-T") + 1]
}
settingsInitialized = true
initializedSettings()
}
Component.onDestruction: {
@@ -827,5 +826,4 @@ QtObject {
text: "100%"
}
property real labelWidth: _sampleLabel.width
property bool settingsInitialized: false
}

View File

@@ -42,7 +42,6 @@ Item{
property size terminalSize: kterminal.terminalSize
property size fontMetrics: kterminal.fontMetrics
property bool sessionStarted: false
// Manage copy and paste
Connections {
@@ -169,12 +168,6 @@ Item{
}
function startSession() {
if (terminalContainer.sessionStarted)
return
terminalContainer.sessionStarted = true
appSettings.initializedSettings.disconnect(startSession);
// Retrieve the variable set in main.cpp if arguments are passed.
if (defaultCmd) {
ksession.setShellProgram(defaultCmd);
@@ -196,10 +189,8 @@ Item{
}
Component.onCompleted: {
appSettings.terminalFontChanged.connect(handleFontChanged);
appSettings.initializedSettings.connect(startSession);
if (appSettings.settingsInitialized)
startSession();
appSettings.updateFont()
startSession();
}
}

View File

@@ -50,7 +50,6 @@ Item {
property ShaderEffectSource source
property BurnInEffect burnInEffect
property ShaderEffectSource bloomSource
property QtObject timeManager
property color fontColor: appSettings.fontColor
property color backgroundColor: appSettings.backgroundColor

View File

@@ -32,7 +32,6 @@ ShaderTerminal {
id: mainShader
opacity: appSettings.windowOpacity * 0.3 + 0.7
timeManager: terminalWindow.timeManager
source: terminal.mainSource
burnInEffect: terminal.burnInEffect
virtualResolution: terminal.virtualResolution

173
app/qml/TerminalWindow.qml Normal file
View File

@@ -0,0 +1,173 @@
/*******************************************************************************
* Copyright (c) 2013-2021 "Filippo Scognamiglio"
* https://github.com/Swordfish90/cool-retro-term
*
* This file is part of cool-retro-term.
*
* cool-retro-term 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 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/>.
*******************************************************************************/
import QtQuick 2.2
import QtQuick.Window 2.1
import QtQuick.Controls 2.3
import "menus"
ApplicationWindow {
id: terminalWindow
width: 1024
height: 768
// Save window properties automatically
onXChanged: appSettings.x = x
onYChanged: appSettings.y = y
onWidthChanged: appSettings.width = width
onHeightChanged: appSettings.height = height
// Load saved window geometry and show the window
Component.onCompleted: {
x = appSettings.x
y = appSettings.y
width = appSettings.width
height = appSettings.height
visible = true
}
minimumWidth: 320
minimumHeight: 240
visible: false
property bool fullscreen: appSettings.fullscreen
onFullscreenChanged: visibility = (fullscreen ? Window.FullScreen : Window.Windowed)
menuBar: qtquickMenuLoader.item
Loader {
id: qtquickMenuLoader
active: !appSettings.isMacOS && appSettings.showMenubar
sourceComponent: WindowMenu { }
}
Loader {
id: globalMenuLoader
active: appSettings.isMacOS
sourceComponent: OSXMenu { }
}
property string wintitle: appSettings.wintitle
color: "#00000000"
title: terminalTabs.title || qsTr(appSettings.wintitle)
Action {
id: showMenubarAction
text: qsTr("Show Menubar")
enabled: !appSettings.isMacOS
shortcut: "Ctrl+Shift+M"
checkable: true
checked: appSettings.showMenubar
onTriggered: appSettings.showMenubar = !appSettings.showMenubar
}
Action {
id: fullscreenAction
text: qsTr("Fullscreen")
enabled: !appSettings.isMacOS
shortcut: "Alt+F11"
onTriggered: appSettings.fullscreen = !appSettings.fullscreen
checkable: true
checked: appSettings.fullscreen
}
Action {
id: newWindowAction
text: qsTr("New Window")
shortcut: "Ctrl+Shift+N"
onTriggered: appRoot.createWindow()
}
Action {
id: quitAction
text: qsTr("Quit")
shortcut: "Ctrl+Shift+Q"
onTriggered: Qt.quit()
}
Action {
id: showsettingsAction
text: qsTr("Settings")
onTriggered: {
settingsWindow.show()
settingsWindow.requestActivate()
settingsWindow.raise()
}
}
Action {
id: copyAction
text: qsTr("Copy")
shortcut: "Ctrl+Shift+C"
}
Action {
id: pasteAction
text: qsTr("Paste")
shortcut: "Ctrl+Shift+V"
}
Action {
id: zoomIn
text: qsTr("Zoom In")
shortcut: "Ctrl++"
onTriggered: appSettings.incrementScaling()
}
Action {
id: zoomOut
text: qsTr("Zoom Out")
shortcut: "Ctrl+-"
onTriggered: appSettings.decrementScaling()
}
Action {
id: showAboutAction
text: qsTr("About")
onTriggered: {
aboutDialog.show()
aboutDialog.requestActivate()
aboutDialog.raise()
}
}
Action {
id: newTabAction
text: qsTr("New Tab")
onTriggered: terminalTabs.addTab()
}
Action {
id: closeTabAction
text: qsTr("Close Tab")
enabled: terminalTabs.count > 1
onTriggered: terminalTabs.closeCurrentTab()
}
TerminalTabs {
id: terminalTabs
width: parent.width
height: (parent.height + Math.abs(y))
}
Loader {
anchors.centerIn: parent
active: appSettings.showTerminalSize
sourceComponent: SizeOverlay {
z: 3
terminalSize: terminalTabs.terminalSize
}
}
onClosing: {
appRoot.closeWindow(terminalWindow)
}
}

View File

@@ -18,169 +18,53 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*******************************************************************************/
import QtQuick 2.2
import QtQuick.Window 2.1
import QtQuick.Controls 2.3
import "menus"
QtObject {
id: appRoot
ApplicationWindow {
id: terminalWindow
width: 1024
height: 768
// Save window properties automatically
onXChanged: appSettings.x = x
onYChanged: appSettings.y = y
onWidthChanged: appSettings.width = width
onHeightChanged: appSettings.height = height
// Load saved window geometry and show the window
Component.onCompleted: {
x = appSettings.x
y = appSettings.y
width = appSettings.width
height = appSettings.height
visible = true
property ApplicationSettings appSettings: ApplicationSettings {
onInitializedSettings: appRoot.createWindow()
}
minimumWidth: 320
minimumHeight: 240
visible: false
property bool fullscreen: appSettings.fullscreen
onFullscreenChanged: visibility = (fullscreen ? Window.FullScreen : Window.Windowed)
menuBar: qtquickMenuLoader.item
Loader {
id: qtquickMenuLoader
active: !appSettings.isMacOS && appSettings.showMenubar
sourceComponent: WindowMenu { }
property TimeManager timeManager: TimeManager {
enableTimer: windowsModel.count > 0
}
Loader {
id: globalMenuLoader
active: appSettings.isMacOS
sourceComponent: OSXMenu { }
}
property string wintitle: appSettings.wintitle
color: "#00000000"
title: terminalTabs.title || qsTr(appSettings.wintitle)
Action {
id: showMenubarAction
text: qsTr("Show Menubar")
enabled: !appSettings.isMacOS
shortcut: "Ctrl+Shift+M"
checkable: true
checked: appSettings.showMenubar
onTriggered: appSettings.showMenubar = !appSettings.showMenubar
}
Action {
id: fullscreenAction
text: qsTr("Fullscreen")
enabled: !appSettings.isMacOS
shortcut: "Alt+F11"
onTriggered: appSettings.fullscreen = !appSettings.fullscreen
checkable: true
checked: appSettings.fullscreen
}
Action {
id: quitAction
text: qsTr("Quit")
shortcut: "Ctrl+Shift+Q"
onTriggered: Qt.quit()
}
Action {
id: showsettingsAction
text: qsTr("Settings")
onTriggered: {
settingswindow.show()
settingswindow.requestActivate()
settingswindow.raise()
}
}
Action {
id: copyAction
text: qsTr("Copy")
shortcut: "Ctrl+Shift+C"
}
Action {
id: pasteAction
text: qsTr("Paste")
shortcut: "Ctrl+Shift+V"
}
Action {
id: zoomIn
text: qsTr("Zoom In")
shortcut: "Ctrl++"
onTriggered: appSettings.incrementScaling()
}
Action {
id: zoomOut
text: qsTr("Zoom Out")
shortcut: "Ctrl+-"
onTriggered: appSettings.decrementScaling()
}
Action {
id: showAboutAction
text: qsTr("About")
onTriggered: {
aboutDialog.show()
aboutDialog.requestActivate()
aboutDialog.raise()
}
}
Action {
id: newTabAction
text: qsTr("New Tab")
onTriggered: terminalTabs.addTab()
}
Action {
id: closeTabAction
text: qsTr("Close Tab")
enabled: terminalTabs.count > 1
onTriggered: terminalTabs.closeCurrentTab()
}
ApplicationSettings {
id: appSettings
}
TimeManager {
id: sharedTimeManager
enableTimer: terminalWindow.visible
}
property alias timeManager: sharedTimeManager
TerminalTabs {
id: terminalTabs
width: parent.width
height: (parent.height + Math.abs(y))
}
SettingsWindow {
id: settingswindow
property SettingsWindow settingsWindow: SettingsWindow {
visible: false
}
AboutDialog {
id: aboutDialog
property AboutDialog aboutWindow: AboutDialog {
visible: false
}
Loader {
anchors.centerIn: parent
active: appSettings.showTerminalSize
sourceComponent: SizeOverlay {
z: 3
terminalSize: terminalTabs.terminalSize
}
property Component windowComponent: Component {
TerminalWindow { }
}
onClosing: {
// OSX Since we are currently supporting only one window
// quit the application when it is closed.
if (appSettings.isMacOS)
property ListModel windowsModel: ListModel { }
function createWindow() {
var window = windowComponent.createObject(null)
if (!window)
return
windowsModel.append({ window: window })
window.show()
window.requestActivate()
}
function closeWindow(window) {
for (var i = 0; i < windowsModel.count; i++) {
if (windowsModel.get(i).window === window) {
windowsModel.remove(i)
break
}
}
window.destroy()
if (windowsModel.count === 0)
Qt.quit()
}
}

View File

@@ -26,6 +26,11 @@ MenuBar {
Menu {
title: qsTr("File")
MenuItem {
text: newWindowAction.text
shortcut: newWindowAction.shortcut
onTriggered: newWindowAction.trigger()
}
MenuItem {
text: quitAction.text
onTriggered: quitAction.trigger()

View File

@@ -26,6 +26,9 @@ MenuBar {
Menu {
title: qsTr("File")
MenuItem {
action: newWindowAction
}
MenuItem {
action: quitAction
}

View File

@@ -5,6 +5,7 @@
<file>CheckableSlider.qml</file>
<file>ApplicationSettings.qml</file>
<file>SettingsWindow.qml</file>
<file>TerminalWindow.qml</file>
<file>Fonts.qml</file>
<file>SettingsGeneralTab.qml</file>
<file>PreprocessedTerminal.qml</file>