diff --git a/app/qml/AboutDialog.qml b/app/qml/AboutDialog.qml index d10a396..c7726db 100644 --- a/app/qml/AboutDialog.qml +++ b/app/qml/AboutDialog.qml @@ -28,8 +28,6 @@ ApplicationWindow { width: 600 height: 400 - modality: Qt.ApplicationModal - ColumnLayout { anchors.fill: parent anchors.margins: 15 diff --git a/app/qml/ApplicationSettings.qml b/app/qml/ApplicationSettings.qml index 92bbe2d..4ce607a 100644 --- a/app/qml/ApplicationSettings.qml +++ b/app/qml/ApplicationSettings.qml @@ -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 } diff --git a/app/qml/PreprocessedTerminal.qml b/app/qml/PreprocessedTerminal.qml index a8c1d0e..a270a72 100644 --- a/app/qml/PreprocessedTerminal.qml +++ b/app/qml/PreprocessedTerminal.qml @@ -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(); } } diff --git a/app/qml/ShaderTerminal.qml b/app/qml/ShaderTerminal.qml index 6f6afb9..958db15 100644 --- a/app/qml/ShaderTerminal.qml +++ b/app/qml/ShaderTerminal.qml @@ -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 diff --git a/app/qml/TerminalContainer.qml b/app/qml/TerminalContainer.qml index c5411b3..07400ef 100644 --- a/app/qml/TerminalContainer.qml +++ b/app/qml/TerminalContainer.qml @@ -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 diff --git a/app/qml/TerminalWindow.qml b/app/qml/TerminalWindow.qml new file mode 100644 index 0000000..fd5a668 --- /dev/null +++ b/app/qml/TerminalWindow.qml @@ -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 . +*******************************************************************************/ +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) + } +} diff --git a/app/qml/main.qml b/app/qml/main.qml index e6321c4..cd16518 100644 --- a/app/qml/main.qml +++ b/app/qml/main.qml @@ -18,169 +18,53 @@ * along with this program. If not, see . *******************************************************************************/ 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() } } diff --git a/app/qml/menus/OSXMenu.qml b/app/qml/menus/OSXMenu.qml index 37844b4..6faa917 100644 --- a/app/qml/menus/OSXMenu.qml +++ b/app/qml/menus/OSXMenu.qml @@ -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() diff --git a/app/qml/menus/WindowMenu.qml b/app/qml/menus/WindowMenu.qml index 74610fb..145af97 100644 --- a/app/qml/menus/WindowMenu.qml +++ b/app/qml/menus/WindowMenu.qml @@ -26,6 +26,9 @@ MenuBar { Menu { title: qsTr("File") + MenuItem { + action: newWindowAction + } MenuItem { action: quitAction } diff --git a/app/qml/resources.qrc b/app/qml/resources.qrc index 4e4fc9c..a82d04a 100644 --- a/app/qml/resources.qrc +++ b/app/qml/resources.qrc @@ -5,6 +5,7 @@ CheckableSlider.qml ApplicationSettings.qml SettingsWindow.qml + TerminalWindow.qml Fonts.qml SettingsGeneralTab.qml PreprocessedTerminal.qml