Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import QtQuick 2.0
import Sailfish.Silica 1.0
import io.thp.pyotherside 1.3
Page {
id: page
property Item contextMenuPlaces
onStatusChanged: {
if (page.status==PageStatus.Active)
{
placesModel.clear();
citiesModel.clear();
py.call('pyveggiesailor.controller.fav_places', [],function(result) {
for (var i=0; i<result.length; i++) {
placesModel.append(result[i]);
}
});
py.call('pyveggiesailor.controller.fav_cities', [],function(result) {
for (var i=0; i<result.length; i++) {
citiesModel.append(result[i]);
}
});
}
}
SilicaFlickable {
width: page.width
height: parent.width
contentHeight: listView.height
contentWidth: listView.width
anchors.fill: parent
Column {
PageHeader {
title: qsTr("Favourites")
}
id: listView
width: page.width
spacing: Theme.paddingLarge
Label {
text: qsTr("Places")
color: Theme.highlightColor
font.pixelSize: Theme.fontSizeLarge
width: parent.width
x: Theme.paddingLarge
}
Repeater {
id: repPlaces
model: ListModel {
id: placesModel
}
delegate: EntryBackgroundItem {
id: bgdPlace
function openPlace(entryUri) {
console.log("open place");
}
onClicked: openPlace(uri)
}
}
Label {
text: qsTr("Cities")
color: Theme.highlightColor
width: parent.width
font.pixelSize: Theme.fontSizeLarge
x: Theme.paddingLarge
}
ListView {
id: repCities
model: ListModel {
id: citiesModel
}
property Item contextMenuCities
delegate: Item {
id: myListItemCities
property bool menuOpen: repCities.contextMenuCities != null && repCities.contextMenuCities.parent === myListItemCities
height: menuOpen ? repCities.contextMenuCities.height + bgdCity.height : bgdCity.height
width: Repeater.view.width
BackgroundItem {
id: bgdCity
height: Theme.itemSizeSmall
width: parent.width
function openCity(cityUri, cityName) {
pageStack.push(Qt.resolvedUrl("Entries.qml"),
{
"uri": cityUri,
"mytext":name
});
}
Label {
text: name
x: Theme.paddingLarge
color: bgdCity.highlighted ? Theme.highlightColor : Theme.primaryColor
}
onClicked: openCity(uri, name)
onPressAndHold: {
console.log("HOLD");
if (!contextMenuCities)
contextMenuCities = contextMenuComponentCities.createObject(repCities)
contextMenuCities.show(myListItemCities)
}
}
}
Component {
id: contextMenuComponentCities
ContextMenu {
MenuItem {
text: "Option 1"
onClicked: console.log("Clicked Option 1")
}
MenuItem {
text: "Option 2"
onClicked: console.log("Clicked Option 2")
}
}
}
}
Python {
id: py
Component.onCompleted: {
addImportPath(Qt.resolvedUrl('.'));
addImportPath(Qt.resolvedUrl('..'));
addImportPath(Qt.resolvedUrl('../..'));
importModule('pyveggiesailor.controller', function () {
});
}
}
}
VerticalScrollDecorator {}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.