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