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 | 25620b0 | 2022-02-23 17:15:16 -0800 | [diff] [blame^] | 6 | Item { |
swissChili | 23958ca | 2022-02-21 19:23:34 -0800 | [diff] [blame] | 7 | id: root |
| 8 | |
swissChili | 4b3105a | 2022-02-22 16:34:39 -0800 | [diff] [blame] | 9 | required property string code |
| 10 | required property string result |
| 11 | |
swissChili | 25620b0 | 2022-02-23 17:15:16 -0800 | [diff] [blame^] | 12 | signal insertBelowClicked() |
| 13 | signal codeEditingFinished(string code) |
| 14 | signal cellFocused() |
swissChili | 23958ca | 2022-02-21 19:23:34 -0800 | [diff] [blame] | 15 | |
swissChili | 25620b0 | 2022-02-23 17:15:16 -0800 | [diff] [blame^] | 16 | height: column.height |
swissChili | 23958ca | 2022-02-21 19:23:34 -0800 | [diff] [blame] | 17 | |
swissChili | 25620b0 | 2022-02-23 17:15:16 -0800 | [diff] [blame^] | 18 | MouseArea { |
| 19 | id: selectCell |
| 20 | |
| 21 | anchors.fill: column |
| 22 | |
| 23 | onClicked: root.cellFocused() |
| 24 | } |
| 25 | |
| 26 | ColumnLayout { |
| 27 | id: column |
| 28 | |
| 29 | width: parent.width |
| 30 | |
| 31 | RowLayout { |
| 32 | id: row |
swissChili | 23958ca | 2022-02-21 19:23:34 -0800 | [diff] [blame] | 33 | Layout.fillWidth: true |
swissChili | 23958ca | 2022-02-21 19:23:34 -0800 | [diff] [blame] | 34 | |
swissChili | 25620b0 | 2022-02-23 17:15:16 -0800 | [diff] [blame^] | 35 | RoundButton { |
| 36 | Layout.alignment: Qt.AlignTop |
| 37 | icon.source: "qrc:///icons/play-circle.svg" |
| 38 | icon.color: Material.color(Material.Grey, Material.Shade600) |
| 39 | flat: true |
| 40 | } |
| 41 | |
| 42 | ColumnLayout { |
swissChili | 23958ca | 2022-02-21 19:23:34 -0800 | [diff] [blame] | 43 | Layout.fillWidth: true |
| 44 | Layout.fillHeight: true |
swissChili | 4b3105a | 2022-02-22 16:34:39 -0800 | [diff] [blame] | 45 | |
swissChili | 25620b0 | 2022-02-23 17:15:16 -0800 | [diff] [blame^] | 46 | TextArea { |
| 47 | Layout.fillWidth: true |
| 48 | Layout.fillHeight: true |
| 49 | id: code |
| 50 | font.family: "monospace" |
| 51 | text: root.code |
| 52 | selectByMouse: true |
| 53 | wrapMode: TextEdit.WrapAtWordBoundaryOrAnywhere |
| 54 | |
| 55 | Keys.onTabPressed: { |
| 56 | var pos = cursorPosition + 4 |
| 57 | text = text.slice(0, cursorPosition) + " " + text.slice(cursorPosition); |
| 58 | cursorPosition = pos |
| 59 | } |
| 60 | |
| 61 | Keys.onEscapePressed: { |
| 62 | root.forceActiveFocus() |
| 63 | } |
| 64 | |
| 65 | onEditingFinished: { |
| 66 | root.codeEditingFinished(text) |
| 67 | } |
| 68 | |
| 69 | onFocusChanged: if (focus) root.cellFocused() |
| 70 | } |
| 71 | |
| 72 | Label { |
| 73 | visible: root.result.length > 0 |
| 74 | Layout.fillWidth: true |
| 75 | font.family: "monospace" |
| 76 | text: root.result |
swissChili | 4b3105a | 2022-02-22 16:34:39 -0800 | [diff] [blame] | 77 | } |
swissChili | 23958ca | 2022-02-21 19:23:34 -0800 | [diff] [blame] | 78 | } |
| 79 | |
swissChili | 25620b0 | 2022-02-23 17:15:16 -0800 | [diff] [blame^] | 80 | RoundButton { |
| 81 | icon.source: "qrc:///icons/trash.svg" |
| 82 | icon.color: Material.color(Material.Grey, Material.theme == Material.Dark ? Material.Shade400 : Material.Shade600) |
| 83 | flat: true |
swissChili | 23958ca | 2022-02-21 19:23:34 -0800 | [diff] [blame] | 84 | } |
| 85 | } |
swissChili | 23958ca | 2022-02-21 19:23:34 -0800 | [diff] [blame] | 86 | |
swissChili | 25620b0 | 2022-02-23 17:15:16 -0800 | [diff] [blame^] | 87 | InsertRow { |
| 88 | onInsertClicked: root.insertBelowClicked() |
| 89 | } |
swissChili | 23958ca | 2022-02-21 19:23:34 -0800 | [diff] [blame] | 90 | } |
| 91 | } |