Advertisement
Guest User

Untitled

a guest
Apr 6th, 2015
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
QML 4.94 KB | None | 0 0
  1. import QtQuick 2.0
  2. import Sailfish.Silica 1.0
  3. import io.thp.pyotherside 1.3
  4.  
  5. Page {
  6.     id: page
  7.     property Item contextMenuPlaces
  8.     onStatusChanged: {
  9.  
  10.  
  11.         if (page.status==PageStatus.Active)
  12.         {
  13.             placesModel.clear();
  14.             citiesModel.clear();
  15.  
  16.  
  17.             py.call('pyveggiesailor.controller.fav_places', [],function(result) {
  18.                 for (var i=0; i<result.length; i++) {
  19.                     placesModel.append(result[i]);
  20.                 }
  21.             });
  22.             py.call('pyveggiesailor.controller.fav_cities', [],function(result) {
  23.                 for (var i=0; i<result.length; i++) {
  24.                     citiesModel.append(result[i]);
  25.                 }
  26.             });
  27.         }
  28.  
  29.     }
  30.     SilicaFlickable {
  31.         width: page.width
  32.         height: parent.width
  33.         contentHeight: listView.height
  34.         contentWidth: listView.width
  35.         anchors.fill: parent
  36.  
  37.  
  38.         Column {
  39.  
  40.             PageHeader {
  41.                 title: qsTr("Favourites")
  42.             }
  43.             id: listView
  44.             width: page.width
  45.  
  46.             spacing: Theme.paddingLarge
  47.  
  48.  
  49.             Label {
  50.                 text: qsTr("Places")
  51.                 color: Theme.highlightColor
  52.                 font.pixelSize: Theme.fontSizeLarge
  53.                 width: parent.width
  54.                 x: Theme.paddingLarge
  55.  
  56.             }
  57.             Repeater {
  58.                 id: repPlaces
  59.                 model: ListModel {
  60.                     id: placesModel
  61.                 }
  62.                 delegate: EntryBackgroundItem {
  63.                     id: bgdPlace
  64.                     function openPlace(entryUri) {
  65.             console.log("open place");
  66.  
  67.                     }
  68.                     onClicked: openPlace(uri)
  69.  
  70.                 }
  71.             }
  72.             Label {
  73.                 text: qsTr("Cities")
  74.                 color: Theme.highlightColor
  75.                 width: parent.width
  76.                 font.pixelSize: Theme.fontSizeLarge
  77.                 x: Theme.paddingLarge
  78.             }
  79.  
  80.             Repeater {
  81.                 id: repCities
  82. //                quickScroll : false
  83.                 model: ListModel {
  84.                     id: citiesModel
  85.                 }
  86.  
  87.                 property Item contextMenuCities
  88.  
  89.  
  90.                 delegate: Item {
  91.  
  92.                     id: myListItemCities
  93.                     property bool menuOpen: repCities.contextMenuCities != null && repCities.contextMenuCities.parent === myListItemCities
  94.  
  95.                     //                        width: ListView.view.width
  96.                     height: menuOpen ? repCities.contextMenuCities.height + bgdCity.height : bgdCity.height
  97.                     width: Repeater.view.width
  98.  
  99.  
  100.                     BackgroundItem {
  101.                         id: bgdCity
  102.                         height: Theme.itemSizeSmall
  103.                         width: parent.width
  104.                         function openCity(cityUri, cityName) {
  105.                             pageStack.push(Qt.resolvedUrl("Entries.qml"),
  106.                                            {
  107.                                                "uri": cityUri,
  108.                                                "mytext":name
  109.                                            });
  110.                         }
  111.  
  112.                         Label {
  113.                             text: name
  114.                             x: Theme.paddingLarge
  115.                             color: bgdCity.highlighted ? Theme.highlightColor : Theme.primaryColor
  116.                         }
  117.                         onClicked: openCity(uri, name)
  118.  
  119.                         onPressAndHold: {
  120.                             console.log("HOLD");
  121.                             if (!contextMenuCities)
  122.                                 contextMenuCities = contextMenuComponentCities.createObject(repCities)
  123.                             contextMenuCities.show(myListItemCities)
  124.                         }
  125.  
  126.                     }
  127.                 }
  128.                 Component {
  129.                     id: contextMenuComponentCities
  130.                     ContextMenu {
  131.                         MenuItem {
  132.                             text: "Option 1"
  133.                             onClicked: console.log("Clicked Option 1")
  134.                         }
  135.                         MenuItem {
  136.                             text: "Option 2"
  137.                             onClicked: console.log("Clicked Option 2")
  138.                         }
  139.                     }
  140.  
  141.                 }
  142.  
  143.             }
  144.             Python {
  145.                 id: py
  146.                 Component.onCompleted: {
  147.                     addImportPath(Qt.resolvedUrl('.'));
  148.                     addImportPath(Qt.resolvedUrl('..'));
  149.                     addImportPath(Qt.resolvedUrl('../..'));
  150.  
  151.                     importModule('pyveggiesailor.controller', function () {
  152.                     });
  153.  
  154.                 }
  155.  
  156.  
  157.             }
  158.  
  159.  
  160.  
  161.         }
  162.         VerticalScrollDecorator {}
  163.  
  164.  
  165.     }
  166. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement