OSDN Git Service

924c8ed851d36b456889f25dcc9783d673df2fdf
[fontmanager/fontmanager.git] / qml / fontmanager / FontsConfEditor.qml
1 /****************************************************************************
2 **
3 ** Copyright (C) 2011 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 com.nokia.extras 1.0
43 import 'UIConstants.js' as UI
44 import 'EditorHelper.js' as Helper
45
46 Item {
47     id: editorPage
48
49     property string family
50     property string familyName
51     property string curSection
52     property string curSectionName
53
54     property variant editorController: null
55
56     property alias listView: preferFamilyListView
57
58     onEditorControllerChanged: {
59         if (editorController) {
60             Helper.setConnection(editorController)
61         }
62     }
63
64     function addHeader(section, sectionName)
65     {
66         Helper.setIndex(curSection, preferFamilyList.count)
67         curSection = section
68         curSectionName = sectionName
69         preferFamilyList.append({
70                                     "title": qsTr("Priority: %1").arg(sectionName),
71                                     "subtitle": "",
72                                     "systemFont": false,
73                                     "header": true,
74                                     "priority": section
75                                 })
76         Helper.setIndex(curSection, preferFamilyList.count)
77     }
78
79     function insertFamily(family, priority, systemFont)
80     {
81         var index = Helper.index(priority)
82         preferFamilyList.insert(index, {
83                                     "title": controller.localeFamily(family),
84                                     "subtitle": (systemFont ? qsTr("System Font") : qsTr("User Font")),
85                                     "systemFont": systemFont,
86                                     "header": false,
87                                     "priority": priority,
88                                     "family": family,
89                                 })
90         Helper.updateInsertIndexes(index)
91     }
92
93     function addFamily(section, family, priority, systemFont)
94     {
95         preferFamilyList.append({
96                                     "title": controller.localeFamily(family),
97                                     "subtitle": (systemFont ? qsTr("System Font") : qsTr("User Font")),
98                                     "systemFont": systemFont,
99                                     "header": false,
100                                     "priority": curSection,
101                                     "family": family,
102                                 })
103         Helper.setIndex(curSection, preferFamilyList.count)
104     }
105
106     function moveUpFamily()
107     {
108         var index = preferFamilyListView.currentIndex
109         if (index < 1)
110             return;
111         var prevItem = preferFamilyList.get(index - 1)
112         if (!prevItem.header) {
113             var item = preferFamilyList.get(index)
114             editorController.moveFamilyUp(item.family, item.priority)
115             preferFamilyList.move(index, index - 1, 1)
116         }
117     }
118
119     function moveDownFamily()
120     {
121         var index = preferFamilyListView.currentIndex
122         if (index >= preferFamilyList.count - 1)
123             return;
124         var nextItem = preferFamilyList.get(index + 1)
125         if (!nextItem.header) {
126             var item = preferFamilyList.get(index)
127             editorController.moveFamilyDown(item.family, item.priority)
128             preferFamilyList.move(index, index + 1, 1)
129         }
130     }
131
132     function removeFamily()
133     {
134         var index = preferFamilyListView.currentIndex
135         var item = preferFamilyList.get(index)
136         editorController.removeFamily(item.family, item.priority)
137         preferFamilyList.remove(index)
138         Helper.updateRemoveIndexes(index)
139         preferFamilyListView.currentIndex = -1
140     }
141
142     Component {
143         id: modelSyncConnections
144         Connections {
145             onClearFamilyList: {
146                 preferFamilyList.clear()
147                 Helper.init()
148             }
149             onStartSection: addHeader(section, sectionName)
150             onAppendFamilyToList: addFamily(section, family, priority, systemFont)
151         }
152     }
153
154     ListModel {
155         id: preferFamilyList
156     }
157
158     Item {
159 //        anchors.top: pageHeader.bottom
160         anchors.fill: parent
161         anchors.topMargin: UI.DEFAULT_MARGIN / 2
162 //        anchors.bottomMargin: UI.DEFAULT_MARGIN / 2
163         clip: true
164
165         ListView {
166             id: preferFamilyListView
167             anchors.fill: parent
168             anchors.leftMargin: UI.DEFAULT_MARGIN
169             anchors.rightMargin: UI.DEFAULT_MARGIN
170
171             cacheBuffer: 100
172
173             currentIndex: -1
174
175             model: preferFamilyList
176             delegate: EditorListDelegate { }
177
178             highlight: Rectangle {
179                 x: - UI.MARGIN_XLARGE / 2
180                 width: preferFamilyListView.width + UI.MARGIN_XLARGE
181                 height: UI.LIST_ITEM_HEIGHT_SMALL
182                 color: "transparent"
183                 border.width: 5
184                 border.color: "#bd543d"
185                 radius: 5
186 //                z: 1
187             }
188             highlightFollowsCurrentItem: true
189             highlightMoveDuration: 100
190         }
191
192         ScrollDecorator {
193             flickableItem: preferFamilyListView
194         }
195
196     }
197
198 }
199