| 1 |
/* |
| 2 |
* Copyright (C) 2011-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 General Public License version 3 as |
| 6 |
* published by the Free Software Foundation. |
| 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 |
* Authors: |
| 17 |
* Jim Nelson <[email protected]> |
| 18 |
* Lucas Beeler <[email protected]> |
| 19 |
* Eric Gregory <[email protected]> |
| 20 |
*/ |
| 21 |
|
| 22 |
import QtQuick 2.9 |
| 23 |
import Lomiri.Components 1.3 |
| 24 |
import "../Components" |
| 25 |
|
| 26 |
// Displays a flickable photo stream. |
| 27 |
// |
| 28 |
// When implementing this, override onCurrentIndexChanged to load the |
| 29 |
// appropriate photo for the index. |
| 30 |
ListView { |
| 31 |
id: mediaListView |
| 32 |
|
| 33 |
/*! |
| 34 |
*/ |
| 35 |
property int currentIndexForHighlight: -1 |
| 36 |
|
| 37 |
// NOTE: These properties should be treated as read-only, as setting them |
| 38 |
// individually can lead to bogus results. Use setCurrentIndex() to |
| 39 |
// initialize the view. |
| 40 |
property alias index: mediaListView.currentIndex |
| 41 |
|
| 42 |
/*! |
| 43 |
*/ |
| 44 |
function setCurrentIndex(index) { |
| 45 |
if (currentIndex === index) |
| 46 |
return; |
| 47 |
|
| 48 |
currentIndex = index; |
| 49 |
positionViewAtIndex(currentIndex, ListView.Beginning); |
| 50 |
} |
| 51 |
|
| 52 |
spacing: units.gu(5) |
| 53 |
orientation: ListView.Horizontal |
| 54 |
snapMode: ListView.SnapOneItem |
| 55 |
highlightRangeMode: ListView.StrictlyEnforceRange |
| 56 |
highlightFollowsCurrentItem: true |
| 57 |
flickDeceleration: units.gu(3) |
| 58 |
maximumFlickVelocity: units.gu(500) |
| 59 |
highlightMoveDuration: units.gu(11) |
| 60 |
boundsBehavior: Flickable.DragOverBounds |
| 61 |
|
| 62 |
onMovingChanged: { |
| 63 |
// TODO: if you scroll through a number of pages without stopping, this |
| 64 |
// never gets updated, so the highlighting stops working. |
| 65 |
if (moving) |
| 66 |
currentIndexForHighlight = currentIndex; |
| 67 |
} |
| 68 |
|
| 69 |
// Keyboard focus while visible |
| 70 |
onVisibleChanged: { |
| 71 |
if (visible) |
| 72 |
forceActiveFocus(); |
| 73 |
} |
| 74 |
|
| 75 |
Keys.onPressed: { |
| 76 |
if (event.key === Qt.Key_Left) { |
| 77 |
decrementCurrentIndex(); |
| 78 |
event.accepted = true; |
| 79 |
} else if (event.key === Qt.Key_Right) { |
| 80 |
incrementCurrentIndex(); |
| 81 |
event.accepted = true; |
| 82 |
} |
| 83 |
} |
| 84 |
|
| 85 |
/* FIXME: We need to handle the onWheel event to be able to navigate |
| 86 |
between photos/videos on MediaListView using two fingers swipe on |
| 87 |
desktop touchpad. There is an issue on Qt 5.2 where wheelEvents |
| 88 |
are not able to flick between items of a ListView with snapMode |
| 89 |
set as SnapOneItem. */ |
| 90 |
MouseAreaWithMultipoint { |
| 91 |
desktop: APP.desktopMode |
| 92 |
anchors.fill: parent |
| 93 |
enabled: APP.desktopMode && (currentItem.state === "unzoomed" || currentItem.state === "stopped") |
| 94 |
propagateComposedEvents: true |
| 95 |
|
| 96 |
onWheel: { |
| 97 |
if (wheel.angleDelta.x < 0) { |
| 98 |
decrementCurrentIndex(); |
| 99 |
wheel.accepted = true; |
| 100 |
} else if (wheel.angleDelta.x > 0) { |
| 101 |
incrementCurrentIndex(); |
| 102 |
wheel.accepted = true; |
| 103 |
} |
| 104 |
} |
| 105 |
|
| 106 |
onPressed: { |
| 107 |
mouse.accepted = false; |
| 108 |
} |
| 109 |
} |
| 110 |
} |