~unity-2d-team/unity-2d/shortcut-hint-overlay

« back to all changes in this revision

Viewing changes to shell/common/visibilityBehaviors/IntelliHideBehavior.qml

  • Committer: Tiago Salem Herrmann
  • Date: 2012-03-19 15:28:41 UTC
  • mfrom: (771.40.182 unity-2d)
  • Revision ID: tiago.herrmann@canonical.com-20120319152841-2hfflo67muks7gca
merge trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
import Unity2d 1.0
21
21
import "../utils.js" as Utils
22
22
 
23
 
// Shows the target when it has the focus or when you move the
24
 
// mouse for 500 msec to the edge of the target or there are no 
25
 
// windows that intersect with the target
 
23
// Shows the target when it has the focus or when you trigger the pointer barrier
 
24
// or there are no windows that intersect with the target
26
25
// Hides the target when none of the above conditions are met
27
26
// and you have not had the mouse over it during more than 1000 msec
28
 
// To use this Behavior your target needs to provide two properties
 
27
// To use this Behavior your target needs to provide one properties
29
28
//  - containsMouse: Defines if the mouse is inside the target
30
 
//  - outerEdgeContainsMouse: Defines if the mouse is in the edge of the target
 
29
// and one signal
 
30
//  - barrierTriggered: Defines when the pointer barrier has been triggered
31
31
 
32
 
BaseBehavior {
 
32
AutoHideBehavior {
33
33
    id: intellihide
34
34
 
35
 
    property bool shownBecauseOfMousePosition: false
36
 
 
37
 
    shown: target !== undefined && (target.activeFocus || shownBecauseOfMousePosition || !windows.intersects)
38
 
 
39
 
    onForcedVisibleChanged:
40
 
    {
41
 
        if (!forcedVisible) {
42
 
            if (!target.containsMouse && forcedVisibleChangeId != "dash") {
43
 
                shownBecauseOfMousePosition = true
44
 
                mouseLeaveTimer.restart()
45
 
            }
46
 
        }
47
 
    }
48
 
 
49
 
    Timer {
50
 
        id: edgeHitTimer
51
 
        interval: 500
52
 
        onTriggered: shownBecauseOfMousePosition = true
53
 
    }
54
 
 
55
 
    Timer {
56
 
        id: mouseLeaveTimer
57
 
        interval: 1000
58
 
        onTriggered: shownBecauseOfMousePosition = false
59
 
    }
60
 
 
61
 
    Connections {
62
 
        target: (intellihide.target !== undefined) ? intellihide.target : null
63
 
        onOuterEdgeContainsMouseChanged: edgeHitTimer.running = target.outerEdgeContainsMouse
64
 
        ignoreUnknownSignals: true
65
 
    }
66
 
 
67
 
    Connections {
68
 
        target: (intellihide.target !== undefined) ? intellihide.target : null
69
 
        onContainsMouseChanged: {
70
 
            if ((shown || forcedVisible) && target.containsMouse) {
71
 
                shownBecauseOfMousePosition = true
72
 
            }
73
 
            mouseLeaveTimer.running = !target.containsMouse
74
 
        }
75
 
        ignoreUnknownSignals: true
76
 
    }
 
35
    property bool intelliHideShown: autoHideShown || (target !== undefined && !windows.intersects)
 
36
 
 
37
    shown: intelliHideShown
77
38
 
78
39
    WindowsIntersectMonitor {
79
40
        id: windows
80
41
        monitoredArea: {
81
42
            if (intellihide.target) {
82
43
                if (Utils.isLeftToRight()) {
83
 
                    return Qt.rect(0,
 
44
                    return Qt.rect(declarativeView.screen.geometry.x,
84
45
                                   intellihide.target.y,
85
46
                                   intellihide.target.width,
86
47
                                   intellihide.target.height)
87
48
                } else {
88
 
                    return Qt.rect(declarativeView.screen.availableGeometry.width - intellihide.target.width,
 
49
                    return Qt.rect(declarativeView.screen.geometry.x + declarativeView.screen.availableGeometry.width - intellihide.target.width,
89
50
                                   intellihide.target.y,
90
51
                                   intellihide.target.width,
91
52
                                   intellihide.target.height)