swissChili | 23958ca | 2022-02-21 19:23:34 -0800 | [diff] [blame] | 1 | import QtQuick 2.0 |
2 | import QtQuick.Controls 2.15 | ||||
3 | import QtQuick.Controls.Material 2.0 | ||||
4 | import QtQuick.Layouts 1.0 | ||||
5 | |||||
swissChili | d85daa9 | 2022-02-24 15:29:02 -0800 | [diff] [blame] | 6 | import sh.swisschili.REFAL 1.0 |
7 | |||||
swissChili | 25620b0 | 2022-02-23 17:15:16 -0800 | [diff] [blame] | 8 | Item { |
swissChili | 23958ca | 2022-02-21 19:23:34 -0800 | [diff] [blame] | 9 | id: root |
10 | |||||
swissChili | 4b3105a | 2022-02-22 16:34:39 -0800 | [diff] [blame] | 11 | required property string code |
12 | required property string result | ||||
swissChili | d85daa9 | 2022-02-24 15:29:02 -0800 | [diff] [blame] | 13 | property int status: Cell.IDLE |
swissChili | 06cec4e | 2022-02-24 19:04:32 -0800 | [diff] [blame] | 14 | property bool cellActive: false |
swissChili | 4b3105a | 2022-02-22 16:34:39 -0800 | [diff] [blame] | 15 | |
swissChili | 25620b0 | 2022-02-23 17:15:16 -0800 | [diff] [blame] | 16 | signal insertBelowClicked() |
17 | signal codeEditingFinished(string code) | ||||
18 | signal cellFocused() | ||||
swissChili | 06cec4e | 2022-02-24 19:04:32 -0800 | [diff] [blame] | 19 | signal cellUnfocused() |
swissChili | d85daa9 | 2022-02-24 15:29:02 -0800 | [diff] [blame] | 20 | signal runClicked() |
swissChili | 06cec4e | 2022-02-24 19:04:32 -0800 | [diff] [blame] | 21 | signal deleteClicked() |
swissChili | 23958ca | 2022-02-21 19:23:34 -0800 | [diff] [blame] | 22 | |
swissChili | 25620b0 | 2022-02-23 17:15:16 -0800 | [diff] [blame] | 23 | height: column.height |
swissChili | 23958ca | 2022-02-21 19:23:34 -0800 | [diff] [blame] | 24 | |
swissChili | 06cec4e | 2022-02-24 19:04:32 -0800 | [diff] [blame] | 25 | Keys.onEscapePressed: root.cellUnfocused() |
swissChili | 25620b0 | 2022-02-23 17:15:16 -0800 | [diff] [blame] | 26 | |
27 | ColumnLayout { | ||||
28 | id: column | ||||
29 | |||||
swissChili | 06cec4e | 2022-02-24 19:04:32 -0800 | [diff] [blame] | 30 | width: parent.width - 20 |
31 | anchors.centerIn: parent | ||||
swissChili | 25620b0 | 2022-02-23 17:15:16 -0800 | [diff] [blame] | 32 | |
swissChili | 06cec4e | 2022-02-24 19:04:32 -0800 | [diff] [blame] | 33 | Item { |
34 | implicitWidth: row.implicitWidth | ||||
35 | implicitHeight: row.implicitHeight | ||||
swissChili | 23958ca | 2022-02-21 19:23:34 -0800 | [diff] [blame] | 36 | Layout.fillWidth: true |
swissChili | 23958ca | 2022-02-21 19:23:34 -0800 | [diff] [blame] | 37 | |
swissChili | 06cec4e | 2022-02-24 19:04:32 -0800 | [diff] [blame] | 38 | Pane { |
39 | anchors.fill: parent | ||||
40 | anchors.topMargin: -5 | ||||
41 | anchors.bottomMargin: -5 | ||||
swissChili | d85daa9 | 2022-02-24 15:29:02 -0800 | [diff] [blame] | 42 | |
swissChili | 06cec4e | 2022-02-24 19:04:32 -0800 | [diff] [blame] | 43 | Material.elevation: root.cellActive ? 4 : 0 |
swissChili | 25620b0 | 2022-02-23 17:15:16 -0800 | [diff] [blame] | 44 | } |
45 | |||||
swissChili | 06cec4e | 2022-02-24 19:04:32 -0800 | [diff] [blame] | 46 | MouseArea { |
47 | id: selectCell | ||||
swissChili | 4b3105a | 2022-02-22 16:34:39 -0800 | [diff] [blame] | 48 | |
swissChili | 06cec4e | 2022-02-24 19:04:32 -0800 | [diff] [blame] | 49 | 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 { | ||||
swissChili | 25620b0 | 2022-02-23 17:15:16 -0800 | [diff] [blame] | 75 | Layout.fillWidth: true |
76 | Layout.fillHeight: true | ||||
swissChili | 25620b0 | 2022-02-23 17:15:16 -0800 | [diff] [blame] | 77 | |
swissChili | 06cec4e | 2022-02-24 19:04:32 -0800 | [diff] [blame] | 78 | 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() | ||||
swissChili | 25620b0 | 2022-02-23 17:15:16 -0800 | [diff] [blame] | 105 | } |
106 | |||||
swissChili | 06cec4e | 2022-02-24 19:04:32 -0800 | [diff] [blame] | 107 | Label { |
108 | visible: root.result.length > 0 | ||||
109 | Layout.fillWidth: true | ||||
110 | font.family: "monospace" | ||||
111 | text: root.result | ||||
swissChili | 25620b0 | 2022-02-23 17:15:16 -0800 | [diff] [blame] | 112 | |
swissChili | 06cec4e | 2022-02-24 19:04:32 -0800 | [diff] [blame] | 113 | Layout.bottomMargin: 5 |
swissChili | 25620b0 | 2022-02-23 17:15:16 -0800 | [diff] [blame] | 114 | } |
swissChili | 25620b0 | 2022-02-23 17:15:16 -0800 | [diff] [blame] | 115 | } |
116 | |||||
swissChili | 06cec4e | 2022-02-24 19:04:32 -0800 | [diff] [blame] | 117 | RoundButton { |
118 | icon.source: "qrc:///icons/menu.svg" | ||||
119 | icon.color: Constants.buttonGrey | ||||
120 | flat: true | ||||
swissChili | 23958ca | 2022-02-21 19:23:34 -0800 | [diff] [blame] | 121 | |
swissChili | 06cec4e | 2022-02-24 19:04:32 -0800 | [diff] [blame] | 122 | 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 | } | ||||
swissChili | 23958ca | 2022-02-21 19:23:34 -0800 | [diff] [blame] | 136 | } |
137 | } | ||||
swissChili | 23958ca | 2022-02-21 19:23:34 -0800 | [diff] [blame] | 138 | |
swissChili | 25620b0 | 2022-02-23 17:15:16 -0800 | [diff] [blame] | 139 | InsertRow { |
140 | onInsertClicked: root.insertBelowClicked() | ||||
141 | } | ||||
swissChili | 23958ca | 2022-02-21 19:23:34 -0800 | [diff] [blame] | 142 | } |
143 | } |