wayland/screencopy: add constrained implicitSize for ScreencopyView

This commit is contained in:
outfoxxed 2025-05-25 20:36:38 -07:00
parent 7390ae28e4
commit 05ed9ff74c
No known key found for this signature in database
GPG key ID: 4C88A185FB89301E
2 changed files with 32 additions and 1 deletions

View file

@ -1,5 +1,6 @@
#include "view.hpp"
#include <qnamespace.h>
#include <qobject.h>
#include <qqmlinfo.h>
#include <qquickitem.h>
@ -12,6 +13,23 @@
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) {
if (captureSource == this->mCaptureSource) return;
auto hadContext = this->context != nullptr;
@ -148,4 +166,9 @@ QSGNode* ScreencopyView::updatePaintNode(QSGNode* oldNode, UpdatePaintNodeData*
return node;
}
void ScreencopyView::updateImplicitSize() {
auto size = this->bImplicitSize.value();
this->setImplicitSize(size.width(), size.height());
}
} // namespace qs::wayland::screencopy