Skip to content

Commit 5639fa0

Browse files
deepin-ci-robot18202781743
authored andcommitted
sync: from linuxdeepin/dtkwidget
Synchronize source files from linuxdeepin/dtkwidget. Source-pull-request: linuxdeepin/dtkwidget#641
1 parent 7859bdb commit 5639fa0

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

src/widgets/ddrawer.cpp

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,9 @@ void DDrawerPrivate::init()
7070
m_animation = new QPropertyAnimation(m_contentLoader, "height", qq);
7171
m_animation->setDuration(400);
7272
m_animation->setEasingCurve(QEasingCurve::InQuad);
73-
qq->connect(m_animation, &QPropertyAnimation::valueChanged, qq, [qq] {
73+
qq->connect(m_animation, &QPropertyAnimation::valueChanged, qq, [this, qq] {
74+
if (!m_enableAnimation)
75+
return;
7476
qq->setFixedHeight(qq->sizeHint().height());
7577
});
7678

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

8486
qq->connect(m_boxWidget, &DBoxWidget::sizeChanged, qq, [this] {
87+
if (!m_enableAnimation) {
88+
updateHeightDirect();
89+
return;
90+
}
8591
if (m_expand) {
8692
int endHeight = 0;
8793
endHeight = m_boxWidget->height();
@@ -94,6 +100,13 @@ void DDrawerPrivate::init()
94100
});
95101
}
96102

103+
void DDrawerPrivate::updateHeightDirect()
104+
{
105+
D_Q(DDrawer);
106+
m_contentLoader->setFixedHeight(m_expand ? m_boxWidget->height() : 0);
107+
q->setFixedHeight(q->sizeHint().height());
108+
}
109+
97110
/*!
98111
\class Dtk::Widget::DDrawer
99112
\inmodule dtkwidget
@@ -210,6 +223,15 @@ void DDrawer::setExpand(bool value)
210223
d->m_expand = value;
211224
Q_EMIT expandChange(value);
212225

226+
// Disable animation to update height when widget is invisible by default.
227+
static const bool disableAnimation(qEnvironmentVariableIsSet("D_DTK_DISABLE_ANIMATIONS"));
228+
d->m_enableAnimation = !disableAnimation && isVisible();
229+
230+
if (!d->m_enableAnimation) {
231+
d->updateHeightDirect();
232+
return;
233+
}
234+
213235
if (value) {
214236
d->m_animation->setStartValue(0);
215237
d->m_animation->setEndValue(d->m_boxWidget->height());

src/widgets/private/ddrawer_p.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class DDrawerPrivate : public DFramePrivate
2525
~DDrawerPrivate();
2626

2727
void init();
28+
void updateHeightDirect();
2829

2930
QWidget *m_header = nullptr;
3031
QWidget *m_content = nullptr;
@@ -35,6 +36,7 @@ class DDrawerPrivate : public DFramePrivate
3536
DHorizontalLine * m_hSeparator = nullptr;
3637
DHorizontalLine *m_bottom_separator = nullptr;
3738
QPropertyAnimation *m_animation = nullptr;
39+
bool m_enableAnimation = false;
3840
bool m_expand = false;
3941
bool m_reservedPadding[7];
4042

0 commit comments

Comments
 (0)