| 1 |
/* |
| 2 |
* Copyright 2015 Canonical Ltd. |
| 3 |
* |
| 4 |
* This program is free software; you can redistribute it and/or modify |
| 5 |
* it under the terms of the GNU Lesser 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 Lesser General Public License for more details. |
| 12 |
* |
| 13 |
* You should have received a copy of the GNU Lesser General Public License |
| 14 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 15 |
*/ |
| 16 |
|
| 17 |
/*! |
| 18 |
\qmltype pageUtils |
| 19 |
\inqmlmodule Lomiri.Components |
| 20 |
\ingroup lomiri |
| 21 |
\internal |
| 22 |
\brief Page-related utility functions. |
| 23 |
*/ |
| 24 |
|
| 25 |
/*! |
| 26 |
\qmlmethod pageUtils::isVerticalFlickable(object) |
| 27 |
Return true if the object is a Flickable that can be flicked in vertical direction. |
| 28 |
*/ |
| 29 |
function isVerticalFlickable(object) { |
| 30 |
if (object && object.hasOwnProperty("flickableDirection") && object.hasOwnProperty("contentHeight")) { |
| 31 |
var direction = object.flickableDirection; |
| 32 |
if ( ((direction === Flickable.AutoFlickDirection) && (object.contentHeight !== object.height) ) |
| 33 |
|| direction === Flickable.VerticalFlick |
| 34 |
|| direction === Flickable.HorizontalAndVerticalFlick) { |
| 35 |
return true; |
| 36 |
} |
| 37 |
} |
| 38 |
return false; |
| 39 |
} |
| 40 |
|
| 41 |
/*! |
| 42 |
\qmlmethod pageUtils::getFlickableChild(item) |
| 43 |
Return the first child of the item that is flickable in the vertical direction. |
| 44 |
*/ |
| 45 |
function getFlickableChild(item) { |
| 46 |
if (item && item.hasOwnProperty("children")) { |
| 47 |
for (var i=0; i < item.children.length; i++) { |
| 48 |
var child = item.children[i]; |
| 49 |
if (isVerticalFlickable(child)) { |
| 50 |
if (child.anchors.top === page.top || child.anchors.fill === page) { |
| 51 |
return item.children[i]; |
| 52 |
} |
| 53 |
} |
| 54 |
} |
| 55 |
} |
| 56 |
return null; |
| 57 |
} |