summaryrefslogtreecommitdiff
path: root/notificationswatchlet/metawatch-digital.qml
blob: fcd1081c48a8842857092969bd92225e565533ea (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import Qt 4.7
import com.javispedro.sowatch.metawatch 1.0

MWPage {
	MWTitle {
		id: title
		anchors.top: parent.top
		anchors.left: parent.left
		anchors.right: parent.right
		text: qsTr("Notifications")
		icon.source: "icon.png"
	}

	MWListView {
		id: notifs
		anchors.top: title.bottom
		anchors.left: parent.left
		anchors.right: parent.right
		anchors.bottom: parent.bottom
		clip: true
		model: notifications

		delegate: Rectangle {
			id: notifDelegate
			property bool selected: ListView.isCurrentItem
			width: parent.width
			height: childrenRect.height
			color: ListView.isCurrentItem ? "black" : "white"
			Column {
				width: parent.width
				MWLabel {
					width: parent.width
					text: title
					wrapMode: Text.WrapAtWordBoundaryOrAnywhere
					color: notifDelegate.selected ? "white" : "black"
					font.pointSize: 12
				}
				MWLabel {
					width: parent.width
					text: body
					wrapMode: Text.WrapAtWordBoundaryOrAnywhere
					color: notifDelegate.selected ? "white" : "black"
				}
			}
		}
		visible: count > 0;
	}

	MWLabel {
		anchors.top: title.bottom
		anchors.horizontalCenter: parent.horizontalCenter
		text: qsTr("No notifications");
		visible: notifs.count == 0;
		wrapMode: Text.Wrap
	}

	Connections {
		target: watch
		onButtonPressed: {
			switch (button) {
			case 1:
				notifs.scrollUp();
				break;
			case 2:
				notifs.scrollDown();
				break;
			}
		}
	}

	Connections {
		target: notifications
		onRowsInserted: {
			if (!watch.active) {
				// Always position into the topmost notification if
				// user is not looking at this list
				notifs.scrollTop();
			}
		}
		onRowsRemoved: {
			if (!watch.active) {
				notifs.scrollTop();
			}
		}
	}
}