Wrap code for better readability

This commit is contained in:
Simon De Backer
2020-08-18 20:08:32 +02:00
parent 790cdc5229
commit 99abc165d6
17 changed files with 274 additions and 119 deletions

View File

@@ -25,7 +25,10 @@
@param duration : the duration of animation
@see void QVariantAnimation::setDuration(int msecs)
*/
QWidgetAnimation::QWidgetAnimation(QWidget *widget, Qt::Orientation orientation, QWidgetAnimation::Behavior behavior, int duration) :
QWidgetAnimation::QWidgetAnimation(QWidget *widget,
Qt::Orientation orientation,
QWidgetAnimation::Behavior behavior,
int duration) :
QPropertyAnimation(widget),
m_orientation(orientation),
m_widget(widget),
@@ -34,7 +37,9 @@ QWidgetAnimation::QWidgetAnimation(QWidget *widget, Qt::Orientation orientation,
m_behavior(behavior)
{
setTargetObject(widget);
setPropertyName( m_orientation == Qt::Vertical ? "maximumHeight" : "maximumWidth");
setPropertyName( m_orientation == Qt::Vertical
? "maximumHeight"
: "maximumWidth");
setDuration(duration);
setEasingCurve(QEasingCurve::OutCubic);
@@ -42,8 +47,11 @@ QWidgetAnimation::QWidgetAnimation(QWidget *widget, Qt::Orientation orientation,
{
m_state = QWidgetAnimation::Finish;
if ( (this->m_orientation == Qt::Vertical && m_widget->geometry().height() == 0) ||
(this->m_orientation == Qt::Horizontal && m_widget->geometry().width() == 0) ) {
if ( (this->m_orientation == Qt::Vertical
&& m_widget->geometry().height() == 0) ||
(this->m_orientation == Qt::Horizontal
&& m_widget->geometry().width() == 0))
{
m_widget->hide();
} else {
m_widget->setMaximumSize(m_maximum);
@@ -78,32 +86,39 @@ void QWidgetAnimation::show()
int end_value = 10000;
if (m_behavior == QWidgetAnimation::minimumSizeHint)
{
end_value = m_orientation == Qt::Horizontal ? m_widget->minimumSizeHint().width() :
m_widget->minimumSizeHint().height();
end_value = m_orientation == Qt::Horizontal
? m_widget->minimumSizeHint().width()
: m_widget->minimumSizeHint().height();
}
else if (m_behavior == QWidgetAnimation::availableSpace && m_widget->parentWidget())
else if (m_behavior == QWidgetAnimation::availableSpace
&& m_widget->parentWidget())
{
m_widget->parentWidget()->layout();
int available_ = m_orientation == Qt::Horizontal ? m_widget->parentWidget()->width() :
m_widget->parentWidget()->height();
int available_ = m_orientation == Qt::Horizontal
? m_widget->parentWidget()->width()
: m_widget->parentWidget()->height();
for (auto w : m_widget_to_substract) {
available_ -= m_orientation == Qt::Horizontal ? w->minimumSizeHint().width() :
w->minimumSizeHint().height();
available_ -= m_orientation == Qt::Horizontal
? w->minimumSizeHint().width()
: w->minimumSizeHint().height();
}
int mini_ = m_orientation == Qt::Horizontal ? m_widget->minimumSizeHint().width() :
m_widget->minimumSizeHint().height();
int mini_ = m_orientation == Qt::Horizontal
? m_widget->minimumSizeHint().width()
: m_widget->minimumSizeHint().height();
end_value = available_ > mini_ ? available_ : mini_;
}
else
{
if (m_last_rect.isValid()) {
end_value = m_orientation == Qt::Horizontal ? m_last_rect.width() :
m_last_rect.height();
end_value = m_orientation == Qt::Horizontal
? m_last_rect.width()
: m_last_rect.height();
} else {
end_value = m_orientation == Qt::Horizontal ? m_maximum.width() :
m_maximum.height();
end_value = m_orientation == Qt::Horizontal
? m_maximum.width()
: m_maximum.height();
}
}
@@ -127,8 +142,9 @@ void QWidgetAnimation::hide()
}
stop();
int start_value = m_orientation == Qt::Horizontal ? m_widget->width() :
m_widget->height();
int start_value = m_orientation == Qt::Horizontal
? m_widget->width()
: m_widget->height();
setStartValue(start_value);
setEndValue(0);
m_state = QWidgetAnimation::Hidding;