┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
path: root/src/selectionmode/actiontexthelper.cpp
blob: 1e331860ae1b97d4e5af617ed4c5633e6f515ca9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/*
    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_ASSERT(action);
    m_registeredActionTextChanges.emplace_back(action, registeredText, TextWhenNothingIsSelected);
}

void ActionTextHelper::textsWhenNothingIsSelectedEnabled(bool enabled)
{
    for (auto i = m_registeredActionTextChanges.begin(); i != m_registeredActionTextChanges.end(); ++i) {
        while (!i->action) {
            i = m_registeredActionTextChanges.erase(i);
            if (i == m_registeredActionTextChanges.end()) {
                break;
            }
        }

        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;
        }
    }
}