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#641
  • Loading branch information
deepin-ci-robot authored and 18202781743 committed Feb 25, 2025
1 parent 7859bdb commit 5639fa0
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
24 changes: 23 additions & 1 deletion src/widgets/ddrawer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ void DDrawerPrivate::init()
m_animation = new QPropertyAnimation(m_contentLoader, "height", qq);
m_animation->setDuration(400);
m_animation->setEasingCurve(QEasingCurve::InQuad);
qq->connect(m_animation, &QPropertyAnimation::valueChanged, qq, [qq] {
qq->connect(m_animation, &QPropertyAnimation::valueChanged, qq, [this, qq] {
if (!m_enableAnimation)
return;
qq->setFixedHeight(qq->sizeHint().height());
});

Expand All @@ -82,6 +84,10 @@ void DDrawerPrivate::init()
qq->setLayout(mainLayout);

qq->connect(m_boxWidget, &DBoxWidget::sizeChanged, qq, [this] {
if (!m_enableAnimation) {
updateHeightDirect();
return;
}
if (m_expand) {
int endHeight = 0;
endHeight = m_boxWidget->height();
Expand All @@ -94,6 +100,13 @@ void DDrawerPrivate::init()
});
}

void DDrawerPrivate::updateHeightDirect()
{
D_Q(DDrawer);
m_contentLoader->setFixedHeight(m_expand ? m_boxWidget->height() : 0);
q->setFixedHeight(q->sizeHint().height());
}

/*!
\class Dtk::Widget::DDrawer
\inmodule dtkwidget
Expand Down Expand Up @@ -210,6 +223,15 @@ void DDrawer::setExpand(bool value)
d->m_expand = value;
Q_EMIT expandChange(value);

// Disable animation to update height when widget is invisible by default.
static const bool disableAnimation(qEnvironmentVariableIsSet("D_DTK_DISABLE_ANIMATIONS"));
d->m_enableAnimation = !disableAnimation && isVisible();

if (!d->m_enableAnimation) {
d->updateHeightDirect();
return;
}

if (value) {
d->m_animation->setStartValue(0);
d->m_animation->setEndValue(d->m_boxWidget->height());
Expand Down
2 changes: 2 additions & 0 deletions src/widgets/private/ddrawer_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class DDrawerPrivate : public DFramePrivate
~DDrawerPrivate();

void init();
void updateHeightDirect();

QWidget *m_header = nullptr;
QWidget *m_content = nullptr;
Expand All @@ -35,6 +36,7 @@ class DDrawerPrivate : public DFramePrivate
DHorizontalLine * m_hSeparator = nullptr;
DHorizontalLine *m_bottom_separator = nullptr;
QPropertyAnimation *m_animation = nullptr;
bool m_enableAnimation = false;
bool m_expand = false;
bool m_reservedPadding[7];

Expand Down

0 comments on commit 5639fa0

Please sign in to comment.