tooltipviewmodel.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. #ifndef TOOLTIPVIEWMODEL_H
  2. #define TOOLTIPVIEWMODEL_H
  3. #include <QObject>
  4. class QQuickItem;
  5. class TooltipViewModel : public QObject
  6. {
  7. Q_OBJECT
  8. Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged)
  9. Q_PROPERTY(int x READ x WRITE setX NOTIFY xChanged)
  10. Q_PROPERTY(int y READ y WRITE setY NOTIFY yChanged)
  11. Q_PROPERTY(bool visible READ visible WRITE setVisible NOTIFY visibleChanged)
  12. Q_PROPERTY(QQuickItem* viewport READ viewport WRITE setViewport NOTIFY viewportChanged)
  13. public:
  14. TooltipViewModel();
  15. int x() const
  16. {
  17. return m_x;
  18. }
  19. int y() const
  20. {
  21. return m_y;
  22. }
  23. bool visible() const
  24. {
  25. return m_visible;
  26. }
  27. QString text() const
  28. {
  29. return m_text;
  30. }
  31. QQuickItem* viewport() const
  32. {
  33. return m_viewport;
  34. }
  35. public slots:
  36. void setX(int x)
  37. {
  38. if (m_x == x)
  39. return;
  40. m_x = x;
  41. emit xChanged(x);
  42. }
  43. void setY(int y)
  44. {
  45. if (m_y == y)
  46. return;
  47. m_y = y;
  48. emit yChanged(y);
  49. }
  50. void setVisible(bool visible)
  51. {
  52. if (m_visible == visible)
  53. return;
  54. m_visible = visible;
  55. emit visibleChanged(visible);
  56. }
  57. void setText(const QString& text)
  58. {
  59. if (m_text == text)
  60. return;
  61. m_text = text;
  62. emit textChanged(text);
  63. }
  64. void setViewport(QQuickItem* viewport)
  65. {
  66. if (m_viewport == viewport)
  67. return;
  68. m_viewport = viewport;
  69. emit viewportChanged(viewport);
  70. }
  71. signals:
  72. void xChanged(int x);
  73. void yChanged(int y);
  74. void visibleChanged(bool visible);
  75. void textChanged(const QString& text);
  76. void viewportChanged(QQuickItem* viewport);
  77. private:
  78. int m_x;
  79. int m_y;
  80. bool m_visible;
  81. QString m_text;
  82. QQuickItem* m_viewport;
  83. };
  84. #endif // TOOLTIPVIEWMODEL_H