Advertisement
Guest User

Untitled

a guest
Oct 14th, 2015
420
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
QML 8.57 KB | None | 0 0
  1. import QtQuick 2.2
  2. import Sailfish.Silica 1.0
  3.  
  4. Page {
  5.     property int categoryID: 0
  6.     property string categoryName: qsTr("Main")
  7.     property string categoryDescription: ""
  8.     property bool filterNote:  true
  9.     property bool filterCategory:  true
  10.     id: page
  11.     function update(){
  12.         itemsModel.clear()
  13.         if (page.categoryID > 0) {
  14.             var res = dbworks.getCategory(categoryID)
  15.             page.categoryName = res[0].name
  16.             page.categoryDescription = res[0].description
  17.         } else {
  18.             page.categoryName = qsTr("Main")
  19.             page.categoryDescription = ""
  20.         }
  21.  
  22.     if(page.filterCategory===true){
  23.         //Загрузка категорий
  24.         var res = dbworks.getCategories(page.categoryID)
  25.         if (res !== false) {
  26.             for (var i = 0; i < res.length; i++) {
  27.                 itemsModel.append({
  28.                                       id: res[i].id,
  29.                                       name: res[i].name,
  30.                                       info: res[i].description,
  31.                                       section: qsTr("Categories"),
  32.                                       type: "category",
  33.                                       childCount: res[i].childCount
  34.                                   })
  35.             }
  36.         }
  37.     }
  38.         if(page.filterNote===true){
  39.         //Загрузка заметок
  40.         res = dbworks.getNotes(page.categoryID)
  41.         if (res !== false) {
  42.             for (i = 0; i < res.length; i++) {
  43.                 itemsModel.append({
  44.                                       id: res[i].id,
  45.                                       name: res[i].name,
  46.                                       info: res[i].text,
  47.                                       section: qsTr("Notes"),
  48.                                       type: "note",
  49.                                       childCount: 0
  50.                                   })
  51.             }
  52.         }
  53.         }
  54.  
  55.     }
  56.  
  57.     //При переходе на страницу обновляется содержимое
  58.     onVisibleChanged: {
  59.         if (page.visible === true) {
  60.             page.update()
  61.  
  62.         }
  63.     }
  64.  
  65.     ListModel {
  66.         id: itemsModel
  67.     }
  68.  
  69.     SilicaListView {
  70.       /*  ViewPlaceholder {
  71.             enabled: listView.count == 0
  72.             text: qsTr("No Content")
  73.             hintText: qsTr("Pull down to add content")
  74.         }*/
  75.    
  76.        footer:Column{
  77.             Label{
  78.                 text:"filter:"
  79.             }
  80.         height:200
  81.  
  82.             Row{
  83.  
  84.                // height:children.height
  85.                 Switch {
  86.                     checked:true
  87.                     icon.source: "../img/dir.png"
  88.                     onCheckedChanged: {
  89.                         page.filterCategory=this.checked
  90.  
  91.                         page.update()
  92.  
  93.  
  94.                     }
  95.                 }
  96.                 Switch {
  97.                     checked:true
  98.                     icon.source: "../img/note.png"
  99.                     onCheckedChanged: {
  100.                         page.filterNote=this.checked
  101.  
  102.                         page.update()
  103.  
  104.  
  105.  
  106.                     }
  107.  
  108.                 }
  109.                 Switch {
  110.                     enabled: false
  111.                     icon.source: "../img/list.png"
  112.  
  113.  
  114.                 }
  115.             }
  116.         }
  117.  
  118.         header: Column {
  119.             width: parent.width
  120.             PageHeader {
  121.                 title: page.categoryName
  122.             }
  123.             Label {
  124.  
  125.                 text: page.categoryDescription
  126.                 font.pixelSize: Theme.fontSizeMedium
  127.                 truncationMode: TruncationMode.Fade
  128.                 maximumLineCount: 2
  129.                 wrapMode: Text.WordWrap
  130.                 color: Theme.primaryColor
  131.                 x: Theme.horizontalPageMargin
  132.                 width: parent.width - 2 * Theme.horizontalPageMargin
  133.             }
  134.         }
  135.  
  136.  
  137.         id: listView
  138.         model: itemsModel
  139.  
  140.  
  141.        anchors.fill: parent
  142.         section {
  143.             property: 'section'
  144.             delegate: SectionHeader {
  145.                 text: section
  146.             }
  147.         }
  148.  
  149.         delegate: ListItem {
  150.             id: listItem
  151.             width: listView.width
  152.             menu: contextMenuComponent
  153.             function remove() {
  154.                 remorseAction(qsTr("Deleting"), function () {
  155.                     console.log(firstName.id)
  156.                     if (firstName.type === "note") {
  157.                         dbworks.deleteNote(firstName.id)
  158.                     } else if (firstName.type === "category") {
  159.                         dbworks.deleteCategory(firstName.id)
  160.                     }
  161.                     itemsModel.remove(index)
  162.                 })
  163.             }
  164.             ListView.onRemove: animateRemoval()
  165.             Component {
  166.  
  167.                 id: contextMenuComponent
  168.                 ContextMenu {
  169.                     MenuItem {
  170.                         text: qsTr("Edit")
  171.                         onClicked: {
  172.                             if (firstName.type === "category") {
  173.                                 pageStack.push(Qt.resolvedUrl(
  174.                                                    "EditCategory.qml"), {
  175.                                                    categoryID: firstName.id
  176.                                                })
  177.                             } else if (firstName.type === "note") {
  178.                                 pageStack.push(Qt.resolvedUrl("EditNote.qml"), {
  179.                                                    noteID: firstName.id
  180.                                                })
  181.                             }
  182.                         }
  183.                     }
  184.                     MenuItem {
  185.                         visible: firstName.childCount === 0
  186.                         text: qsTr("Delete")
  187.                         onClicked: remove()
  188.                     }
  189.                 }
  190.             }
  191.  
  192.             Label {
  193.                 truncationMode: TruncationMode.Fade
  194.                 id: firstName
  195.                 property int id: model.id
  196.                 property string name: model.name
  197.                 property string type: model.type
  198.                 property int childCount: model.childCount
  199.                 color: highlighted ? Theme.highlightColor : Theme.primaryColor
  200.                 x: Theme.horizontalPageMargin
  201.                 width: parent.width - 2 * Theme.horizontalPageMargin
  202.  
  203.                 anchors.verticalCenter: parent.verticalCenter
  204.  
  205.                 Row {
  206.                     id: row
  207.                     anchors.verticalCenter: parent.verticalCenter
  208.                     spacing: 20
  209.                     Image {
  210.                         id: img
  211.                         anchors.verticalCenter: parent.verticalCenter
  212.                         width: 32
  213.                         height: 32
  214.                         source: (model.type === "note") ? "../img/note.png" : "../img/dir.png"
  215.                     }
  216.  
  217.                     Column {
  218.  
  219.                         anchors.verticalCenter: parent.verticalCenter
  220.  
  221.                         Label {
  222.                             font.pixelSize: Theme.fontSizeMedium
  223.                             maximumLineCount: 1
  224.                             text: model.name
  225.                             truncationMode: TruncationMode.Fade
  226.                             width: firstName.width - img.width - row.spacing
  227.                         }
  228.                         Label {
  229.                             color: Theme.secondaryColor
  230.                             font.pixelSize: Theme.fontSizeExtraSmall
  231.                             font.italic: true
  232.                             maximumLineCount: 1
  233.                             text: model.info
  234.                             truncationMode: TruncationMode.Fade
  235.                             x: 20
  236.                             width: firstName.width - img.width - row.spacing - x
  237.                         }
  238.                     }
  239.                 }
  240.             }
  241.  
  242.             onClicked: {
  243.                 if (firstName.type === "category") {
  244.                     pageStack.push(Qt.resolvedUrl("ViewCategory.qml"), {
  245.                                        categoryID: firstName.id,
  246.                                        categoryName: firstName.name
  247.                                    })
  248.                 } else if (firstName.type === "note") {
  249.                     pageStack.push(Qt.resolvedUrl("ViewNote.qml"), {
  250.                                        noteID: firstName.id
  251.                                    })
  252.                 }
  253.             }
  254.         }
  255.         VerticalScrollDecorator {}
  256.     }
  257. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement