Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: [computer] item radius follows dcc setting. #1941

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#include <QGraphicsScene>
#include <QGraphicsPixmapItem>
#include <QGraphicsBlurEffect>
#include <QDBusInterface>
#include <QDBusConnection>

namespace dfmplugin_computer {

Expand Down Expand Up @@ -57,10 +59,15 @@

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<ComputerView *>(parent);
watchWindowRadius();
}

ComputerItemDelegate::~ComputerItemDelegate()
Expand Down Expand Up @@ -201,6 +208,16 @@
Qt::DirectConnection, Q_ARG(QWidget *, editor));
}

void ComputerItemDelegate::onAppearancePropertiesChanged(const QString &addr, const QVariantMap &properties, const QStringList &)

Check warning on line 211 in src/plugins/filemanager/core/dfmplugin-computer/delegate/computeritemdelegate.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

The function 'onAppearancePropertiesChanged' is never used.
{
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());
Expand All @@ -223,7 +240,7 @@
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;
Expand Down Expand Up @@ -258,7 +275,7 @@
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);
Expand Down Expand Up @@ -512,4 +529,16 @@
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 &)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 };
};

}
Expand Down
Loading