Skip to content

Commit

Permalink
sync: from linuxdeepin/dtkwidget
Browse files Browse the repository at this point in the history
Synchronize source files from linuxdeepin/dtkwidget.

Source-pull-request: linuxdeepin/dtkwidget#607
  • Loading branch information
deepin-ci-robot authored and FeiWang1119 committed Sep 26, 2024
1 parent e3c9426 commit d88429a
Show file tree
Hide file tree
Showing 10 changed files with 6 additions and 120 deletions.
15 changes: 2 additions & 13 deletions include/widgets/dtoolbutton.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,23 @@
#ifndef DTOOLBUTTON_H
#define DTOOLBUTTON_H

#include <dtkwidget_global.h>

#include <QToolButton>

#include <DDciIcon>
#include <DDciIconPlayer>
#include <dtkwidget_global.h>

DWIDGET_BEGIN_NAMESPACE
DGUI_USE_NAMESPACE

class DToolButtonPrivate;
class LIBDTKWIDGETSHARED_EXPORT DToolButton : public QToolButton, public DCORE_NAMESPACE::DObject
class LIBDTKWIDGETSHARED_EXPORT DToolButton : public QToolButton
{
Q_OBJECT
public:
DToolButton(QWidget *parent = nullptr);
void setAlignment(Qt::Alignment flag);
Qt::Alignment alignment() const;
void setDciIcon(const DDciIcon &dciIcon);

protected:
void paintEvent(QPaintEvent *event) override;
void initStyleOption(QStyleOptionToolButton *option) const;
QSize sizeHint() const override;
bool event(QEvent *e) override;

private:
D_DECLARE_PRIVATE(DToolButton)
};

