~ps-jenkins/ubuntu-ui-extras/trusty-proposed

« back to all changes in this revision

Viewing changes to src/Ubuntu/Components/Extras/Browser/Selection.qml

  • Committer: Ugo Riboni
  • Date: 2013-06-05 16:18:44 UTC
  • Revision ID: ugo.riboni@canonical.com-20130605161844-yvbl1s39jcmnjoe7
Initial commit, only plugin, no tests, no translations

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright 2013 Canonical Ltd.
 
3
 *
 
4
 * This file is part of webbrowser-app.
 
5
 *
 
6
 * webbrowser-app is free software; you can redistribute it and/or modify
 
7
 * it under the terms of the GNU General Public License as published by
 
8
 * the Free Software Foundation; version 3.
 
9
 *
 
10
 * webbrowser-app is distributed in the hope that it will be useful,
 
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
 * GNU General Public License for more details.
 
14
 *
 
15
 * You should have received a copy of the GNU General Public License
 
16
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
17
 */
 
18
 
 
19
import QtQuick 2.0
 
20
import Ubuntu.Components 0.1
 
21
 
 
22
Item {
 
23
    id: __container
 
24
 
 
25
    property alias rect: __rect
 
26
 
 
27
    property real __minimumWidth: units.gu(5)
 
28
    property real __minimumHeight: units.gu(5)
 
29
 
 
30
    signal resized()
 
31
 
 
32
    MouseArea {
 
33
        anchors.fill: parent
 
34
        // dismiss the selection when tapping anywhere except for the handles
 
35
        onClicked: __container.visible = false
 
36
    }
 
37
 
 
38
    Item {
 
39
        id: __rect
 
40
    }
 
41
 
 
42
    Rectangle {
 
43
        id: __outline
 
44
 
 
45
        color: "transparent"
 
46
 
 
47
        Rectangle {
 
48
            anchors.fill: parent
 
49
            radius: parent.radius
 
50
            color: parent.border.color
 
51
            opacity: 0.1
 
52
            z: -1
 
53
        }
 
54
 
 
55
        border {
 
56
            width: units.dp(3)
 
57
            color: "#19B6EE"
 
58
        }
 
59
        radius: units.dp(3)
 
60
        antialiasing: true
 
61
 
 
62
        x: __rect.x
 
63
        width: {
 
64
            if (__leftHandle.dragging) {
 
65
                return __rect.x + __rect.width - (__leftHandle.x + __leftHandle.width / 2)
 
66
            } else if (__rightHandle.dragging) {
 
67
                return __rightHandle.x + __rightHandle.width / 2 - __rect.x
 
68
            } else {
 
69
                return __rect.width
 
70
            }
 
71
        }
 
72
 
 
73
        y: __rect.y
 
74
        height: {
 
75
            if (__topHandle.dragging) {
 
76
                return __rect.y + __rect.height - (__topHandle.y + __topHandle.height / 2)
 
77
            } else if (__bottomHandle.dragging) {
 
78
                return __bottomHandle.y + __bottomHandle.height / 2 - __rect.y
 
79
            } else {
 
80
                return __rect.height
 
81
            }
 
82
        }
 
83
 
 
84
        anchors {
 
85
            left: __rightHandle.dragging ? __rect.left: undefined
 
86
            right: __leftHandle.dragging ? __rect.right : undefined
 
87
            top: __bottomHandle.dragging ? __rect.top : undefined
 
88
            bottom: __topHandle.dragging ? __rect.bottom : undefined
 
89
        }
 
90
    }
 
91
 
 
92
    SelectionHandle {
 
93
        id: __leftHandle
 
94
        axis: Drag.XAxis
 
95
        x: __rect.x - width / 2
 
96
        y: (__topHandle.y + __bottomHandle.y) / 2
 
97
        minimum: 0
 
98
        maximum: __rightHandle.x - __container.__minimumWidth
 
99
        onDraggingChanged: {
 
100
            if (!dragging) {
 
101
                __rect.width = __rightHandle.x - __leftHandle.x
 
102
                __rect.x = __leftHandle.x + __leftHandle.width / 2
 
103
                __container.resized()
 
104
            }
 
105
        }
 
106
    }
 
107
 
 
108
    SelectionHandle {
 
109
        id: __topHandle
 
110
        axis: Drag.YAxis
 
111
        x: (__leftHandle.x + __rightHandle.x) / 2
 
112
        y: __rect.y - height / 2
 
113
        minimum: 0
 
114
        maximum: __bottomHandle.y - __container.__minimumHeight
 
115
        onDraggingChanged: {
 
116
            if (!dragging) {
 
117
                __rect.height = __bottomHandle.y - __topHandle.y
 
118
                __rect.y = __topHandle.y + __topHandle.height / 2
 
119
                __container.resized()
 
120
            }
 
121
        }
 
122
    }
 
123
 
 
124
    SelectionHandle {
 
125
        id: __rightHandle
 
126
        axis: Drag.XAxis
 
127
        x: __rect.x + __rect.width - width / 2
 
128
        y: (__topHandle.y + __bottomHandle.y) / 2
 
129
        minimum: __leftHandle.x + __container.__minimumWidth
 
130
        maximum: __container.width
 
131
        onDraggingChanged: {
 
132
            if (!dragging) {
 
133
                __rect.width = __rightHandle.x - __leftHandle.x
 
134
                __container.resized()
 
135
            }
 
136
        }
 
137
    }
 
138
 
 
139
    SelectionHandle {
 
140
        id: __bottomHandle
 
141
        axis: Drag.YAxis
 
142
        x: (__leftHandle.x + __rightHandle.x) / 2
 
143
        y: __rect.y + __rect.height - height / 2
 
144
        minimum: __topHandle.y + __container.__minimumHeight
 
145
        maximum: __container.height
 
146
        onDraggingChanged: {
 
147
            if (!dragging) {
 
148
                __rect.height = __bottomHandle.y - __topHandle.y
 
149
                __container.resized()
 
150
            }
 
151
        }
 
152
    }
 
153
}