Remove "All rights reserved" line from license headers.
[profile/ivi/qtdeclarative.git] / examples / tutorials / gettingStartedQml / parts / part5 / core / FileMenu.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 import "../filedialog" 1.0
43
44 Rectangle {
45     id: fileMenu
46     height: 480; width:1000
47     property color buttonBorderColor: "#7F8487"
48     property color buttonFillColor: "#8FBDCACD"
49     property string fileContent:directory.fileContent
50     
51     //the menuName is accessible from outside this QML file
52     property string menuName: "File"
53         
54     //used to divide the screen into parts.
55     property real partition: 1/3
56
57     color: "#6C646A" 
58         gradient: Gradient{
59                         GradientStop { position: 0.0; color: "#6C646A" }
60                         GradientStop { position: 1.0; color: Qt.darker("#6A6D6A") }
61         }
62
63     Directory{
64         id:directory
65         filename: textInput.text
66         onDirectoryChanged:fileDialog.notifyRefresh()
67     }
68
69     Rectangle{
70         id:actionContainer
71
72         //make this rectangle invisible
73         color:"transparent"
74         anchors.left: parent.left
75
76         //the height is a good proportion that creates more space at the top of the column of buttons
77         width: fileMenu.width * partition; height: fileMenu.height
78         
79         Column{
80             anchors.centerIn: parent
81             spacing: parent.height/32
82             Button{
83                 id: saveButton
84                 label: "Save"                
85                 borderColor: buttonBorderColor
86                 buttonColor: buttonFillColor
87                 width: actionContainer.width/ 1.3
88                 height:actionContainer.height / 8
89                 labelSize:24
90                 onButtonClick:{
91                     directory.fileContent = textArea.textContent
92                     directory.filename = textInput.text
93                     directory.saveFile()
94                 }
95                 gradient: Gradient {
96                     GradientStop { position: 0.0; color: Qt.lighter(buttonFillColor,1.25) }
97                     GradientStop { position: 0.67; color: Qt.darker(buttonFillColor,1.3) }
98                 }
99     
100             }            
101             Button{
102                 id: loadButton
103                 width: actionContainer.width/ 1.3
104                 height:actionContainer.height/ 8
105                 buttonColor: buttonFillColor
106                 borderColor: buttonBorderColor
107                 label: "Load"
108                 labelSize:24
109                 onButtonClick:{
110                     directory.filename = textInput.text
111                     directory.loadFile()
112                     textArea.textContent = directory.fileContent
113                 }
114                 gradient: Gradient {
115                     GradientStop { position: 0.0; color: Qt.lighter(buttonFillColor,1.25) }
116                     GradientStop { position: 0.67; color: Qt.darker(buttonFillColor,1.3) }
117                 }
118             }
119             Button{
120                 id: newButton
121                 width: actionContainer.width/ 1.3
122                 height:actionContainer.height/ 8
123                 buttonColor: buttonFillColor
124                 borderColor: buttonBorderColor
125                 label: "New"
126                 labelSize:24
127                 onButtonClick:{
128                     textArea.textContent = ""
129                     textInput.text = ""
130                 }
131                 gradient: Gradient {
132                     GradientStop { position: 0.0; color: Qt.lighter(buttonFillColor,1.25) }
133                     GradientStop { position: 0.67; color: Qt.darker(buttonFillColor,1.3) }
134                 }
135
136             }
137             Rectangle{
138                 id: space    
139                 width: actionContainer.width/ 1.3
140                 height:actionContainer.height / 16
141                 color:"transparent"
142             }
143             Button{
144                 id: exitButton
145                 width: actionContainer.width/ 1.3
146                 height:actionContainer.height/ 8                
147                 label: "Exit"
148                 labelSize:24
149                 buttonColor: buttonFillColor
150                 borderColor: buttonBorderColor
151                 onButtonClick:Qt.quit()
152                 gradient: Gradient {
153                     GradientStop { position: 0.0; color: Qt.lighter(buttonFillColor,1.25) }
154                     GradientStop { position: 0.67; color: Qt.darker(buttonFillColor,1.3) }
155                 }
156             }
157         }
158     }
159
160     Rectangle{
161         id:dialogContainer
162
163         width: 2*fileMenu.width * partition; height: fileMenu.height
164         anchors.right:parent.right
165         color:"transparent"
166
167         Column {
168             anchors.centerIn: parent
169             spacing: parent.height /640
170             FileDialog{
171                 id:fileDialog
172                 height: 2*dialogContainer.height * partition; width: dialogContainer.width
173                 onSelectChanged: textInput.text = selectedFile
174             }
175     
176             Rectangle{
177                 id:lowerPartition
178                 height: dialogContainer.height * partition; width: dialogContainer.width
179                 color: "transparent"
180
181                 Rectangle{
182                     id: nameField
183                     gradient: Gradient{
184                         GradientStop { position: 0.0; color: "#806F6F6F" }
185                         GradientStop { position: 1.0; color: "#136F6F6F" }
186                     }
187
188                     radius: 10
189                     anchors {centerIn:parent; leftMargin: 15; rightMargin: 15; topMargin: 15}
190                     height: parent.height-15; width: parent.width -20
191                     border {color:"#4A4A4A"; width:1}
192
193                     TextInput{
194                         id: textInput
195                         z:2
196                         anchors {bottom: parent.bottom; topMargin: 10; horizontalCenter:parent.horizontalCenter}
197                         width: parent.width - 10
198                         height: parent.height -10
199                         font.pointSize: 40
200                         color:"lightsteelblue"
201                         focus:true
202                     }
203                     Text{
204                         id: textInstruction
205                         anchors.centerIn:parent
206                         text: "Select file name and press save or load"
207                         font {pointSize: 11; weight:Font.Light; italic: true}
208                         color: "lightblue"
209                         z:2
210                         opacity: (textInput.text == "") ? 1: 0
211                     }
212                     Text{
213                         id:fieldLabel
214                         anchors {top: parent.top; left: parent.left}
215                         text: "  file name: "
216                         font {pointSize: 11; weight: Font.Light; italic: true}
217                         color: "lightblue"
218                         z:2
219                     }
220                     MouseArea{
221                             anchors.centerIn:parent
222                             width: nameField.width; height: nameField.height
223                             onClicked:{
224                                 textInput.text = ""
225                                 textInput.focus = true
226                                 textInput.forceFocus()
227                             }
228                     }
229                 }
230             }
231         }
232     }
233 }