| 1 |
/* |
| 2 |
* Copyright (C) 2012-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 |
* Charles Lindsay <[email protected]> |
| 18 |
*/ |
| 19 |
|
| 20 |
import QtQuick 2.9 |
| 21 |
import Gallery 1.0 |
| 22 |
import "../../../js/Gallery.js" as Gallery |
| 23 |
|
| 24 |
// A group of animated pages flippable from the AlbumSpreadViewer. Because of |
| 25 |
// how there are multiple pages to be flipped at once, keyed off a single |
| 26 |
// incremental value, this involves a lot of non-obvious math internally. The |
| 27 |
// interface is simple, though: set the album and destinationPage, then simply |
| 28 |
// move flipFraction from 0 -> 1 to incrementally flip the page(s) or call |
| 29 |
// turnToDestination() or ...Origin() to animate it automatically. |
| 30 |
Item { |
| 31 |
id: albumPageFlipper |
| 32 |
|
| 33 |
/*! |
| 34 |
*/ |
| 35 |
signal flipFinished(bool toDestination) |
| 36 |
|
| 37 |
/*! |
| 38 |
*/ |
| 39 |
property Album album |
| 40 |
/*! |
| 41 |
*/ |
| 42 |
property int currentPage |
| 43 |
/*! |
| 44 |
*/ |
| 45 |
property int destinationPage |
| 46 |
/*! |
| 47 |
*/ |
| 48 |
property int duration: Gallery.FAST_DURATION |
| 49 |
/*! |
| 50 |
*/ |
| 51 |
property real flipFraction |
| 52 |
/*! |
| 53 |
*/ |
| 54 |
property bool isPortrait |
| 55 |
/*! |
| 56 |
*/ |
| 57 |
property int pagesPerSpread |
| 58 |
|
| 59 |
// readonly |
| 60 |
/*! |
| 61 |
*/ |
| 62 |
property bool isFlipping: (flipFraction != 0 && flipFraction != 1) |
| 63 |
/*! |
| 64 |
*/ |
| 65 |
property bool isForward: (destinationPage > currentPage) |
| 66 |
/*! |
| 67 |
*/ |
| 68 |
property int firstPage: (isForward ? currentPage : destinationPage) |
| 69 |
/*! |
| 70 |
*/ |
| 71 |
property int lastPage: (isForward ? destinationPage : currentPage) |
| 72 |
/*! |
| 73 |
*/ |
| 74 |
property alias isRunning: animator.running |
| 75 |
|
| 76 |
// internal |
| 77 |
/*! |
| 78 |
*/ |
| 79 |
property int maxPages: 5 |
| 80 |
/*! |
| 81 |
*/ |
| 82 |
property int numPages: Math.min(maxPages, |
| 83 |
Math.abs(destinationPage - currentPage) / |
| 84 |
pagesPerSpread) |
| 85 |
/*! |
| 86 |
*/ |
| 87 |
property real pageFlipFraction: (isForward ? flipFraction : 1 - flipFraction) |
| 88 |
/*! |
| 89 |
*/ |
| 90 |
property real gapBetweenPages: (isPortrait ? 0.12 : 0.1) // Eyeballed. |
| 91 |
/*! |
| 92 |
*/ |
| 93 |
property real flipSlope: 1 / (1 - gapBetweenPages * (numPages - 1)) |
| 94 |
|
| 95 |
/*! |
| 96 |
*/ |
| 97 |
function flipToDestination() { |
| 98 |
animator.to = 1; |
| 99 |
animator.duration = (1 - flipFraction) * duration; |
| 100 |
animator.restart(); |
| 101 |
} |
| 102 |
|
| 103 |
/*! |
| 104 |
*/ |
| 105 |
function flipToOrigin() { |
| 106 |
animator.to = 0; |
| 107 |
animator.duration = flipFraction * duration; |
| 108 |
animator.restart(); |
| 109 |
} |
| 110 |
|
| 111 |
AlbumPageFlipperPage { |
| 112 |
flipperPage: 0 |
| 113 |
} |
| 114 |
|
| 115 |
AlbumPageFlipperPage { |
| 116 |
flipperPage: 1 |
| 117 |
} |
| 118 |
|
| 119 |
AlbumPageFlipperPage { |
| 120 |
flipperPage: 2 |
| 121 |
} |
| 122 |
|
| 123 |
AlbumPageFlipperPage { |
| 124 |
flipperPage: 3 |
| 125 |
} |
| 126 |
|
| 127 |
AlbumPageFlipperPage { |
| 128 |
flipperPage: 4 |
| 129 |
} |
| 130 |
|
| 131 |
NumberAnimation { |
| 132 |
id: animator |
| 133 |
|
| 134 |
target: albumPageFlipper |
| 135 |
property: "flipFraction" |
| 136 |
easing.type: Easing.OutQuad |
| 137 |
|
| 138 |
onRunningChanged: { |
| 139 |
if (!running) |
| 140 |
flipFinished(flipFraction == 1); |
| 141 |
} |
| 142 |
} |
| 143 |
} |