From c3cb02b86ae203aa01d587639d3a8fbdf970d073 Mon Sep 17 00:00:00 2001 From: xust Date: Fri, 12 Apr 2024 15:00:36 +0800 Subject: [PATCH] feat: [computer] item radius follows dcc setting. as title. Log: as title. --- .../delegate/computeritemdelegate.cpp | 33 +++++++++++++++++-- .../delegate/computeritemdelegate.h | 7 ++++ 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/src/plugins/filemanager/core/dfmplugin-computer/delegate/computeritemdelegate.cpp b/src/plugins/filemanager/core/dfmplugin-computer/delegate/computeritemdelegate.cpp index ebc4250a9f..2114eb37c5 100644 --- a/src/plugins/filemanager/core/dfmplugin-computer/delegate/computeritemdelegate.cpp +++ b/src/plugins/filemanager/core/dfmplugin-computer/delegate/computeritemdelegate.cpp @@ -19,6 +19,8 @@ #include #include #include +#include +#include namespace dfmplugin_computer { @@ -57,10 +59,15 @@ static int editorMarginTop(const QString &family) DWIDGET_USE_NAMESPACE +static constexpr char kAppearanceService[] = "com.deepin.daemon.Appearance"; +static constexpr char kAppearancePath[] = "/com/deepin/daemon/Appearance"; +static constexpr char kAppearanceInterface[] = "com.deepin.daemon.Appearance"; + ComputerItemDelegate::ComputerItemDelegate(QObject *parent) : QStyledItemDelegate(parent) { view = qobject_cast(parent); + watchWindowRadius(); } ComputerItemDelegate::~ComputerItemDelegate() @@ -201,6 +208,16 @@ void ComputerItemDelegate::closeEditor(ComputerView *view) Qt::DirectConnection, Q_ARG(QWidget *, editor)); } +void ComputerItemDelegate::onAppearancePropertiesChanged(const QString &addr, const QVariantMap &properties, const QStringList &) +{ + if (addr == kAppearanceService) { + if (properties.contains("WindowRadius")) { + windowRadius = properties.value("WindowRadius").toInt(); + view->update(); + } + } +} + void ComputerItemDelegate::paintSplitter(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const { QFont fnt(view->font()); @@ -223,7 +240,7 @@ void ComputerItemDelegate::paintSmallItem(QPainter *painter, const QStyleOptionV prepareColor(painter, option, index); // draw round rect - painter->drawRoundedRect(option.rect.adjusted(1, 1, -1, -1), 18, 18); + painter->drawRoundedRect(option.rect.adjusted(1, 1, -1, -1), windowRadius, windowRadius); const int IconSize = view->iconSize().width(); const int TopMargin = 16; @@ -258,7 +275,7 @@ void ComputerItemDelegate::paintLargeItem(QPainter *painter, const QStyleOptionV prepareColor(painter, option, index); // draw round rect - painter->drawRoundedRect(option.rect.adjusted(1, 1, -1, -1), 18, 18); + painter->drawRoundedRect(option.rect.adjusted(1, 1, -1, -1), windowRadius, windowRadius); drawDeviceIcon(painter, option, index); drawDeviceLabelAndFs(painter, option, index); @@ -512,4 +529,16 @@ QPixmap ComputerItemDelegate::renderBlurShadow(const QPixmap &pm, int blurRadius return ret; } +void ComputerItemDelegate::watchWindowRadius() +{ + QDBusInterface iface(kAppearanceService, kAppearancePath, kAppearanceInterface); + if (iface.isValid()) + windowRadius = iface.property("WindowRadius").toInt(); + QDBusConnection::sessionBus().connect(kAppearanceService, + kAppearancePath, + "org.freedesktop.DBus.Properties", + "PropertiesChanged", + this, + SLOT(onAppearancePropertiesChanged(const QString &, const QVariantMap &, const QStringList &))); +} } diff --git a/src/plugins/filemanager/core/dfmplugin-computer/delegate/computeritemdelegate.h b/src/plugins/filemanager/core/dfmplugin-computer/delegate/computeritemdelegate.h index 8fcc854a94..928ff88167 100644 --- a/src/plugins/filemanager/core/dfmplugin-computer/delegate/computeritemdelegate.h +++ b/src/plugins/filemanager/core/dfmplugin-computer/delegate/computeritemdelegate.h @@ -31,6 +31,9 @@ class ComputerItemDelegate : public QStyledItemDelegate void closeEditor(ComputerView *view); +private Q_SLOTS: + void onAppearancePropertiesChanged(const QString &, const QVariantMap &, const QStringList &); + private: void paintSplitter(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const; void paintCustomWidget(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const; @@ -45,10 +48,14 @@ class ComputerItemDelegate : public QStyledItemDelegate QPixmap renderBlurShadow(const QSize &sz, const QColor &color, int blurRadius) const; QPixmap renderBlurShadow(const QPixmap &pm, int blurRadius) const; + void watchWindowRadius(); + private: ComputerView *view { nullptr }; mutable QLineEdit *renameEditor { nullptr }; mutable QModelIndex editingIndex; + + int windowRadius { 18 }; }; }