X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/cd2e64154fd5446a7e19aff4cb147efe2f2ba31e..6e752f507a1dd82a40d4bd140457203842fc0c80:/src/selectionmode/topbar.cpp diff --git a/src/selectionmode/topbar.cpp b/src/selectionmode/topbar.cpp index d58d10fb4..5d77a4c00 100644 --- a/src/selectionmode/topbar.cpp +++ b/src/selectionmode/topbar.cpp @@ -16,18 +16,13 @@ #include #include #include -#include #include using namespace SelectionMode; TopBar::TopBar(QWidget *parent) - : QWidget{parent} + : AnimatedHeightWidget{parent} { - // Showing of this widget is normally animated. We hide it for now and make it small. - hide(); - setMaximumHeight(0); - setToolTip(KToolTipHelper::whatsThisHintOnly()); setWhatsThis(xi18nc("@info:whatsthis", "Selection ModeSelect files or folders to manage or manipulate them." @@ -36,25 +31,10 @@ TopBar::TopBar(QWidget *parent) "Selection rectangles (created by dragging from an empty area) invert the selection status of items within." "The available action buttons at the bottom change depending on the current selection.")); - auto fillParentLayout = new QGridLayout(this); - fillParentLayout->setContentsMargins(0, 0, 0, 0); - - // Put the contents into a QScrollArea. This prevents increasing the view width - // in case that not enough width for the contents is available. (this trick is also used in bottombar.cpp.) - auto scrollArea = new QScrollArea(this); - fillParentLayout->addWidget(scrollArea); - scrollArea->setFrameShape(QFrame::NoFrame); - scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); - scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); - scrollArea->setWidgetResizable(true); - - auto contentsContainer = new QWidget(scrollArea); - scrollArea->setWidget(contentsContainer); + QWidget *contentsContainer = prepareContentsContainer(); BackgroundColorHelper::instance()->controlBackgroundColor(this); - setMinimumWidth(0); - m_fullLabelString = i18nc("@info label above the view explaining the state", "Selection Mode: Click on files or folders to select or deselect them."); m_shortLabelString = i18nc("@info label above the view explaining the state", "Selection Mode"); m_label = new QLabel(contentsContainer); @@ -69,7 +49,6 @@ TopBar::TopBar(QWidget *parent) QHBoxLayout *layout = new QHBoxLayout(contentsContainer); auto contentsMargins = layout->contentsMargins(); m_preferredHeight = contentsMargins.top() + m_label->sizeHint().height() + contentsMargins.bottom(); - scrollArea->setMaximumHeight(m_preferredHeight); m_closeButton->setFixedHeight(m_preferredHeight); layout->setContentsMargins(0, 0, 0, 0); @@ -79,33 +58,10 @@ TopBar::TopBar(QWidget *parent) layout->addWidget(m_closeButton); } -void TopBar::setVisible(bool visible, Animated animated) -{ - Q_ASSERT_X(animated == WithAnimation, "SelectionModeTopBar::setVisible", "This wasn't implemented."); - - if (m_heightAnimation) { - m_heightAnimation->stop(); // deletes because of QAbstractAnimation::DeleteWhenStopped. - } - m_heightAnimation = new QPropertyAnimation(this, "maximumHeight"); - m_heightAnimation->setDuration(2 * style()->styleHint(QStyle::SH_Widget_Animation_Duration, nullptr, this) * GlobalConfig::animationDurationFactor()); - - m_heightAnimation->setStartValue(height()); - m_heightAnimation->setEasingCurve(QEasingCurve::OutCubic); - if (visible) { - show(); - m_heightAnimation->setEndValue(m_preferredHeight); - } else { - m_heightAnimation->setEndValue(0); - connect(m_heightAnimation, &QAbstractAnimation::finished, this, &QWidget::hide); - } - - m_heightAnimation->start(QAbstractAnimation::DeleteWhenStopped); -} - void TopBar::resizeEvent(QResizeEvent *resizeEvent) { updateLabelString(); - return QWidget::resizeEvent(resizeEvent); + return AnimatedHeightWidget::resizeEvent(resizeEvent); } void TopBar::updateLabelString() @@ -119,3 +75,5 @@ void TopBar::updateLabelString() m_label->setText(m_shortLabelString); } } + +#include "moc_topbar.cpp"