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:
188
app/qml/main.qml
188
app/qml/main.qml
@@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user