@@ -6,31 +6,98 @@ import QtQuick
66import org.deepin.dtk 1.0 as D
77import org.deepin.dtk.style 1.0 as DS
88
9- ToolTip {
9+ // AlertToolTip is implemented with Control (not Popup) so it stays in the visual
10+ // tree, scrolls with content and gets clipped properly. Enter/exit animation
11+ // is driven by the visible state.
12+ Control {
1013 id: control
1114 property Item target
15+ property string text
16+ property alias font: contentText .font
17+ property int timeout: 0
1218
1319 x: 0
14- y: target ? target .height + DS .Style .control .spacing : 0
20+ y: _displayY
21+ z: D .DTK .TopOrder
22+
1523 topPadding: DS .Style .alertToolTip .verticalPadding
1624 bottomPadding: DS .Style .alertToolTip .verticalPadding
1725 leftPadding: DS .Style .alertToolTip .horizontalPadding
1826 rightPadding: DS .Style .alertToolTip .horizontalPadding
19- implicitWidth: Math .min (DS .Style .control .implicitWidth (control), target .width )
20- implicitHeight: DS .Style .control .implicitHeight (control)
21- margins: 0
22- closePolicy: Popup .NoAutoClose
2327
24- background: FloatingPanel {
25- radius: DS .Style .alertToolTip .radius
28+ readonly property real __naturalWidth: Math .max (DS .Style .alertToolTip .width ,
29+ contentText .implicitWidth + DS .Style .alertToolTip .horizontalPadding * 2 )
30+ implicitWidth: target ? Math .min (__naturalWidth, target .width ) : __naturalWidth
31+ implicitHeight: Math .max (DS .Style .alertToolTip .height ,
32+ contentText .implicitHeight + DS .Style .alertToolTip .verticalPadding * 2 )
33+ width: implicitWidth
34+ height: implicitHeight
35+
36+ // Animated y so tip stays attached to target; enter = from below target to final, exit = back.
37+ property real _displayY: target ? target .height : 0
38+ function _updateDisplayY () {
39+ if (target) {
40+ if (visible)
41+ _displayY = target .height + DS .Style .control .spacing
42+ else
43+ _displayY = target .height
44+ }
45+ }
46+ onVisibleChanged: _updateDisplayY ()
47+ onTargetChanged: _updateDisplayY ()
48+ Connections {
49+ target: control .target
50+ function onHeightChanged () { control ._updateDisplayY () }
51+ }
52+ Component .onCompleted : _updateDisplayY ()
53+ Behavior on _displayY {
54+ NumberAnimation { duration: 200 }
55+ }
56+
57+ Timer {
58+ interval: control .timeout
59+ running: control .timeout > 0 && control .visible
60+ onTriggered: control .visible = false
61+ }
62+
63+ background: Item {
2664 implicitWidth: DS .Style .alertToolTip .width
2765 implicitHeight: DS .Style .alertToolTip .height
28- backgroundColor: DS .Style .alertToolTip .background
29- insideBorderColor: DS .Style .alertToolTip .insideBorder
30- outsideBorderColor: DS .Style .alertToolTip .outsideBorder
66+
67+ FloatingPanel {
68+ anchors .fill : parent
69+ radius: DS .Style .alertToolTip .radius
70+ implicitWidth: DS .Style .alertToolTip .width
71+ implicitHeight: DS .Style .alertToolTip .height
72+ backgroundColor: DS .Style .alertToolTip .background
73+ insideBorderColor: DS .Style .alertToolTip .insideBorder
74+ outsideBorderColor: DS .Style .alertToolTip .outsideBorder
75+ }
76+
77+ BoxShadow {
78+ id: connector
79+ property D .Palette dropShadowColor: DS .Style .alertToolTip .connecterdropShadow
80+ property D .Palette backgroundColor: DS .Style .alertToolTip .connecterBackground
81+ property D .Palette borderColor: DS .Style .control .border
82+ y: - height * 0.75
83+ width: DS .Style .alertToolTip .connectorWidth
84+ height: DS .Style .alertToolTip .connectorHeight
85+ shadowBlur: 4
86+ shadowOffsetY: 2
87+ shadowColor: D .ColorSelector .dropShadowColor
88+ cornerRadius: DS .Style .control .radius
89+
90+ Rectangle {
91+ anchors .fill : parent
92+ color: connector .D .ColorSelector .backgroundColor
93+ border .color : connector .D .ColorSelector .borderColor
94+ border .width : 1
95+ }
96+ }
3197 }
3298
3399 contentItem: Text {
100+ id: contentText
34101 property D .Palette textColor: DS .Style .alertToolTip .text
35102 horizontalAlignment: Text .AlignLeft
36103 verticalAlignment: Text .AlignVCenter
@@ -39,36 +106,4 @@ ToolTip {
39106 color: D .ColorSelector .textColor
40107 wrapMode: Text .Wrap
41108 }
42-
43- enter: Transition {
44- // TODO: Transparency causes tooltips to appear through the window background - temporarily removed
45- // NumberAnimation { properties: "opacity"; from: 0.0; to: 1.0; duration: 200 }
46- NumberAnimation { properties: " y" ; from: control .target .height ; to: control .target .height + DS .Style .control .spacing ; duration: 200 }
47- }
48-
49- exit: Transition {
50- // NumberAnimation { properties: "opacity"; from: 1.0; to: 0.0 }
51- NumberAnimation { properties: " y" ; from: control .target .height + DS .Style .control .spacing ; to: control .target .height }
52- }
53-
54- BoxShadow {
55- id: line
56- property D .Palette dropShadowColor: DS .Style .alertToolTip .connecterdropShadow
57- property D .Palette backgroundColor: DS .Style .alertToolTip .connecterBackground
58- property D .Palette borderColor: DS .Style .control .border
59- y: - height * (0.75 ) - control .topMargin - control .topPadding
60- width: DS .Style .alertToolTip .connectorWidth
61- height: DS .Style .alertToolTip .connectorHeight
62- shadowBlur: 4
63- shadowOffsetY: 2
64- shadowColor: D .ColorSelector .dropShadowColor
65- cornerRadius: DS .Style .control .radius
66-
67- Rectangle {
68- anchors .fill : parent
69- color: line .D .ColorSelector .backgroundColor
70- border .color : line .D .ColorSelector .borderColor
71- border .width : 1
72- }
73- }
74109}
0 commit comments