Remove "All rights reserved" line from license headers.
[profile/ivi/qtdeclarative.git] / examples / tutorials / gettingStartedQml / parts / part4 / MenuBar.qml
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
5 **
6 ** This file is part of the QtDeclarative module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:BSD$
9 ** You may use this file under the terms of the BSD license as follows:
10 **
11 ** "Redistribution and use in source and binary forms, with or without
12 ** modification, are permitted provided that the following conditions are
13 ** met:
14 **   * Redistributions of source code must retain the above copyright
15 **     notice, this list of conditions and the following disclaimer.
16 **   * Redistributions in binary form must reproduce the above copyright
17 **     notice, this list of conditions and the following disclaimer in
18 **     the documentation and/or other materials provided with the
19 **     distribution.
20 **   * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
21 **     the names of its contributors may be used to endorse or promote
22 **     products derived from this software without specific prior written
23 **     permission.
24 **
25 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26 ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27 ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28 ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29 ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30 ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31 ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35 ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
36 **
37 ** $QT_END_LICENSE$
38 **
39 ****************************************************************************/
40
41 import QtQuick 2.0
42
43 Rectangle {
44     id: menuBar
45     width: 1000
46     height:300
47
48     property color fileColor: "plum"
49     property color editColor: "powderblue"
50
51     //container for the header and the buttons
52     Rectangle{
53         
54         id: labelList
55         height:parent.height/10
56         width: parent.width
57         color: "beige"
58         gradient: Gradient {
59                         GradientStop { position: 0.0; color: "#8C8F8C" }
60                         GradientStop { position: 0.17; color: "#6A6D6A" }
61                         GradientStop { position: 0.98;color: "#3F3F3F" }
62                         GradientStop { position: 1.0; color: "#0e1B20" }
63                 }
64
65         //default z is 0, items with higher z values are shown on top of items with lower z values
66         z: 1
67
68         //row displays its children in a vertical row
69         Row{
70             anchors.centerIn: parent
71             spacing:40
72             Button{
73                 height: 20
74                 width: 50
75                 label: "File"
76                 id: fileButton
77                 buttonColor : menuListView.currentIndex == 0? fileColor : Qt.darker(fileColor, 1.5)
78                 scale: menuListView.currentIndex == 0? 1.25: 1
79                 radius: 1
80
81                 //on a button click, change the list's currently selected item to FileMenu
82                 onButtonClick: {
83                     menuListView.currentIndex = 0
84                 }
85             }
86             Button{
87                 height: 20
88                 width: 50
89                 id: editButton
90                 buttonColor : menuListView.currentIndex == 1?  editColor : Qt.darker(editColor, 1.5)
91                 scale: menuListView.currentIndex == 1? 1.25: 1    
92                 label: "Edit"
93                 radius: 1
94
95                 //on a button click, change the list's currently selected item to EditMenu
96                 onButtonClick: {
97                     menuListView.currentIndex = 1    
98                 }
99
100                 
101             }
102
103
104         }
105     }
106
107     //a list of visual items already have delegates handling their display
108     VisualItemModel{
109         id: menuListModel
110
111         FileMenu{
112             width: menuListView.width
113             height: menuBar.height
114             color: fileColor
115         }
116         EditMenu{
117             color: editColor
118             width:  menuListView.width
119             height: menuBar.height
120             
121         }
122     }
123
124     //list view will display a model according to a delegate
125     ListView{
126         id: menuListView
127         anchors.fill:parent
128         anchors.bottom: parent.bottom
129         width:parent.width
130         height: parent.height
131
132         //the model contains the data
133         model: menuListModel
134
135         //control the movement of the menu switching
136         snapMode: ListView.SnapOneItem
137         orientation: ListView.Horizontal
138         boundsBehavior: Flickable.StopAtBounds 
139         flickDeceleration: 5000
140         highlightFollowsCurrentItem: true
141         highlightMoveDuration:240
142         highlightRangeMode: ListView.StrictlyEnforceRange
143     }
144
145
146 }