Added Tooltip alignment

CURA-6004
This commit is contained in:
Aleksei S 2018-12-19 14:24:02 +01:00
parent 17cddac024
commit 3953c7bb3a
3 changed files with 30 additions and 3 deletions

View file

@ -31,6 +31,8 @@ Button
property alias shadowColor: shadow.color
property alias shadowEnabled: shadow.visible
property alias toolTipContentAlignment: tooltip.contentAlignment
// This property is used to indicate whether the button has a fixed width or the width would depend on the contents
// Be careful when using fixedWidthMode, the translated texts can be too long that they won't fit. In any case,
// we elide the text to the right so the text will be cut off with the three dots at the end.

View file

@ -123,6 +123,8 @@ Column
tooltip: text
fixedWidthMode: true
toolTipContentAlignment: Cura.ToolTip.ContentAlignment.AlignLeft
onClicked: UM.Controller.setActiveStage("PreviewStage")
visible: UM.Controller.activeStage != null && UM.Controller.activeStage.stageId != "PreviewStage"

View file

@ -5,14 +5,26 @@ import QtQuick 2.7
import QtQuick.Controls 2.3
import UM 1.0 as UM
import Cura 1.0 as Cura
ToolTip
{
enum ContentAlignment
{
AlignLeft,
AlignRight
}
// This property indicates when the tooltip has to show, for instance when a button is hovered
property bool show: false
// Defines the alignment of the content, by default to the left
property int contentAlignment: Cura.ToolTip.ContentAlignment.AlignRight
property alias tooltipText: tooltip.text
property var targetPoint: Qt.point(0, 0)
property var targetPoint: Qt.point(parent.x, y + Math.round(height/2))
id: tooltip
text: ""
@ -20,13 +32,24 @@ ToolTip
visible: text != "" && show
font: UM.Theme.getFont("default")
x:
{
if (contentAlignment == Cura.ToolTip.ContentAlignment.AlignLeft)
{
return (label.width + Math.round(UM.Theme.getSize("default_arrow").width * 1.2) + padding * 2) * -1
}
return parent.width + Math.round(UM.Theme.getSize("default_arrow").width * 1.2 + padding)
}
y: Math.round(parent.height / 2 - label.height / 2 ) - padding
padding: 2
background: UM.PointingRectangle
{
id: backgroundRect
color: UM.Theme.getColor("tooltip")
target: Qt.point(targetPoint.x - tooltip.x, targetPoint.y - tooltip.y)
arrowSize: UM.Theme.getSize("default_arrow").width
}