summaryrefslogtreecommitdiff
path: root/src/hmi/qml/Core/NavigationAppHMIMenu.qml
blob: 7fc37773c268a998711bda018764dfd2144fabce (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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
/**
* @licence app begin@
* SPDX-License-Identifier: MPL-2.0
*
*
* \file HMIMenu.qml
*
* \brief This file is part of the navigation hmi.
*
* \author Martin Schaller <martin.schaller@it-schaller.de>
*
* \version 
*
* This Source Code Form is subject to the terms of the
* Mozilla Public License (MPL), v. 2.0.
* If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/.
*
* For further information see http://www.genivi.org/.
*
* List of changes:
* <date>, <name>, <description of change>
*
* @licence end@
*/
import QtQuick 2.1 
import "genivi.js" as Genivi;
import "../../style-sheets/style-constants.js" as Constants;
import lbs.plugin.wheelarea 1.0

Rectangle {
	id: menu
    property alias loader: pageLoader
    property string pageBack
	property Item next
	property Item prev
    color: "transparent"
	focus: true
	anchors.fill: parent

	KeyNavigation.tab:next
	KeyNavigation.backtab:prev

	MouseArea {
		acceptedButtons: Qt.MiddleButton
		anchors.fill: parent
		onClicked: {
			var focus=find_focus(menu);
			focus.mclicked(focus);
		}

	}

	function focus_next()
	{
		var focus=find_focus(menu);
		if (focus.next != focus && focus.giveFocus)
			focus.giveFocus();
		do {
			focus=focus.next;
		} while (focus.disabled);
		if (focus.takeFocus) {
			focus.takeFocus(1);
		} else {
			focus.forceActiveFocus();
		}
	}

	function focus_prev()
	{
		var focus=find_focus(menu);
		if (focus.prev != focus && focus.giveFocus)
			focus.giveFocus();
		do {
			focus=focus.prev;
		} while (focus.disabled);
		if (focus.takeFocus) {
			focus.takeFocus(-1);
		} else {
			focus.forceActiveFocus();
		}
	}

	Keys.onBacktabPressed:{focus_prev();}

	Keys.onTabPressed:{focus_next();}

	WheelArea {
		property real deltasum;
		property real step: 120;
		property real dir: 1;
		anchors.fill: parent
		onWheel: {
			deltasum+=delta*dir;
			//console.log(delta);
			while (deltasum >= step) {
				focus_next();
				deltasum-=step;
			}
			while (deltasum <= -step) {
				focus_prev();
				deltasum+=step;
			}
		}
	}

	property real wspc: 60
	property real hspc: 60

	function w(cols) {
		return ((menu.width - (cols+1)*wspc) / cols);
	}

	function h(rows) {
		return ((menu.height - (rows+1)*hspc) / rows);
	}

	function find_focus(it) {
		//console.log("testing "+it);
		if (it.focus && it.next && it.prev)
			return it;
		for (var i = 0 ; i < it.children.length ; i++) {
			var ret=find_focus(it.children[i]);
			if (ret)
				return ret;
		}
		//console.log("no focus found");
		return null;
	}
			

	Loader {
		id: pageLoader
		states: State {
			name: "visible"
			PropertyChanges { target: pageLoader; opacity: 1 }
		}
		transitions: Transition {
        	        NumberAnimation { properties: "scale"; easing.type: "OutExpo"; duration: 200 }
        	        NumberAnimation { properties: "opacity"; easing.type: "InQuad"; duration: 200 }
        	}
	}

    function entryMenu(dltInterface,inmenu,outmenu)
    {
        Genivi.entrybackheapsize += 1;
        Genivi.hookMessage(dltInterface,"Menu level",Genivi.entrybackheapsize);
        Genivi.entryback[Genivi.entrybackheapsize] = outmenu.pagefile;
        outmenu.state = "hidden";
        container.load(inmenu);
    }

    function leaveMenu(dltInterface)
    {
        var outmenu=Genivi.entryback[Genivi.entrybackheapsize];
        Genivi.entrybackheapsize -= 1;
        Genivi.hookMessage(dltInterface,"Menu level",Genivi.entrybackheapsize);
        menu.state="hidden";
        container.load(outmenu);
    }

    function pageOpen(dltInterface,page) {
        menu.state="hidden";
        container.load(page);
	}

    states: State {
		name: "hidden"
        PropertyChanges { target: parent; opacity: 0 }
	}
	transitions: Transition {
                NumberAnimation { properties: "scale"; easing.type: "OutExpo"; duration: 200 }
                NumberAnimation { properties: "opacity"; easing.type: "InQuad"; duration: 200 }
        }

    Component.onCompleted: {
    }
}