1b13b20d2d25d7167fb953ce0f2bef64d061da5e
[profile/ivi/qtdeclarative.git] / examples / tutorials / gettingStartedQml / core / FileMenu.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 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
77         //the column of buttons
78         width: fileMenu.width * partition; height: fileMenu.height
79
80         Column {
81             anchors.centerIn: parent
82             spacing: parent.height/32
83             Button {
84                 id: saveButton
85                 label: "Save"
86                 borderColor: buttonBorderColor
87                 buttonColor: buttonFillColor
88                 width: actionContainer.width/ 1.3
89                 height:actionContainer.height / 8
90                 labelSize:24
91                 onButtonClick: {
92                     directory.fileContent = textArea.textContent
93                     directory.filename = textInput.text
94                     directory.saveFile()
95                 }
96                 gradient: Gradient {
97                     GradientStop { position: 0.0; color: Qt.lighter(buttonFillColor,1.25) }
98                     GradientStop { position: 0.67; color: Qt.darker(buttonFillColor,1.3) }
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     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
172                 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                     radius: 10
188                     anchors { centerIn:parent; leftMargin: 15; rightMargin: 15; topMargin: 15 }
189                     height: parent.height-15
190                     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 }