2
0

ToolTip.qml 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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 QtQuick.Controls 1.4
  21. import "../scripts/coordinates.js" as Coordinates
  22. Rectangle {
  23. property alias text: label.text
  24. property alias textColor: label.color
  25. property alias backgroundColor: rect.color
  26. property int delay: 1000
  27. property Item target: parent
  28. readonly property bool hovered: target.hovered
  29. id: rect
  30. width: label.width + 20
  31. height: label.height + 10
  32. anchors.top: target.bottom
  33. anchors.horizontalCenter: target.horizontalCenter
  34. anchors.horizontalCenterOffset: Math.max(0, width/2 - (Coordinates.absoluteCoordinatesOf(target).x+target.width/2))
  35. radius: 6
  36. color: palette.dark
  37. visible: false
  38. onHoveredChanged: {
  39. if (hovered) {
  40. if (timer.running)
  41. timer.restart();
  42. else
  43. timer.start();
  44. }
  45. else
  46. {
  47. if (timer.running)
  48. timer.stop();
  49. visible = false;
  50. }
  51. }
  52. Label {
  53. id: label
  54. anchors.centerIn: parent
  55. color: palette.highlightedText
  56. }
  57. Timer {
  58. id: timer
  59. interval: delay
  60. repeat: false
  61. onTriggered: parent.visible = true
  62. }
  63. SystemPalette {
  64. id: palette
  65. }
  66. }