Serial-Studio/assets/qml/Windows/JsonEditor.qml

226 lines
6.3 KiB
QML
Raw Normal View History

2021-09-17 01:41:50 -05:00
/*
* Copyright (c) 2020-2021 Alex Spataru <https://github.com/alex-spataru>
*
* 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.
*/
2021-09-30 19:07:39 -05:00
import QtQuick
import QtQuick.Window
import QtQuick.Layouts
import QtQuick.Controls
import Qt.labs.settings
2021-09-17 01:41:50 -05:00
2021-09-25 21:48:06 -05:00
import "../JsonEditor"
2021-09-30 19:07:39 -05:00
import "../Widgets" as Widgets
2021-09-17 01:41:50 -05:00
2021-09-17 17:45:05 -05:00
ApplicationWindow {
2021-09-17 01:41:50 -05:00
id: root
//
// Window options
//
2021-09-24 15:07:43 -05:00
minimumWidth: 910
minimumHeight: 720
2021-09-17 17:45:05 -05:00
title: qsTr("JSON Editor - %1").arg(Cpp_JSON_Editor.jsonFileName)
//
// Ensure that current JSON file is shown
//
onVisibleChanged: {
if (visible)
Cpp_JSON_Editor.openJsonFile(Cpp_JSON_Generator.jsonMapFilepath)
}
//
// Ask user to save changes before closing the window
//
2021-09-28 14:43:06 -05:00
onClosing: (close) => close.accepted = Cpp_JSON_Editor.askSave()
2021-09-17 01:41:50 -05:00
2021-09-17 19:44:59 -05:00
//
// Dummy string to increase width of buttons
//
readonly property string _btSpacer: " "
2021-09-17 01:41:50 -05:00
//
// Save window size
//
Settings {
category: "JSONEditor"
property alias windowX: root.x
property alias windowY: root.y
property alias windowWidth: root.width
property alias windowHeight: root.height
}
//
// Use page item to set application palette
//
Page {
anchors.margins: 0
anchors.fill: parent
palette.text: Cpp_ThemeManager.text
palette.buttonText: Cpp_ThemeManager.text
palette.windowText: Cpp_ThemeManager.text
palette.window: Cpp_ThemeManager.dialogBackground
2021-10-05 05:05:54 -05:00
background: Rectangle {
color: Cpp_ThemeManager.windowBackground
}
2021-09-17 01:41:50 -05:00
2021-10-07 03:12:37 -05:00
//
// Shadows
//
Widgets.Shadow {
2021-10-15 23:54:55 -05:00
source: header
2021-10-07 03:12:37 -05:00
horizontalOffset: 0
2021-10-15 23:54:55 -05:00
anchors.fill: header
2021-10-07 03:12:37 -05:00
} Widgets.Shadow {
2021-10-15 23:54:55 -05:00
source: footer
2021-10-07 03:12:37 -05:00
verticalOffset: -3
horizontalOffset: 0
2021-10-15 23:54:55 -05:00
anchors.fill: footer
2021-10-07 03:12:37 -05:00
}
2021-09-17 01:41:50 -05:00
//
2021-10-05 05:03:00 -05:00
// Header (project properties)
2021-09-17 01:41:50 -05:00
//
2021-10-15 23:54:55 -05:00
Header {
id: header
2021-10-05 05:03:00 -05:00
anchors {
margins: 0
top: parent.top
left: parent.left
right: parent.right
}
}
//
// Footer background
//
2021-10-15 23:54:55 -05:00
Footer {
id: footer
onCloseWindow: root.close()
onScrollToBottom: groupEditor.scrollToBottom()
2021-10-05 05:03:00 -05:00
anchors {
margins: 0
left: parent.left
right: parent.right
bottom: parent.bottom
}
}
//
// Window controls
//
2021-10-15 23:54:55 -05:00
RowLayout {
2021-10-05 05:03:00 -05:00
clip: true
anchors.fill: parent
2021-10-15 23:54:55 -05:00
spacing: app.spacing
anchors.topMargin: header.height
anchors.bottomMargin: footer.height
2021-10-05 05:03:00 -05:00
2021-09-17 01:41:50 -05:00
//
2021-10-15 23:54:55 -05:00
// Horizontal spacer
2021-09-17 01:41:50 -05:00
//
Item {
2021-10-15 23:54:55 -05:00
Layout.fillHeight: true
Layout.minimumWidth: app.spacing
Layout.maximumWidth: app.spacing
2021-09-17 01:41:50 -05:00
}
//
2021-10-15 23:54:55 -05:00
// JSON structure tree
2021-09-17 01:41:50 -05:00
//
2021-10-05 05:03:00 -05:00
Item {
2021-09-17 01:41:50 -05:00
Layout.fillHeight: true
2021-10-15 23:54:55 -05:00
Layout.minimumWidth: 240
Layout.maximumWidth: 240
Layout.topMargin: app.spacing * 2
Layout.bottomMargin: app.spacing * 2
visible: Cpp_JSON_Editor.groupCount !== 0
Widgets.Shadow {
source: jsonTree
anchors.fill: jsonTree
}
2021-09-17 01:41:50 -05:00
2021-10-15 23:54:55 -05:00
TreeView {
id: jsonTree
2021-09-17 01:41:50 -05:00
anchors.fill: parent
2021-10-15 23:54:55 -05:00
}
}
2021-09-17 01:41:50 -05:00
2021-10-15 23:54:55 -05:00
//
// Group editor
//
GroupEditor {
id: groupEditor
Layout.fillWidth: true
Layout.fillHeight: true
visible: Cpp_JSON_Editor.groupCount !== 0
}
2021-10-07 03:12:37 -05:00
2021-10-15 23:54:55 -05:00
//
// Empty project text & icon
//
Item {
Layout.fillWidth: true
Layout.fillHeight: true
visible: Cpp_JSON_Editor.groupCount === 0
2021-09-17 01:41:50 -05:00
2021-09-17 19:44:59 -05:00
ColumnLayout {
spacing: app.spacing
anchors.centerIn: parent
2021-09-17 01:41:50 -05:00
2021-10-06 23:50:17 -05:00
Widgets.Icon {
width: 128
height: 128
color: Cpp_ThemeManager.text
2021-09-17 19:44:59 -05:00
Layout.alignment: Qt.AlignHCenter
2021-10-06 23:50:17 -05:00
source: "qrc:/icons/developer-board.svg"
2021-09-17 19:44:59 -05:00
}
Label {
font.bold: true
font.pixelSize: 24
Layout.alignment: Qt.AlignHCenter
text: qsTr("Start something awesome")
}
Label {
opacity: 0.8
font.pixelSize: 18
Layout.alignment: Qt.AlignHCenter
2021-10-15 23:54:55 -05:00
text: qsTr("Click on the \"Add group\" button to begin")
2021-09-17 19:44:59 -05:00
}
2021-09-17 01:41:50 -05:00
}
}
//
2021-10-15 23:54:55 -05:00
// Horizontal spacer
2021-09-17 01:41:50 -05:00
//
Item {
2021-10-15 23:54:55 -05:00
Layout.fillHeight: true
Layout.minimumWidth: app.spacing
Layout.maximumWidth: app.spacing
2021-09-17 01:41:50 -05:00
}
2021-10-05 05:03:00 -05:00
}
2021-09-17 01:41:50 -05:00
}
}