Skip to content

Commit 5ae8e49

Browse files
committed
core/window: move implicit width/height to bindable properties
1 parent cb195d4 commit 5ae8e49

File tree

2 files changed

+27
-16
lines changed

2 files changed

+27
-16
lines changed

src/window/proxywindow.cpp

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -300,25 +300,19 @@ qint32 ProxyWindowBase::y() const {
300300
else return this->window->y();
301301
}
302302

303-
qint32 ProxyWindowBase::implicitWidth() const { return this->mImplicitWidth; }
304-
305303
void ProxyWindowBase::setImplicitWidth(qint32 implicitWidth) {
306-
if (implicitWidth == this->mImplicitWidth) return;
307-
this->mImplicitWidth = implicitWidth;
308-
emit this->implicitWidthChanged();
304+
if (implicitWidth == this->bImplicitWidth) return;
305+
this->bImplicitWidth = implicitWidth;
309306

310307
if (this->window) this->trySetWidth(implicitWidth);
311308
else emit this->widthChanged();
312309
}
313310

314311
void ProxyWindowBase::trySetWidth(qint32 implicitWidth) { this->window->setWidth(implicitWidth); }
315312

316-
qint32 ProxyWindowBase::implicitHeight() const { return this->mImplicitHeight; }
317-
318313
void ProxyWindowBase::setImplicitHeight(qint32 implicitHeight) {
319-
if (implicitHeight == this->mImplicitHeight) return;
320-
this->mImplicitHeight = implicitHeight;
321-
emit this->implicitHeightChanged();
314+
if (implicitHeight == this->bImplicitHeight) return;
315+
this->bImplicitHeight = implicitHeight;
322316

323317
if (this->window) this->trySetHeight(implicitHeight);
324318
else emit this->heightChanged();

src/window/proxywindow.hpp

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <qevent.h>
66
#include <qnamespace.h>
77
#include <qobject.h>
8+
#include <qproperty.h>
89
#include <qqmllist.h>
910
#include <qqmlparserstatus.h>
1011
#include <qquickitem.h>
@@ -42,8 +43,8 @@ class ProxyWindowBase: public Reloadable {
4243
Q_PROPERTY(QQuickWindow* _backingWindow READ backingWindow);
4344
Q_PROPERTY(QQuickItem* contentItem READ contentItem CONSTANT);
4445
Q_PROPERTY(bool visible READ isVisible WRITE setVisible NOTIFY visibleChanged);
45-
Q_PROPERTY(qint32 implicitWidth READ implicitWidth WRITE setImplicitWidth NOTIFY implicitWidthChanged);
46-
Q_PROPERTY(qint32 implicitHeight READ implicitHeight WRITE setImplicitHeight NOTIFY implicitHeightChanged);
46+
Q_PROPERTY(qint32 implicitWidth READ implicitWidth WRITE setImplicitWidth NOTIFY implicitWidthChanged BINDABLE bindableImplicitWidth);
47+
Q_PROPERTY(qint32 implicitHeight READ implicitHeight WRITE setImplicitHeight NOTIFY implicitHeightChanged BINDABLE bindableImplicitHeight);
4748
Q_PROPERTY(qint32 width READ width WRITE setWidth NOTIFY widthChanged);
4849
Q_PROPERTY(qint32 height READ height WRITE setHeight NOTIFY heightChanged);
4950
Q_PROPERTY(qreal devicePixelRatio READ devicePixelRatio NOTIFY devicePixelRatioChanged);
@@ -94,11 +95,13 @@ class ProxyWindowBase: public Reloadable {
9495
[[nodiscard]] virtual qint32 x() const;
9596
[[nodiscard]] virtual qint32 y() const;
9697

97-
[[nodiscard]] qint32 implicitWidth() const;
98+
[[nodiscard]] qint32 implicitWidth() const { return this->bImplicitWidth; }
9899
void setImplicitWidth(qint32 implicitWidth);
100+
QBindable<qint32> bindableImplicitWidth() { return &this->bImplicitWidth; }
99101

100-
[[nodiscard]] qint32 implicitHeight() const;
102+
[[nodiscard]] qint32 implicitHeight() const { return this->bImplicitHeight; }
101103
void setImplicitHeight(qint32 implicitHeight);
104+
QBindable<qint32> bindableImplicitHeight() { return &this->bImplicitHeight; }
102105

103106
[[nodiscard]] virtual qint32 width() const;
104107
void setWidth(qint32 width);
@@ -158,8 +161,6 @@ protected slots:
158161

159162
protected:
160163
bool mVisible = true;
161-
qint32 mImplicitWidth = 100;
162-
qint32 mImplicitHeight = 100;
163164
QScreen* mScreen = nullptr;
164165
QColor mColor = Qt::white;
165166
PendingRegion* mMask = nullptr;
@@ -174,6 +175,22 @@ protected slots:
174175
bool inputMask : 1 = false;
175176
} pendingPolish;
176177

178+
Q_OBJECT_BINDABLE_PROPERTY_WITH_ARGS(
179+
ProxyWindowBase,
180+
qint32,
181+
bImplicitWidth,
182+
100,
183+
&ProxyWindowBase::implicitWidthChanged
184+
);
185+
186+
Q_OBJECT_BINDABLE_PROPERTY_WITH_ARGS(
187+
ProxyWindowBase,
188+
qint32,
189+
bImplicitHeight,
190+
100,
191+
&ProxyWindowBase::implicitHeightChanged
192+
);
193+
177194
private:
178195
void polishItems();
179196
void updateMask();

0 commit comments

Comments
 (0)