Skip to content

Commit

Permalink
fix: adjust switchbutton dci icon (#603)
Browse files Browse the repository at this point in the history
adjust switchbutton dci icon

Log:
  • Loading branch information
Whale107 authored and deepin-bot[bot] committed Sep 23, 2024
1 parent 6cfb9ab commit b968087
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 14 deletions.
Binary file modified src/widgets/assets/icons/bloom/switch_off.dci
Binary file not shown.
Binary file modified src/widgets/assets/icons/bloom/switch_on.dci
Binary file not shown.
14 changes: 1 addition & 13 deletions src/widgets/dswitchbutton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,10 @@
#include <DGuiApplicationHelper>

#include <QApplication>
#include <QTimer>

DWIDGET_BEGIN_NAMESPACE

constexpr int DCI_ICON_SIZE = 120;
constexpr int TIMER_INTERVAL = 200;

/*!
@~english
Expand Down Expand Up @@ -63,7 +61,7 @@ void DSwitchButton::paintEvent(QPaintEvent *e)
painter.drawControl(DStyle::CE_SwitchButton, opt);

painter.setRenderHint(QPainter::SmoothPixmapTransform);
painter.drawImage(rect().adjusted(2, -10, -2, 8), d->player.currentImage()); // 为了显示按钮的阴影所留的空白
painter.drawImage(rect().adjusted(4, -8, -4, 8), d->player.currentImage()); // 为了显示按钮的阴影所留的空白
}

/*!
Expand Down Expand Up @@ -98,7 +96,6 @@ void DSwitchButton::initStyleOption(DStyleOptionButton *option) const

DSwitchButtonPrivate::DSwitchButtonPrivate(DSwitchButton *qq)
: DObjectPrivate(qq)
, timer(new QTimer(qq))
{

}
Expand All @@ -113,7 +110,6 @@ void DSwitchButtonPrivate::init()
checked = false;
animationStartValue = 0;
animationEndValue = 1;
timer->setInterval(TIMER_INTERVAL);

D_Q(DSwitchButton);

Expand Down Expand Up @@ -143,7 +139,6 @@ void DSwitchButtonPrivate::init()
DDciIcon icon = checked ? DDciIcon::fromTheme("switch_on") : DDciIcon::fromTheme("switch_off");
player.setIcon(icon);
player.play(DDciIcon::Mode::Normal);
timer->start();

Q_EMIT q->checkedChanged(checked);
});
Expand All @@ -152,13 +147,6 @@ void DSwitchButtonPrivate::init()
q->update();
});

q->connect(timer, &QTimer::timeout, q, [q, this]() {
player.stop();
player.setIcon(!q->isChecked() ? DDciIcon::fromTheme("switch_on") : DDciIcon::fromTheme("switch_off"));
player.setMode(DDciIcon::Normal);
timer->stop();
});

q->connect(DGuiApplicationHelper::instance(), &DGuiApplicationHelper::themeTypeChanged, q, initPlayer);
}

Expand Down
1 change: 0 additions & 1 deletion src/widgets/private/dswitchbutton_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ class DSwitchButtonPrivate : public DTK_CORE_NAMESPACE::DObjectPrivate
double animationEndValue = 0.0;

DDciIconPlayer player;
QTimer *timer;

public:
D_DECLARE_PUBLIC(DSwitchButton)
Expand Down

0 comments on commit b968087

Please sign in to comment.