blob: f51ffaa12e8d8f1a0bb23cf61f9fd48645de9926 [file] [log] [blame]
swissChili23958ca2022-02-21 19:23:34 -08001import QtQuick 2.0
2import QtQuick.Controls 2.15
3import QtQuick.Controls.Material 2.0
4import QtQuick.Layouts 1.0
5
swissChilid85daa92022-02-24 15:29:02 -08006import sh.swisschili.REFAL 1.0
7
swissChili25620b02022-02-23 17:15:16 -08008Item {
swissChili23958ca2022-02-21 19:23:34 -08009 id: root
10
swissChili4b3105a2022-02-22 16:34:39 -080011 required property string code
12 required property string result
swissChilid85daa92022-02-24 15:29:02 -080013 property int status: Cell.IDLE
swissChili4b3105a2022-02-22 16:34:39 -080014
swissChili25620b02022-02-23 17:15:16 -080015 signal insertBelowClicked()
16 signal codeEditingFinished(string code)
17 signal cellFocused()
swissChilid85daa92022-02-24 15:29:02 -080018 signal runClicked()
swissChili23958ca2022-02-21 19:23:34 -080019
swissChili25620b02022-02-23 17:15:16 -080020 height: column.height
swissChili23958ca2022-02-21 19:23:34 -080021
swissChili25620b02022-02-23 17:15:16 -080022 MouseArea {
23 id: selectCell
24
25 anchors.fill: column
26
27 onClicked: root.cellFocused()
28 }
29
30 ColumnLayout {
31 id: column
32
33 width: parent.width
34
35 RowLayout {
36 id: row
swissChili23958ca2022-02-21 19:23:34 -080037 Layout.fillWidth: true
swissChili23958ca2022-02-21 19:23:34 -080038
swissChili25620b02022-02-23 17:15:16 -080039 RoundButton {
40 Layout.alignment: Qt.AlignTop
swissChilid85daa92022-02-24 15:29:02 -080041 icon.source: iconForState(root.state)
swissChili25620b02022-02-23 17:15:16 -080042 icon.color: Material.color(Material.Grey, Material.Shade600)
43 flat: true
swissChilid85daa92022-02-24 15:29:02 -080044
45 onClicked: root.runClicked()
46
47 function iconForState(state) {
48 if (state === Cell.RUNNING)
49 return "qrc:///icons/square.svg"
50
51 return "qrc:///icons/play-circle.svg"
52 }
swissChili25620b02022-02-23 17:15:16 -080053 }
54
55 ColumnLayout {
swissChili23958ca2022-02-21 19:23:34 -080056 Layout.fillWidth: true
57 Layout.fillHeight: true
swissChili4b3105a2022-02-22 16:34:39 -080058
swissChili25620b02022-02-23 17:15:16 -080059 TextArea {
60 Layout.fillWidth: true
61 Layout.fillHeight: true
62 id: code
63 font.family: "monospace"
64 text: root.code
65 selectByMouse: true
66 wrapMode: TextEdit.WrapAtWordBoundaryOrAnywhere
67
68 Keys.onTabPressed: {
69 var pos = cursorPosition + 4
70 text = text.slice(0, cursorPosition) + " " + text.slice(cursorPosition);
71 cursorPosition = pos
72 }
73
74 Keys.onEscapePressed: {
75 root.forceActiveFocus()
76 }
77
78 onEditingFinished: {
79 root.codeEditingFinished(text)
80 }
81
82 onFocusChanged: if (focus) root.cellFocused()
83 }
84
85 Label {
86 visible: root.result.length > 0
87 Layout.fillWidth: true
88 font.family: "monospace"
89 text: root.result
swissChili4b3105a2022-02-22 16:34:39 -080090 }
swissChili23958ca2022-02-21 19:23:34 -080091 }
92
swissChili25620b02022-02-23 17:15:16 -080093 RoundButton {
94 icon.source: "qrc:///icons/trash.svg"
95 icon.color: Material.color(Material.Grey, Material.theme == Material.Dark ? Material.Shade400 : Material.Shade600)
96 flat: true
swissChili23958ca2022-02-21 19:23:34 -080097 }
98 }
swissChili23958ca2022-02-21 19:23:34 -080099
swissChili25620b02022-02-23 17:15:16 -0800100 InsertRow {
101 onInsertClicked: root.insertBelowClicked()
102 }
swissChili23958ca2022-02-21 19:23:34 -0800103 }
104}