| 1 | // Copyright (C) 2018 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 QQMLPREVIEWSERVICE_H |
| 5 | #define QQMLPREVIEWSERVICE_H |
| 6 | |
| 7 | // |
| 8 | // W A R N I N G |
| 9 | // ------------- |
| 10 | // |
| 11 | // This file is not part of the Qt API. It exists purely as an |
| 12 | // implementation detail. This header file may change from version to |
| 13 | // version without notice, or even be removed. |
| 14 | // |
| 15 | // We mean it. |
| 16 | // |
| 17 | |
| 18 | #include "qqmlpreviewhandler.h" |
| 19 | #include "qqmlpreviewfileengine.h" |
| 20 | #include <private/qqmldebugserviceinterfaces_p.h> |
| 21 | |
| 22 | QT_BEGIN_NAMESPACE |
| 23 | |
| 24 | class QQmlPreviewFileEngineHandler; |
| 25 | class QQmlPreviewHandler; |
| 26 | class QQmlPreviewServiceImpl : public QQmlDebugService |
| 27 | { |
| 28 | Q_OBJECT |
| 29 | |
| 30 | public: |
| 31 | enum Command { |
| 32 | File, |
| 33 | Load, |
| 34 | Request, |
| 35 | Error, |
| 36 | Rerun, |
| 37 | Directory, |
| 38 | ClearCache, |
| 39 | Zoom, |
| 40 | Fps |
| 41 | }; |
| 42 | |
| 43 | static const QString s_key; |
| 44 | |
| 45 | QQmlPreviewServiceImpl(QObject *parent = nullptr); |
| 46 | virtual ~QQmlPreviewServiceImpl(); |
| 47 | |
| 48 | void messageReceived(const QByteArray &message) override; |
| 49 | void engineAboutToBeAdded(QJSEngine *engine) override; |
| 50 | void engineAboutToBeRemoved(QJSEngine *engine) override; |
| 51 | void stateChanged(State state) override; |
| 52 | |
| 53 | void forwardRequest(const QString &file); |
| 54 | void forwardError(const QString &error); |
| 55 | void forwardFps(const QQmlPreviewHandler::FpsInfo &frames); |
| 56 | |
| 57 | QQuickItem *currentRootItem(); |
| 58 | |
| 59 | Q_SIGNALS: |
| 60 | void error(const QString &file); |
| 61 | void file(const QString &file, const QByteArray &contents); |
| 62 | void directory(const QString &file, const QStringList &entries); |
| 63 | void load(const QUrl &url); |
| 64 | void drop(const QUrl &url); |
| 65 | void rerun(); |
| 66 | void clearCache(); |
| 67 | void zoom(qreal factor); |
| 68 | |
| 69 | private: |
| 70 | QScopedPointer<QQmlPreviewFileEngineHandler> m_fileEngine; |
| 71 | QScopedPointer<QQmlPreviewFileLoader> m_loader; |
| 72 | QQmlPreviewHandler m_handler; |
| 73 | QUrl m_currentUrl; |
| 74 | }; |
| 75 | |
| 76 | QT_END_NAMESPACE |
| 77 | |
| 78 | #endif // QQMLPREVIEWSERVICE_H |
| 79 | |