File indexing completed on 2024-12-08 13:21:57

0001 /*
0002     SPDX-FileCopyrightText: 2016 Martin Graesslin <mgraesslin@kde.org>
0003 
0004     SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0005 
0006 */
0007 
0008 #pragma once
0009 
0010 #include <KSharedConfig>
0011 #include <QObject>
0012 #include <memory>
0013 
0014 class QPropertyAnimation;
0015 class QTimer;
0016 class QQmlContext;
0017 class QQmlComponent;
0018 class QQmlEngine;
0019 
0020 namespace KWin
0021 {
0022 
0023 class OnScreenNotificationInputEventSpy;
0024 
0025 class OnScreenNotification : public QObject
0026 {
0027     Q_OBJECT
0028     Q_PROPERTY(bool visible READ isVisible WRITE setVisible NOTIFY visibleChanged)
0029     Q_PROPERTY(QString message READ message WRITE setMessage NOTIFY messageChanged)
0030     Q_PROPERTY(QString iconName READ iconName WRITE setIconName NOTIFY iconNameChanged)
0031     Q_PROPERTY(int timeout READ timeout WRITE setTimeout NOTIFY timeoutChanged)
0032 
0033 public:
0034     explicit OnScreenNotification(QObject *parent = nullptr);
0035     ~OnScreenNotification() override;
0036     bool isVisible() const;
0037     QString message() const;
0038     QString iconName() const;
0039     int timeout() const;
0040 
0041     QRect geometry() const;
0042 
0043     void setVisible(bool m_visible);
0044     void setMessage(const QString &message);
0045     void setIconName(const QString &iconName);
0046     void setTimeout(int timeout);
0047 
0048     void setConfig(KSharedConfigPtr config);
0049     void setEngine(QQmlEngine *engine);
0050 
0051     void setContainsPointer(bool contains);
0052     void setSkipCloseAnimation(bool skip);
0053 
0054 Q_SIGNALS:
0055     void visibleChanged();
0056     void messageChanged();
0057     void iconNameChanged();
0058     void timeoutChanged();
0059 
0060 private:
0061     void show();
0062     void ensureQmlContext();
0063     void ensureQmlComponent();
0064     void createInputSpy();
0065     bool m_visible = false;
0066     QString m_message;
0067     QString m_iconName;
0068     QTimer *m_timer;
0069     KSharedConfigPtr m_config;
0070     std::unique_ptr<QQmlContext> m_qmlContext;
0071     std::unique_ptr<QQmlComponent> m_qmlComponent;
0072     QQmlEngine *m_qmlEngine = nullptr;
0073     std::unique_ptr<QObject> m_mainItem;
0074     std::unique_ptr<OnScreenNotificationInputEventSpy> m_spy;
0075     QPropertyAnimation *m_animation = nullptr;
0076     bool m_containsPointer = false;
0077 };
0078 }