Reworked ModeButton to use a Switch
[harmattan/cameraplus] / qml / IconButton.qml
1 // -*- qml -*-
2
3 /*!
4  * This file is part of CameraPlus.
5  *
6  * Copyright (C) 2012 Mohammed Sameer <msameer@foolab.org>
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
21  */
22
23 import QtQuick 1.1
24 import com.nokia.meego 1.1
25
26 Item {
27         id: root
28         width: Math.max(150, Math.max(label.width, icon.width) + 20);
29         height: 120
30
31         property string normalIcon: ""
32         property string checkedIcon: ""
33         property int value: -1
34         property int savedValue: -1
35
36         property alias iconSource: icon.source
37         property alias text: label.text
38
39         signal clicked
40
41         MouseArea {
42                 anchors.fill: parent
43                 onClicked: root.clicked();
44         }
45
46         Image {
47                 id: icon
48
49                 anchors.top: parent.top
50                 anchors.left: parent.left
51                 anchors.right: parent.right
52                 anchors.topMargin: 10
53                 anchors.leftMargin: 10
54                 anchors.rightMargin: 10
55                 source: root.value == root.savedValue ? checkedIcon : normalIcon
56                 fillMode: Image.PreserveAspectFit
57         }
58
59         Label {
60                 id: label
61                 anchors.left: parent.left
62                 anchors.right: parent.right
63                 anchors.bottom: parent.bottom
64                 anchors.top: icon.bottom
65                 anchors.bottomMargin: 10
66                 anchors.leftMargin: 10
67                 anchors.rightMargin: 10
68                 anchors.topMargin: 10
69                 horizontalAlignment: Text.AlignHCenter
70                 wrapMode: Text.NoWrap
71                 font.pixelSize: 22
72         }
73 }