on xenial help sign in
Added indicator highlight drag offset
commit2700f8bad8754df2e11914365f20274ac55362d7 authorNick Dedekind <nicholas.dedekind@gmail.com> dateWed 18 Dec 2013, 11:26 (13 years ago) parent209d012
3 files changed+43−23
Panel/IndicatorItem.qml−12 Panel/IndicatorRow.qml+24 Panel/Indicators.qml+19−11
Panel/IndicatorItem.qml−12
@@ -46,16 +46,4 @@ Item {
4646 }
4747 }
4848 }
49−
50− Rectangle {
51− color: Theme.palette.selected.foreground
52− objectName: "highlight"
53− height: units.dp(2)
54− width: parent.width
55− anchors.top: parent.bottom
56− visible: highlighted
57−
58− opacity: highlighted ? 1 : 0
59− Behavior on opacity { StandardAnimation {} }
60− }
6149}
Panel/IndicatorRow.qml+24
@@ -29,6 +29,7 @@ Item {
2929 property var visibleIndicators: defined
3030 property int overFlowWidth: width
3131 property bool showAll: false
32+ property real currentItemOffset: 0.0
3233
3334 width: units.gu(40)
3435 height: units.gu(3)
@@ -145,4 +146,27 @@ Item {
145146 }
146147 }
147148 }
149+
150+ Rectangle {
151+ id: highlight
152+ color: Theme.palette.selected.foreground
153+ objectName: "highlight"
154+ height: units.dp(2)
155+ anchors.top: row.bottom
156+ visible: indicatorRow.currentItem != null
157+ x: row.x + (indicatorRow.currentItem != null ? indicatorRow.currentItem.x + centerOffset : 0)
158+ width: indicatorRow.currentItem != null ? indicatorRow.currentItem.width : 0
159+
160+ property real centerOffset: {
161+ if (indicatorRow.currentItemOffset > 0.2) {
162+ return (indicatorRow.currentItemOffset - 0.2) * units.gu(0.4);
163+ } else if (indicatorRow.currentItemOffset < -0.2) {
164+ return (indicatorRow.currentItemOffset + 0.2) * units.gu(0.4);
165+ }
166+ return 0.0;
167+ }
168+
169+ Behavior on width { UbuntuNumberAnimation { duration: UbuntuAnimation.FastDuration } }
170+ Behavior on x { UbuntuNumberAnimation { duration: UbuntuAnimation.FastDuration } }
171+ }
148172}
Panel/Indicators.qml+19−11
@@ -128,23 +128,31 @@ Showable {
128128 rowCoordinates = indicatorRow.mapToItem(indicatorRow.row, xValue, 0);
129129 // get the current delegate
130130 currentItem = indicatorRow.row.childAt(rowCoordinates.x, 0);
131− if (currentItem && currentItem != indicatorRow.currentItem ) {
131+ if (currentItem) {
132132 itemCoordinates = indicatorRow.row.mapToItem(currentItem, rowCoordinates.x, 0);
133133 distanceFromRightEdge = (currentItem.width - itemCoordinates.x) / (currentItem.width);
134− if (Math.abs(currentItem.ownIndex - indicatorRow.currentItemIndex) > 1) {
135− bufferExceeded = true;
136− } else {
137− if (indicatorRow.currentItemIndex < currentItem.ownIndex && distanceFromRightEdge < (1 - effectiveBufferThreshold)) {
138− bufferExceeded = true;
139− } else if (indicatorRow.currentItemIndex > currentItem.ownIndex && distanceFromRightEdge > effectiveBufferThreshold) {
134+ if (currentItem != indicatorRow.currentItem) {
135+ if (Math.abs(currentItem.ownIndex - indicatorRow.currentItemIndex) > 1) {
140136 bufferExceeded = true;
137+ } else {
138+ if (indicatorRow.currentItemIndex < currentItem.ownIndex && distanceFromRightEdge < (1 - effectiveBufferThreshold)) {
139+ bufferExceeded = true;
140+ } else if (indicatorRow.currentItemIndex > currentItem.ownIndex && distanceFromRightEdge > effectiveBufferThreshold) {
141+ bufferExceeded = true;
142+ }
141143 }
144+ if ((!useBuffer || (useBuffer && bufferExceeded)) || indicatorRow.currentItemIndex < 0 || indicatorRow.currentItem == null) {
145+ indicatorRow.currentItem = currentItem;
146+ }
147+
148+ // need to re-init the distanceFromRightEdge for offset calculation
149+ itemCoordinates = indicatorRow.row.mapToItem(indicatorRow.currentItem, rowCoordinates.x, 0);
150+ distanceFromRightEdge = (indicatorRow.currentItem.width - itemCoordinates.x) / (indicatorRow.currentItem.width);
142151 }
143− if ((!useBuffer || (useBuffer && bufferExceeded)) || indicatorRow.currentItem < 0 || indicatorRow.currentItem == null) {
144− indicatorRow.currentItem = currentItem;
145− }
146− } else if (!currentItem) {
152+ indicatorRow.currentItemOffset = 1 - (distanceFromRightEdge * 2);
153+ } else {
147154 indicatorRow.setDefaultItem();
155+ indicatorRow.currentItemOffset = 0;
148156 }
149157 initalizeItem = indicatorRow.currentItem == null;
150158 }