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 | 4b3105a | 2022-02-22 16:34:39 -0800 | [diff] [blame] | 14 | |
swissChili | 25620b0 | 2022-02-23 17:15:16 -0800 | [diff] [blame] | 15 | signal insertBelowClicked() |
| 16 | signal codeEditingFinished(string code) |
| 17 | signal cellFocused() |
swissChili | d85daa9 | 2022-02-24 15:29:02 -0800 | [diff] [blame] | 18 | signal runClicked() |
swissChili | 23958ca | 2022-02-21 19:23:34 -0800 | [diff] [blame] | 19 | |
swissChili | 25620b0 | 2022-02-23 17:15:16 -0800 | [diff] [blame] | 20 | height: column.height |
swissChili | 23958ca | 2022-02-21 19:23:34 -0800 | [diff] [blame] | 21 | |
swissChili | 25620b0 | 2022-02-23 17:15:16 -0800 | [diff] [blame] | 22 | 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 |
swissChili | 23958ca | 2022-02-21 19:23:34 -0800 | [diff] [blame] | 37 | Layout.fillWidth: true |
swissChili | 23958ca | 2022-02-21 19:23:34 -0800 | [diff] [blame] | 38 | |
swissChili | 25620b0 | 2022-02-23 17:15:16 -0800 | [diff] [blame] | 39 | RoundButton { |
| 40 | Layout.alignment: Qt.AlignTop |
swissChili | d85daa9 | 2022-02-24 15:29:02 -0800 | [diff] [blame] | 41 | icon.source: iconForState(root.state) |
swissChili | 25620b0 | 2022-02-23 17:15:16 -0800 | [diff] [blame] | 42 | icon.color: Material.color(Material.Grey, Material.Shade600) |
| 43 | flat: true |
swissChili | d85daa9 | 2022-02-24 15:29:02 -0800 | [diff] [blame] | 44 | |
| 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 | } |
swissChili | 25620b0 | 2022-02-23 17:15:16 -0800 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | ColumnLayout { |
swissChili | 23958ca | 2022-02-21 19:23:34 -0800 | [diff] [blame] | 56 | Layout.fillWidth: true |
| 57 | Layout.fillHeight: true |
swissChili | 4b3105a | 2022-02-22 16:34:39 -0800 | [diff] [blame] | 58 | |
swissChili | 25620b0 | 2022-02-23 17:15:16 -0800 | [diff] [blame] | 59 | 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 |
swissChili | 4b3105a | 2022-02-22 16:34:39 -0800 | [diff] [blame] | 90 | } |
swissChili | 23958ca | 2022-02-21 19:23:34 -0800 | [diff] [blame] | 91 | } |
| 92 | |
swissChili | 25620b0 | 2022-02-23 17:15:16 -0800 | [diff] [blame] | 93 | 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 |
swissChili | 23958ca | 2022-02-21 19:23:34 -0800 | [diff] [blame] | 97 | } |
| 98 | } |
swissChili | 23958ca | 2022-02-21 19:23:34 -0800 | [diff] [blame] | 99 | |
swissChili | 25620b0 | 2022-02-23 17:15:16 -0800 | [diff] [blame] | 100 | InsertRow { |
| 101 | onInsertClicked: root.insertBelowClicked() |
| 102 | } |
swissChili | 23958ca | 2022-02-21 19:23:34 -0800 | [diff] [blame] | 103 | } |
| 104 | } |