From 30d5fce355f68cb5a4c5cf456ff34427bfa15234 Mon Sep 17 00:00:00 2001 From: deepin-ci-robot Date: Thu, 8 Aug 2024 11:35:49 +0000 Subject: [PATCH] sync: from linuxdeepin/dtkgui Synchronize source files from linuxdeepin/dtkgui. Source-pull-request: https://github.com/linuxdeepin/dtkgui/pull/249 --- examples/animation-dci/main.cpp | 27 +++++++++++++++++++++++ include/kernel/dplatformhandle.h | 37 +++++++++++++++++++++++++++++++- src/kernel/dplatformhandle.cpp | 22 +++++++++++++++++++ src/util/ddciiconplayer.cpp | 2 +- 4 files changed, 86 insertions(+), 2 deletions(-) diff --git a/examples/animation-dci/main.cpp b/examples/animation-dci/main.cpp index cc8a534..20999f6 100644 --- a/examples/animation-dci/main.cpp +++ b/examples/animation-dci/main.cpp @@ -16,9 +16,12 @@ #include #include #include +#include #include #include +#include +#include DGUI_USE_NAMESPACE @@ -46,6 +49,7 @@ class IconWidget : public QMainWindow IconWidget(const QString &iconName) { setCentralWidget(label = new QLabel(this)); + label->setAcceptDrops(true); centralWidget()->setAttribute(Qt::WA_MouseTracking); centralWidget()->installEventFilter(this); statusBar()->addWidget(message = new QLabel()); @@ -66,12 +70,21 @@ class IconWidget : public QMainWindow connect(disabled, &QPushButton::clicked, this, [this] { player.setMode(DDciIcon::Disabled); }); + + auto open = new QPushButton("..."); + connect(open, &QPushButton::clicked, this, [this] { + QString dciFile = QFileDialog::getOpenFileName(this, "select a dci icon file", "", "*.dci"); + player.setIcon(DDciIcon(dciFile)); + player.setMode(DDciIcon::Normal); + }); + QWidget *menuWidget = new QWidget(this); QHBoxLayout *layout = new QHBoxLayout(menuWidget); layout->addWidget(normal); layout->addWidget(hover); layout->addWidget(pressed); layout->addWidget(disabled); + layout->addWidget(open); setMenuWidget(menuWidget); icon = DDciIcon::fromTheme(iconName); @@ -112,6 +125,20 @@ class IconWidget : public QMainWindow player.setMode(DDciIcon::Pressed); } else if (event->type() == QEvent::MouseButtonRelease) { player.setMode(label->hasMouseTracking() ? DDciIcon::Hover : DDciIcon::Normal); + } else if (event->type() == QEvent::DragEnter) { + event->accept(); + } else if (event->type() == QEvent::Drop) { + auto de = static_cast(event); + if (de->mimeData()->hasFormat("text/uri-list")) { + QString uris = de->mimeData()->data("text/uri-list"); + QUrl url(uris.split("\r\n").value(0)); + + DDciIcon icon(url.path()); + if (!icon.isNull()) { + player.setIcon(icon); + player.setMode(DDciIcon::Normal); + } + } } else { return false; } diff --git a/include/kernel/dplatformhandle.h b/include/kernel/dplatformhandle.h index b851002..a9a8ab4 100644 --- a/include/kernel/dplatformhandle.h +++ b/include/kernel/dplatformhandle.h @@ -30,6 +30,8 @@ class DPlatformHandle : public QObject Q_PROPERTY(int shadowRadius READ shadowRadius WRITE setShadowRadius NOTIFY shadowRadiusChanged) Q_PROPERTY(QPoint shadowOffset READ shadowOffset WRITE setShadowOffset NOTIFY shadowOffsetChanged) Q_PROPERTY(QColor shadowColor READ shadowColor WRITE setShadowColor NOTIFY shadowColorChanged) + Q_PROPERTY(EffectScene windowEffect READ windowEffect WRITE setWindowEffect NOTIFY windowEffectChanged) + Q_PROPERTY(EffectType windowStartUpEffect READ windowStartUpEffect WRITE setWindowStartUpEffect NOTIFY windowStartUpEffectChanged) Q_PROPERTY(QPainterPath clipPath READ clipPath WRITE setClipPath NOTIFY clipPathChanged) Q_PROPERTY(QRegion frameMask READ frameMask WRITE setFrameMask NOTIFY frameMaskChanged) Q_PROPERTY(QMargins frameMargins READ frameMargins NOTIFY frameMarginsChanged) @@ -72,6 +74,30 @@ class DPlatformHandle : public QObject PreserveAspectFit = 0x00000001 }; + enum EffectScene { + EffectNoRadius = 0x01, // 取消窗口圆角 + EffectNoShadow = 0x02, // 取消窗口阴影 + EffectNoBorder = 0x04, // 取消窗口边框 + EffectNoStart = 0x10, // 取消启动场景动效 + EffectNoClose = 0x20, // 取消关闭场景动效 + EffectNoMaximize = 0x40, // 取消最大化场景动效 + EffectNoMinimize = 0x80 // 取消最小化场景动效 + }; + + enum EffectType { + EffectNormal = 0x01, // 标准缩放动效 + EffectCursor = 0x02, // 鼠标位置展开动效 + EffectTop = 0x04, // 从上往下展开 + EffectBottom = 0x08 // 从下往上展开 + }; + + Q_ENUM(EffectScene) + Q_ENUM(EffectType) + Q_DECLARE_FLAGS(EffectScenes, EffectScene) + Q_DECLARE_FLAGS(EffectTypes, EffectType) + Q_ENUM(EffectScenes) + Q_ENUM(EffectTypes) + static bool setWindowBlurAreaByWM(QWindow *window, const QVector &area); static bool setWindowBlurAreaByWM(QWindow *window, const QList &paths); static bool setWindowWallpaperParaByWM(QWindow *window, const QRect &area, WallpaperScaleMode sMode, WallpaperFillMode fMode); @@ -92,6 +118,9 @@ class DPlatformHandle : public QObject QPoint shadowOffset() const; QColor shadowColor() const; + EffectScene windowEffect(); + EffectType windowStartUpEffect(); + QPainterPath clipPath() const; QRegion frameMask() const; QMargins frameMargins() const; @@ -107,10 +136,12 @@ class DPlatformHandle : public QObject public Q_SLOTS: void setWindowRadius(int windowRadius); - void setBorderWidth(int borderWidth); void setBorderColor(const QColor &borderColor); + void setWindowEffect(EffectScenes effectScene); + void setWindowStartUpEffect(EffectTypes effectType); + void setShadowRadius(int shadowRadius); void setShadowOffset(const QPoint &shadowOffset); void setShadowColor(const QColor &shadowColor); @@ -132,6 +163,8 @@ public Q_SLOTS: void shadowRadiusChanged(); void shadowOffsetChanged(); void shadowColorChanged(); + void windowEffectChanged(); + void windowStartUpEffectChanged(); void clipPathChanged(); void frameMaskChanged(); void translucentBackgroundChanged(); @@ -173,5 +206,7 @@ Q_DECLARE_METATYPE(QPainterPath) Q_DECLARE_METATYPE(QMargins) #endif Q_DECLARE_METATYPE(QRegion) +Q_DECLARE_OPERATORS_FOR_FLAGS(DPlatformHandle::EffectScenes) +Q_DECLARE_OPERATORS_FOR_FLAGS(DPlatformHandle::EffectTypes) #endif // DPLATFORMHANDLE_H diff --git a/src/kernel/dplatformhandle.cpp b/src/kernel/dplatformhandle.cpp index 0fac22e..04ec80e 100644 --- a/src/kernel/dplatformhandle.cpp +++ b/src/kernel/dplatformhandle.cpp @@ -25,6 +25,8 @@ DEFINE_CONST_CHAR(netWmStates); DEFINE_CONST_CHAR(windowRadius); DEFINE_CONST_CHAR(borderWidth); DEFINE_CONST_CHAR(borderColor); +DEFINE_CONST_CHAR(windowEffect); +DEFINE_CONST_CHAR(windowStartUpEffect); DEFINE_CONST_CHAR(shadowRadius); DEFINE_CONST_CHAR(shadowOffset); DEFINE_CONST_CHAR(shadowColor); @@ -1088,6 +1090,16 @@ QColor DPlatformHandle::shadowColor() const return qvariant_cast(m_window->property(_shadowColor)); } +DPlatformHandle::EffectScene DPlatformHandle::windowEffect() +{ + return qvariant_cast(m_window->property(_windowEffect)); +} + +DPlatformHandle::EffectType DPlatformHandle::windowStartUpEffect() +{ + return qvariant_cast(m_window->property(_windowStartUpEffect)); +} + QPainterPath DPlatformHandle::clipPath() const { return qvariant_cast(m_window->property(_clipPath)); @@ -1164,6 +1176,16 @@ void DPlatformHandle::setBorderColor(const QColor &borderColor) setWindowProperty(m_window, _borderColor, QVariant::fromValue(borderColor)); } +void DPlatformHandle::setWindowEffect(DPlatformHandle::EffectScenes effectScene) +{ + setWindowProperty(m_window, _windowEffect, static_cast(effectScene)); +} + +void DPlatformHandle::setWindowStartUpEffect(DPlatformHandle::EffectTypes effectType) +{ + setWindowProperty(m_window, _windowStartUpEffect, static_cast(effectType)); +} + void DPlatformHandle::setShadowRadius(int shadowRadius) { setWindowProperty(m_window, _shadowRadius, shadowRadius); diff --git a/src/util/ddciiconplayer.cpp b/src/util/ddciiconplayer.cpp index 82741f2..e0cb347 100644 --- a/src/util/ddciiconplayer.cpp +++ b/src/util/ddciiconplayer.cpp @@ -692,7 +692,7 @@ bool DDciIconPlayerPrivate::ensureHoverModeLastImage() } if (!image.atEnd()) return false; - Q_ASSERT(!player); + Q_ASSERT(player); hoverModeLastImage = image.toImage(player->palette()); return !hoverModeLastImage.isNull(); }