blob: 559e8ea69c6646971d5a2b90122bd002709e6667 (
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include "abstractaction.h"
#include <utils/icon.h>
namespace QmlDesigner {
AbstractAction::AbstractAction(const QString &description)
: m_pureAction(new DefaultAction(description))
{
const Utils::Icon defaultIcon({
{":/utils/images/select.png", Utils::Theme::QmlDesigner_FormEditorForegroundColor}}, Utils::Icon::MenuTintedStyle);
action()->setIcon(defaultIcon.icon());
}
AbstractAction::AbstractAction(PureActionInterface *action)
: m_pureAction(action)
{
}
QAction *AbstractAction::action() const
{
return m_pureAction->action();
}
void AbstractAction::currentContextChanged(const SelectionContext &selectionContext)
{
m_selectionContext = selectionContext;
updateContext();
}
void AbstractAction::updateContext()
{
m_pureAction->setSelectionContext(m_selectionContext);
if (m_selectionContext.isValid()) {
QAction *action = m_pureAction->action();
action->setEnabled(isEnabled(m_selectionContext));
action->setVisible(isVisible(m_selectionContext));
if (action->isCheckable())
action->setChecked(isChecked(m_selectionContext));
}
}
bool AbstractAction::isChecked(const SelectionContext &) const
{
return false;
}
void AbstractAction::setCheckable(bool checkable)
{
action()->setCheckable(checkable);
}
PureActionInterface *AbstractAction::pureAction() const
{
return m_pureAction.data();
}
SelectionContext AbstractAction::selectionContext() const
{
return m_selectionContext;
}
DefaultAction::DefaultAction(const QString &description)
: QAction(description, nullptr)
, PureActionInterface(this)
{
connect(this, &QAction::triggered, this, &DefaultAction::actionTriggered);
}
void DefaultAction::setSelectionContext(const SelectionContext &selectionContext)
{
m_selectionContext = selectionContext;
}
PureActionInterface::PureActionInterface(QAction *action)
: m_action(action)
{
}
QAction *PureActionInterface::action()
{
return m_action;
}
} // namespace QmlDesigner
|