e74ee12135e6fae1847934b11fbe733d4879d25b
[quandoparte] / application / resources / harmattan / qml / PageHeader.qml
1 import QtQuick 1.0
2 import com.nokia.meego 1.0
3 import com.nokia.extras 1.0
4 import "uiconstants.js" as UiConstants
5
6 Rectangle {
7     property alias text: label.text
8     property alias options: dialog.model
9     property alias selectedIndex: dialog.selectedIndex
10
11     id: root
12     width: parent.width
13     height: screen.currentOrientation === Screen.Landscape ?
14                 UiConstants.HeaderDefaultHeightLandscape :
15                 UiConstants.HeaderDefaultHeightPortrait
16     gradient: Gradient {
17         GradientStop { color: Qt.darker(UiConstants.AccentColor, mouse.pressed ? 1.5 : 1.25); position: 0.0 }
18         GradientStop { color: Qt.lighter(UiConstants.AccentColor, 1.5); position: 1.0 }
19     }
20
21     TumblerButtonStyle {
22         id: style
23         inverted: true
24     }
25     Label {
26         id: label
27         anchors {
28             left: parent.left;
29             leftMargin: UiConstants.DefaultMargin;
30             verticalCenter: parent.verticalCenter;
31         }
32         font {
33             pixelSize: UiConstants.HeaderFontPixelSize
34             bold: false
35         }
36         color: style.textColor
37     }
38     MouseArea {
39         id: mouse
40         anchors.fill: parent
41         onClicked: if (options.count > 1) dialog.open()
42     }
43
44     Image {
45         id: icon
46         anchors {
47             right: (label.text != "") ? parent.right : undefined;
48             rightMargin: UiConstants.DefaultMargin;
49             horizontalCenter: (label.text != "") ? undefined : parent.horizontalCenter;
50             verticalCenter: parent.verticalCenter;
51         }
52         visible: options.count > 1
53         height: label.height
54         source: "image://theme/meegotouch-combobox-indicator" +
55                 (style.inverted ? "-inverted" : "") +
56                 (root.enabled ? "" : "-disabled") +
57                 (mouse.pressed ? "-pressed" : "")
58     }
59     SelectionDialog {
60         id: dialog
61         titleText: qsTr("Show")
62     }
63     onSelectedIndexChanged: {
64         console.log("Selection changed to: " + selectedIndex)
65         if (options === undefined || options.count === 0 ||
66                 options.get(selectedIndex) === undefined) {
67             header.text = " "
68         } else {
69             header.text = options.get(selectedIndex).name
70             console.log("Selection text is: " + header.text)
71         }
72     }
73 }