┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
path: root/src/selectionmode/actiontexthelper.cpp
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.cpp
parent402b4a5698f3d12d1848b298c38828d509abfd0d (diff)
Better separation of classes
Make obvious when actions trigger selection mode.
Diffstat (limited to 'src/selectionmode/actiontexthelper.cpp')
-rw-r--r--src/selectionmode/actiontexthelper.cpp41
1 files changed, 41 insertions, 0 deletions
diff --git a/src/selectionmode/actiontexthelper.cpp b/src/selectionmode/actiontexthelper.cpp
new file mode 100644
index 000000000..3eb868a8c
--- /dev/null
+++ b/src/selectionmode/actiontexthelper.cpp
@@ -0,0 +1,41 @@
+/*
+ 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
+*/
+
+#include "actiontexthelper.h"
+
+using namespace SelectionMode;
+
+ActionTextHelper::ActionTextHelper(QObject *parent) :
+ QObject(parent)
+{ }
+
+void ActionTextHelper::registerTextWhenNothingIsSelected(QAction *action, QString registeredText)
+{
+ Q_CHECK_PTR(action);
+ m_registeredActionTextChanges.emplace_back(action, registeredText, TextWhenNothingIsSelected);
+}
+
+void ActionTextHelper::textsWhenNothingIsSelectedEnabled(bool enabled)
+{
+ for (auto i = m_registeredActionTextChanges.begin(); i != m_registeredActionTextChanges.end(); ++i) {
+ if (!i->action) {
+ i = m_registeredActionTextChanges.erase(i);
+ continue;
+ }
+ if (enabled && i->textStateOfRegisteredText == TextWhenNothingIsSelected) {
+ QString textWhenSomethingIsSelected = i->action->text();
+ i->action->setText(i->registeredText);
+ i->registeredText = textWhenSomethingIsSelected;
+ i->textStateOfRegisteredText = TextWhenSomethingIsSelected;
+ } else if (!enabled && i->textStateOfRegisteredText == TextWhenSomethingIsSelected) {
+ QString textWhenNothingIsSelected = i->action->text();
+ i->action->setText(i->registeredText);
+ i->registeredText = textWhenNothingIsSelected;
+ i->textStateOfRegisteredText = TextWhenNothingIsSelected;
+ }
+ }
+}