summaryrefslogtreecommitdiff
path: root/qml/watch/WidgetView.qml
blob: 9e64fac350ff3ce3cb56ee7061aa0b539b970e4b (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
87
88
89
90
91
92
93
import QtQuick 2.0
import com.javispedro.salmeta 1.0

Rectangle {
	id: view
	width: 96*4
	height: 96

	color: "white";

	property alias model: rep.model
	property bool editMode: false

	signal emptyWidgetClicked(int page, int pos)

	Grid {
		id: editGrid
		anchors.fill: parent
		columns: 2 * 4
		rows: 2
		visible: editMode

		function _calculatePagePosFromIndex(index) {
			switch (index) {
			case 0:  return [0, 0];
			case 1:  return [0, 1];
			case 8:  return [0, 2];
			case 9:  return [0, 3];
			case 2:  return [1, 0];
			case 3:  return [1, 1];
			case 10: return [1, 2];
			case 11: return [1, 3];
			case 4:  return [2, 0];
			case 5:  return [2, 1];
			case 12: return [2, 2];
			case 13: return [2, 3];
			case 6:  return [3, 0];
			case 7:  return [3, 1];
			case 14: return [3, 2];
			case 15: return [3, 3];
			}
		}

		Repeater {
			model: 16
			Rectangle {
				width: 96 / 2
				height: 96 / 2
				Image {
					anchors.centerIn: parent
					source: "add_widget.png"
				}
				MouseArea {
					anchors.fill: parent
					onClicked: {
						var pagePos = editGrid._calculatePagePosFromIndex(index);
						view.emptyWidgetClicked(pagePos[0], pagePos[1]);
					}
				}
			}
		}
	}

	Repeater {
		id: rep

		Item {
			id: widgetItem

			x: (model.page * 96) + (model.position === WidgetInfo.PosNE || model.position === WidgetInfo.PosSE ? 96 / 2 : 0)
			y: (model.position === WidgetInfo.PosSE || model.position === WidgetInfo.PosSW ? 96 / 2 : 0)
			width: model.size === WidgetInfo.Size2QHorizontal | model.size === WidgetInfo.Size4Q ? 96 : 96 / 2
			height: model.size === WidgetInfo.Size2QVertical | model.size === WidgetInfo.Size4Q ? 96 : 96 / 2

			visible: widgetLoader.status === Loader.Ready;

			Loader {
				id: widgetLoader
				anchors.fill: parent
				source: url
			}

			MouseArea {
				anchors.fill: parent
				enabled: editMode

				onClicked: {
					curWidgets.removeWidget(index);
				}
			}
		}
	}
}