You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

339 lines
7.3 KiB

import QtQuick 2.2
import QtQuick.Controls 1.1
import QtQuick.Controls.Styles 1.1
import QtQuick.Layouts 1.1
10 years ago
import QtQuick.Dialogs 1.2
import QtQuick.Window 2.0
import QtQuick.Dialogs 1.1
import Qt.labs.settings 1.0
import "js/Debugger.js" as Debugger
import "js/ErrorLocationFormater.js" as ErrorLocationFormater
import "."
ColumnLayout
{
id: blockChainSelector
10 years ago
signal restored(variant scenario)
signal saved(variant scenario)
signal duplicated(variant scenario)
signal loaded(variant scenario)
signal renamed(variant scenario)
10 years ago
spacing: 0
function init()
{
scenarioList.load()
}
function needSaveOrReload()
{
editStatus.visible = true
}
10 years ago
Rectangle
{
Layout.fillWidth: true
Layout.preferredHeight: 30
color: "transparent"
Rectangle
{
anchors.verticalCenter: parent.verticalCenter
anchors.horizontalCenter: parent.horizontalCenter
color: "transparent"
10 years ago
Label
{
anchors.verticalCenter: parent.verticalCenter
anchors.horizontalCenter: parent.horizontalCenter
id: scenarioName
10 years ago
font.bold: true
}
10 years ago
TextInput
{
id: scenarioNameEdit
visible: false
10 years ago
anchors.verticalCenter: parent.verticalCenter
anchors.horizontalCenter: parent.horizontalCenter
Keys.onEnterPressed:
{
save()
10 years ago
}
function edit()
10 years ago
{
editIconRect.anchors.left = scenarioNameEdit.right
editStatus.parent.anchors.left = scenarioNameEdit.right
scenarioNameEdit.forceActiveFocus()
}
function save()
{
editIconRect.anchors.left = scenarioName.right
editStatus.parent.anchors.left = scenarioName.right
scenarioName.text = scenarioNameEdit.text
scenarioName.visible = true
scenarioNameEdit.visible = false
projectModel.stateListModel.getState(scenarioList.currentIndex).title = scenarioName.text
projectModel.saveProjectFile()
saved(state)
scenarioList.model.get(scenarioList.currentIndex).title = scenarioName.text
scenarioList.currentIndex = scenarioList.currentIndex
renamed(projectModel.stateListModel.getState(scenarioList.currentIndex))
10 years ago
}
}
Connections
10 years ago
{
target: blockChainSelector
onLoaded:
10 years ago
{
scenarioName.text = scenario.title
scenarioNameEdit.text = scenario.title
10 years ago
}
}
10 years ago
Rectangle
{
anchors.left: scenarioName.right
anchors.top: scenarioName.top
anchors.leftMargin: 2
Layout.preferredWidth: 20
Text {
id: editStatus
text: "*"
visible: false
10 years ago
}
}
10 years ago
Rectangle
{
id: editIconRect
anchors.left: scenarioName.right
anchors.leftMargin: 15
Image {
source: "qrc:/qml/img/edit.png"
width: 10
fillMode: Image.PreserveAspectFit
anchors.verticalCenter: parent.verticalCenter
anchors.horizontalCenter: parent.horizontalCenter
MouseArea
{
anchors.fill: parent
onClicked:
{
scenarioName.visible = !scenarioName.visible
scenarioNameEdit.visible = !scenarioNameEdit.visible
if (!scenarioNameEdit.visible)
scenarioNameEdit.save()
else
scenarioNameEdit.edit()
}
10 years ago
}
}
}
}
}
RowLayout
10 years ago
{
10 years ago
Layout.preferredWidth: 560
anchors.horizontalCenter: parent.horizontalCenter
Layout.preferredHeight: 50
spacing: 0
10 years ago
Row
10 years ago
{
Layout.preferredWidth: 100 * 5
Layout.preferredHeight: 50
10 years ago
spacing: 15
10 years ago
10 years ago
Rectangle
10 years ago
{
10 years ago
color: "transparent"
width: 251
height: 30
10 years ago
Rectangle
{
10 years ago
width: 10
height: parent.height
anchors.right: scenarioList.left
anchors.rightMargin: -8
radius: 15
}
10 years ago
ComboBox
{
10 years ago
id: scenarioList
model: projectModel.stateListModel
textRole: "title"
height: parent.height
width: 150
onCurrentIndexChanged:
{
restoreScenario.restore()
}
10 years ago
function load()
{
var state = projectModel.stateListModel.getState(currentIndex)
loaded(state)
}
10 years ago
style: ComboBoxStyle {
background: Rectangle {
color: "white"
anchors.fill: parent
}
label: Rectangle {
anchors.fill: parent
color: "white"
Label {
id: comboLabel
maximumLineCount: 1
elide: Text.ElideRight
width: parent.width
anchors.verticalCenter: parent.verticalCenter
anchors.horizontalCenter: parent.horizontalCenter
text: {
if (projectModel.stateListModel.getState(scenarioList.currentIndex))
return projectModel.stateListModel.getState(scenarioList.currentIndex).title
else
return ""
}
10 years ago
Connections {
target: blockChainSelector
onLoaded: {
comboLabel.text = projectModel.stateListModel.getState(scenarioList.currentIndex).title
}
onRenamed: {
comboLabel.text = scenario.title
}
}
}
}
}
}
10 years ago
Rectangle
{
width: 1
height: parent.height
anchors.right: addScenario.left
color: "#ededed"
}
ScenarioButton {
id: addScenario
anchors.left: scenarioList.right
width: 100
height: parent.height
buttonShortcut: ""
sourceImg: "qrc:/qml/img/restoreicon@2x.png"
onClicked: {
var item = projectModel.stateListModel.createDefaultState();
item.title = qsTr("New Scenario")
projectModel.stateListModel.appendState(item)
projectModel.stateListModel.save()
scenarioList.currentIndex = projectModel.stateListModel.count - 1
scenarioNameEdit.edit()
}
text: qsTr("New..")
roundRight: true
roundLeft: false
}
}
10 years ago
Rectangle
{
width: 100 * 3
height: 30
10 years ago
color: "transparent"
Rectangle
{
10 years ago
width: 10
height: parent.height
anchors.right: restoreScenario.left
anchors.rightMargin: -4
radius: 15
}
ScenarioButton {
id: restoreScenario
width: 100
height: parent.height
buttonShortcut: ""
sourceImg: "qrc:/qml/img/restoreicon@2x.png"
onClicked: {
restore()
}
text: qsTr("Restore")
function restore()
{
10 years ago
var state = projectModel.stateListModel.reloadStateFromFromProject(scenarioList.currentIndex)
if (state)
{
editStatus.visible = false
restored(state)
loaded(state)
}
}
10 years ago
roundRight: false
roundLeft: true
}
10 years ago
10 years ago
Rectangle
{
width: 1
height: parent.height
anchors.right: saveScenario.left
color: "#ededed"
}
10 years ago
10 years ago
ScenarioButton {
id: saveScenario
anchors.left: restoreScenario.right
text: qsTr("Save")
onClicked: {
projectModel.saveProjectFile()
saved(state)
}
width: 100
height: parent.height
buttonShortcut: ""
sourceImg: "qrc:/qml/img/saveicon@2x.png"
roundRight: false
roundLeft: false
}
10 years ago
10 years ago
Rectangle
{
width: 1
height: parent.height
anchors.right: duplicateScenario.left
color: "#ededed"
}
ScenarioButton
{
id: duplicateScenario
anchors.left: saveScenario.right
text: qsTr("Duplicate")
onClicked: {
projectModel.stateListModel.duplicateState(scenarioList.currentIndex)
duplicated(state)
}
width: 100
height: parent.height
buttonShortcut: ""
sourceImg: "qrc:/qml/img/duplicateicon@2x.png"
roundRight: true
roundLeft: false
}
10 years ago
}
}
}
}