OSDN Git Service

2366732da661a8ada176c05456cefdf45cf6e9be
[fontmanager/fontmanager.git] / qml / fontmanager / FontInstallPage.qml
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Takumi Asaki
4 ** All rights reserved.
5 ** Contact: Takumi Asaki (takumi.asaki@gmail.com)
6 **
7 ** This file is part of the fontmanager application.
8 **
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 ****************************************************************************/
38
39 // import QtQuick 1.0 // to target S60 5th Edition or Maemo 5
40 import QtQuick 1.1
41 import com.nokia.meego 1.0
42 import 'UIConstants.js' as UI
43
44 Page {
45     id: fontInstallPage
46     tools: backToolBar
47
48     property variant fontInfo
49
50     signal saveProperties
51
52     function installFont(checked)
53     {
54         if (!checked && controller.fontExists(fontInfo))
55             openOverwriteFontDialog()
56         else
57             controller.installFont(fontInfo);
58     }
59
60     Component.onDestruction: {
61         if (fontInfo) {
62             fontInfo.destroy()
63         }
64     }
65
66     PageHeader {
67         id: pageHeader
68         anchors.top: parent.top
69         anchors.left: parent.left
70         anchors.right: parent.right
71         text: qsTr("Install Font")
72     }
73
74     Item {
75         id: contents
76         anchors.top: pageHeader.bottom
77         anchors.bottom: parent.bottom
78         anchors.left: parent.left
79         anchors.right: parent.right
80
81         Flickable {
82             id: view
83             anchors.top: parent.top
84             anchors.left: parent.left
85             anchors.right: parent.right
86             anchors.bottom: bottomField.top
87             anchors.topMargin: UI.DEFAULT_MARGIN / 2
88             anchors.bottomMargin: UI.DEFAULT_MARGIN / 2
89             anchors.leftMargin: UI.DEFAULT_MARGIN / 2
90             anchors.rightMargin: UI.DEFAULT_MARGIN / 2
91             clip: true
92
93
94             contentHeight: contentColumn.height
95
96             Column {
97                 id: contentColumn
98                 width: parent.width
99                 spacing: UI.DEFAULT_MARGIN
100
101                 Repeater {
102                     width: parent.width
103                     model: fontInfo.families
104
105                     delegate: Item {
106                         width: parent.width
107                         height: itemColumn.height + UI.DEFAULT_MARGIN * 2
108                         Rectangle {
109                             width: parent.width - 1
110                             height: parent.height - 1
111                             border.width: 1
112                             color: "transparent"
113                             Column {
114                                 id: itemColumn
115                                 anchors.top: parent.top
116                                 anchors.left: parent.left
117                                 anchors.right: parent.right
118                                 //                        width: parent.width
119                                 anchors.margins: UI.DEFAULT_MARGIN
120                                 spacing: UI.DEFAULT_MARGIN
121                                 Label {
122                                     width: parent.width
123                                     text: qsTr("<b>Font Family</b>: %1").arg(modelData)
124                                 }
125                                 Label {
126                                     width: parent.width
127                                     text: qsTr("<b>Example</b>: ")
128                                 }
129                                 Label {
130                                     width: parent.width - UI.DEFAULT_MARGIN * 2
131                                     x: UI.DEFAULT_MARGIN
132                                     text: qsTr("The quick brown fox jumps over the lazy dog")
133                                     font.family: modelData
134                                 }
135                                 FontsConfProperties {
136                                     id: fontProp
137                                     width: parent.width
138                                     fontconf: fontInfo.fontProperty(modelData)
139                                     Connections {
140                                         target: fontInstallPage
141                                         onSaveProperties: {
142                                             fontProp.save()
143                                         }
144                                     }
145                                 }
146                             }
147                         }
148                     }
149                 }
150
151             }
152
153         }
154
155         ScrollDecorator {
156             flickableItem: view
157         }
158
159         Item {
160             id: bottomField
161             anchors.bottom: parent.bottom
162             anchors.left: parent.left
163             anchors.right: parent.right
164             height: installButton.height + UI.DEFAULT_MARGIN * 2
165
166             Rectangle {
167                 id: bgrect
168                 anchors.fill: parent
169                 gradient: Gradient {
170                     GradientStop { position: 0.0; color: Qt.lighter("#76221d") }
171                     GradientStop { position: 1.0; color: Qt.lighter("#bd543d") }
172                 }
173             }
174
175             Button {
176                 id: installButton
177                 anchors.centerIn: parent
178                 text: qsTr("Install")
179                 onClicked: {
180                     saveProperties()
181                     if (!controller.fontDirExists)
182                         openCreateFontDirDialog()
183                     else
184                         installFont(false)
185                 }
186             }
187         }
188     }
189
190
191     function openCreateFontDirDialog()
192     {
193         queryDialog.titleText = qsTr("Create it?")
194         queryDialog.message = qsTr("Local fonts directory '%1' does not exists!  Create it now?").arg(controller.fontDir)
195         queryDialog.acceptButtonText = qsTr("OK")
196         queryDialog.rejectButtonText = qsTr("Cancel")
197         queryDialog.accepted.connect(createFontDir)
198         queryDialog.open()
199     }
200
201     function createFontDir()
202     {
203         queryDialog.accepted.disconnect(createFontDir)
204         controller.createFontDir()
205         installFont(false)
206     }
207
208     function openOverwriteFontDialog()
209     {
210         queryDialog.titleText = qsTr("Overwrite it?")
211         queryDialog.message = qsTr("Local font '%1' already exists!  Overwrite it?").arg(fontInfo.fileName)
212         queryDialog.acceptButtonText = qsTr("OK")
213         queryDialog.rejectButtonText = qsTr("Cancel")
214         queryDialog.accepted.connect(overwriteFont)
215         queryDialog.open()
216     }
217
218     function overwriteFont()
219     {
220         queryDialog.accepted.disconnect(overwriteFont)
221         installFont(true)
222     }
223
224     ToolBarLayout {
225         id: backToolBar
226         ToolIcon {
227             platformIconId: "toolbar-back"
228             onClicked: pageStack.pop()
229         }
230     }
231
232 }