1 /****************************************************************************
3 ** Copyright (C) 2011 Takumi Asaki
4 ** All rights reserved.
5 ** Contact: Takumi Asaki (takumi.asaki@gmail.com)
7 ** This file is part of the fontmanager application.
9 ** You may use this file under the terms of the BSD license as follows:
11 ** "Redistribution and use in source and binary forms, with or without
12 ** modification, are permitted provided that the following conditions are
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
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
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."
37 ****************************************************************************/
39 // import QtQuick 1.0 // to target S60 5th Edition or Maemo 5
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
49 property string family
50 property string familyName
51 property string curSection
52 property string curSectionName
54 property variant editorController: null
56 property alias listView: preferFamilyListView
58 onEditorControllerChanged: {
59 if (editorController) {
60 Helper.setConnection(editorController)
64 function addHeader(section, sectionName)
66 Helper.setIndex(curSection, preferFamilyList.count)
68 curSectionName = sectionName
69 preferFamilyList.append({
70 "title": qsTr("Priority: %1").arg(sectionName),
76 Helper.setIndex(curSection, preferFamilyList.count)
79 function insertFamily(family, priority, systemFont)
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,
90 Helper.updateInsertIndexes(index)
93 function addFamily(section, family, priority, systemFont)
95 preferFamilyList.append({
96 "title": controller.localeFamily(family),
97 "subtitle": (systemFont ? qsTr("System Font") : qsTr("User Font")),
98 "systemFont": systemFont,
100 "priority": curSection,
103 Helper.setIndex(curSection, preferFamilyList.count)
106 function moveUpFamily()
108 var index = preferFamilyListView.currentIndex
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)
119 function moveDownFamily()
121 var index = preferFamilyListView.currentIndex
122 if (index >= preferFamilyList.count - 1)
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)
132 function removeFamily()
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
143 id: modelSyncConnections
146 preferFamilyList.clear()
149 onStartSection: addHeader(section, sectionName)
150 onAppendFamilyToList: addFamily(section, family, priority, systemFont)
159 // anchors.top: pageHeader.bottom
161 anchors.topMargin: UI.DEFAULT_MARGIN / 2
162 // anchors.bottomMargin: UI.DEFAULT_MARGIN / 2
166 id: preferFamilyListView
168 anchors.leftMargin: UI.DEFAULT_MARGIN
169 anchors.rightMargin: UI.DEFAULT_MARGIN
175 model: preferFamilyList
176 delegate: EditorListDelegate { }
178 highlight: Rectangle {
179 x: - UI.MARGIN_XLARGE / 2
180 width: preferFamilyListView.width + UI.MARGIN_XLARGE
181 height: UI.LIST_ITEM_HEIGHT_SMALL
184 border.color: "#bd543d"
188 highlightFollowsCurrentItem: true
189 highlightMoveDuration: 100
193 flickableItem: preferFamilyListView