harbour-muchkin/qml/Icon.qml

157 lines
4.7 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
import Nemo.Notifications 1.0
2021-05-10 18:59:52 +00:00
Page {
id: iconEditor
property var attrs
property var corners: [true, true, true, true]
Notification {
id: notification
appIcon: "/usr/share/icons/hicolor/86x86/apps/harbour-muchkin"
expireTimeout: 5000
2021-05-10 18:59:52 +00:00
function sendMessage(msg) {
notification.previewBody = msg
notification.publish()
}
}
2021-05-10 18:59:52 +00:00
SilicaFlickable {
id: mainList
anchors.fill: parent
2021-05-10 18:59:52 +00:00
PullDownMenu {
MenuItem {
text: "Search a better icon"
onClicked: {
py.importModule("main", function(){
py.call("main.scrape_icon", [iconEditor.attrs.URL], function(result){
if(result) {
icon.source = result;
iconEditor.attrs.Icon = result;
notification.sendMessage("A better icon found");
} else {
notification.sendMessage("Not better icon found");
}
})
})
}
2021-05-10 18:59:52 +00:00
}
}
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 {
idCell: 0
activated: true
}
ListElement {
idCell: 1
activated: true
}
ListElement {
idCell: 2
activated: true
}
ListElement {
idCell: 3
activated: true
}
2021-05-10 18:59:52 +00:00
}
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, size.value], function(result){
icon.source = result
})
})
}
2021-05-10 18:59:52 +00:00
}
}
Image {
id: icon
anchors.top: header.bottom
width: parent.width
height: width
}
Slider {
id: size
anchors.top: icon.bottom
anchors.horizontalCenter: parent.horizontalCenter
anchors.topMargin: 10
label: "Size:"
width: parent.width
minimumValue: 0
maximumValue: 100
stepSize: 10
value: 100
onReleased: {
2021-05-10 18:59:52 +00:00
py.importModule("main", function(){
2024-04-02 07:16:08 +00:00
py.call("main.sailify", [(iconEditor.attrs.old_icon || iconEditor.attrs.Icon).toString(), iconEditor.corners, size.value], function(result){
2021-05-10 20:12:10 +00:00
icon.source = result
2021-05-10 18:59:52 +00:00
})
})
}
}
Button {
anchors.top: size.bottom
anchors.horizontalCenter: parent.horizontalCenter
anchors.topMargin: 20
text: "Save"
onClicked: {
if(iconEditor.attrs.old_icon === undefined) {
iconEditor.attrs.old_icon = iconEditor.attrs.Icon.toString()
}
iconEditor.attrs.Icon = icon.source.toString()
py.importModule("main", function(){
py.call("main.save_icon", [iconEditor.attrs], function(result){
if(result){
pageStack.pop()
pageStack.completeAnimation()
pageStack.currentPage.mainList.reload()
}
})
2024-04-02 07:16:08 +00:00
})
}
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"));
py.importModule("main", function(){
py.call("main.sailify", [(iconEditor.attrs.old_icon || iconEditor.attrs.Icon).toString(), [1, 1, 1, 1], size.value], function(result){
icon.source = result
})
2021-05-10 20:12:10 +00:00
})
}
2021-05-10 18:59:52 +00:00
}
2021-05-10 18:59:52 +00:00
}
2021-05-10 18:59:52 +00:00
}