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 | 732628e | 2022-02-25 10:35:56 -0800 | [diff] [blame^] | 25 | Keys.onEscapePressed: { |
26 | root.cellUnfocused() | ||||
27 | code.focus = false | ||||
28 | } | ||||
swissChili | 25620b0 | 2022-02-23 17:15:16 -0800 | [diff] [blame] | 29 | |
30 | ColumnLayout { | ||||
31 | id: column | ||||
32 | |||||
swissChili | 06cec4e | 2022-02-24 19:04:32 -0800 | [diff] [blame] | 33 | width: parent.width - 20 |
34 | anchors.centerIn: parent | ||||
swissChili | 25620b0 | 2022-02-23 17:15:16 -0800 | [diff] [blame] | 35 | |
swissChili | 06cec4e | 2022-02-24 19:04:32 -0800 | [diff] [blame] | 36 | Item { |
37 | implicitWidth: row.implicitWidth | ||||
38 | implicitHeight: row.implicitHeight | ||||
swissChili | 23958ca | 2022-02-21 19:23:34 -0800 | [diff] [blame] | 39 | Layout.fillWidth: true |
swissChili | 23958ca | 2022-02-21 19:23:34 -0800 | [diff] [blame] | 40 | |
swissChili | 06cec4e | 2022-02-24 19:04:32 -0800 | [diff] [blame] | 41 | Pane { |
42 | anchors.fill: parent | ||||
43 | anchors.topMargin: -5 | ||||
44 | anchors.bottomMargin: -5 | ||||
swissChili | d85daa9 | 2022-02-24 15:29:02 -0800 | [diff] [blame] | 45 | |
swissChili | 06cec4e | 2022-02-24 19:04:32 -0800 | [diff] [blame] | 46 | Material.elevation: root.cellActive ? 4 : 0 |
swissChili | 25620b0 | 2022-02-23 17:15:16 -0800 | [diff] [blame] | 47 | } |
48 | |||||
swissChili | 06cec4e | 2022-02-24 19:04:32 -0800 | [diff] [blame] | 49 | MouseArea { |
50 | id: selectCell | ||||
swissChili | 4b3105a | 2022-02-22 16:34:39 -0800 | [diff] [blame] | 51 | |
swissChili | 06cec4e | 2022-02-24 19:04:32 -0800 | [diff] [blame] | 52 | anchors.fill: row |
53 | |||||
54 | onClicked: root.cellFocused() | ||||
55 | } | ||||
56 | |||||
57 | RowLayout { | ||||
58 | anchors.fill: parent | ||||
59 | id: row | ||||
60 | |||||
61 | RoundButton { | ||||
62 | Layout.alignment: Qt.AlignTop | ||||
63 | icon.source: iconForState(root.state) | ||||
64 | icon.color: Material.color(Material.Grey, Material.Shade600) | ||||
65 | flat: true | ||||
66 | |||||
67 | onClicked: root.runClicked() | ||||
68 | |||||
69 | function iconForState(state) { | ||||
70 | if (state === Cell.RUNNING) | ||||
71 | return "qrc:///icons/square.svg" | ||||
72 | |||||
73 | return "qrc:///icons/play-circle.svg" | ||||
74 | } | ||||
75 | } | ||||
76 | |||||
77 | ColumnLayout { | ||||
swissChili | 25620b0 | 2022-02-23 17:15:16 -0800 | [diff] [blame] | 78 | Layout.fillWidth: true |
79 | Layout.fillHeight: true | ||||
swissChili | 25620b0 | 2022-02-23 17:15:16 -0800 | [diff] [blame] | 80 | |
swissChili | 06cec4e | 2022-02-24 19:04:32 -0800 | [diff] [blame] | 81 | TextArea { |
swissChili | 732628e | 2022-02-25 10:35:56 -0800 | [diff] [blame^] | 82 | id: code |
83 | |||||
swissChili | 06cec4e | 2022-02-24 19:04:32 -0800 | [diff] [blame] | 84 | Layout.fillWidth: true |
85 | Layout.fillHeight: true | ||||
swissChili | 732628e | 2022-02-25 10:35:56 -0800 | [diff] [blame^] | 86 | |
swissChili | 06cec4e | 2022-02-24 19:04:32 -0800 | [diff] [blame] | 87 | font.family: "monospace" |
88 | text: root.code | ||||
89 | selectByMouse: true | ||||
90 | wrapMode: TextEdit.WrapAtWordBoundaryOrAnywhere | ||||
91 | |||||
92 | placeholderText: "Write some code..." | ||||
93 | |||||
94 | Keys.onTabPressed: { | ||||
95 | var pos = cursorPosition + 4 | ||||
96 | text = text.slice(0, cursorPosition) + " " + text.slice(cursorPosition); | ||||
97 | cursorPosition = pos | ||||
98 | } | ||||
99 | |||||
100 | // Keys.onEscapePressed: { | ||||
101 | // focus = false | ||||
102 | // } | ||||
103 | |||||
104 | onEditingFinished: { | ||||
105 | root.codeEditingFinished(text) | ||||
106 | } | ||||
107 | |||||
108 | onFocusChanged: if (focus) root.cellFocused() | ||||
109 | onActiveFocusChanged: if (activeFocus) root.cellFocused() | ||||
swissChili | 25620b0 | 2022-02-23 17:15:16 -0800 | [diff] [blame] | 110 | } |
111 | |||||
swissChili | 06cec4e | 2022-02-24 19:04:32 -0800 | [diff] [blame] | 112 | Label { |
113 | visible: root.result.length > 0 | ||||
114 | Layout.fillWidth: true | ||||
115 | font.family: "monospace" | ||||
116 | text: root.result | ||||
swissChili | 25620b0 | 2022-02-23 17:15:16 -0800 | [diff] [blame] | 117 | |
swissChili | 06cec4e | 2022-02-24 19:04:32 -0800 | [diff] [blame] | 118 | Layout.bottomMargin: 5 |
swissChili | 25620b0 | 2022-02-23 17:15:16 -0800 | [diff] [blame] | 119 | } |
swissChili | 25620b0 | 2022-02-23 17:15:16 -0800 | [diff] [blame] | 120 | } |
121 | |||||
swissChili | 06cec4e | 2022-02-24 19:04:32 -0800 | [diff] [blame] | 122 | RoundButton { |
swissChili | 732628e | 2022-02-25 10:35:56 -0800 | [diff] [blame^] | 123 | Layout.alignment: Qt.AlignTop |
124 | |||||
swissChili | 06cec4e | 2022-02-24 19:04:32 -0800 | [diff] [blame] | 125 | icon.source: "qrc:///icons/menu.svg" |
126 | icon.color: Constants.buttonGrey | ||||
127 | flat: true | ||||
swissChili | 23958ca | 2022-02-21 19:23:34 -0800 | [diff] [blame] | 128 | |
swissChili | 06cec4e | 2022-02-24 19:04:32 -0800 | [diff] [blame] | 129 | onClicked: cellContextMenu.popup() |
130 | |||||
131 | Menu { | ||||
132 | id: cellContextMenu | ||||
133 | |||||
134 | MenuItem { | ||||
135 | icon.source: "qrc:///icons/trash.svg" | ||||
136 | icon.color: Material.color(Material.Red) | ||||
137 | text: "Delete" | ||||
138 | |||||
139 | onClicked: root.deleteClicked() | ||||
140 | } | ||||
141 | } | ||||
142 | } | ||||
swissChili | 23958ca | 2022-02-21 19:23:34 -0800 | [diff] [blame] | 143 | } |
144 | } | ||||
swissChili | 23958ca | 2022-02-21 19:23:34 -0800 | [diff] [blame] | 145 | |
swissChili | 25620b0 | 2022-02-23 17:15:16 -0800 | [diff] [blame] | 146 | InsertRow { |
147 | onInsertClicked: root.insertBelowClicked() | ||||
148 | } | ||||
swissChili | 23958ca | 2022-02-21 19:23:34 -0800 | [diff] [blame] | 149 | } |
150 | } |