// SPDX-FileCopyrightText: Nheko Contributors // // SPDX-License-Identifier: GPL-3.0-or-later #pragma once #include #include #include #include #include #include class NhekoMenuVisibilityFilter : public QObject , public QQmlPropertyValueSource { Q_OBJECT Q_INTERFACES(QQmlPropertyValueSource) Q_CLASSINFO("DefaultProperty", "items") Q_PROPERTY(QQmlListProperty items READ items CONSTANT FINAL) Q_PROPERTY(QQmlComponent *delegate MEMBER delegate FINAL) Q_PROPERTY(QVariantList model MEMBER model FINAL) QML_ELEMENT public: NhekoMenuVisibilityFilter(QObject *parent = nullptr) : QObject(parent) { } QQmlListProperty items(); void setTarget(const QQmlProperty &prop) override; private: QQmlProperty targetProperty; QList items_; QQmlComponent *delegate = nullptr; QVariantList model; static void appendItem(QQmlListProperty *, QQmlComponent *); static qsizetype itemCount(QQmlListProperty *); static QQmlComponent *getItem(QQmlListProperty *, qsizetype index); static void clearItems(QQmlListProperty *); static void replaceItem(QQmlListProperty *, qsizetype index, QQmlComponent *); static void removeLast(QQmlListProperty *); public slots: // call this before showing the menu. We don't want to update elsewhere to prevent jumping menus // and useless work void updateTarget(); };