on xenial help sign in
Refactor the way we deal with tooltip delay timer.
commitc2796ab3bfa4421940fed0a36062906a5ff5608b authorAndrea Azzarone <azzaronea@gmail.com> dateWed 19 Oct 2016, 01:30 (10 years ago) parentf3abaa9
3 files changed+39−43
qml/Launcher/LauncherPanel.qml+2−21 qml/Launcher/Tooltip.qml+24−21 tests/qmltests/Launcher/tst_Launcher.qml+13−1
qml/Launcher/LauncherPanel.qml+2−21
@@ -845,18 +845,10 @@ Rectangle {
845845 margins: units.gu(1)
846846 }
847847
848− Binding on text {
849− when: !!tooltipShape.hoveredItem
850− value: !!tooltipShape.hoveredItem ? tooltipShape.hoveredItem.name : ""
851− }
852−
853848 property var hoveredItem: dndArea.containsMouse ? launcherListView.itemAt(dndArea.mouseX, dndArea.mouseY + launcherListView.realContentY) : null
854− property int itemCenter: 0
849+ property int itemCenter: hoveredItem ? root.mapFromItem(hoveredItem, 0, 0).y + (hoveredItem.height / 2) + hoveredItem.offset : 0
855850
856− Binding on itemCenter {
857− when: !!tooltipShape.hoveredItem
858− value: !!tooltipShape.hoveredItem ? root.mapFromItem(tooltipShape.hoveredItem, 0, 0).y + (tooltipShape.hoveredItem.height / 2) + tooltipShape.hoveredItem.offset : 0
859− }
851+ text: hoveredItem ? hoveredItem.name : ""
860852 }
861853
862854 DSM.StateMachine {
@@ -884,11 +876,6 @@ Rectangle {
884876 guard: tooltipShape.hoveredItem == null
885877 }
886878
887− DSM.SignalTransition {
888− targetState: tooltipHiddenState
889− signal: dndArea.exited
890− }
891−
892879 DSM.SignalTransition {
893880 targetState: tooltipDismissedState
894881 signal: dndArea.onPressed
@@ -899,12 +886,6 @@ Rectangle {
899886 signal: quickList.stateChanged
900887 guard: quickList.state === "open"
901888 }
902−
903− DSM.SignalTransition {
904− targetState: tooltipDismissedState
905− signal: root.movingChanged
906− guard: root.moving
907− }
908889 }
909890
910891 DSM.State {
qml/Launcher/Tooltip.qml+24−21
@@ -21,8 +21,8 @@ UbuntuShape {
2121 id: root
2222
2323 // This property holds the delay (milliseconds) after which the tool tip is shown.
24− // A tooltip with a negative delay is shown immediately. The default value is UbuntuAnimation.SlowDuration.
25− property alias delay: delayTimer.interval
24+ // A tooltip with a negative delay is shown immediately. The default value is 500 ms.
25+ property int delay: 500
2626
2727 // This property holds the text shown on the tool tip.
2828 property alias text: label.text
@@ -31,25 +31,7 @@ UbuntuShape {
3131 color: theme.palette.normal.background
3232 width: label.implicitWidth + units.gu(4)
3333 height: label.implicitHeight + units.gu(2)
34−
35− Behavior on opacity {
36− UbuntuNumberAnimation {
37− duration: UbuntuAnimation.BriskDuration
38− }
39− }
40−
41− Binding on opacity {
42− when: !visible
43− value: 0
44− }
45−
46− Timer {
47− id: delayTimer
48− running: root.visible
49− triggeredOnStart: true
50− interval: UbuntuAnimation.SlowDuration
51− onTriggered: root.opacity = (running ? .0 : .95)
52− }
34+ opacity: 0
5335
5436 Image {
5537 anchors {
@@ -66,4 +48,25 @@ UbuntuShape {
6648 anchors.centerIn: parent
6749 color: theme.palette.normal.backgroundText
6850 }
51+
52+ states: [
53+ State {
54+ name: "visible"
55+ when: root.visible
56+ PropertyChanges {
57+ target: root
58+ opacity: 0.95
59+ }
60+ }
61+ ]
62+
63+ transitions: [
64+ Transition {
65+ from: ""; to: "visible"
66+ SequentialAnimation {
67+ PauseAnimation { duration: root.delay }
68+ UbuntuNumberAnimation { target: root; property: "opacity"; duration: UbuntuAnimation.BriskDuration }
69+ }
70+ }
71+ ]
6972}
tests/qmltests/Launcher/tst_Launcher.qml+13−1
@@ -1366,15 +1366,18 @@ Rectangle {
13661366
13671367 // Initial state
13681368 tryCompare(tooltipShape, "visible", false);
1369+ tryCompare(tooltipShape, "opacity", .0);
13691370
13701371 // Move the mouse on the launcher icon
13711372 mouseMove(item, item.width / 2, item.height / 2, 10);
13721373 mouseMove(item, item.width / 2 + 1, item.height / 2, 10);
13731374 tryCompare(tooltipShape, "visible", true);
1375+ tryCompare(tooltipShape, "opacity", .95);
13741376
13751377 // Move the mouse away
13761378 mouseMove(root, root.width, root.height / 2, 10);
13771379 tryCompare(tooltipShape, "visible", false);
1380+ tryCompare(tooltipShape, "opacity", .0);
13781381 }
13791382
13801383 function test_quicklist_dismisses_tooltip() {
@@ -1390,26 +1393,31 @@ Rectangle {
13901393
13911394 // Initial state
13921395 tryCompare(tooltipShape, "visible", false);
1396+ tryCompare(tooltipShape, "opacity", .0);
13931397
13941398 // Move the mouse on the launcher icon
13951399 mouseMove(item, item.width / 2, item.height / 2, 10);
13961400 mouseMove(item, item.width / 2 + 1, item.height / 2, 10);
13971401 tryCompare(tooltipShape, "visible", true);
1402+ tryCompare(tooltipShape, "opacity", .95);
13981403
13991404 // Right click to show the quicklist
14001405 mouseClick(item, item.width / 2, item.height / 2, Qt.RightButton);
14011406 tryCompare(quickListShape, "visible", true);
14021407 tryCompare(tooltipShape, "visible", false);
1408+ tryCompare(tooltipShape, "opacity", .0);
14031409
14041410 // Left click hides the quicklist, tooltip is still dismissed
14051411 mouseClick(item, item.width / 2, item.height / 2, Qt.LefftButton);
14061412 tryCompare(quickListShape, "visible", false);
14071413 tryCompare(tooltipShape, "visible", false);
1414+ tryCompare(tooltipShape, "opacity", .0);
14081415
14091416 // Mouse motion should should show tooltip again
14101417 mouseMove(item, item.width / 2, item.height / 2, 10);
14111418 mouseMove(item, item.width / 2 + 1, item.height / 2, 10);
14121419 tryCompare(tooltipShape, "visible", true);
1420+ tryCompare(tooltipShape, "opacity", .95);
14131421 }
14141422
14151423 function test_click_dismisses_tooltip() {
@@ -1423,21 +1431,25 @@ Rectangle {
14231431 mouseMove(root, root.width, root.height / 2, 10);
14241432
14251433 // Initial state
1426− compare(tooltipShape.visible, false);
1434+ tryCompare(tooltipShape, "visible", false);
1435+ tryCompare(tooltipShape, "opacity", .0);
14271436
14281437 // Move the mouse on the launcher icon
14291438 mouseMove(item, item.width / 2, item.height / 2, 10);
14301439 mouseMove(item, item.width / 2 + 1, item.height / 2, 10);
14311440 tryCompare(tooltipShape, "visible", true);
1441+ tryCompare(tooltipShape, "opacity", .95);
14321442
14331443 // Left click should dismiss the tooltip
14341444 mouseClick(item, item.width / 2 + 1, item.height / 2, Qt.LeftButton);
14351445 tryCompare(tooltipShape, "visible", false);
1446+ tryCompare(tooltipShape, "opacity", .0);
14361447
14371448 // Mouse motion should should show tooltip again
14381449 mouseMove(item, item.width / 2, item.height / 2, 10);
14391450 mouseMove(item, item.width / 2 + 1, item.height / 2, 10);
14401451 tryCompare(tooltipShape, "visible", true);
1452+ tryCompare(tooltipShape, "opacity", .95);
14411453 }
14421454 }
14431455}