┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
path: root/src/selectionmode/actionwithwidget.h
diff options
context:
space:
mode:
authorFelix Ernst <[email protected]>2021-09-12 15:33:39 +0200
committerFelix Ernst <[email protected]>2022-08-14 14:42:40 +0000
commit3b7c05b385dc56fbc0b9ffdd332f8d30e7624d0c (patch)
treea54c8338e3dc7d420fd2223bbcfb5af0a186348e /src/selectionmode/actionwithwidget.h
parent9dbe48137748c6197363236b67f6302e20b72167 (diff)
Add Selection Mode
The selection mode action is a checkable toggle action named "Select Files and Folders" which has "Space" as the default shortcut. In selection mode a bottom bar with contextual actions is shown. These should mostly mirror the actions which are available through the right-click context menu aka DolphinContextMenu. Resizing of the window might make a overflow button appear in the bottom selection mode bar. This commit makes press and hold in the view activate selection mode. This behaviour is not triggered if the press and hold is used to either start a rubberband selection or a drag operation within a short time. The length of the short timeframe is defined by a QStyleHint. This is currently not implemented in touch because I can't test it. Mix the selection mode bars' background colors using a nice combination of colors from the current color scheme BUG: 427202
Diffstat (limited to 'src/selectionmode/actionwithwidget.h')
-rw-r--r--src/selectionmode/actionwithwidget.h86
1 files changed, 86 insertions, 0 deletions
diff --git a/src/selectionmode/actionwithwidget.h b/src/selectionmode/actionwithwidget.h
new file mode 100644
index 000000000..722fdf284
--- /dev/null
+++ b/src/selectionmode/actionwithwidget.h
@@ -0,0 +1,86 @@
+/*
+ This file is part of the KDE project
+ SPDX-FileCopyrightText: 2022 Felix Ernst <[email protected]>
+
+ SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
+*/
+
+#ifndef ACTIONWITHWIDGET_H
+#define ACTIONWITHWIDGET_H
+
+#include <QAction>
+#include <QPointer>
+#include <QWidget>
+
+class QAbstractButton;
+
+/**
+ * @brief Small wrapper/helper class that contains an action and its widget.
+ *
+ * This class takes neither the responsibility for deleting its action() nor its widget().
+ */
+class ActionWithWidget
+{
+public:
+ ActionWithWidget(QAction *action);
+
+ /**
+ * Connect @p action and @p button using copyActionDataToButton() and the
+ * wraps the two together in the ActionWithWidget object.
+ * ActionWithWidget doesn't take any ownership.
+ *
+ * @see copyActionDataToButton()
+ *
+ * @param button the button to be styled and used to fit the @p action.
+ */
+ ActionWithWidget(QAction *action, QAbstractButton *button);
+
+ /** @returns the action of this object. Crashes if that action has been deleted elsewhere in the meantime. */
+ inline QAction *action() {
+ Q_CHECK_PTR(m_action);
+ return m_action;
+ };
+
+ /** @returns the widget of this object. */
+ inline QWidget *widget() {
+ return m_widget;
+ }
+
+ /**
+ * @returns a widget with parent @p parent for the action() of this object.
+ *
+ * For most actions some sort of button will be returned. For separators a vertical line will be returned.
+ * If this ActionWithWidget already has a widget(), this method will crash.
+ */
+ QWidget *newWidget(QWidget *parent);
+
+ /** returns true if the widget exists and is visible. false otherwise. */
+ inline bool isWidgetVisible() const {
+ return m_widget && m_widget->isVisible();
+ };
+
+private:
+ QPointer<QAction> m_action;
+ QPointer<QWidget> m_widget;
+};
+
+/**
+ * A small helper method.
+ * @return a button with the correct styling for the general mode of the SelectionModeBottomBar which can be added to its layout.
+ */
+QAbstractButton *newButtonForAction(QAction *action, QWidget *parent);
+
+/**
+ * Normally, if one wants a button that represents a QAction one would use a QToolButton
+ * and simply call QToolButton::setDefaultAction(action). However if one does this, all
+ * control over the style, text, etc. of the button is forfeited. One can't for example
+ * have text on the button then, if the action has a low QAction::priority().
+ *
+ * This method styles the @p button based on the @p action without using QToolButton::setDefaultAction().
+ *
+ * Another reason why this is necessary is because the actions have application-wide scope while
+ * these buttons belong to one ViewContainer.
+ */
+void copyActionDataToButton(QAbstractButton *button, QAction *action);
+
+#endif // ACTIONWITHWIDGET_H