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