File indexing completed on 2025-03-09 05:02:42

0001 /*
0002     SPDX-FileCopyrightText: 2011 Marco Martin <mart@kde.org>
0003     SPDX-FileCopyrightText: 2013 Sebastian Kügler <sebas@kde.org>
0004 
0005     SPDX-License-Identifier: GPL-2.0-or-later
0006 */
0007 #ifndef DIALOG_PROXY_P
0008 #define DIALOG_PROXY_P
0009 
0010 #include <QPoint>
0011 #include <QQmlParserStatus>
0012 #include <QQuickItem>
0013 #include <QQuickWindow>
0014 #include <QScopedPointer>
0015 
0016 #include <Plasma/Plasma>
0017 #include <Plasma/Theme>
0018 
0019 #include <netwm_def.h>
0020 
0021 #include <plasmaquick/plasmaquick_export.h>
0022 
0023 //
0024 //  W A R N I N G
0025 //  -------------
0026 //
0027 // This file is not part of the public Plasma API.  It exists purely as an
0028 // implementation detail.  This header file may change from version to
0029 // version without notice, or even be removed.
0030 //
0031 // We mean it.
0032 //
0033 
0034 class QQuickItem;
0035 class QScreen;
0036 
0037 namespace PlasmaQuick
0038 {
0039 class DialogPrivate;
0040 
0041 /**
0042  * Dialog creates a Plasma themed top level window that can contain any QML component.
0043  *
0044  * It can be automatically positioned relative to a visual parent
0045  * The dialog will resize to the size of the main item
0046  *
0047  * @code{.qml}
0048  *  import QtQuick 2.0
0049  *  import org.kde.plasma.core as PlasmaCore
0050  *  Item {
0051  *     PlasmaCore.Dialog {
0052  *          visible: true
0053  *          mainItem: Item {
0054  *              width: 500
0055  *              height: 500
0056  *
0057  *              Text {
0058  *                  anchors.centerIn: parent
0059  *                  color: "red"
0060  *                  text: "text"
0061  *              }
0062  *          }
0063  *      }
0064  * }
0065  * @endcode
0066  *
0067  * <b>Import Statement</b>
0068  * @code import org.kde.plasma.core @endcode
0069  * @version 2.0
0070  */
0071 class PLASMAQUICK_EXPORT Dialog : public QQuickWindow, public QQmlParserStatus
0072 {
0073     Q_OBJECT
0074     Q_INTERFACES(QQmlParserStatus)
0075 
0076     /**
0077      * The main QML item that will be displayed in the Dialog
0078      */
0079     Q_PROPERTY(QQuickItem *mainItem READ mainItem WRITE setMainItem NOTIFY mainItemChanged)
0080 
0081     /**
0082      * The main QML item that will be displayed in the Dialog
0083      */
0084     Q_PROPERTY(QQuickItem *visualParent READ visualParent WRITE setVisualParent NOTIFY visualParentChanged)
0085 
0086     /**
0087      * Margins of the dialog around the mainItem.
0088      * @see DialogMargins
0089      */
0090     Q_PROPERTY(QObject *margins READ margins CONSTANT)
0091 
0092     /**
0093      * Margins where the dialog background actually starts, excluiding things like shadows or borders
0094      * @see DialogMargins
0095      * @since 5.77
0096      */
0097     Q_PROPERTY(QObject *inset READ inset CONSTANT)
0098 
0099     /**
0100      * Plasma Location of the dialog window. Useful if this dialog is a popup for a panel
0101      */
0102     Q_PROPERTY(Plasma::Types::Location location READ location WRITE setLocation NOTIFY locationChanged)
0103 
0104     /**
0105      * Type of the window
0106      */
0107     Q_PROPERTY(WindowType type READ type WRITE setType NOTIFY typeChanged)
0108 
0109     /**
0110      * Whether the dialog should be hidden when the dialog loses focus.
0111      *
0112      * The default value is @c false.
0113      **/
0114     Q_PROPERTY(bool hideOnWindowDeactivate READ hideOnWindowDeactivate WRITE setHideOnWindowDeactivate NOTIFY hideOnWindowDeactivateChanged)
0115 
0116     /**
0117      * Whether the dialog is output only. Default value is @c false. If it is @c true
0118      * the dialog does not accept input and all pointer events are not accepted, thus the dialog
0119      * is click through.
0120      *
0121      * This property is currently only supported on the X11 platform. On any other platform the
0122      * property has no effect.
0123      **/
0124     Q_PROPERTY(bool outputOnly READ isOutputOnly WRITE setOutputOnly NOTIFY outputOnlyChanged)
0125 
0126     /**
0127      * This property holds the window flags of the window.
0128      * The window flags control the window's appearance in the windowing system,
0129      * whether it's a dialog, popup, or a regular window, and whether it should
0130      * have a title bar, etc.
0131      * Regardless to what the user sets, the flags will always have the
0132      * FramelessWindowHint flag set
0133      */
0134     Q_PROPERTY(Qt::WindowFlags flags READ flags WRITE setFramelessFlags NOTIFY flagsChanged)
0135 
0136     /**
0137      * This property holds how (and if at all) the dialog should draw its own background
0138      * or if it is complete responsibility of the content item to render a background.
0139      * Note that in case of NoBackground it loses kwin side shadows and blur
0140      */
0141     Q_PROPERTY(BackgroundHints backgroundHints READ backgroundHints WRITE setBackgroundHints NOTIFY backgroundHintsChanged)
0142 
0143     Q_PROPERTY(bool visible READ isVisible WRITE setVisible NOTIFY visibleChangedProxy)
0144 
0145     /**
0146      * This property holds by how much the applet should be floating even if the location
0147      * is set to a certain screen side; if this value is positive, the dialog will draw
0148      * all four sides and maintain the required distance from the screen borders.
0149      */
0150     Q_PROPERTY(int floating READ floating WRITE setFloating NOTIFY floatingChanged)
0151 
0152     /**
0153      * This property holds a pointer to the AppletInterface used by an applet. It is
0154      * null when the dialog is not used for an applet.
0155      */
0156     // TODO: plasmoidItem?
0157     Q_PROPERTY(QQuickItem *appletInterface READ appletInterface WRITE setAppletInterface NOTIFY appletInterfaceChanged)
0158 
0159     Q_CLASSINFO("DefaultProperty", "mainItem")
0160 
0161 public:
0162     enum WindowType {
0163         Normal = NET::Normal,
0164         Dock = NET::Dock,
0165         DialogWindow = NET::Dialog,
0166         PopupMenu = NET::PopupMenu,
0167         Tooltip = NET::Tooltip,
0168         Notification = NET::Notification,
0169         OnScreenDisplay = NET::OnScreenDisplay,
0170         CriticalNotification = NET::CriticalNotification,
0171         AppletPopup = NET::AppletPopup,
0172     };
0173     Q_ENUM(WindowType)
0174 
0175     enum BackgroundHints {
0176         NoBackground = 0, /**< Not drawing a background under the applet, the dialog has its own implementation */
0177         StandardBackground = 1, /**< The standard background from the theme is drawn */
0178         SolidBackground = 2, /**< The solid version of the background is preferred */
0179     };
0180     Q_ENUM(BackgroundHints)
0181 
0182     explicit Dialog(QQuickItem *parent = nullptr);
0183     ~Dialog() override;
0184 
0185     // PROPERTIES ACCESSORS
0186     QQuickItem *mainItem() const;
0187     void setMainItem(QQuickItem *mainItem);
0188 
0189     QQuickItem *visualParent() const;
0190     void setVisualParent(QQuickItem *visualParent);
0191 
0192     Plasma::Types::Location location() const;
0193     void setLocation(Plasma::Types::Location location);
0194 
0195     QObject *margins() const;
0196     QObject *inset() const;
0197 
0198     void setFramelessFlags(Qt::WindowFlags flags);
0199 
0200     void setType(WindowType type);
0201     WindowType type() const;
0202 
0203     bool hideOnWindowDeactivate() const;
0204     void setHideOnWindowDeactivate(bool hide);
0205 
0206     void setOutputOnly(bool outputOnly);
0207     bool isOutputOnly() const;
0208 
0209     BackgroundHints backgroundHints() const;
0210     void setBackgroundHints(BackgroundHints hints);
0211 
0212     bool isVisible() const;
0213     void setVisible(bool visible);
0214 
0215     int floating() const;
0216     void setFloating(int floating);
0217 
0218     QQuickItem *appletInterface() const;
0219     void setAppletInterface(QQuickItem *appletInterface);
0220 
0221     /**
0222      * @returns The suggested screen position for the popup
0223      * @param item the item the popup has to be positioned relatively to. if null, the popup will be positioned in the center of the window
0224      * @param size the size that the popup will have, which influences the final position
0225      */
0226     virtual QPoint popupPosition(QQuickItem *item, const QSize &size);
0227 
0228 Q_SIGNALS:
0229     void mainItemChanged();
0230     void locationChanged();
0231     void visualParentChanged();
0232     void typeChanged();
0233     void hideOnWindowDeactivateChanged();
0234     void outputOnlyChanged();
0235     void flagsChanged();
0236     void floatingChanged();
0237     void backgroundHintsChanged();
0238     void visibleChangedProxy(); // redeclaration of QQuickWindow::visibleChanged
0239     void appletInterfaceChanged();
0240     /**
0241      * Emitted when the @see hideOnWindowDeactivate property is @c true and this dialog lost focus to a
0242      * window that is neither a parent dialog to nor a child dialog of this dialog.
0243      */
0244     void windowDeactivated();
0245 
0246 protected:
0247     /**
0248      * set the dialog position. subclasses may change it. ToolTipDialog adjusts the position in an animated way
0249      */
0250     virtual void adjustGeometry(const QRect &geom);
0251 
0252     // Reimplementations
0253     void classBegin() override;
0254     void componentComplete() override;
0255     void resizeEvent(QResizeEvent *re) override;
0256     void focusInEvent(QFocusEvent *ev) override;
0257     void focusOutEvent(QFocusEvent *ev) override;
0258     void showEvent(QShowEvent *event) override;
0259     void hideEvent(QHideEvent *event) override;
0260     void moveEvent(QMoveEvent *) override;
0261     bool event(QEvent *event) override;
0262 
0263 private:
0264     friend class DialogPrivate;
0265     const QScopedPointer<DialogPrivate> d;
0266 
0267     Q_PRIVATE_SLOT(d, void updateTheme())
0268     Q_PRIVATE_SLOT(d, void updateVisibility(bool visible))
0269 
0270     Q_PRIVATE_SLOT(d, void updateMinimumWidth())
0271     Q_PRIVATE_SLOT(d, void updateMinimumHeight())
0272     Q_PRIVATE_SLOT(d, void updateMaximumWidth())
0273     Q_PRIVATE_SLOT(d, void updateMaximumHeight())
0274     Q_PRIVATE_SLOT(d, void updateLayoutParameters())
0275 
0276     Q_PRIVATE_SLOT(d, void slotMainItemSizeChanged())
0277 };
0278 
0279 }
0280 
0281 #endif