2 This file is part of the KDE project
3 SPDX-FileCopyrightText: 2022 Felix Ernst <felixernst@kde.org>
5 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
10 #include "backgroundcolorhelper.h"
12 #include <KColorScheme>
13 #include <KLocalizedString>
14 #include <KToolTipHelper>
16 #include <QHBoxLayout>
18 #include <QPushButton>
21 using namespace SelectionMode
;
23 TopBar::TopBar(QWidget
*parent
)
24 : AnimatedHeightWidget
{parent
}
26 setToolTip(KToolTipHelper::whatsThisHintOnly());
27 setWhatsThis(xi18nc("@info:whatsthis",
28 "<title>Selection Mode</title><para>Select files or folders to manage or manipulate them."
29 "<list><item>Press on a file or folder to select it.</item><item>Press on an already selected file or folder to deselect it.</item>"
30 "<item>Pressing an empty area does <emphasis>not</emphasis> clear the selection.</item>"
31 "<item>Selection rectangles (created by dragging from an empty area) invert the selection status of items within.</item></list></para>"
32 "<para>The available action buttons at the bottom change depending on the current selection.</para>"));
34 QWidget
*contentsContainer
= prepareContentsContainer();
36 BackgroundColorHelper::instance()->controlBackgroundColor(this);
38 m_fullLabelString
= i18nc("@info label above the view explaining the state", "Selection Mode: Click on files or folders to select or deselect them.");
39 m_shortLabelString
= i18nc("@info label above the view explaining the state", "Selection Mode");
40 m_label
= new QLabel(contentsContainer
);
41 m_label
->setMinimumWidth(0);
42 BackgroundColorHelper::instance()->controlBackgroundColor(m_label
);
44 m_closeButton
= new QPushButton(QIcon::fromTheme(QStringLiteral("window-close-symbolic")), "", contentsContainer
);
45 m_closeButton
->setText(i18nc("@action:button", "Exit Selection Mode"));
46 m_closeButton
->setFlat(true);
47 connect(m_closeButton
, &QAbstractButton::clicked
, this, &TopBar::selectionModeLeavingRequested
);
49 QHBoxLayout
*layout
= new QHBoxLayout(contentsContainer
);
50 auto contentsMargins
= layout
->contentsMargins();
51 m_preferredHeight
= contentsMargins
.top() + m_label
->sizeHint().height() + contentsMargins
.bottom();
52 m_closeButton
->setFixedHeight(m_preferredHeight
);
53 layout
->setContentsMargins(0, 0, 0, 0);
56 layout
->addWidget(m_label
);
58 layout
->addWidget(m_closeButton
);
61 void TopBar::resizeEvent(QResizeEvent
*resizeEvent
)
64 return AnimatedHeightWidget::resizeEvent(resizeEvent
);
67 void TopBar::updateLabelString()
69 QFontMetrics fontMetrics
= m_label
->fontMetrics();
70 if (fontMetrics
.horizontalAdvance(m_fullLabelString
) + m_closeButton
->sizeHint().width() + style()->pixelMetric(QStyle::PM_LayoutLeftMargin
) * 2
71 + style()->pixelMetric(QStyle::PM_LayoutRightMargin
) * 2
73 m_label
->setText(m_fullLabelString
);
75 m_label
->setText(m_shortLabelString
);
79 #include "moc_topbar.cpp"