From 8e55f2c2409fd6ca9ebc66a6568f4d3bcbef7576 Mon Sep 17 00:00:00 2001 From: Felix Ernst Date: Sun, 24 Apr 2022 13:18:30 +0200 Subject: Better separation of classes Make obvious when actions trigger selection mode. --- src/selectionmode/selectionmodetopbar.cpp | 125 ------------------------------ 1 file changed, 125 deletions(-) delete mode 100644 src/selectionmode/selectionmodetopbar.cpp (limited to 'src/selectionmode/selectionmodetopbar.cpp') diff --git a/src/selectionmode/selectionmodetopbar.cpp b/src/selectionmode/selectionmodetopbar.cpp deleted file mode 100644 index 83aa8e849..000000000 --- a/src/selectionmode/selectionmodetopbar.cpp +++ /dev/null @@ -1,125 +0,0 @@ -/* - This file is part of the KDE project - SPDX-FileCopyrightText: 2022 Felix Ernst - - SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL -*/ - -#include "selectionmodetopbar.h" - -#include "backgroundcolorhelper.h" - -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -SelectionModeTopBar::SelectionModeTopBar(QWidget *parent) : - QWidget{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." - "Press on a file or folder to select it.Press on an already selected file or folder to deselect it." - "Pressing an empty area does not clear the selection." - "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 selectionmodebottombar.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); - - 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); - m_label->setMinimumWidth(0); - BackgroundColorHelper::instance()->controlBackgroundColor(m_label); - - m_closeButton = new QPushButton(QIcon::fromTheme(QStringLiteral("window-close-symbolic")), "", contentsContainer); - m_closeButton->setToolTip(i18nc("@action:button", "Exit Selection Mode")); - m_closeButton->setAccessibleName(m_closeButton->toolTip()); - m_closeButton->setFlat(true); - connect(m_closeButton, &QAbstractButton::pressed, - this, &SelectionModeTopBar::leaveSelectionModeRequested); - - 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); - - layout->addStretch(); - layout->addWidget(m_label); - layout->addStretch(); - layout->addWidget(m_closeButton); -} - -void SelectionModeTopBar::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 SelectionModeTopBar::resizeEvent(QResizeEvent */* resizeEvent */) -{ - updateLabelString(); -} - -void SelectionModeTopBar::updateLabelString() -{ - QFontMetrics fontMetrics = m_label->fontMetrics(); - if (fontMetrics.horizontalAdvance(m_fullLabelString) + m_closeButton->sizeHint().width() + style()->pixelMetric(QStyle::PM_LayoutLeftMargin) * 2 + style()->pixelMetric(QStyle::PM_LayoutRightMargin) * 2 < width()) { - m_label->setText(m_fullLabelString); - } else { - m_label->setText(m_shortLabelString); - } -} -- cgit v1.3