Guest User

Untitled

a guest
Aug 6th, 2013
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import QtQuick 2.0
  2. import Sailfish.Silica 1.0
  3. import Sailfish.Silica.theme 1.0
  4. import net.khertan.python 1.0
  5.  
  6.  
  7. Page {
  8.     id: page
  9.    
  10.  
  11.  
  12.     // To enable PullDownMenu, place our content in a SilicaFlickable
  13.     SilicaFlickable {
  14.         anchors.fill: parent
  15.        
  16.         // PullDownMenu and PushUpMenu must be declared in SilicaFlickable, SilicaListView or SilicaGridView
  17.         PullDownMenu {
  18.             MenuItem {
  19.                 text: "Show Page 2"
  20.                 onClicked: pageStack.push(Qt.resolvedUrl("SecondPage.qml"))
  21.             }
  22.         }
  23.        
  24.         // Tell SilicaFlickable the height of its content.
  25.         contentHeight: childrenRect.height
  26.  
  27.         ListModel {
  28.             id: notesModel
  29.  
  30.             function applyFilter(searchText) {
  31.                 pyNotes.listNotes(searchText);
  32.             }
  33.  
  34.             function fill(data) {
  35.                 notesModel.clear();
  36.  
  37.                 // Python returns a list of dicts - we can simply append
  38.                 // each dict in the list to the list model
  39.                 /*for (var i=0; i<data.length; i++) {
  40.                     notesModel.append(data[i]);
  41.                     console.debug(data[i].title);
  42.                 }*/
  43.  
  44.                 console.debug('notesModel filled');
  45.             }
  46.  
  47.  
  48.         }
  49.  
  50.         Connections {
  51.             target: pyNotes
  52.             onMessage: {
  53.                 notesModel.fill(message)
  54.             }
  55.             onRequireRefresh: {
  56.                 notesModel.applyFilter()
  57.             }
  58.  
  59.         }
  60.  
  61.         // Place our content in a Column.  The PageHeader is always placed at the top
  62.         // of the page, followed by our content.
  63.  
  64.         Component {
  65.             id:notesViewDelegate
  66.             BackgroundItem {
  67.                 /*                Column {
  68.                     x: Theme.paddingLarge
  69.                     height: Theme.itemSizeSmall
  70.                     width: notesView.width*/
  71.  
  72.                 Label {
  73.                     text: model.title
  74.                     truncationMode: TruncationMode.Fade
  75.                     //font.family: Theme.fontFamily
  76.                     //font.pixelSize: Theme.fontSizeMedium
  77.                     //font.weight: Font.Bold
  78.                     //color:Theme.primaryColor
  79.                     x: Theme.paddingLarge
  80.                     //anchors.left: parent.left
  81.                     //anchors.right: parent.right
  82.                     //elide: Text.ElideRight
  83.                     //maximumLineCount: 1
  84.                     anchors {
  85.                         left: parent.left
  86.                         rightMargin: Theme.paddingSmall
  87.                     }
  88.                 }
  89.  
  90.                 /*                    Label {
  91.                         text: model.timestamp;
  92.                         font.family: Theme.fontFamily
  93.                         font.pixelSize: Theme.fontSizeSmall
  94.                         color: Theme.secondaryColor
  95.                         anchors.left: parent.left;
  96.                         anchors.right: parent.right
  97.                         elide: Text.ElideRight
  98.                         //maximumLineCount: 1
  99.                     }
  100.  
  101.                 }*/
  102.                 onClicked: {
  103.  
  104.                     console.log("Clicked " + path)
  105.                     //var editingPage = Qt.createComponent(Qt.resolvedUrl("EditPage.qml"));
  106.                     //pageStack.push(editingPage, {path: path});
  107.                 }
  108.             }
  109.         }
  110.  
  111.         SilicaListView {
  112.             id: notesView
  113.             model: notesModel
  114.             anchors.fill: parent
  115.             header: PageHeader {
  116.                 title: "ownNotes"
  117.             }
  118.             delegate: notesViewDelegate
  119.  
  120.             ViewPlaceholder {
  121.                 enabled: notesModel.count == 0
  122.                 text: "No notes."
  123.             }
  124.  
  125.         }
  126.         Component.onCompleted: {
  127.             console.debug('onCompleted notesModel')
  128.             pyNotes.listNotes('');
  129.         }
  130.     }
  131.  
  132.  
  133. }
Advertisement
Add Comment
Please, Sign In to add comment