File indexing completed on 2025-01-12 05:01:30

0001 /*
0002     SPDX-FileCopyrightText: 2016 Kai Uwe Broulik <kde@privat.broulik.de>
0003 
0004     SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0005 */
0006 
0007 #pragma once
0008 
0009 #include <Plasma/Applet>
0010 
0011 #include <QAbstractItemModel>
0012 #include <QPointer>
0013 
0014 class QQuickItem;
0015 class QMenu;
0016 
0017 class AppMenuApplet : public Plasma::Applet
0018 {
0019     Q_OBJECT
0020 
0021     Q_PROPERTY(QObject *containment READ containment CONSTANT)
0022     Q_PROPERTY(QAbstractItemModel *model READ model WRITE setModel NOTIFY modelChanged)
0023 
0024     Q_PROPERTY(int view READ view WRITE setView NOTIFY viewChanged)
0025 
0026     Q_PROPERTY(int currentIndex READ currentIndex NOTIFY currentIndexChanged)
0027 
0028     Q_PROPERTY(QQuickItem *buttonGrid READ buttonGrid WRITE setButtonGrid NOTIFY buttonGridChanged)
0029 
0030 public:
0031     enum ViewType {
0032         FullView,
0033         CompactView,
0034     };
0035 
0036     explicit AppMenuApplet(QObject *parent, const KPluginMetaData &data, const QVariantList &args);
0037     ~AppMenuApplet() override;
0038 
0039     void init() override;
0040 
0041     int currentIndex() const;
0042 
0043     QQuickItem *buttonGrid() const;
0044     void setButtonGrid(QQuickItem *buttonGrid);
0045 
0046     QAbstractItemModel *model() const;
0047     void setModel(QAbstractItemModel *model);
0048 
0049     int view() const;
0050     void setView(int type);
0051 
0052 Q_SIGNALS:
0053     void modelChanged();
0054     void viewChanged();
0055     void currentIndexChanged();
0056     void buttonGridChanged();
0057     void requestActivateIndex(int index);
0058 
0059 public Q_SLOTS:
0060     void trigger(QQuickItem *ctx, int idx);
0061 
0062 protected:
0063     bool eventFilter(QObject *watched, QEvent *event) override;
0064 
0065 private:
0066     QMenu *createMenu(int idx) const;
0067     void setCurrentIndex(int currentIndex);
0068     void onMenuAboutToHide();
0069 
0070     int m_currentIndex = -1;
0071     int m_viewType = FullView;
0072     QPointer<QMenu> m_currentMenu;
0073     QPointer<QQuickItem> m_buttonGrid;
0074     QPointer<QAbstractItemModel> m_model;
0075     static int s_refs;
0076 };