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

sync: from linuxdeepin/dtkwidget #91

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
9 changes: 9 additions & 0 deletions include/widgets/dstyle.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@ QT_BEGIN_NAMESPACE
class QTextLayout;
QT_END_NAMESPACE

#define ENABLE_ANIMATIONS (!qEnvironmentVariableIsSet("DTK_DISABLE_ANIMATIONS"))
#define ENABLE_ANIMATION_BUTTONBOX (!qEnvironmentVariableIsSet("DTK_DISABLE_ANIMATION_BUTTONBOX"))
#define ENABLE_ANIMATION_MESSAGE (!qEnvironmentVariableIsSet("DTK_DISABLE_ANIMATION_MESSAGE"))
#define ENABLE_ANIMATION_LISTVIEWBOUNCE (!qEnvironmentVariableIsSet("DTK_DISABLE_ANIMATION_LISTVIREBOUNCE"))
#define ENABLE_ANIMATION_SEARCH (!qEnvironmentVariableIsSet("DTK_DISABLE_ANIMATION_SEARCH"))
#define ENABLE_ANIMATION_SWITCHBUTTON (!qEnvironmentVariableIsSet("DTK_DISABLE_ANIMATION_SWITCHBUTTON"))
#define ENABLE_ANIMATION_PROGRESSBAR (!qEnvironmentVariableIsSet("DTK_DISABLE_ANIMATION_PROGRESSBAR"))
#define ENABLE_ANIMATION_RADIOBUTTON (!qEnvironmentVariableIsSet("DTK_DISABLE_ANIMATION_RADIOBUTTON"))
#define ENABLE_ANIMATION_CHECKBOX (!qEnvironmentVariableIsSet("DTK_DISABLE_ANIMATION_CHECKBOX"))

DWIDGET_BEGIN_NAMESPACE

Expand Down
45 changes: 32 additions & 13 deletions src/widgets/dbuttonbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,10 @@ void DButtonBoxButton::paintEvent(QPaintEvent *e)
DStylePainter p(this);
DStyleOptionButtonBoxButton option;
initStyleOption(&option);
option.palette.setColor(QPalette::HighlightedText, this->palette().highlight().color());

if (ENABLE_ANIMATIONS && ENABLE_ANIMATION_BUTTONBOX)
option.palette.setColor(QPalette::HighlightedText, this->palette().highlight().color());

p.drawControl(DStyle::CE_ButtonBoxButton, option);
}

Expand Down Expand Up @@ -363,10 +366,13 @@ DButtonBoxPrivate::DButtonBoxPrivate(DButtonBox *qq)
, m_hoverId(-1)
, m_checkedId(-1)
, m_pressId(-1)
, m_hoverAnimation(new QVariantAnimation(qq))
, m_checkMoveAnimation(new QVariantAnimation(qq))
, m_hoverAnimation(nullptr)
, m_checkMoveAnimation(nullptr)
{

if (ENABLE_ANIMATIONS && ENABLE_ANIMATION_BUTTONBOX) {
m_hoverAnimation = new QVariantAnimation(qq);
m_checkMoveAnimation = new QVariantAnimation(qq);
}
}

void DButtonBoxPrivate::init()
Expand All @@ -380,14 +386,17 @@ void DButtonBoxPrivate::init()
q->connect(group, SIGNAL(buttonPressed(QAbstractButton*)), q, SIGNAL(buttonPressed(QAbstractButton*)));
q->connect(group, SIGNAL(buttonReleased(QAbstractButton*)), q, SIGNAL(buttonReleased(QAbstractButton*)));
q->connect(group, SIGNAL(buttonToggled(QAbstractButton*, bool)), q, SIGNAL(buttonToggled(QAbstractButton*, bool)));
q->connect(m_hoverAnimation, &QVariantAnimation::valueChanged, q, [q]() {
q->update();
});
q->connect(m_checkMoveAnimation, &QVariantAnimation::valueChanged, q, [q]() {
q->update();
});
m_hoverAnimation->setDuration(HOVER_ANI_DURATION);
m_checkMoveAnimation->setDuration(CHECK_ANI_DURATION);

if (ENABLE_ANIMATIONS && ENABLE_ANIMATION_BUTTONBOX) {
q->connect(m_hoverAnimation, &QVariantAnimation::valueChanged, q, [q]() {
q->update();
});
q->connect(m_checkMoveAnimation, &QVariantAnimation::valueChanged, q, [q]() {
q->update();
});
m_hoverAnimation->setDuration(HOVER_ANI_DURATION);
m_checkMoveAnimation->setDuration(CHECK_ANI_DURATION);
}

layout = new QHBoxLayout(q);
layout->setContentsMargins(0, 0, 0, 0);
Expand Down Expand Up @@ -506,7 +515,9 @@ void DButtonBox::setButtonList(const QList<DButtonBoxButton *> &list, bool check
d->group->addButton(button);

button->setCheckable(checkable);
button->installEventFilter(this);

if (ENABLE_ANIMATIONS && ENABLE_ANIMATION_BUTTONBOX)
button->installEventFilter(this);
}
}

Expand Down Expand Up @@ -616,6 +627,11 @@ void DButtonBox::paintEvent(QPaintEvent *e)
opt.state |= QStyle::State_Active;
}

if (!ENABLE_ANIMATIONS || !ENABLE_ANIMATION_BUTTONBOX) {
p.drawControl(QStyle::CE_PushButtonBevel, opt);
return;
}

