summaryrefslogtreecommitdiff
path: root/src/tutorials/TooltipArea.qml
blob: 48a50f761fb1ea17f9c09a296eb7df4f41b5672f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import QtQuick 1.1

Rectangle {
  radius: 2
  color: clickable ? "#AA6666AA" : "#AA882222"
  height: 100
  border.color: "black"
  border.width: 2
  z: 1
  smooth: true
  property bool wasLocked: false
  property bool clickable: false
  property string tooltipText: ""

  MouseArea {
    id: clickArea
    anchors.fill: parent
    hoverEnabled: true

    onMousePositionChanged: {
      if (parent.parent.width - (parent.x + mouseX) < tooltip.width + 50) {
        tooltip.x = parent.x +  mouseX - 15 - tooltip.width
      } else {
        tooltip.x = parent.x + mouseX + 15
      }

      if (parent.parent.height - (parent.y + mouseY) < tooltip.height + 50) {
        tooltip.y = parent.y + mouseY - 15 - tooltip.height
      } else {
        tooltip.y = parent.y + mouseY + 15
      }
    }

    onEntered: {
      tooltip.visible = true
      tooltip.text = tooltipText
    }

    onPressed: {
      wasLocked = tutToplevel.backgroundEnabled()
      if (wasLocked && clickable) {
        tutorialControl.simulateClick(mouseX + parent.x, mouseY + parent.y)
      }
      mouse.accepted = false
    }

    onCanceled: {
      tooltip.visible = false
    }

    onExited: {
      tooltip.visible = false
    }
  }
}