DWIDGET_END_NAMESPACE
Expand Down
Binary file removed src/widgets/assets/icons/bloom/checkbox_checked.dci
Binary file not shown.
Binary file not shown.
Binary file removed src/widgets/assets/icons/bloom/radio_checked.dci
Binary file not shown.
Binary file removed src/widgets/assets/icons/bloom/radio_unchecked.dci
Binary file not shown.
4 changes: 0 additions & 4 deletions src/widgets/assets/icons/dtk-icon-theme.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,5 @@
<file alias="window_normal.dci">bloom/window_normal.dci</file>
<file alias="switch_on.dci">bloom/switch_on.dci</file>
<file alias="switch_off.dci">bloom/switch_off.dci</file>
<file alias="radio_checked.dci">bloom/radio_checked.dci</file>
<file alias="radio_unchecked.dci">bloom/radio_unchecked.dci</file>
<file alias="checkbox_checked.dci">bloom/checkbox_checked.dci</file>
<file alias="checkbox_unchecked.dci">bloom/checkbox_unchecked.dci</file>
</qresource>
</RCC>
2 changes: 1 addition & 1 deletion src/widgets/dbounceanimation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ bool DBounceAnimation::eventFilter(QObject *o, QEvent *e)
if (auto absscroll = dynamic_cast<QAbstractScrollArea *>(o)) {
if (auto wheelEvent = dynamic_cast<QWheelEvent *>(e)) {
if (absscroll->verticalScrollBar()->value() <= 0 || absscroll->verticalScrollBar()->value() >= absscroll->verticalScrollBar()->maximum()) {
d->m_deltaSum += wheelEvent->pixelDelta().x() != 0 ? wheelEvent->pixelDelta().x() : wheelEvent->pixelDelta().y();
d->m_deltaSum += wheelEvent->delta();
bounceBack(wheelEvent->angleDelta().x() == 0 ? Qt::Vertical : Qt::Horizontal);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/widgets/dmessagemanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class ImageLabel : public QLabel {
QPainter p(this);
p.setRenderHint(QPainter::Antialiasing);
p.setOpacity(m_opacity);
p.drawPixmap(rect().marginsRemoved(contentsMargins()), pixmap(Qt::ReturnByValue));
p.drawPixmap(rect().marginsRemoved(contentsMargins()), *pixmap());
};
private:
qreal m_opacity;
Expand Down
77 changes: 2 additions & 75 deletions src/widgets/dtoolbutton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,13 @@
//
// SPDX-License-Identifier: LGPL-3.0-or-later

#include "private/dtoolbutton_p.h"

#include <DGuiApplicationHelper>
#include <DStyle>
#include "dtoolbutton.h"

#include <QStyleOptionButton>
#include <QStylePainter>
#include <QEvent>
#include <QDebug>
#include <QKeyEvent>

DWIDGET_BEGIN_NAMESPACE

Dtk::Widget::DToolButtonPrivate::DToolButtonPrivate(DToolButton *qq)
: DObjectPrivate(qq)
{

}

/*!
@~english
@class Dtk::Widget::DToolButton
Expand All @@ -29,15 +17,8 @@ Dtk::Widget::DToolButtonPrivate::DToolButtonPrivate(DToolButton *qq)

DToolButton::DToolButton(QWidget *parent)
: QToolButton(parent)
, DObject(*new DToolButtonPrivate(this))
{
D_D(DToolButton);
connect(this, &DToolButton::pressed, this, [d]() {
d->m_dciPlayer.play(DDciIcon::Pressed);
});
connect(this, &DToolButton::released, this, [d]() {
d->m_dciPlayer.play(DDciIcon::Normal);
});

}

/*!
Expand All @@ -49,26 +30,10 @@ DToolButton::DToolButton(QWidget *parent)

void DToolButton::paintEvent(QPaintEvent *event)
{
D_D(DToolButton);
Q_UNUSED(event)
QStylePainter p(this);
QStyleOptionToolButton opt;
initStyleOption(&opt);

if (!d->m_dciIcon.isNull()) {
p.setRenderHint(QPainter::SmoothPixmapTransform);
p.drawImage(rect(), d->m_dciPlayer.currentImage());

if (opt.state & QStyle::State_HasFocus) {
p.setPen(QPen(palette().highlight().color(), 2));
p.setBrush(Qt::NoBrush);
p.setRenderHint(QPainter::Antialiasing);
int radius = DStyle::pixelMetric(style(), DStyle::PM_FrameRadius);
p.drawRoundedRect(opt.rect.marginsRemoved(QMargins(1, 1, 1, 1)), radius, radius);
}
return;
}

p.drawComplexControl(QStyle::CC_ToolButton, opt);
}

Expand All @@ -95,26 +60,6 @@ QSize DToolButton::sizeHint() const
return QToolButton::sizeHint();
}

bool DToolButton::event(QEvent *e)
{
D_D(DToolButton);
if (d->m_dciIcon.isNull())
return QToolButton::event(e);

if (e->type() == QEvent::WindowActivate) {
auto palette = DDciIconPalette::fromQPalette(this->palette());
d->m_dciPlayer.setPalette(palette);
d->m_dciPlayer.setTheme(DGuiApplicationHelper::instance()->themeType() == DGuiApplicationHelper::DarkType
? DDciIcon::Dark : DDciIcon::Light);
d->m_dciPlayer.setMode(DDciIcon::Normal);
} else if (e->type() == QEvent::HoverEnter) {
d->m_dciPlayer.play(DDciIcon::Hover);
} else if (e->type() == QEvent::HoverLeave) {
d->m_dciPlayer.play(DDciIcon::Normal);
}
return QToolButton::event(e);
}

/*!
@~english
@fn void DToolButton::setAlignment(Qt::Alignment flag)
Expand All @@ -140,22 +85,4 @@ Qt::Alignment DToolButton::alignment() const
return Qt::AlignLeft;
}

void DToolButton::setDciIcon(const DDciIcon &dciIcon)
{
D_D(DToolButton);
d->m_dciIcon = dciIcon;
d->m_dciPlayer.setIcon(dciIcon);
d->m_dciPlayer.setIconSize(120);

connect(&d->m_dciPlayer, &DDciIconPlayer::updated, this, [this]() {
update();
});

connect(DGuiApplicationHelper::instance(), &DGuiApplicationHelper::themeTypeChanged, this, [this, d](DGuiApplicationHelper::ColorType colorType) {
auto palette = DDciIconPalette::fromQPalette(this->palette());
d->m_dciPlayer.setPalette(palette);
d->m_dciPlayer.setTheme(colorType ? DDciIcon::Dark : DDciIcon::Light);
});
}

DWIDGET_END_NAMESPACE
26 changes: 0 additions & 26 deletions src/widgets/private/dtoolbutton_p.h

This file was deleted.

0 comments on commit d88429a

Please sign in to comment.