File indexing completed on 2024-04-28 05:35:58
0001 /* 0002 SPDX-FileCopyrightText: 2013 Marco Martin <mart@kde.org> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #pragma once 0008 0009 #include <optional> 0010 0011 #include <PlasmaQuick/ConfigView> 0012 #include <PlasmaQuick/ContainmentView> 0013 #include <QPointer> 0014 0015 #include <KConfigWatcher> 0016 0017 #include "config-workspace.h" 0018 0019 namespace LayerShellQt 0020 { 0021 class Window; 0022 } 0023 0024 class DesktopView : public PlasmaQuick::ContainmentView 0025 { 0026 Q_OBJECT 0027 0028 Q_PROPERTY(QVariantMap candidateContainments READ candidateContainmentsGraphicItems NOTIFY candidateContainmentsChanged) 0029 0030 /** 0031 * Whether the desktop is used in accent color extraction 0032 * 0033 * @note When usedInAccentColor becomes @c true, \Kirigami.ImageColors 0034 * will be loaded and update the accent color, and \setAccentColor will 0035 * be called 0036 */ 0037 Q_PROPERTY(bool usedInAccentColor READ usedInAccentColor NOTIFY usedInAccentColorChanged) 0038 0039 Q_PROPERTY(QColor accentColor READ accentColor WRITE setAccentColor RESET resetAccentColor NOTIFY accentColorChanged) 0040 0041 #if PROJECT_VERSION_PATCH >= 80 || PROJECT_VERSION_MINOR >= 80 0042 Q_PROPERTY(bool showPreviewBanner READ showPreviewBanner CONSTANT) 0043 Q_PROPERTY(QString previewBannerTitle READ previewBannerTitle CONSTANT) 0044 Q_PROPERTY(QString previewBannerText READ previewBannerText CONSTANT) 0045 #endif 0046 0047 public: 0048 explicit DesktopView(Plasma::Corona *corona, QScreen *targetScreen = nullptr); 0049 ~DesktopView() override; 0050 0051 /*This is different from screen() as is always there, even if the window is 0052 temporarily outside the screen or if is hidden: only plasmashell will ever 0053 change this property, unlike QWindow::screen()*/ 0054 void setScreenToFollow(QScreen *screen); 0055 QScreen *screenToFollow() const; 0056 0057 void adaptToScreen(); 0058 void showEvent(QShowEvent *) override; 0059 0060 bool usedInAccentColor() const; 0061 0062 QColor accentColor() const; 0063 void setAccentColor(const QColor &); 0064 void resetAccentColor(); 0065 0066 #if PROJECT_VERSION_PATCH >= 80 || PROJECT_VERSION_MINOR >= 80 0067 bool showPreviewBanner() const; 0068 QString previewBannerTitle() const; 0069 QString previewBannerText() const; 0070 #endif 0071 0072 QVariantMap candidateContainmentsGraphicItems() const; 0073 0074 Q_INVOKABLE QString fileFromPackage(const QString &key, const QString &fileName); 0075 0076 protected: 0077 bool event(QEvent *e) override; 0078 void keyPressEvent(QKeyEvent *e) override; 0079 0080 protected Q_SLOTS: 0081 /** 0082 * It will be called when the configuration is requested 0083 */ 0084 void showConfigurationInterface(Plasma::Applet *applet) override; 0085 0086 private Q_SLOTS: 0087 void slotContainmentChanged(); 0088 void slotScreenChanged(int newId); 0089 void screenGeometryChanged(); 0090 0091 Q_SIGNALS: 0092 void stayBehindChanged(); 0093 void candidateContainmentsChanged(); 0094 void geometryChanged(); 0095 void usedInAccentColorChanged(); 0096 void accentColorChanged(const QColor &accentColor); 0097 0098 private: 0099 void coronaPackageChanged(const KPackage::Package &package); 0100 void setAccentColorFromWallpaper(const QColor &accentColor); 0101 bool handleKRunnerTextInput(QKeyEvent *e); 0102 0103 std::optional<QColor> m_accentColor; 0104 QPointer<PlasmaQuick::ConfigView> m_configView; 0105 QPointer<QScreen> m_screenToFollow; 0106 LayerShellQt::Window *m_layerWindow = nullptr; 0107 QString m_krunnerText; 0108 0109 // KRunner config 0110 KConfigWatcher::Ptr m_configWatcher; 0111 bool m_activateKRunnerWhenTypingOnDesktop; 0112 0113 // Accent color config 0114 Plasma::Containment *m_containment = nullptr; 0115 int m_containmentScreenId = -1; 0116 };