File indexing completed on 2022-11-29 15:03:59

0001 /*
0002     SPDX-FileCopyrightText: 2022 Michail Vourlakos <mvourlakos@gmail.com>
0003     SPDX-License-Identifier: GPL-2.0-or-later
0004 */
0005 
0006 #ifndef CONTEXTMENULAYERQUICKITEM_H
0007 #define CONTEXTMENULAYERQUICKITEM_H
0008 
0009 // Qt
0010 #include <QEvent>
0011 #include <QMenu>
0012 #include <QMetaMethod>
0013 #include <QQuickItem>
0014 #include <QQuickView>
0015 #include <QPointer>
0016 #include <QMouseEvent>
0017 #include <QObject>
0018 
0019 // Plasma
0020 #include <Plasma>
0021 
0022 namespace Plasma {
0023 class Applet;
0024 class Containment;
0025 class Types;
0026 }
0027 
0028 namespace Latte {
0029 class View;
0030 }
0031 
0032 namespace Latte {
0033 
0034 class ContextMenuLayerQuickItem : public QQuickItem
0035 {
0036     Q_OBJECT
0037     Q_PROPERTY(bool menuIsShown READ menuIsShown NOTIFY menuChanged)
0038     Q_PROPERTY(QObject *view READ view WRITE setView NOTIFY viewChanged)
0039 
0040 public:
0041     ContextMenuLayerQuickItem(QQuickItem *parent = nullptr);
0042     ~ContextMenuLayerQuickItem() override;
0043 
0044     QObject *view() const;
0045     void setView(QObject *view);
0046 
0047     bool menuIsShown() const;
0048 
0049 signals:
0050     void menuChanged();
0051     void viewChanged();
0052 
0053 protected:
0054     void mousePressEvent(QMouseEvent *event) override;
0055     void mouseReleaseEvent(QMouseEvent *event) override;
0056 
0057 private slots:
0058     void onMenuAboutToHide();
0059 
0060 private:
0061     void addAppletActions(QMenu *desktopMenu, Plasma::Applet *applet, QEvent *event);
0062     void addContainmentActions(QMenu *desktopMenu, QEvent *event);
0063     void updateAppletContainsMethod();
0064 
0065     QPoint popUpRelevantToParent(const QRect &parentItem, const QRect popUpRect);
0066     QPoint popUpRelevantToGlobalPoint(const QRect &parentItem, const QRect popUpRect);
0067 
0068     QPoint popUpTopLeft(Plasma::Applet *applet, const QRect popUpRect);
0069 
0070     Plasma::Containment *containmentById(uint id);
0071 
0072 
0073 private:
0074     Plasma::Types::ItemStatus m_lastContainmentStatus;
0075 
0076     QPointer<QMenu> m_contextMenu;
0077     QMetaMethod m_appletContainsMethod;
0078     QQuickItem *m_appletContainsMethodItem{nullptr};
0079 
0080     Latte::View *m_latteView{nullptr};
0081 
0082     friend class Latte::View;
0083 };
0084 
0085 }
0086 
0087 #endif // DOCKMENUMANAGER_H