File indexing completed on 2024-04-21 05:31:18

0001 /*
0002     SPDX-FileCopyrightText: 2020 Michail Vourlakos <mvourlakos@gmail.com>
0003     SPDX-License-Identifier: GPL-2.0-or-later
0004 */
0005 
0006 #ifndef LATTEDIALOG_H
0007 #define LATTEDIALOG_H
0008 
0009 // Qt
0010 #include <QEvent>
0011 #include <QObject>
0012 
0013 #include <QMetaObject>
0014 
0015 #include <array>
0016 
0017 // Plasma
0018 #include <Plasma>
0019 #include <PlasmaQuick/Dialog>
0020 
0021 namespace Latte {
0022 namespace Quick {
0023 
0024 class Dialog : public PlasmaQuick::Dialog {
0025     Q_OBJECT
0026     Q_PROPERTY (bool containsMouse READ containsMouse NOTIFY containsMouseChanged)
0027 
0028     //! it is used instead of location property in order to not break borders drawing
0029     Q_PROPERTY(Plasma::Types::Location edge READ edge WRITE setEdge NOTIFY edgeChanged)
0030 
0031 public:
0032     explicit Dialog(QQuickItem *parent = nullptr);
0033 
0034     bool containsMouse() const;
0035 
0036     Plasma::Types::Location edge() const;
0037     void setEdge(const Plasma::Types::Location &edge);
0038 
0039     QPoint popupPosition(QQuickItem *item, const QSize &size) override;
0040 
0041 signals:
0042     void containsMouseChanged();
0043     void edgeChanged();
0044 
0045 protected:
0046   //  void adjustGeometry(const QRect &geom) override;
0047 
0048     bool event(QEvent *e) override;
0049 
0050 private slots:
0051     void setContainsMouse(bool contains);
0052     void updatePopUpEnabledBorders();
0053 
0054     void onVisualParentChanged();
0055     void updateGeometry();
0056 
0057 private:
0058     bool isRespectingAppletsLayoutGeometry() const;
0059     QRect appletsLayoutGeometryFromContainment() const;
0060 
0061     int appletsPopUpMargin() const;
0062 
0063 private:
0064     bool m_containsMouse{false};
0065 
0066     Plasma::Types::Location m_edge{Plasma::Types::BottomEdge};
0067 
0068     std::array<QMetaObject::Connection, 2> m_visualParentConnections;
0069 
0070 };
0071 
0072 }
0073 }
0074 
0075 #endif