quickshell/src/cpp/shell.cpp

58 lines
1.3 KiB
C++

#include "shell.hpp"
#include <utility>
#include <qlogging.h>
#include <qobject.h>
#include <qqmlcontext.h>
#include <qqmlengine.h>
#include <qqmllist.h>
#include "rootwrapper.hpp"
void QtShell::reload(bool hard) {
auto* rootobj = QQmlEngine::contextForObject(this)->engine()->parent();
auto* root = qobject_cast<RootWrapper*>(rootobj);
if (root == nullptr) {
qWarning() << "cannot find RootWrapper for reload, ignoring request";
return;
}
root->reloadGraph(hard);
}
void QtShell::earlyInit(QObject* old) {
auto* oldshell = qobject_cast<QtShell*>(old);
if (oldshell != nullptr) {
this->scavengeableChildren = std::move(oldshell->children);
}
}
QObject* QtShell::scavengeTargetFor(QObject* /* child */) {
if (this->scavengeableChildren.length() > this->children.length()) {
return this->scavengeableChildren[this->children.length()];
}
return nullptr;
}
QQmlListProperty<QObject> QtShell::components() {
return QQmlListProperty<QObject>(
this,
nullptr,
&QtShell::appendComponent,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr
);
}
void QtShell::appendComponent(QQmlListProperty<QObject>* list, QObject* component) {
auto* shell = static_cast<QtShell*>(list->object); // NOLINT
component->setParent(shell);
shell->children.append(component);
}