Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import QtQuick 2.2
- import Sailfish.Silica 1.0
- Page {
- property int categoryID: 0
- property string categoryName: qsTr("Main")
- property string categoryDescription: ""
- property bool filterNote: true
- property bool filterCategory: true
- id: page
- function update(){
- itemsModel.clear()
- if (page.categoryID > 0) {
- var res = dbworks.getCategory(categoryID)
- page.categoryName = res[0].name
- page.categoryDescription = res[0].description
- } else {
- page.categoryName = qsTr("Main")
- page.categoryDescription = ""
- }
- if(page.filterCategory===true){
- //Загрузка категорий
- var res = dbworks.getCategories(page.categoryID)
- if (res !== false) {
- for (var i = 0; i < res.length; i++) {
- itemsModel.append({
- id: res[i].id,
- name: res[i].name,
- info: res[i].description,
- section: qsTr("Categories"),
- type: "category",
- childCount: res[i].childCount
- })
- }
- }
- }
- if(page.filterNote===true){
- //Загрузка заметок
- res = dbworks.getNotes(page.categoryID)
- if (res !== false) {
- for (i = 0; i < res.length; i++) {
- itemsModel.append({
- id: res[i].id,
- name: res[i].name,
- info: res[i].text,
- section: qsTr("Notes"),
- type: "note",
- childCount: 0
- })
- }
- }
- }
- }
- //При переходе на страницу обновляется содержимое
- onVisibleChanged: {
- if (page.visible === true) {
- page.update()
- }
- }
- ListModel {
- id: itemsModel
- }
- SilicaListView {
- /* ViewPlaceholder {
- enabled: listView.count == 0
- text: qsTr("No Content")
- hintText: qsTr("Pull down to add content")
- }*/
- footer:Column{
- Label{
- text:"filter:"
- }
- height:200
- Row{
- // height:children.height
- Switch {
- checked:true
- icon.source: "../img/dir.png"
- onCheckedChanged: {
- page.filterCategory=this.checked
- page.update()
- }
- }
- Switch {
- checked:true
- icon.source: "../img/note.png"
- onCheckedChanged: {
- page.filterNote=this.checked
- page.update()
- }
- }
- Switch {
- enabled: false
- icon.source: "../img/list.png"
- }
- }
- }
- header: Column {
- width: parent.width
- PageHeader {
- title: page.categoryName
- }
- Label {
- text: page.categoryDescription
- font.pixelSize: Theme.fontSizeMedium
- truncationMode: TruncationMode.Fade
- maximumLineCount: 2
- wrapMode: Text.WordWrap
- color: Theme.primaryColor
- x: Theme.horizontalPageMargin
- width: parent.width - 2 * Theme.horizontalPageMargin
- }
- }
- id: listView
- model: itemsModel
- anchors.fill: parent
- section {
- property: 'section'
- delegate: SectionHeader {
- text: section
- }
- }
- delegate: ListItem {
- id: listItem
- width: listView.width
- menu: contextMenuComponent
- function remove() {
- remorseAction(qsTr("Deleting"), function () {
- console.log(firstName.id)
- if (firstName.type === "note") {
- dbworks.deleteNote(firstName.id)
- } else if (firstName.type === "category") {
- dbworks.deleteCategory(firstName.id)
- }
- itemsModel.remove(index)
- })
- }
- ListView.onRemove: animateRemoval()
- Component {
- id: contextMenuComponent
- ContextMenu {
- MenuItem {
- text: qsTr("Edit")
- onClicked: {
- if (firstName.type === "category") {
- pageStack.push(Qt.resolvedUrl(
- "EditCategory.qml"), {
- categoryID: firstName.id
- })
- } else if (firstName.type === "note") {
- pageStack.push(Qt.resolvedUrl("EditNote.qml"), {
- noteID: firstName.id
- })
- }
- }
- }
- MenuItem {
- visible: firstName.childCount === 0
- text: qsTr("Delete")
- onClicked: remove()
- }
- }
- }
- Label {
- truncationMode: TruncationMode.Fade
- id: firstName
- property int id: model.id
- property string name: model.name
- property string type: model.type
- property int childCount: model.childCount
- color: highlighted ? Theme.highlightColor : Theme.primaryColor
- x: Theme.horizontalPageMargin
- width: parent.width - 2 * Theme.horizontalPageMargin
- anchors.verticalCenter: parent.verticalCenter
- Row {
- id: row
- anchors.verticalCenter: parent.verticalCenter
- spacing: 20
- Image {
- id: img
- anchors.verticalCenter: parent.verticalCenter
- width: 32
- height: 32
- source: (model.type === "note") ? "../img/note.png" : "../img/dir.png"
- }
- Column {
- anchors.verticalCenter: parent.verticalCenter
- Label {
- font.pixelSize: Theme.fontSizeMedium
- maximumLineCount: 1
- text: model.name
- truncationMode: TruncationMode.Fade
- width: firstName.width - img.width - row.spacing
- }
- Label {
- color: Theme.secondaryColor
- font.pixelSize: Theme.fontSizeExtraSmall
- font.italic: true
- maximumLineCount: 1
- text: model.info
- truncationMode: TruncationMode.Fade
- x: 20
- width: firstName.width - img.width - row.spacing - x
- }
- }
- }
- }
- onClicked: {
- if (firstName.type === "category") {
- pageStack.push(Qt.resolvedUrl("ViewCategory.qml"), {
- categoryID: firstName.id,
- categoryName: firstName.name
- })
- } else if (firstName.type === "note") {
- pageStack.push(Qt.resolvedUrl("ViewNote.qml"), {
- noteID: firstName.id
- })
- }
- }
- }
- VerticalScrollDecorator {}
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement