blob: 240e7f8f9b52e7b59386521573cc5c04ef6b598f [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
swissChili06cec4e2022-02-24 19:04:32 -080014 property bool cellActive: false
swissChili4b3105a2022-02-22 16:34:39 -080015
swissChili25620b02022-02-23 17:15:16 -080016 signal insertBelowClicked()
17 signal codeEditingFinished(string code)
18 signal cellFocused()
swissChili06cec4e2022-02-24 19:04:32 -080019 signal cellUnfocused()
swissChilid85daa92022-02-24 15:29:02 -080020 signal runClicked()
swissChili06cec4e2022-02-24 19:04:32 -080021 signal deleteClicked()
swissChili23958ca2022-02-21 19:23:34 -080022
swissChili25620b02022-02-23 17:15:16 -080023 height: column.height
swissChili23958ca2022-02-21 19:23:34 -080024
swissChili06cec4e2022-02-24 19:04:32 -080025 Keys.onEscapePressed: root.cellUnfocused()
swissChili25620b02022-02-23 17:15:16 -080026
27 ColumnLayout {
28 id: column
29
swissChili06cec4e2022-02-24 19:04:32 -080030 width: parent.width - 20
31 anchors.centerIn: parent
swissChili25620b02022-02-23 17:15:16 -080032
swissChili06cec4e2022-02-24 19:04:32 -080033 Item {
34 implicitWidth: row.implicitWidth
35 implicitHeight: row.implicitHeight
swissChili23958ca2022-02-21 19:23:34 -080036 Layout.fillWidth: true
swissChili23958ca2022-02-21 19:23:34 -080037
swissChili06cec4e2022-02-24 19:04:32 -080038 Pane {
39 anchors.fill: parent
40 anchors.topMargin: -5
41 anchors.bottomMargin: -5
swissChilid85daa92022-02-24 15:29:02 -080042
swissChili06cec4e2022-02-24 19:04:32 -080043 Material.elevation: root.cellActive ? 4 : 0
swissChili25620b02022-02-23 17:15:16 -080044 }
45
swissChili06cec4e2022-02-24 19:04:32 -080046 MouseArea {
47 id: selectCell
swissChili4b3105a2022-02-22 16:34:39 -080048
swissChili06cec4e2022-02-24 19:04:32 -080049 anchors.fill: row
50
51 onClicked: root.cellFocused()
52 }
53
54 RowLayout {
55 anchors.fill: parent
56 id: row
57
58 RoundButton {
59 Layout.alignment: Qt.AlignTop
60 icon.source: iconForState(root.state)
61 icon.color: Material.color(Material.Grey, Material.Shade600)
62 flat: true
63
64 onClicked: root.runClicked()
65
66 function iconForState(state) {
67 if (state === Cell.RUNNING)
68 return "qrc:///icons/square.svg"
69
70 return "qrc:///icons/play-circle.svg"
71 }
72 }
73
74 ColumnLayout {
swissChili25620b02022-02-23 17:15:16 -080075 Layout.fillWidth: true
76 Layout.fillHeight: true
swissChili25620b02022-02-23 17:15:16 -080077
swissChili06cec4e2022-02-24 19:04:32 -080078 TextArea {
79 Layout.fillWidth: true
80 Layout.fillHeight: true
81 id: code
82 font.family: "monospace"
83 text: root.code
84 selectByMouse: true
85 wrapMode: TextEdit.WrapAtWordBoundaryOrAnywhere
86
87 placeholderText: "Write some code..."
88
89 Keys.onTabPressed: {
90 var pos = cursorPosition + 4
91 text = text.slice(0, cursorPosition) + " " + text.slice(cursorPosition);
92 cursorPosition = pos
93 }
94
95// Keys.onEscapePressed: {
96// focus = false
97// }
98
99 onEditingFinished: {
100 root.codeEditingFinished(text)
101 }
102
103 onFocusChanged: if (focus) root.cellFocused()
104 onActiveFocusChanged: if (activeFocus) root.cellFocused()
swissChili25620b02022-02-23 17:15:16 -0800105 }
106
swissChili06cec4e2022-02-24 19:04:32 -0800107 Label {
108 visible: root.result.length > 0
109 Layout.fillWidth: true
110 font.family: "monospace"
111 text: root.result
swissChili25620b02022-02-23 17:15:16 -0800112
swissChili06cec4e2022-02-24 19:04:32 -0800113 Layout.bottomMargin: 5
swissChili25620b02022-02-23 17:15:16 -0800114 }
swissChili25620b02022-02-23 17:15:16 -0800115 }
116
swissChili06cec4e2022-02-24 19:04:32 -0800117 RoundButton {
118 icon.source: "qrc:///icons/menu.svg"
119 icon.color: Constants.buttonGrey
120 flat: true
swissChili23958ca2022-02-21 19:23:34 -0800121
swissChili06cec4e2022-02-24 19:04:32 -0800122 onClicked: cellContextMenu.popup()
123
124 Menu {
125 id: cellContextMenu
126
127 MenuItem {
128 icon.source: "qrc:///icons/trash.svg"
129 icon.color: Material.color(Material.Red)
130 text: "Delete"
131
132 onClicked: root.deleteClicked()
133 }
134 }
135 }
swissChili23958ca2022-02-21 19:23:34 -0800136 }
137 }
swissChili23958ca2022-02-21 19:23:34 -0800138
swissChili25620b02022-02-23 17:15:16 -0800139 InsertRow {
140 onInsertClicked: root.insertBelowClicked()
141 }
swissChili23958ca2022-02-21 19:23:34 -0800142 }
143}