Libplasma

popupplasmawindow.h
1/*
2 SPDX-FileCopyrightText: 2023 David Edmundson <davidedmundson@kde.org>
3 SPDX-License-Identifier: LGPL-2.0-or-later
4*/
5
6#pragma once
7
8#include "plasmawindow.h"
9
10#include <QQuickItem>
11#include <plasmaquick/plasmaquick_export.h>
12
13namespace PlasmaQuick
14{
15class PopupPlasmaWindowPrivate;
16
17/**
18 * @brief The PopupPlasmaWindow class is a styled Plasma window that can be positioned
19 * relative to an existing Item on another window. When shown the popup is placed correctly.
20 *
21 * On Wayland this is currently an XdgTopLevel with the PlasmaShellSurface used on top.
22 * Do not rely on that implementation detail
23 */
24class PLASMAQUICK_EXPORT PopupPlasmaWindow : public PlasmaWindow
25{
27
28 /**
29 * The anchor item to place the popup relative to.
30 */
31 Q_PROPERTY(QQuickItem *visualParent READ visualParent WRITE setVisualParent NOTIFY visualParentChanged)
32
33 /**
34 * Defines the default direction to place the popup relative to the visualParent.
35 */
36 Q_PROPERTY(Qt::Edge popupDirection READ popupDirection WRITE setPopupDirection NOTIFY popupDirectionChanged)
37
38 /**
39 * Defines the direction the popup was placed relative to the visualParent.
40 * This property is read-only and is updated when the popup is shown.
41 * The value whilst the popup is hidden is undefined.
42 */
43 Q_PROPERTY(Qt::Edge effectivePopupDirection READ effectivePopupDirection NOTIFY effectivePopupDirectionChanged)
44
45 /**
46 * Defines whether the popup can appaer (float) over the parent window. The default is false.
47 */
48 Q_PROPERTY(bool floating READ floating WRITE setFloating NOTIFY floatingChanged)
49
50 /**
51 * Defines whether the popup is animated on show and close. The default is false.
52 */
53 Q_PROPERTY(bool animated READ animated WRITE setAnimated NOTIFY animatedChanged)
54
55 /**
56 * Defines which borders should be enabled/disabled when the popup is shown. The default is to show all borders
57 */
58 Q_PROPERTY(RemoveBorders removeBorderStrategy READ removeBorderStrategy WRITE setRemoveBorderStrategy NOTIFY removeBorderStrategyChanged)
59
60 /**
61 * If set provides a gap between the parent window and all screen edges
62 */
63 Q_PROPERTY(int margin READ margin WRITE setMargin NOTIFY marginChanged)
64
65public:
66 enum RemoveBorder { Never = 0x0, AtScreenEdges = 0x1, AtPanelEdges = 0x2 };
67 Q_DECLARE_FLAGS(RemoveBorders, RemoveBorder)
68 Q_ENUM(RemoveBorder);
69
70 PopupPlasmaWindow(const QString &svgPrefix = QStringLiteral("dialogs/background"));
71 ~PopupPlasmaWindow() override;
72 QQuickItem *visualParent() const;
73 void setVisualParent(QQuickItem *parent);
74
75 Qt::Edge popupDirection() const;
76 void setPopupDirection(Qt::Edge popupDirection);
77
78 Qt::Edge effectivePopupDirection() const;
79
80 bool floating() const;
81 void setFloating(bool floating);
82
83 bool animated() const;
84 void setAnimated(bool animated);
85
86 RemoveBorders removeBorderStrategy() const;
87 void setRemoveBorderStrategy(RemoveBorders borders);
88
89 int margin() const;
90 void setMargin(int margin);
91
92 bool event(QEvent *event) override;
93
94 // Popups that have positive margin won't be directly touching
95 // any screen edge or panel, so they will not have disabled borders.
96 // However, knowing which borders the margin leans on is still
97 // useful, as an example, to correctly set the resize handle edges.
98 Qt::Edges nearbyBorders() const;
99
100Q_SIGNALS:
101 void visualParentChanged();
102 void popupDirectionChanged();
103 void effectivePopupDirectionChanged();
104 void floatingChanged();
105 void animatedChanged();
106 void removeBorderStrategyChanged();
107 void marginChanged();
108 void nearbyBordersChanged();
109
110protected Q_SLOTS:
111 void queuePositionUpdate();
112
113private:
114 Q_PRIVATE_SLOT(d, void updateVisualParentWindow())
115
116 friend class PopupPlasmaWindowPrivate;
117 const std::unique_ptr<PopupPlasmaWindowPrivate> d;
118};
119
120Q_DECLARE_OPERATORS_FOR_FLAGS(PopupPlasmaWindow::RemoveBorders)
121}
The PopupPlasmaWindow class is a styled Plasma window that can be positioned relative to an existing ...
Qt::Edge effectivePopupDirection
Defines the direction the popup was placed relative to the visualParent.
Qt::Edge popupDirection
Defines the default direction to place the popup relative to the visualParent.
QQuickItem * visualParent
The anchor item to place the popup relative to.
bool animated
Defines whether the popup is animated on show and close.
bool floating
Defines whether the popup can appaer (float) over the parent window.
RemoveBorders removeBorderStrategy
Defines which borders should be enabled/disabled when the popup is shown.
int margin
If set provides a gap between the parent window and all screen edges.
The EdgeEventForwarder class This class forwards edge events to be replayed within the given margin T...
Definition action.h:20
Q_OBJECTQ_OBJECT
Q_PROPERTY(...)
This file is part of the KDE documentation.
Documentation copyright © 1996-2025 The KDE developers.
Generated on Fri Jan 24 2025 11:48:23 by doxygen 1.13.2 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.