@@ -36,10 +36,13 @@ class ScreencopyView: public QQuickItem {
3636 Q_PROPERTY (bool hasContent READ default NOTIFY hasContentChanged BINDABLE bindableHasContent);
3737 // / The size of the source image. Valid when @@hasContent is true.
3838 Q_PROPERTY (QSize sourceSize READ default NOTIFY sourceSizeChanged BINDABLE bindableSourceSize);
39+ // / If nonzero, the width and height constraints set for this property will constrain those
40+ // / dimensions of the ScreencopyView's implicit size, maintaining the image's aspect ratio.
41+ Q_PROPERTY (QSizeF constraintSize READ default WRITE default NOTIFY constraintSizeChanged BINDABLE bindableConstraintSize);
3942 // clang-format on
4043
4144public:
42- explicit ScreencopyView (QQuickItem* parent = nullptr ): QQuickItem(parent) {}
45+ explicit ScreencopyView (QQuickItem* parent = nullptr );
4346
4447 void componentComplete () override ;
4548
@@ -57,6 +60,7 @@ class ScreencopyView: public QQuickItem {
5760
5861 [[nodiscard]] QBindable<bool > bindableHasContent () { return &this ->bHasContent ; }
5962 [[nodiscard]] QBindable<QSize> bindableSourceSize () { return &this ->bSourceSize ; }
63+ [[nodiscard]] QBindable<QSizeF> bindableConstraintSize () { return &this ->bConstraintSize ; }
6064
6165signals:
6266 // / The compositor has ended the video stream. Attempting to restart it may or may not work.
@@ -67,6 +71,7 @@ class ScreencopyView: public QQuickItem {
6771 void liveChanged ();
6872 void hasContentChanged ();
6973 void sourceSizeChanged ();
74+ void constraintSizeChanged ();
7075
7176protected:
7277 QSGNode* updatePaintNode (QSGNode* oldNode, UpdatePaintNodeData* data) override ;
@@ -80,10 +85,13 @@ private slots:
8085private:
8186 void destroyContext (bool update = true );
8287 void createContext ();
88+ void updateImplicitSize ();
8389
8490 // clang-format off
8591 Q_OBJECT_BINDABLE_PROPERTY (ScreencopyView, bool , bHasContent, &ScreencopyView::hasContentChanged);
8692 Q_OBJECT_BINDABLE_PROPERTY (ScreencopyView, QSize, bSourceSize, &ScreencopyView::sourceSizeChanged);
93+ Q_OBJECT_BINDABLE_PROPERTY (ScreencopyView, QSizeF, bConstraintSize, &ScreencopyView::constraintSizeChanged);
94+ Q_OBJECT_BINDABLE_PROPERTY (ScreencopyView, QSizeF, bImplicitSize, &ScreencopyView::updateImplicitSize);
8795 // clang-format on
8896
8997 QObject* mCaptureSource = nullptr ;
0 commit comments