File indexing completed on 2025-03-09 05:02:43
0001 /* 0002 SPDX-FileCopyrightText: 2023 David Edmundson <davidedmundson@kde.org> 0003 SPDX-License-Identifier: LGPL-2.0-or-later 0004 */ 0005 0006 #pragma once 0007 0008 #include "plasmawindow.h" 0009 0010 #include <QQuickItem> 0011 #include <plasmaquick/plasmaquick_export.h> 0012 0013 namespace PlasmaQuick 0014 { 0015 class PopupPlasmaWindowPrivate; 0016 0017 /** 0018 * @brief The PopupPlasmaWindow class is a styled Plasma window that can be positioned 0019 * relative to an existing Item on another window. When shown the popup is placed correctly. 0020 * 0021 * On Wayland this is currently an XdgTopLevel with the PlasmaShellSurface used on top. 0022 * Do not rely on that implementation detail 0023 */ 0024 class PLASMAQUICK_EXPORT PopupPlasmaWindow : public PlasmaWindow 0025 { 0026 Q_OBJECT 0027 0028 /** 0029 * The anchor item to place the popup relative to. 0030 */ 0031 Q_PROPERTY(QQuickItem *visualParent READ visualParent WRITE setVisualParent NOTIFY visualParentChanged) 0032 0033 /** 0034 * Defines the default direction to place the popup relative to the visualParent. 0035 */ 0036 Q_PROPERTY(Qt::Edge popupDirection READ popupDirection WRITE setPopupDirection NOTIFY popupDirectionChanged) 0037 0038 /** 0039 * Defines the direction the popup was placed relative to the visualParent. 0040 * This property is read-only and is updated when the popup is shown. 0041 * The value whilst the popup is hidden is undefined. 0042 */ 0043 Q_PROPERTY(Qt::Edge effectivePopupDirection READ effectivePopupDirection NOTIFY effectivePopupDirectionChanged) 0044 0045 /** 0046 * Defines whether the popup can appaer (float) over the parent window. The default is false. 0047 */ 0048 Q_PROPERTY(bool floating READ floating WRITE setFloating NOTIFY floatingChanged) 0049 0050 /** 0051 * Defines whether the popup is animated on show and close. The default is false. 0052 */ 0053 Q_PROPERTY(bool animated READ animated WRITE setAnimated NOTIFY animatedChanged) 0054 0055 /** 0056 * Defines which borders should be enabled/disabled when the popup is shown. The default is to show all borders 0057 */ 0058 Q_PROPERTY(RemoveBorders removeBorderStrategy READ removeBorderStrategy WRITE setRemoveBorderStrategy NOTIFY removeBorderStrategyChanged) 0059 0060 /** 0061 * If set provides a gap between the parent window and all screen edges 0062 */ 0063 Q_PROPERTY(int margin READ margin WRITE setMargin NOTIFY marginChanged) 0064 0065 public: 0066 enum RemoveBorder { Never = 0x0, AtScreenEdges = 0x1, AtPanelEdges = 0x2 }; 0067 Q_DECLARE_FLAGS(RemoveBorders, RemoveBorder) 0068 Q_ENUM(RemoveBorder); 0069 0070 PopupPlasmaWindow(const QString &svgPrefix = QStringLiteral("dialogs/background")); 0071 ~PopupPlasmaWindow() override; 0072 QQuickItem *visualParent() const; 0073 void setVisualParent(QQuickItem *parent); 0074 0075 Qt::Edge popupDirection() const; 0076 void setPopupDirection(Qt::Edge popupDirection); 0077 0078 Qt::Edge effectivePopupDirection() const; 0079 0080 bool floating() const; 0081 void setFloating(bool floating); 0082 0083 bool animated() const; 0084 void setAnimated(bool animated); 0085 0086 RemoveBorders removeBorderStrategy() const; 0087 void setRemoveBorderStrategy(RemoveBorders borders); 0088 0089 int margin() const; 0090 void setMargin(int margin); 0091 0092 bool event(QEvent *event) override; 0093 0094 Q_SIGNALS: 0095 void visualParentChanged(); 0096 void popupDirectionChanged(); 0097 void effectivePopupDirectionChanged(); 0098 void floatingChanged(); 0099 void animatedChanged(); 0100 void removeBorderStrategyChanged(); 0101 void marginChanged(); 0102 0103 protected Q_SLOTS: 0104 void queuePositionUpdate(); 0105 0106 private: 0107 Q_PRIVATE_SLOT(d, void updateVisualParentWindow()) 0108 0109 friend class PopupPlasmaWindowPrivate; 0110 const std::unique_ptr<PopupPlasmaWindowPrivate> d; 0111 }; 0112 0113 Q_DECLARE_OPERATORS_FOR_FLAGS(PopupPlasmaWindow::RemoveBorders) 0114 }