File indexing completed on 2025-02-09 06:41:24

0001 /*
0002     SPDX-FileCopyrightText: 2023 David Edmundson <davidedmundson@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #pragma once
0008 
0009 #include "popupplasmawindow.h"
0010 
0011 #include <QQuickItem>
0012 
0013 #include <plasmaquick/plasmaquick_export.h>
0014 
0015 namespace PlasmaQuick
0016 {
0017 
0018 class AppletQuickItem;
0019 class LayoutChangedProxy;
0020 
0021 /**
0022  * @brief The AppletPopup class shows a popup for an applet either in the panel or on the desktop
0023  *
0024  * In addition to the new API this class is resizable and can forward any input events recieved
0025  * on the margin to the main item
0026  *
0027  * Size hints are transferred from the mainItem's size hints.
0028  */
0029 class PLASMAQUICK_EXPORT AppletPopup : public PopupPlasmaWindow
0030 {
0031     Q_OBJECT
0032     /**
0033      * This property holds a pointer to the AppletInterface used by
0034      */
0035     Q_PROPERTY(QQuickItem *appletInterface READ appletInterface WRITE setAppletInterface NOTIFY appletInterfaceChanged)
0036 
0037     /**
0038      * Whether the dialog should be hidden when the dialog loses focus.
0039      *
0040      * The default value is @c false.
0041      **/
0042     Q_PROPERTY(bool hideOnWindowDeactivate READ hideOnWindowDeactivate WRITE setHideOnWindowDeactivate NOTIFY hideOnWindowDeactivateChanged)
0043 
0044 public:
0045     AppletPopup();
0046     ~AppletPopup() override;
0047     QQuickItem *appletInterface() const;
0048     void setAppletInterface(QQuickItem *appletInterface);
0049 
0050     bool hideOnWindowDeactivate() const;
0051     void setHideOnWindowDeactivate(bool hideOnWindowDeactivate);
0052 
0053 Q_SIGNALS:
0054     void appletInterfaceChanged();
0055     void hideOnWindowDeactivateChanged();
0056 
0057 protected:
0058     void hideEvent(QHideEvent *event) override;
0059     void focusOutEvent(QFocusEvent *event) override;
0060 
0061 private:
0062     void onMainItemChanged();
0063     void updateMinSize();
0064     void updateMaxSize();
0065     void updateSize();
0066 
0067     QPointer<AppletQuickItem> m_appletInterface;
0068     QPointer<QScreen> m_oldScreen;
0069     bool m_hideOnWindowDeactivate = false;
0070     bool m_sizeExplicitlySetFromConfig = false;
0071     QScopedPointer<LayoutChangedProxy> m_layoutChangedProxy;
0072 };
0073 
0074 }