Skip to content

Commit bf67c69

Browse files
committed
Fix tooltips in undocked settings window
1 parent af468d4 commit bf67c69

2 files changed

Lines changed: 60 additions & 19 deletions

File tree

resources/qml/SidebarStageMenu.qml

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -178,18 +178,11 @@ Item
178178
}
179179
onTextChanged: function()
180180
{
181-
/* The div automatically adapts to 100% of the parent width and
182-
wraps properly, so this causes the tooltips to be wrapped to the width
183-
of the tooltip as set by the operating system. */
184-
185-
sidebarToolWindow.tooltipText = "<div>" + tooltip.text + "</div>"
181+
sidebarToolWindow.toolTipText = tooltip.text
186182
}
187-
onYChanged: function()
183+
onTargetChanged: function()
188184
{
189-
sidebarToolWindow.tooltipPosition = Qt.point(
190-
UM.Theme.getSize("default_margin").width,
191-
tooltip.y + 3 * UM.Theme.getSize("default_margin").height
192-
)
185+
sidebarToolWindow.toolTipY = tooltip.target.y
193186
}
194187
}
195188

@@ -322,6 +315,8 @@ Item
322315
// tool window is closed by window manager (not via our collapse button)
323316
UM.Preferences.setValue("view/settings_visible", false)
324317
stageMenu.settingsVisible = false
318+
319+
printSetupTooltip.visible = true
325320
}
326321
}
327322
}

resources/qml/SidebarToolWindow.qml

Lines changed: 55 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import QtQuick 2.7
22
import QtQuick.Controls 2.3
33
import QtQuick.Window 2.2
44

5-
import UM 1.5 as UM
5+
import UM 1.3 as UM
66
import Cura 1.1 as Cura
77

88
Window
@@ -50,17 +50,28 @@ Window
5050
onXChanged: UM.Preferences.setValue("sidebargui/settings_window_left", x)
5151
onYChanged: UM.Preferences.setValue("sidebargui/settings_window_top", y)
5252

53-
property string tooltipText
54-
property var tooltipPosition
53+
property string toolTipText
54+
property int toolTipY
5555
function showTooltip()
5656
{
57-
toolTip.tooltipText = tooltipText
58-
toolTip.show()
57+
toolTip.text = toolTipText
58+
toolTip.target = Qt.point(4 * UM.Theme.getSize("default_margin").width, toolTipY)
59+
if (toolTipY < (sidebarToolWindow.height / 2))
60+
{
61+
toolTip.y = toolTipY + 2 * UM.Theme.getSize("default_margin").height
62+
toolTip.anchors.bottom = undefined
63+
}
64+
else
65+
{
66+
toolTip.y = toolTipY - toolTip.height - 1 * UM.Theme.getSize("default_margin").height
67+
toolTip.anchors.top = undefined
68+
}
69+
toolTip.opacity = 1
5970
}
6071

6172
function hideTooltip()
6273
{
63-
toolTip.hide()
74+
toolTip.opacity = 0
6475
}
6576

6677
visible: !settingsDocked && settingsVisible && (prepareStageActive || !preSlicedData)
@@ -73,7 +84,7 @@ Window
7384
sidebarToolWindow.x = base.x + base.width - sidebarToolWindow.width + UM.Theme.getSize("wide_margin").width
7485
sidebarToolWindow.y = base.y + UM.Theme.getSize("wide_margin").width
7586
}
76-
printSetupWindow.children = [sidebarContents]
87+
printSetupWindow.children = [sidebarContents, toolTip]
7788
printSetupTooltip.visible = false // hide vestigial tooltip in main window
7889
}
7990
else
@@ -88,12 +99,47 @@ Window
8899
id: printSetupWindow
89100

90101
anchors.fill: parent
102+
}
103+
104+
Item
105+
{
106+
visible: false
91107

92-
UM.ToolTip
108+
UM.PointingRectangle
93109
{
94110
id: toolTip
95111

96-
width: printSetupWindow.width - 2 * UM.Theme.getSize("default_margin").width
112+
width: printSetupWindow.width - 2 * UM.Theme.getSize("default_margin").width - UM.Theme.getSize("thick_margin").width
113+
x: UM.Theme.getSize("thick_margin").width
114+
height: Math.min(label.height + 2 * UM.Theme.getSize("default_margin").height, 400)
115+
116+
property alias text: label.text
117+
color: UM.Theme.getColor("tooltip")
118+
arrowSize: UM.Theme.getSize("default_arrow").width
119+
120+
opacity: 0
121+
// This should be disabled when invisible, otherwise it will catch mouse events.
122+
visible: opacity > 0
123+
enabled: visible
124+
125+
Behavior on opacity
126+
{
127+
NumberAnimation { duration: 200; }
128+
}
129+
130+
Label
131+
{
132+
id: label
133+
anchors.left: parent.left
134+
anchors.right: parent.right
135+
anchors.top: parent.top
136+
anchors.margins: UM.Theme.getSize("tooltip_margins").width
137+
textFormat: Text.RichText
138+
color: UM.Theme.getColor("tooltip_text")
139+
font: UM.Theme.getFont("default")
140+
wrapMode: Text.Wrap
141+
renderType: Qt.platform.os == "osx" ? Text.QtRendering : Text.NativeRendering
142+
}
97143
}
98144
}
99145
}

0 commit comments

Comments
 (0)