| 1 |
/* |
| 2 |
* This file is part of unity-2d |
| 3 |
* |
| 4 |
* Copyright 2012 Canonical Ltd. |
| 5 |
* |
| 6 |
* This program 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 |
* This program 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 |
|
| 21 |
// Shows the target when it has the focus or when you trigger the pointer barrier |
| 22 |
// in the edge of the target |
| 23 |
// Hides the target when none of the above conditions are met |
| 24 |
// and you have not had the mouse over it during more than 1000 msec |
| 25 |
// To use this Behavior your target needs to provide two properties |
| 26 |
// - containsMouse: Defines if the mouse is inside the target |
| 27 |
// - animating: Defines if the target is being animated |
| 28 |
// and one signal |
| 29 |
// - barrierTriggered: Defines when the pointer barrier has been triggered |
| 30 |
|
| 31 |
BaseBehavior { |
| 32 |
id: autoHide |
| 33 |
|
| 34 |
property bool shownRegardlessOfFocus: true |
| 35 |
property bool autoHideShown: target !== undefined && (target.activeFocus || shownRegardlessOfFocus) |
| 36 |
|
| 37 |
shown: autoHideShown |
| 38 |
|
| 39 |
onForcedVisibleChanged: |
| 40 |
{ |
| 41 |
if (!forcedVisible) { |
| 42 |
if (!target.containsMouse && forcedVisibleChangeId != "dash") { |
| 43 |
shownRegardlessOfFocus = true |
| 44 |
autoHideTimer.restart() |
| 45 |
} |
| 46 |
} |
| 47 |
} |
| 48 |
|
| 49 |
onForcedHiddenChanged: |
| 50 |
{ |
| 51 |
if (forcedHidden) { |
| 52 |
autoHideTimer.stop() |
| 53 |
if (!target.containsMouse) { |
| 54 |
shownRegardlessOfFocus = false |
| 55 |
} |
| 56 |
} |
| 57 |
} |
| 58 |
|
| 59 |
Timer { |
| 60 |
id: autoHideTimer |
| 61 |
interval: 1000 |
| 62 |
running: (target !== undefined) ? !target.containsMouse : false |
| 63 |
onTriggered: shownRegardlessOfFocus = false |
| 64 |
} |
| 65 |
|
| 66 |
Connections { |
| 67 |
target: (autoHide.target !== undefined) ? autoHide.target : null |
| 68 |
onContainsMouseChanged: { |
| 69 |
if ((shown || forcedVisible) && target.containsMouse) { |
| 70 |
shownRegardlessOfFocus = true |
| 71 |
} |
| 72 |
} |
| 73 |
} |
| 74 |
|
| 75 |
Connections { |
| 76 |
target: autoHide.target !== undefined ? autoHide.target : null |
| 77 |
onBarrierTriggered: shownRegardlessOfFocus = true |
| 78 |
onAnimatingChanged: |
| 79 |
{ |
| 80 |
if (!target.animating && !target.containsMouse && shownRegardlessOfFocus) { |
| 81 |
autoHideTimer.start(); |
| 82 |
} |
| 83 |
} |
| 84 |
} |
| 85 |
} |