Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion src/core/region.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ void PendingRegion::setItem(QQuickItem* item) {

if (this->mItem != nullptr) {
QObject::disconnect(this->mItem, nullptr, this, nullptr);
this->disconnectParentChain();
}

this->mItem = item;
Expand All @@ -42,15 +43,41 @@ void PendingRegion::setItem(QQuickItem* item) {
QObject::connect(this->mItem, &QQuickItem::yChanged, this, &PendingRegion::itemChanged);
QObject::connect(this->mItem, &QQuickItem::widthChanged, this, &PendingRegion::itemChanged);
QObject::connect(this->mItem, &QQuickItem::heightChanged, this, &PendingRegion::itemChanged);
this->connectParentChain(item);
}

emit this->itemChanged();
}

void PendingRegion::onItemDestroyed() { this->mItem = nullptr; }
void PendingRegion::onItemDestroyed() {
this->mItem = nullptr;
this->disconnectParentChain();
}

void PendingRegion::onChildDestroyed() { this->mRegions.removeAll(this->sender()); }

void PendingRegion::connectParentChain(QQuickItem* item) {
this->disconnectParentChain();

auto* parent = item->parentItem();
while (parent != nullptr) {
this->mParentConnections.push_back(
QObject::connect(parent, &QQuickItem::xChanged, this, &PendingRegion::itemChanged)
);
this->mParentConnections.push_back(
QObject::connect(parent, &QQuickItem::yChanged, this, &PendingRegion::itemChanged)
);
parent = parent->parentItem();
}
}

void PendingRegion::disconnectParentChain() {
for (const auto& connection: this->mParentConnections) {
QObject::disconnect(connection);
}
this->mParentConnections.clear();
}

qint32 PendingRegion::radius() const { return this->mRadius; }

void PendingRegion::setRadius(qint32 radius) {
Expand Down
4 changes: 4 additions & 0 deletions src/core/region.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,9 @@ private slots:
static void
regionsReplace(QQmlListProperty<PendingRegion>* prop, qsizetype i, PendingRegion* region);

void connectParentChain(QQuickItem* item);
void disconnectParentChain();

enum CornerOverride : quint8 {
TopLeft = 0b1,
TopRight = 0b10,
Expand All @@ -198,4 +201,5 @@ private slots:
quint8 mCornerOverrides = 0;

QList<PendingRegion*> mRegions;
QList<QMetaObject::Connection> mParentConnections;
};
Loading