blob: f51ffaa12e8d8f1a0bb23cf61f9fd48645de9926 [file] [log] [blame]
import QtQuick 2.0
import QtQuick.Controls 2.15
import QtQuick.Controls.Material 2.0
import QtQuick.Layouts 1.0
import sh.swisschili.REFAL 1.0
Item {
id: root
required property string code
required property string result
property int status: Cell.IDLE
signal insertBelowClicked()
signal codeEditingFinished(string code)
signal cellFocused()
signal runClicked()
height: column.height
MouseArea {
id: selectCell
anchors.fill: column
onClicked: root.cellFocused()
}
ColumnLayout {
id: column
width: parent.width
RowLayout {
id: row
Layout.fillWidth: true
RoundButton {
Layout.alignment: Qt.AlignTop
icon.source: iconForState(root.state)
icon.color: Material.color(Material.Grey, Material.Shade600)
flat: true
onClicked: root.runClicked()
function iconForState(state) {
if (state === Cell.RUNNING)
return "qrc:///icons/square.svg"
return "qrc:///icons/play-circle.svg"
}
}
ColumnLayout {
Layout.fillWidth: true
Layout.fillHeight: true
TextArea {
Layout.fillWidth: true
Layout.fillHeight: true
id: code
font.family: "monospace"
text: root.code
selectByMouse: true
wrapMode: TextEdit.WrapAtWordBoundaryOrAnywhere
Keys.onTabPressed: {
var pos = cursorPosition + 4
text = text.slice(0, cursorPosition) + " " + text.slice(cursorPosition);
cursorPosition = pos
}
Keys.onEscapePressed: {
root.forceActiveFocus()
}
onEditingFinished: {
root.codeEditingFinished(text)
}
onFocusChanged: if (focus) root.cellFocused()
}
Label {
visible: root.result.length > 0
Layout.fillWidth: true
font.family: "monospace"
text: root.result
}
}
RoundButton {
icon.source: "qrc:///icons/trash.svg"
icon.color: Material.color(Material.Grey, Material.theme == Material.Dark ? Material.Shade400 : Material.Shade600)
flat: true
}
}
InsertRow {
onInsertClicked: root.insertBelowClicked()
}
}
}