bool isDarkType = DGuiApplicationHelper::instance()->themeType() == DGuiApplicationHelper::DarkType;
int radius = DStyle::pixelMetric(style(), DStyle::PM_FrameRadius);
QColor background;
Expand Down Expand Up @@ -706,6 +722,9 @@ void DButtonBox::paintEvent(QPaintEvent *e)

bool DButtonBox::eventFilter(QObject *o, QEvent *e)
{
if (!ENABLE_ANIMATIONS || !ENABLE_ANIMATION_BUTTONBOX)
return QWidget::eventFilter(o, e);

D_D(DButtonBox);
for (int i = 0; i < buttonList().size(); ++i) {
if (o == buttonList().at(i)) {
Expand Down
31 changes: 22 additions & 9 deletions src/widgets/dfloatingmessage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,23 @@ void DFloatingMessagePrivate::init()
iconButton->setIconSize(DSizeModeHelper::element(QSize(20, 20), QSize(30, 30)));

hBoxLayout->addWidget(iconButton);
hBoxLayout->addSpacing(10);

if (ENABLE_ANIMATIONS && ENABLE_ANIMATION_MESSAGE)
hBoxLayout->addSpacing(10);

hBoxLayout->addWidget(labMessage);

if (notifyType == DFloatingMessage::MessageType::TransientType) { //临时消息
timer = new QTimer(q);
timer->setInterval(4000);
timer->setSingleShot(true);
q->connect(timer, &QTimer::timeout, q, [q]() {
q->close();
Q_EMIT q->messageClosed();
});
if (ENABLE_ANIMATIONS && ENABLE_ANIMATION_MESSAGE)
q->connect(timer, &QTimer::timeout, q, [q]() {
q->close();
Q_EMIT q->messageClosed();
});
else
q->connect(timer, &QTimer::timeout, q, &DFloatingMessage::close);
} else { //常驻消息
content = nullptr;
closeButton = new DDialogCloseButton(q);
Expand All @@ -74,12 +80,19 @@ void DFloatingMessagePrivate::init()

hBoxLayout->addWidget(closeButton);
q->connect(closeButton, &DIconButton::clicked, q, &DFloatingMessage::closeButtonClicked);
q->connect(closeButton, &DIconButton::clicked, q, [q]() {
q->close();
Q_EMIT q->messageClosed();
});

if(ENABLE_ANIMATIONS && ENABLE_ANIMATION_MESSAGE)
q->connect(closeButton, &DIconButton::clicked, q, [q]() {
q->close();
Q_EMIT q->messageClosed();
});
else
q->connect(closeButton, &DIconButton::clicked, q, &DFloatingMessage::close);
}

if (!ENABLE_ANIMATIONS || !ENABLE_ANIMATION_MESSAGE)
return;

auto effect = new QGraphicsDropShadowEffect(q);
effect->setColor(QColor(0, 0, 0, 0.1 * 255));
effect->setBlurRadius(20);
Expand Down
23 changes: 19 additions & 4 deletions src/widgets/dindeterminateprogressbar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,26 @@ DIndeterminateProgressbarPrivate::DIndeterminateProgressbarPrivate(DIndeterminat
, m_sliderWidget(new QWidget(qq))
, m_timer(new QTimer(qq))
, m_leftToRight(true)
, m_spotWidget(new QWidget(qq))
, m_animation(new QPropertyAnimation(m_spotWidget, "pos", qq))
, m_spotWidget(nullptr)
, m_animation(nullptr)
{
if (!ENABLE_ANIMATIONS && !ENABLE_ANIMATION_PROGRESSBAR)
return;

m_spotWidget = new QWidget(qq);
m_animation = new QPropertyAnimation(m_spotWidget, "pos", qq);
}

DIndeterminateProgressbar::DIndeterminateProgressbar(QWidget *parent)
: QWidget(parent)
, DObject(*new DIndeterminateProgressbarPrivate(this))
{
D_D(DIndeterminateProgressbar);
d->m_spotWidget->setFixedSize(SPOT_WIDGET_WIDTH, height());
d->m_spotWidget->move(-SPOT_WIDGET_WIDTH, 0);

if (ENABLE_ANIMATIONS && ENABLE_ANIMATION_PROGRESSBAR) {
d->m_spotWidget->setFixedSize(SPOT_WIDGET_WIDTH, height());
d->m_spotWidget->move(-SPOT_WIDGET_WIDTH, 0);
}

d->m_sliderWidget->setFixedWidth(150);
d->m_sliderWidget->move(0, 0);
Expand All @@ -60,6 +68,10 @@ void DIndeterminateProgressbar::resizeEvent(QResizeEvent *e)
{
D_D(DIndeterminateProgressbar);
d->m_sliderWidget->setFixedHeight(height());

if (!ENABLE_ANIMATIONS || !ENABLE_ANIMATION_PROGRESSBAR)
QWidget::resizeEvent(e);

d->m_spotWidget->setFixedSize(SPOT_WIDGET_WIDTH, height());

d->m_animation->setStartValue(QPoint(-SPOT_WIDGET_WIDTH, 0));
Expand Down Expand Up @@ -111,6 +123,9 @@ void DIndeterminateProgressbar::paintEvent(QPaintEvent *e)
p.setPen(pen);
p.drawRoundedRect(d->m_sliderWidget->geometry(), radius, radius);

if (!ENABLE_ANIMATIONS || !ENABLE_ANIMATION_PROGRESSBAR)
return;

if (d->m_sliderWidget->width() < d->m_spotWidget->width() / 2)
return;

Expand Down
Loading
Loading