harbour-muchkin/qml/Icon.qml

99 lines
2.6 KiB
QML
Raw Normal View History

2021-05-10 18:59:52 +00:00
import QtQuick 2.0
import Sailfish.Silica 1.0
import io.thp.pyotherside 1.3
Page {
id: iconEditor
property var attrs
property var corners: [true, true, true, true]
PageHeader {
id: header
width: parent.width
title: "name: " + attrs.Name
}
SilicaGridView {
anchors.top: header.bottom
width: parent.width
height: width
cellWidth: width / 2
cellHeight: cellWidth
model: ListModel {
id: gridItems
ListElement {
2021-05-10 20:12:10 +00:00
idCell: 0
2021-05-10 18:59:52 +00:00
activated: true
}
ListElement {
2021-05-10 20:12:10 +00:00
idCell: 1
2021-05-10 18:59:52 +00:00
activated: true
}
ListElement {
2021-05-10 20:12:10 +00:00
idCell: 2
2021-05-10 18:59:52 +00:00
activated: true
}
ListElement {
2021-05-10 20:12:10 +00:00
idCell: 3
2021-05-10 18:59:52 +00:00
activated: true
}
}
delegate: GridItem {
onClicked: {
activated = !activated
iconEditor.corners[idCell] = activated
py.importModule("main", function(){
py.call("main.sailify", [(iconEditor.attrs.old_icon || iconEditor.attrs.Icon).toString(), iconEditor.corners], function(result){
2021-05-10 20:12:10 +00:00
icon.source = result
2021-05-10 18:59:52 +00:00
})
})
}
}
}
Image {
id: icon
anchors.top: header.bottom
width: parent.width
height: width
}
Button {
anchors.top: icon.bottom
anchors.horizontalCenter: parent.horizontalCenter
2021-05-10 20:12:10 +00:00
anchors.topMargin: 10
2021-05-10 18:59:52 +00:00
text: "Save"
2021-05-10 20:12:10 +00:00
onClicked: {
if(iconEditor.attrs.old_icon === undefined) {
iconEditor.attrs.old_icon = iconEditor.attrs.Icon.toString()
}
2021-05-10 20:12:10 +00:00
iconEditor.attrs.Icon = icon.source.toString()
py.importModule("main", function(){
py.call("main.save_icon", [iconEditor.attrs], function(result){
if(result){
2021-05-16 19:59:28 +00:00
pageStack.pop()
pageStack.completeAnimation()
pageStack.currentPage.mainList.reload()
2021-05-10 20:12:10 +00:00
}
})
})
}
2021-05-10 18:59:52 +00:00
}
Python {
id: py
Component.onCompleted: {
py.addImportPath(Qt.resolvedUrl("../src"));
2021-05-10 20:12:10 +00:00
py.importModule("main", function(){
py.call("main.sailify", [(iconEditor.attrs.old_icon || iconEditor.attrs.Icon).toString(), [1, 1, 1, 1]], function(result){
2021-05-10 20:12:10 +00:00
icon.source = result
})
})
2021-05-10 18:59:52 +00:00
}
}
}