File indexing completed on 2024-12-08 08:02:45

0001 /*
0002     SPDX-FileCopyrightText: 2021 Kai Uwe Broulik <kde@broulik.de>
0003 
0004     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0005 */
0006 
0007 #pragma once
0008 
0009 #include <QObject>
0010 #include <QPointer>
0011 #include <QQmlParserStatus>
0012 
0013 class QAbstractItemModel;
0014 class QMenu;
0015 class QQuickItem;
0016 
0017 namespace QPulseAudio
0018 {
0019 class CardModel;
0020 class PulseObject;
0021 }
0022 
0023 class ListItemMenu : public QObject, public QQmlParserStatus
0024 {
0025     Q_OBJECT
0026     Q_INTERFACES(QQmlParserStatus)
0027 
0028     Q_PROPERTY(ItemType itemType READ itemType WRITE setItemType NOTIFY itemTypeChanged)
0029 
0030     Q_PROPERTY(QPulseAudio::PulseObject *pulseObject READ pulseObject WRITE setPulseObject NOTIFY pulseObjectChanged)
0031 
0032     Q_PROPERTY(QAbstractItemModel *sourceModel READ sourceModel WRITE setSourceModel NOTIFY sourceModelChanged)
0033 
0034     Q_PROPERTY(QPulseAudio::CardModel *cardModel READ cardModel WRITE setCardModel NOTIFY cardModelChanged)
0035 
0036     Q_PROPERTY(bool visible READ isVisible NOTIFY visibleChanged)
0037 
0038     Q_PROPERTY(bool hasContent READ hasContent NOTIFY hasContentChanged)
0039 
0040     Q_PROPERTY(QQuickItem *visualParent READ visualParent WRITE setVisualParent NOTIFY visualParentChanged)
0041 
0042 public:
0043     explicit ListItemMenu(QObject *parent = nullptr);
0044     ~ListItemMenu() override;
0045 
0046     enum ItemType {
0047         None,
0048         Sink,
0049         SinkInput,
0050         Source,
0051         SourceOutput,
0052     };
0053     Q_ENUM(ItemType)
0054 
0055     ItemType itemType() const;
0056     void setItemType(ItemType itemType);
0057     Q_SIGNAL void itemTypeChanged();
0058 
0059     QPulseAudio::PulseObject *pulseObject() const;
0060     void setPulseObject(QPulseAudio::PulseObject *pulseObject);
0061     Q_SIGNAL void pulseObjectChanged();
0062 
0063     QAbstractItemModel *sourceModel() const;
0064     void setSourceModel(QAbstractItemModel *sourceModel);
0065     Q_SIGNAL void sourceModelChanged();
0066 
0067     QPulseAudio::CardModel *cardModel() const;
0068     void setCardModel(QPulseAudio::CardModel *cardModel);
0069     Q_SIGNAL void cardModelChanged();
0070 
0071     bool isVisible() const;
0072     Q_SIGNAL void visibleChanged();
0073 
0074     bool hasContent() const;
0075     Q_SIGNAL void hasContentChanged();
0076 
0077     QQuickItem *visualParent() const;
0078     void setVisualParent(QQuickItem *visualParent);
0079     Q_SIGNAL void visualParentChanged();
0080 
0081     void classBegin() override;
0082     void componentComplete() override;
0083 
0084     Q_INVOKABLE void open(int x, int y);
0085     Q_INVOKABLE void openRelative();
0086 
0087 private:
0088     void setVisible(bool visible);
0089 
0090     void update();
0091     bool checkHasContent();
0092     QMenu *createMenu();
0093 
0094     bool m_complete = false;
0095     bool m_visible = false;
0096     bool m_hasContent = false;
0097     QPointer<QQuickItem> m_visualParent;
0098 
0099     ItemType m_itemType = None;
0100     QPointer<QPulseAudio::PulseObject> m_pulseObject;
0101     QPointer<QAbstractItemModel> m_sourceModel;
0102     QPointer<QPulseAudio::CardModel> m_cardModel;
0103 };