┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
path: root/src/selectionmode/actiontexthelper.h
diff options
context:
space:
mode:
authorFelix Ernst <[email protected]>2022-04-24 13:18:30 +0200
committerFelix Ernst <[email protected]>2022-08-14 14:42:40 +0000
commit8e55f2c2409fd6ca9ebc66a6568f4d3bcbef7576 (patch)
treeabc2aa68ceb8f79addf0f74615e91efa08a44172 /src/selectionmode/actiontexthelper.h
parent402b4a5698f3d12d1848b298c38828d509abfd0d (diff)
Better separation of classes
Make obvious when actions trigger selection mode.
Diffstat (limited to 'src/selectionmode/actiontexthelper.h')
-rw-r--r--src/selectionmode/actiontexthelper.h71
1 files changed, 71 insertions, 0 deletions
diff --git a/src/selectionmode/actiontexthelper.h b/src/selectionmode/actiontexthelper.h
new file mode 100644
index 000000000..8f7501fa4
--- /dev/null
+++ b/src/selectionmode/actiontexthelper.h
@@ -0,0 +1,71 @@
+/*
+ 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 ACTIONTEXTHELPER_H
+#define ACTIONTEXTHELPER_H
+
+#include <QAction>
+#include <QPointer>
+#include <QString>
+
+namespace SelectionMode
+{
+
+/**
+ * @brief Helps changing the texts of actions depending on the current selection.
+ */
+class ActionTextHelper : QObject
+{
+public:
+ explicit ActionTextHelper(QObject *parent);
+
+ /**
+ * Changes the text of \a action to \a text whenever textsWhenNothingIsSelectedEnabled(true) is called.
+ * The texts can be changed back by calling textsWhenNothingIsSelectedEnabled(false) is called.
+ * @see textsWhenNothingIsSelectedEnabled()
+ */
+ void registerTextWhenNothingIsSelected(QAction *action, QString registeredText);
+
+ /**
+ * Changes all texts that were registered previously using registerTextWhenNothingIsSelected() to those
+ * registered texts if called with \a enabled == true. Otherwise resets the texts to the original one.
+ */
+ void textsWhenNothingIsSelectedEnabled(bool enabled);
+
+private:
+ enum TextState {
+ TextWhenNothingIsSelected,
+ TextWhenSomethingIsSelected
+ };
+
+ /**
+ * Utility struct to allow switching back and forth between registered actions showing their
+ * distinct texts for when no items are selected or when items are selected.
+ * An example is "Copy" or "Copy…". The latter one is used when nothing is selected and signifies
+ * that it will trigger SelectionMode so items can be selected and then copied.
+ */
+ struct RegisteredActionTextChange {
+ QPointer<QAction> action;
+ QString registeredText;
+ TextState textStateOfRegisteredText;
+
+ RegisteredActionTextChange(QAction *action, QString registeredText, TextState state) :
+ action{action},
+ registeredText{registeredText},
+ textStateOfRegisteredText{state}
+ { };
+ };
+
+ /**
+ * @see RegisteredActionTextChange
+ */
+ std::vector<RegisteredActionTextChange> m_registeredActionTextChanges;
+};
+
+}
+
+#endif // ACTIONTEXTHELPER_H