File indexing completed on 2024-05-05 16:07:16

0001 /*
0002     This file is part of the KDE libraries
0003     SPDX-FileCopyrightText: 2015 Marco Martin <mart@kde.org>
0004 
0005     SPDX-License-Identifier: LGPL-2.0-or-later
0006 */
0007 
0008 #ifndef QUICKVIEWSHAREDENGINE_H
0009 #define QUICKVIEWSHAREDENGINE_H
0010 
0011 #include "quickaddons_export.h"
0012 
0013 #include <QQmlComponent>
0014 #include <QQmlError>
0015 #include <QQuickWindow>
0016 #include <QUrl>
0017 #include <memory>
0018 
0019 class QQuickItem;
0020 class QQmlEngine;
0021 
0022 namespace KQuickAddons
0023 {
0024 class QuickViewSharedEnginePrivate;
0025 
0026 /**
0027  * @class KQuickAddons::QuickViewSharedEngine quickviewsharedengine.h KQuickAddons/QuickViewSharedEngine
0028  *
0029  * TODO
0030  */
0031 class QUICKADDONS_EXPORT QuickViewSharedEngine : public QQuickWindow
0032 {
0033     Q_OBJECT
0034 
0035     Q_PROPERTY(ResizeMode resizeMode READ resizeMode WRITE setResizeMode NOTIFY resizeModeChanged)
0036     Q_PROPERTY(QQmlComponent::Status status READ status NOTIFY statusChanged)
0037     Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged)
0038 
0039 public:
0040     enum ResizeMode {
0041         SizeViewToRootObject,
0042         SizeRootObjectToView,
0043     };
0044     Q_ENUM(ResizeMode)
0045 
0046     explicit QuickViewSharedEngine(QWindow *parent = nullptr);
0047     ~QuickViewSharedEngine() override;
0048 
0049     /**
0050      * Installs a translation domain for all
0051      * i18n global functions. If a translation domain is set all i18n calls delegate to the
0052      * matching i18nd calls with the provided translation domain.
0053      *
0054      * The translationDomain affects all i18n calls including those from imports. Because of
0055      * that modules intended to be used as imports should prefer the i18nd variants and set
0056      * the translation domain explicitly in each call.
0057      *
0058      * This method is only required if your declarative usage is inside a library. If it's
0059      * in an application there is no need to set the translation domain as the application's
0060      * domain can be used.
0061      *
0062      * @param translationDomain The translation domain to be used for i18n calls.
0063      * @since 5.25
0064      */
0065     void setTranslationDomain(const QString &translationDomain);
0066 
0067     /**
0068      * @return the translation domain for the i18n calls done in this QML engine
0069      * @since 5.25
0070      */
0071     QString translationDomain() const;
0072 
0073     QQmlEngine *engine() const;
0074     QList<QQmlError> errors() const;
0075     QSize sizeHint() const;
0076     QSize initialSize() const;
0077     QQmlContext *rootContext() const;
0078     QQuickItem *rootObject() const;
0079     QUrl source() const;
0080     QQmlComponent::Status status() const;
0081     ResizeMode resizeMode() const;
0082     void setResizeMode(ResizeMode);
0083 
0084 protected:
0085     void resizeEvent(QResizeEvent *e) override;
0086 
0087 public Q_SLOTS:
0088     void setSource(const QUrl &url);
0089 
0090 Q_SIGNALS:
0091     void statusChanged(QQmlComponent::Status status);
0092     void resizeModeChanged(QuickViewSharedEngine::ResizeMode resizeMode);
0093     void sourceChanged(const QUrl &source);
0094 
0095 private:
0096     const std::unique_ptr<QuickViewSharedEnginePrivate> d;
0097 
0098     Q_PRIVATE_SLOT(d, void executionFinished())
0099     Q_PRIVATE_SLOT(d, void syncWidth())
0100     Q_PRIVATE_SLOT(d, void syncHeight())
0101 };
0102 
0103 }
0104 
0105 #endif // QuickViewSharedEngine_H