~unity-team/unity8/trunk

« back to all changes in this revision

Viewing changes to Hud/SearchBar.qml

  • Committer: Michał Sawicz
  • Date: 2013-06-05 22:03:08 UTC
  • Revision ID: michal.sawicz@canonical.com-20130605220308-yny8fv3futtr04fg
Inital unity8 commit.

Previous history can be found at https://code.launchpad.net/~unity-team/unity/phablet

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2012, 2013 Canonical, Ltd.
 
3
 *
 
4
 * This program is free software; you can redistribute it and/or modify
 
5
 * it under the terms of the GNU General Public License as published by
 
6
 * the Free Software Foundation; version 3.
 
7
 *
 
8
 * This program is distributed in the hope that it will be useful,
 
9
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
 * GNU General Public License for more details.
 
12
 *
 
13
 * You should have received a copy of the GNU General Public License
 
14
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
15
 */
 
16
 
 
17
import QtQuick 2.0
 
18
import Ubuntu.Components 0.1
 
19
 
 
20
Item {
 
21
    id: root
 
22
    property alias activityIndicatorVisible: activityIndicator.visible
 
23
    property alias text: searchBar.text
 
24
    property alias placeholderText: searchBar.placeholderText
 
25
    property alias searchEnabled: searchBar.enabled
 
26
    signal microphoneClicked
 
27
    signal textFocused
 
28
 
 
29
    readonly property real imageSize: units.gu(3)
 
30
 
 
31
    function unfocus()
 
32
    {
 
33
        searchBar.focus = false
 
34
    }
 
35
 
 
36
    ActivityIndicator {
 
37
        id: activityIndicator
 
38
        height: imageSize
 
39
        width: height
 
40
        x: magnifierImage.x
 
41
        y: magnifierImage.y
 
42
        running: visible
 
43
    }
 
44
 
 
45
    TextField {
 
46
        id: searchBar
 
47
        anchors.fill: parent
 
48
 
 
49
        hasClearButton: false
 
50
        font.pixelSize: FontUtils.sizeToPixels("large")
 
51
 
 
52
        onActiveFocusChanged: {
 
53
            if (activeFocus) {
 
54
                root.textFocused()
 
55
            }
 
56
        }
 
57
 
 
58
        // Don't let the style play with our opacity
 
59
        Binding {
 
60
            target: searchBar.ItemStyle.style
 
61
            property: "opacity"
 
62
            value: 1
 
63
        }
 
64
 
 
65
        Item {
 
66
            id: primary
 
67
            height: searchBar.height
 
68
            width: height
 
69
 
 
70
            Image {
 
71
                id: magnifierImage
 
72
                height: imageSize
 
73
                width: height
 
74
                anchors.centerIn: parent
 
75
                source: "graphics/icon_search.png"
 
76
                visible: !activityIndicator.visible && !clearImage.visible
 
77
            }
 
78
 
 
79
            Image {
 
80
                id: clearImage
 
81
                height: imageSize
 
82
                width: height
 
83
                anchors.centerIn: parent
 
84
                source: "graphics/icon_clear.png"
 
85
                visible: !activityIndicator.visible && searchBar.text != ""
 
86
                MouseArea {
 
87
                    anchors.fill: parent
 
88
                    onClicked: searchBar.text = ""
 
89
                }
 
90
            }
 
91
        }
 
92
 
 
93
        primaryItem: primary
 
94
        secondaryItem: MouseArea {
 
95
            height: searchBar.height
 
96
            width: height
 
97
            onClicked: microphoneClicked()
 
98
 
 
99
            Image {
 
100
                height: imageSize
 
101
                width: height
 
102
                anchors.centerIn: parent
 
103
                source: "graphics/microphone.png"
 
104
            }
 
105
        }
 
106
    }
 
107
}