swissChili | ece1ac8 | 2022-02-25 11:20:42 -0800 | [diff] [blame] | 1 | import QtQuick 2.5 |
swissChili | 23958ca | 2022-02-21 19:23:34 -0800 | [diff] [blame] | 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 | ece1ac8 | 2022-02-25 11:20:42 -0800 | [diff] [blame] | 14 | property int resultType: Cell.EXPRESSION |
swissChili | 06cec4e | 2022-02-24 19:04:32 -0800 | [diff] [blame] | 15 | property bool cellActive: false |
swissChili | 4b3105a | 2022-02-22 16:34:39 -0800 | [diff] [blame] | 16 | |
swissChili | 25620b0 | 2022-02-23 17:15:16 -0800 | [diff] [blame] | 17 | signal insertBelowClicked() |
18 | signal codeEditingFinished(string code) | ||||
19 | signal cellFocused() | ||||
swissChili | 06cec4e | 2022-02-24 19:04:32 -0800 | [diff] [blame] | 20 | signal cellUnfocused() |
swissChili | d85daa9 | 2022-02-24 15:29:02 -0800 | [diff] [blame] | 21 | signal runClicked() |
swissChili | 06cec4e | 2022-02-24 19:04:32 -0800 | [diff] [blame] | 22 | signal deleteClicked() |
swissChili | 23958ca | 2022-02-21 19:23:34 -0800 | [diff] [blame] | 23 | |
swissChili | 25620b0 | 2022-02-23 17:15:16 -0800 | [diff] [blame] | 24 | height: column.height |
swissChili | 23958ca | 2022-02-21 19:23:34 -0800 | [diff] [blame] | 25 | |
swissChili | 732628e | 2022-02-25 10:35:56 -0800 | [diff] [blame] | 26 | Keys.onEscapePressed: { |
27 | root.cellUnfocused() | ||||
28 | code.focus = false | ||||
29 | } | ||||
swissChili | 25620b0 | 2022-02-23 17:15:16 -0800 | [diff] [blame] | 30 | |
31 | ColumnLayout { | ||||
32 | id: column | ||||
33 | |||||
swissChili | 06cec4e | 2022-02-24 19:04:32 -0800 | [diff] [blame] | 34 | width: parent.width - 20 |
35 | anchors.centerIn: parent | ||||
swissChili | 25620b0 | 2022-02-23 17:15:16 -0800 | [diff] [blame] | 36 | |
swissChili | 06cec4e | 2022-02-24 19:04:32 -0800 | [diff] [blame] | 37 | Item { |
38 | implicitWidth: row.implicitWidth | ||||
39 | implicitHeight: row.implicitHeight | ||||
swissChili | 23958ca | 2022-02-21 19:23:34 -0800 | [diff] [blame] | 40 | Layout.fillWidth: true |
swissChili | 23958ca | 2022-02-21 19:23:34 -0800 | [diff] [blame] | 41 | |
swissChili | 06cec4e | 2022-02-24 19:04:32 -0800 | [diff] [blame] | 42 | Pane { |
43 | anchors.fill: parent | ||||
44 | anchors.topMargin: -5 | ||||
45 | anchors.bottomMargin: -5 | ||||
swissChili | d85daa9 | 2022-02-24 15:29:02 -0800 | [diff] [blame] | 46 | |
swissChili | 06cec4e | 2022-02-24 19:04:32 -0800 | [diff] [blame] | 47 | Material.elevation: root.cellActive ? 4 : 0 |
swissChili | 25620b0 | 2022-02-23 17:15:16 -0800 | [diff] [blame] | 48 | } |
49 | |||||
swissChili | 06cec4e | 2022-02-24 19:04:32 -0800 | [diff] [blame] | 50 | MouseArea { |
51 | id: selectCell | ||||
swissChili | 4b3105a | 2022-02-22 16:34:39 -0800 | [diff] [blame] | 52 | |
swissChili | 06cec4e | 2022-02-24 19:04:32 -0800 | [diff] [blame] | 53 | anchors.fill: row |
54 | |||||
55 | onClicked: root.cellFocused() | ||||
56 | } | ||||
57 | |||||
58 | RowLayout { | ||||
59 | anchors.fill: parent | ||||
60 | id: row | ||||
61 | |||||
62 | RoundButton { | ||||
63 | Layout.alignment: Qt.AlignTop | ||||
64 | icon.source: iconForState(root.state) | ||||
65 | icon.color: Material.color(Material.Grey, Material.Shade600) | ||||
66 | flat: true | ||||
67 | |||||
68 | onClicked: root.runClicked() | ||||
69 | |||||
70 | function iconForState(state) { | ||||
71 | if (state === Cell.RUNNING) | ||||
72 | return "qrc:///icons/square.svg" | ||||
73 | |||||
74 | return "qrc:///icons/play-circle.svg" | ||||
75 | } | ||||
76 | } | ||||
77 | |||||
78 | ColumnLayout { | ||||
swissChili | 25620b0 | 2022-02-23 17:15:16 -0800 | [diff] [blame] | 79 | Layout.fillWidth: true |
80 | Layout.fillHeight: true | ||||
swissChili | 25620b0 | 2022-02-23 17:15:16 -0800 | [diff] [blame] | 81 | |
swissChili | 06cec4e | 2022-02-24 19:04:32 -0800 | [diff] [blame] | 82 | TextArea { |
swissChili | 732628e | 2022-02-25 10:35:56 -0800 | [diff] [blame] | 83 | id: code |
84 | |||||
swissChili | 06cec4e | 2022-02-24 19:04:32 -0800 | [diff] [blame] | 85 | Layout.fillWidth: true |
86 | Layout.fillHeight: true | ||||
swissChili | 732628e | 2022-02-25 10:35:56 -0800 | [diff] [blame] | 87 | |
swissChili | 06cec4e | 2022-02-24 19:04:32 -0800 | [diff] [blame] | 88 | font.family: "monospace" |
89 | text: root.code | ||||
90 | selectByMouse: true | ||||
91 | wrapMode: TextEdit.WrapAtWordBoundaryOrAnywhere | ||||
92 | |||||
93 | placeholderText: "Write some code..." | ||||
94 | |||||
95 | Keys.onTabPressed: { | ||||
96 | var pos = cursorPosition + 4 | ||||
97 | text = text.slice(0, cursorPosition) + " " + text.slice(cursorPosition); | ||||
98 | cursorPosition = pos | ||||
99 | } | ||||
100 | |||||
swissChili | ece1ac8 | 2022-02-25 11:20:42 -0800 | [diff] [blame] | 101 | onTextChanged: { |
swissChili | 06cec4e | 2022-02-24 19:04:32 -0800 | [diff] [blame] | 102 | root.codeEditingFinished(text) |
103 | } | ||||
104 | |||||
swissChili | ece1ac8 | 2022-02-25 11:20:42 -0800 | [diff] [blame] | 105 | onPressed: root.cellFocused() |
106 | |||||
swissChili | 06cec4e | 2022-02-24 19:04:32 -0800 | [diff] [blame] | 107 | onFocusChanged: if (focus) root.cellFocused() |
108 | onActiveFocusChanged: if (activeFocus) root.cellFocused() | ||||
swissChili | 25620b0 | 2022-02-23 17:15:16 -0800 | [diff] [blame] | 109 | } |
110 | |||||
swissChili | 06cec4e | 2022-02-24 19:04:32 -0800 | [diff] [blame] | 111 | Label { |
112 | visible: root.result.length > 0 | ||||
113 | Layout.fillWidth: true | ||||
114 | font.family: "monospace" | ||||
115 | text: root.result | ||||
swissChili | ece1ac8 | 2022-02-25 11:20:42 -0800 | [diff] [blame] | 116 | textFormat: root.resultType === Cell.EXPRESSION ? Text.PlainText : Text.RichText |
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 | } |