添加壁纸透明功能,为动态壁纸铺路

This commit is contained in:
柚子 2023-01-15 21:17:49 +08:00 committed by GitHub
parent 03f44ef7be
commit 821a05d067
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 15 additions and 5 deletions

View file

@ -41,6 +41,11 @@ QString DesktopSettings::wallpaper() const
return m_wallpaper; return m_wallpaper;
} }
bool DesktopSettings::backgroundVisible() const
{
return m_interface.property("backgroundVisible").toBool();
}
bool DesktopSettings::dimsWallpaper() const bool DesktopSettings::dimsWallpaper() const
{ {
return m_interface.property("darkModeDimsWallpaer").toBool(); return m_interface.property("darkModeDimsWallpaer").toBool();
@ -71,7 +76,7 @@ void DesktopSettings::init()
connect(&m_interface, SIGNAL(darkModeDimsWallpaerChanged()), this, SIGNAL(dimsWallpaperChanged())); connect(&m_interface, SIGNAL(darkModeDimsWallpaerChanged()), this, SIGNAL(dimsWallpaperChanged()));
connect(&m_interface, SIGNAL(backgroundTypeChanged()), this, SIGNAL(backgroundTypeChanged())); connect(&m_interface, SIGNAL(backgroundTypeChanged()), this, SIGNAL(backgroundTypeChanged()));
connect(&m_interface, SIGNAL(backgroundColorChanged()), this, SIGNAL(backgroundColorChanged())); connect(&m_interface, SIGNAL(backgroundColorChanged()), this, SIGNAL(backgroundColorChanged()));
connect(&m_interface, SIGNAL(backgroundVisibleChanged()), this, SIGNAL(backgroundVisibleChanged()));
m_wallpaper = m_interface.property("wallpaper").toString(); m_wallpaper = m_interface.property("wallpaper").toString();
emit wallpaperChanged(); emit wallpaperChanged();
} }

View file

@ -28,7 +28,7 @@ class DesktopSettings : public QObject
Q_OBJECT Q_OBJECT
Q_PROPERTY(QString wallpaper READ wallpaper NOTIFY wallpaperChanged) Q_PROPERTY(QString wallpaper READ wallpaper NOTIFY wallpaperChanged)
Q_PROPERTY(bool dimsWallpaper READ dimsWallpaper NOTIFY dimsWallpaperChanged) Q_PROPERTY(bool dimsWallpaper READ dimsWallpaper NOTIFY dimsWallpaperChanged)
Q_PROPERTY(bool backgroundVisible READ backgroundVisible NOTIFY backgroundVisibleChanged)
Q_PROPERTY(int backgroundType READ backgroundType NOTIFY backgroundTypeChanged) Q_PROPERTY(int backgroundType READ backgroundType NOTIFY backgroundTypeChanged)
Q_PROPERTY(QString backgroundColor READ backgroundColor NOTIFY backgroundColorChanged) Q_PROPERTY(QString backgroundColor READ backgroundColor NOTIFY backgroundColorChanged)
@ -37,7 +37,7 @@ public:
QString wallpaper() const; QString wallpaper() const;
bool dimsWallpaper() const; bool dimsWallpaper() const;
bool backgroundVisible() const;
int backgroundType() const; int backgroundType() const;
QString backgroundColor() const; QString backgroundColor() const;
@ -48,6 +48,7 @@ signals:
void dimsWallpaperChanged(); void dimsWallpaperChanged();
void backgroundColorChanged(); void backgroundColorChanged();
void backgroundTypeChanged(); void backgroundTypeChanged();
void backgroundVisibleChanged();
private slots: private slots:
void init(); void init();

View file

@ -35,12 +35,14 @@ DesktopView::DesktopView(QScreen *screen, QQuickView *parent)
, m_screen(screen) , m_screen(screen)
{ {
m_screenRect = m_screen->geometry(); m_screenRect = m_screen->geometry();
this->setFlag(Qt::FramelessWindowHint);
this->setColor(QColor(Qt::transparent));
KWindowSystem::setType(winId(), NET::Desktop); KWindowSystem::setType(winId(), NET::Desktop);
KWindowSystem::setState(winId(), NET::KeepBelow); KWindowSystem::setState(winId(), NET::KeepBelow);
engine()->rootContext()->setContextProperty("desktopView", this); engine()->rootContext()->setContextProperty("desktopView", this);
engine()->rootContext()->setContextProperty("Dock", DockDBusInterface::self()); engine()->rootContext()->setContextProperty("Dock", DockDBusInterface::self());
QWindow::fromWinId(winId())->setOpacity(0.99);
engine()->addImageProvider("thumbnailer", new ThumbnailProvider()); engine()->addImageProvider("thumbnailer", new ThumbnailProvider());
setTitle(tr("Desktop")); setTitle(tr("Desktop"));

View file

@ -26,6 +26,7 @@ Item {
Rectangle { Rectangle {
anchors.fill: parent anchors.fill: parent
visible: settings.backgroundVisible
color: settings.backgroundColor color: settings.backgroundColor
} }
} }
@ -39,6 +40,7 @@ Item {
height * Screen.devicePixelRatio) height * Screen.devicePixelRatio)
fillMode: Image.PreserveAspectCrop fillMode: Image.PreserveAspectCrop
clip: true clip: true
visible: settings.backgroundVisible
cache: false cache: false
// Clear cache // Clear cache