ToolTip.qml 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. * Copyright (C) 2015 Malte Veerman <maldela@halloarsch.de>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU Lesser General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU Lesser General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Lesser General Public License along
  15. * with this program; if not, write to the Free Software Foundation, Inc.,
  16. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  17. *
  18. */
  19. import QtQuick 2.4
  20. import "../javascript/coordinates.js" as Coordinates
  21. Rectangle {
  22. property alias text: text.text
  23. property alias textColor: text.color
  24. property alias backgroundColor: rect.color
  25. property int delay: 1000
  26. property Item target: parent
  27. readonly property bool hovered: target.hovered
  28. id: rect
  29. width: text.width + 20
  30. height: text.height + 10
  31. anchors.top: target.bottom
  32. anchors.horizontalCenter: target.horizontalCenter
  33. anchors.horizontalCenterOffset: Math.max(0, width/2 - (Coordinates.absoluteCoordinatesOf(target).x+target.width/2))
  34. radius: 6
  35. color: palette.dark
  36. visible: false
  37. onHoveredChanged: {
  38. if (hovered) {
  39. if (timer.running)
  40. timer.restart();
  41. else
  42. timer.start();
  43. }
  44. else
  45. {
  46. if (timer.running)
  47. timer.stop();
  48. visible = false;
  49. }
  50. }
  51. Text {
  52. id: text
  53. anchors.centerIn: parent
  54. color: palette.highlightedText
  55. }
  56. Timer {
  57. id: timer
  58. interval: delay
  59. repeat: false
  60. onTriggered: parent.visible = true
  61. }
  62. SystemPalette {
  63. id: palette
  64. }
  65. }