2 * Copyright (C) 2014 Canonical, Ltd.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 3.
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.
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/>.
18import Ubuntu.Components 1.3
23 property alias expanded: row.expanded
24 property alias interactive: flickable.interactive
25 property alias model: row.model
26 property alias unitProgress: row.unitProgress
27 property alias enableLateralChanges: row.enableLateralChanges
28 property alias overFlowWidth: row.overFlowWidth
29 readonly property alias currentItemIndex: row.currentItemIndex
30 property real lateralPosition: -1
31 property int alignment: Qt.AlignRight
33 property alias showRowTitle: row.showRowTitle
34 property alias rowTitle: row.rowTitle
35 property alias rowItemDelegate: row.delegate
37 implicitWidth: flickable.contentWidth
39 function selectItemAt(lateralPosition) {
41 row.resetCurrentItem();
43 var mapped = root.mapToItem(row, lateralPosition, 0);
44 row.selectItemAt(mapped.x);
47 function setCurrentItemIndex(index) {
49 row.resetCurrentItem();
51 row.setCurrentItemIndex(index);
55 function addScrollOffset(scrollAmmout) {
56 if (root.alignment == Qt.AlignLeft) {
57 scrollAmmout = -scrollAmmout;
60 if (scrollAmmout < 0) { // left scroll
61 if (flickable.contentX + flickable.width > row.width) return; // already off the left.
63 if (flickable.contentX + flickable.width - scrollAmmout > row.width) { // going to be off the left
64 scrollAmmout = (flickable.contentX + flickable.width) - row.width;
66 } else { // right scroll
67 if (flickable.contentX < 0) return; // already off the right.
68 if (flickable.contentX - scrollAmmout < 0) { // going to be off the right
69 scrollAmmout = flickable.contentX;
72 d.scrollOffset = d.scrollOffset + scrollAmmout;
77 property var initialItem
78 // the non-expanded distance from alignment edge to center of initial item
79 property real originalDistanceFromEdge: -1
81 // calculate the distance from row alignment edge edge to center of initial item
82 property real distanceFromEdge: {
83 if (originalDistanceFromEdge == -1) return 0;
84 if (!initialItem) return 0;
86 if (root.alignment == Qt.AlignLeft) {
87 return initialItem.x - initialItem.width / 2;
89 return row.width - initialItem.x - initialItem.width / 2;
93 // offset to the intially selected expanded item
94 property real rowOffset: 0
95 property real scrollOffset: 0
96 property real alignmentAdjustment: 0
97 property real combinedOffset: 0
99 // when the scroll offset changes, we need to reclaculate the relative lateral position
100 onScrollOffsetChanged: root.lateralPositionChanged()
102 onInitialItemChanged: {
103 if (root.alignment == Qt.AlignLeft) {
104 originalDistanceFromEdge = initialItem ? (initialItem.x - initialItem.width/2) : -1;
106 originalDistanceFromEdge = initialItem ? (row.width - initialItem.x - initialItem.width/2) : -1;
110 Behavior on alignmentAdjustment {
111 NumberAnimation { duration: UbuntuAnimation.BriskDuration; easing: UbuntuAnimation.StandardEasing}
114 function alignIndicators() {
115 flickable.resetContentXComponents();
117 if (expanded && !flickable.moving) {
119 if (root.alignment == Qt.AlignLeft) {
120 // current item overlap on left
121 if (row.currentItem && flickable.contentX > row.currentItem.x) {
122 d.alignmentAdjustment -= (flickable.contentX - row.currentItem.x);
124 // current item overlap on right
125 } else if (row.currentItem && flickable.contentX + flickable.width < row.currentItem.x + row.currentItem.width) {
126 d.alignmentAdjustment += (row.currentItem.x + row.currentItem.width) - (flickable.contentX + flickable.width);
129 // gap between left and row?
130 if (flickable.contentX + flickable.width > row.width) {
131 // row width is less than flickable
132 if (row.width < flickable.width) {
133 d.alignmentAdjustment -= flickable.contentX;
135 d.alignmentAdjustment -= ((flickable.contentX + flickable.width) - row.width);
138 // gap between right and row?
139 } else if (flickable.contentX < 0) {
140 d.alignmentAdjustment -= flickable.contentX;
142 // current item overlap on left
143 } else if (row.currentItem && (flickable.contentX + flickable.width) < (row.width - row.currentItem.x)) {
144 d.alignmentAdjustment += ((row.width - row.currentItem.x) - (flickable.contentX + flickable.width));
146 // current item overlap on right
147 } else if (row.currentItem && flickable.contentX > (row.width - row.currentItem.x - row.currentItem.width)) {
148 d.alignmentAdjustment -= flickable.contentX - (row.width - row.currentItem.x - row.currentItem.width);
159 anchors.bottom: parent.bottom
162 opacity: expanded ? 1.0 : 0.0
163 Behavior on opacity { NumberAnimation { duration: UbuntuAnimation.SnapDuration } }
169 clip: expanded || row.width > rowContainer.width
173 objectName: "flickable"
175 // we rotate it because we want the Flickable to align its content item
176 // on the right instead of on the left
177 rotation: root.alignment != Qt.AlignRight ? 0 : 180
180 contentWidth: row.width
181 contentX: d.combinedOffset
184 // contentX can change by user interaction as well as user offset changes
185 // This function re-aligns the offsets so that the offsets match the contentX
186 function resetContentXComponents() {
187 d.scrollOffset += d.combinedOffset - flickable.contentX;
190 rebound: Transition {
194 easing.type: Easing.OutCubic
200 objectName: "panelItemRow"
203 bottom: parent.bottom
206 // Compensate for the Flickable rotation (ie, counter-rotate)
207 rotation: root.alignment != Qt.AlignRight ? 0 : 180
210 if (root.lateralPosition == -1) return -1;
212 var mapped = root.mapToItem(row, root.lateralPosition, 0);
213 return Math.min(Math.max(mapped.x, 0), row.width);
216 onCurrentItemChanged: {
217 if (!currentItem) d.initialItem = undefined;
218 else if (!d.initialItem) d.initialItem = currentItem;
223 enabled: root.expanded
225 row.selectItemAt(mouse.x);
236 interval: UbuntuAnimation.FastDuration // enough for row animation.
239 onTriggered: d.alignIndicators();
250 alignmentAdjustment: 0
252 restoreEntryValues: false
257 when: expanded && !interactive
261 combinedOffset: rowOffset + alignmentAdjustment - scrollOffset
266 if (!initialItem) return 0;
267 if (distanceFromEdge - initialItem.width <= 0) return 0;
269 var rowOffset = distanceFromEdge - originalDistanceFromEdge;
272 restoreEntryValues: false
277 when: expanded && interactive
281 // don't use row offset anymore.
282 d.scrollOffset -= d.rowOffset;
284 d.initialItem = undefined;
285 alignmentTimer.start();
290 combinedOffset: rowOffset + alignmentAdjustment - scrollOffset
291 restoreEntryValues: false
302 properties: "rowOffset, scrollOffset, alignmentAdjustment"
307 properties: "combinedOffset"
308 duration: UbuntuAnimation.SnapDuration
309 easing: UbuntuAnimation.StandardEasing
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list