forked from quickshell/quickshell
		
	wayland/screencopy: add constrained implicitSize for ScreencopyView
This commit is contained in:
		
							parent
							
								
									7390ae28e4
								
							
						
					
					
						commit
						05ed9ff74c
					
				
					 2 changed files with 32 additions and 1 deletions
				
			
		| 
						 | 
					@ -1,5 +1,6 @@
 | 
				
			||||||
#include "view.hpp"
 | 
					#include "view.hpp"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <qnamespace.h>
 | 
				
			||||||
#include <qobject.h>
 | 
					#include <qobject.h>
 | 
				
			||||||
#include <qqmlinfo.h>
 | 
					#include <qqmlinfo.h>
 | 
				
			||||||
#include <qquickitem.h>
 | 
					#include <qquickitem.h>
 | 
				
			||||||
| 
						 | 
					@ -12,6 +13,23 @@
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace qs::wayland::screencopy {
 | 
					namespace qs::wayland::screencopy {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					ScreencopyView::ScreencopyView(QQuickItem* parent): QQuickItem(parent) {
 | 
				
			||||||
 | 
						this->bImplicitSize.setBinding([this] {
 | 
				
			||||||
 | 
							auto constraint = this->bConstraintSize.value();
 | 
				
			||||||
 | 
							auto size = this->bSourceSize.value().toSizeF();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if (constraint.width() != 0 && constraint.height() != 0) {
 | 
				
			||||||
 | 
								size.scale(constraint.width(), constraint.height(), Qt::KeepAspectRatio);
 | 
				
			||||||
 | 
							} else if (constraint.width() != 0) {
 | 
				
			||||||
 | 
								size = QSizeF(constraint.width(), size.height() / constraint.width());
 | 
				
			||||||
 | 
							} else if (constraint.height() != 0) {
 | 
				
			||||||
 | 
								size = QSizeF(size.width() / constraint.height(), constraint.height());
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							return size;
 | 
				
			||||||
 | 
						});
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void ScreencopyView::setCaptureSource(QObject* captureSource) {
 | 
					void ScreencopyView::setCaptureSource(QObject* captureSource) {
 | 
				
			||||||
	if (captureSource == this->mCaptureSource) return;
 | 
						if (captureSource == this->mCaptureSource) return;
 | 
				
			||||||
	auto hadContext = this->context != nullptr;
 | 
						auto hadContext = this->context != nullptr;
 | 
				
			||||||
| 
						 | 
					@ -148,4 +166,9 @@ QSGNode* ScreencopyView::updatePaintNode(QSGNode* oldNode, UpdatePaintNodeData*
 | 
				
			||||||
	return node;
 | 
						return node;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void ScreencopyView::updateImplicitSize() {
 | 
				
			||||||
 | 
						auto size = this->bImplicitSize.value();
 | 
				
			||||||
 | 
						this->setImplicitSize(size.width(), size.height());
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
} // namespace qs::wayland::screencopy
 | 
					} // namespace qs::wayland::screencopy
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -36,10 +36,13 @@ class ScreencopyView: public QQuickItem {
 | 
				
			||||||
	Q_PROPERTY(bool hasContent READ default NOTIFY hasContentChanged BINDABLE bindableHasContent);
 | 
						Q_PROPERTY(bool hasContent READ default NOTIFY hasContentChanged BINDABLE bindableHasContent);
 | 
				
			||||||
	/// The size of the source image. Valid when @@hasContent is true.
 | 
						/// The size of the source image. Valid when @@hasContent is true.
 | 
				
			||||||
	Q_PROPERTY(QSize sourceSize READ default NOTIFY sourceSizeChanged BINDABLE bindableSourceSize);
 | 
						Q_PROPERTY(QSize sourceSize READ default NOTIFY sourceSizeChanged BINDABLE bindableSourceSize);
 | 
				
			||||||
 | 
						/// If nonzero, the width and height constraints set for this property will constrain those
 | 
				
			||||||
 | 
						/// dimensions of the ScreencopyView's implicit size, maintaining the image's aspect ratio.
 | 
				
			||||||
 | 
						Q_PROPERTY(QSizeF constraintSize READ default WRITE default NOTIFY constraintSizeChanged BINDABLE bindableConstraintSize);
 | 
				
			||||||
	// clang-format on
 | 
						// clang-format on
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public:
 | 
					public:
 | 
				
			||||||
	explicit ScreencopyView(QQuickItem* parent = nullptr): QQuickItem(parent) {}
 | 
						explicit ScreencopyView(QQuickItem* parent = nullptr);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	void componentComplete() override;
 | 
						void componentComplete() override;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -57,6 +60,7 @@ public:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	[[nodiscard]] QBindable<bool> bindableHasContent() { return &this->bHasContent; }
 | 
						[[nodiscard]] QBindable<bool> bindableHasContent() { return &this->bHasContent; }
 | 
				
			||||||
	[[nodiscard]] QBindable<QSize> bindableSourceSize() { return &this->bSourceSize; }
 | 
						[[nodiscard]] QBindable<QSize> bindableSourceSize() { return &this->bSourceSize; }
 | 
				
			||||||
 | 
						[[nodiscard]] QBindable<QSizeF> bindableConstraintSize() { return &this->bConstraintSize; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
signals:
 | 
					signals:
 | 
				
			||||||
	/// The compositor has ended the video stream. Attempting to restart it may or may not work.
 | 
						/// The compositor has ended the video stream. Attempting to restart it may or may not work.
 | 
				
			||||||
| 
						 | 
					@ -67,6 +71,7 @@ signals:
 | 
				
			||||||
	void liveChanged();
 | 
						void liveChanged();
 | 
				
			||||||
	void hasContentChanged();
 | 
						void hasContentChanged();
 | 
				
			||||||
	void sourceSizeChanged();
 | 
						void sourceSizeChanged();
 | 
				
			||||||
 | 
						void constraintSizeChanged();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
protected:
 | 
					protected:
 | 
				
			||||||
	QSGNode* updatePaintNode(QSGNode* oldNode, UpdatePaintNodeData* data) override;
 | 
						QSGNode* updatePaintNode(QSGNode* oldNode, UpdatePaintNodeData* data) override;
 | 
				
			||||||
| 
						 | 
					@ -80,10 +85,13 @@ private slots:
 | 
				
			||||||
private:
 | 
					private:
 | 
				
			||||||
	void destroyContext(bool update = true);
 | 
						void destroyContext(bool update = true);
 | 
				
			||||||
	void createContext();
 | 
						void createContext();
 | 
				
			||||||
 | 
						void updateImplicitSize();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// clang-format off
 | 
						// clang-format off
 | 
				
			||||||
	Q_OBJECT_BINDABLE_PROPERTY(ScreencopyView, bool, bHasContent, &ScreencopyView::hasContentChanged);
 | 
						Q_OBJECT_BINDABLE_PROPERTY(ScreencopyView, bool, bHasContent, &ScreencopyView::hasContentChanged);
 | 
				
			||||||
	Q_OBJECT_BINDABLE_PROPERTY(ScreencopyView, QSize, bSourceSize, &ScreencopyView::sourceSizeChanged);
 | 
						Q_OBJECT_BINDABLE_PROPERTY(ScreencopyView, QSize, bSourceSize, &ScreencopyView::sourceSizeChanged);
 | 
				
			||||||
 | 
						Q_OBJECT_BINDABLE_PROPERTY(ScreencopyView, QSizeF, bConstraintSize, &ScreencopyView::constraintSizeChanged);
 | 
				
			||||||
 | 
						Q_OBJECT_BINDABLE_PROPERTY(ScreencopyView, QSizeF, bImplicitSize, &ScreencopyView::updateImplicitSize);
 | 
				
			||||||
	// clang-format on
 | 
						// clang-format on
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	QObject* mCaptureSource = nullptr;
 | 
						QObject* mCaptureSource = nullptr;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue