OSDN Git Service

6a997fb156ec56c41794501ab2a8d69fd6cc1a94
[fontmanager/fontmanager.git] / qml / fontmanager / ConfigValueComboBox.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.1
40 import com.nokia.meego 1.0
41 import 'UIConstants.js' as UI
42
43 Item {
44     id: comboBox
45     property int selectedIndex: 0
46     property string comboLabel: value
47
48 //    width: parent.width
49     height: Math.max(UI.LIST_ITEM_HEIGHT_SMALL, labelColumn.height)
50
51     function valueLabel(index)
52     {
53         return qsTr(configValueModel.get(index).name)
54     }
55
56     Column {
57         id: labelColumn
58         anchors.left: parent.left
59         width: parent.width - comboIcon.width
60         Label {
61             id: titlelabel
62             text: comboLabel
63             font.bold: true
64             font.family: UI.FONT_DEFAULT
65         }
66         Label {
67             id: valuelabel
68             text: valueLabel(selectedIndex)
69             font.bold: false
70             font.family: UI.FONT_LSMALL
71             color: UI.COLOR_SECONDARY_FOREGROUND
72         }
73     }
74     Image {
75         id: comboIcon
76         anchors.verticalCenter: parent.verticalCenter
77         anchors.right: parent.right
78         source: "image://theme/meegotouch-combobox-indicator" +
79                 (mouseArea.pressed ? "-pressed" : "")
80     }
81     MouseArea {
82         id: mouseArea
83         anchors.fill: parent
84         onClicked: selectionDialog.open()
85     }
86
87     ListModel {
88         id: configValueModel
89         ListElement { name: QT_TR_NOOP("Default") }
90         ListElement { name: QT_TR_NOOP("Yes") }
91         ListElement { name: QT_TR_NOOP("No") }
92     }
93
94     SelectionDialog {
95         id: selectionDialog
96         model: configValueModel
97         titleText: comboLabel
98         selectedIndex: comboBox.selectedIndex
99         onAccepted: {
100             comboBox.selectedIndex = selectedIndex
101         }
102     }
103 }