| 1 | // Copyright (C) 2016 The Qt Company Ltd. |
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
| 3 | |
| 4 | #ifndef HIGHLIGHT_H |
| 5 | #define HIGHLIGHT_H |
| 6 | |
| 7 | #include <QtCore/QPointer> |
| 8 | #include <QtCore/QPointF> |
| 9 | #include <QtGui/QTransform> |
| 10 | #include <QtQuick/QQuickPaintedItem> |
| 11 | |
| 12 | QT_BEGIN_NAMESPACE |
| 13 | |
| 14 | namespace QmlJSDebugger { |
| 15 | |
| 16 | class Highlight : public QQuickPaintedItem |
| 17 | { |
| 18 | Q_OBJECT |
| 19 | |
| 20 | public: |
| 21 | Highlight(QQuickItem *parent); |
| 22 | Highlight(QQuickItem *item, QQuickItem *parent); |
| 23 | |
| 24 | void setItem(QQuickItem *item); |
| 25 | QQuickItem *item() {return m_item;} |
| 26 | |
| 27 | protected: |
| 28 | QTransform transform() {return m_transform;} |
| 29 | |
| 30 | private: |
| 31 | void initRenderDetails(); |
| 32 | void adjust(); |
| 33 | |
| 34 | private: |
| 35 | QPointer<QQuickItem> m_item; |
| 36 | QTransform m_transform; |
| 37 | }; |
| 38 | |
| 39 | /** |
| 40 | * A highlight suitable for indicating selection. |
| 41 | */ |
| 42 | class SelectionHighlight : public Highlight |
| 43 | { |
| 44 | Q_OBJECT |
| 45 | |
| 46 | public: |
| 47 | SelectionHighlight(const QString &name, QQuickItem *item, QQuickItem *parent); |
| 48 | void paint(QPainter *painter) override; |
| 49 | void showName(const QPointF &displayPoint); |
| 50 | |
| 51 | private: |
| 52 | QPointF m_displayPoint; |
| 53 | QString m_name; |
| 54 | bool m_nameDisplayActive; |
| 55 | |
| 56 | void disableNameDisplay(); |
| 57 | }; |
| 58 | |
| 59 | /** |
| 60 | * A highlight suitable for indicating hover. |
| 61 | */ |
| 62 | class HoverHighlight : public Highlight |
| 63 | { |
| 64 | public: |
| 65 | HoverHighlight(QQuickItem *parent) |
| 66 | : Highlight(parent) |
| 67 | { |
| 68 | setZ(1); // hover highlight on top of selection highlight |
| 69 | } |
| 70 | |
| 71 | void paint(QPainter *painter) override; |
| 72 | }; |
| 73 | |
| 74 | } // namespace QmlJSDebugger |
| 75 | |
| 76 | QT_END_NAMESPACE |
| 77 | |
| 78 | #endif // HIGHLIGHT_H |
| 79 | |