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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
|
// Copyright (C) 2016 Konstantin Tokarev.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include "commandbutton.h"
#include "actionmanager.h"
#include "command.h"
#include <utils/proxyaction.h>
#include <utils/qtcassert.h>
using namespace Core;
using namespace Utils;
/*!
\class Core::CommandAction
\inheaderfile coreplugin/actionmanager/commandbutton.h
\inmodule QtCreator
\brief The CommandAction class is an action associated with one of
the registered Command objects.
It shares the icon and text of the command.
The tooltip of the action consists of toolTipBase property value and Command's
key sequence which is automatically updated when user changes it.
*/
/*!
\class Core::CommandButton
\inheaderfile coreplugin/actionmanager/commandbutton.h
\inmodule QtCreator
\brief The CommandButton class is an action associated with one of
the registered Command objects.
The tooltip of the button consists of toolTipBase property value and Command's
key sequence which is automatically updated when user changes it.
*/
/*!
\internal
*/
CommandAction::CommandAction(QWidget *parent)
: QAction(parent)
, m_command(nullptr)
{
}
/*!
\internal
*/
CommandAction::CommandAction(Id id, QWidget *parent)
: QAction(parent)
, m_command(nullptr)
{
setCommandId(id);
}
/*!
Sets the ID of the command associated with this tool button to \a id.
*/
void CommandAction::setCommandId(Id id)
{
if (m_command)
disconnect(m_command.data(),
&Command::keySequenceChanged,
this,
&CommandAction::updateToolTip);
m_command = ActionManager::command(id);
QTC_ASSERT(m_command, return);
if (m_toolTipBase.isEmpty())
m_toolTipBase = m_command->description();
setIcon(m_command->action()->icon());
setIconText(m_command->action()->iconText());
setText(m_command->action()->text());
updateToolTip();
connect(m_command.data(), &Command::keySequenceChanged, this, &CommandAction::updateToolTip);
}
/*!
The base tool tip that is extended with the command's shortcut.
Defaults to the command's description.
\sa Command::description()
*/
QString CommandAction::toolTipBase() const
{
return m_toolTipBase;
}
/*!
Sets the base tool tip that is extended with the command's shortcut.
\sa toolTipBase()
*/
void CommandAction::setToolTipBase(const QString &toolTipBase)
{
m_toolTipBase = toolTipBase;
updateToolTip();
}
void CommandAction::updateToolTip()
{
if (m_command)
setToolTip(Utils::ProxyAction::stringWithAppendedShortcut(m_toolTipBase,
m_command->keySequence()));
}
/*!
\internal
*/
CommandButton::CommandButton(QWidget *parent)
: QToolButton(parent)
{}
/*!
\internal
*/
CommandButton::CommandButton(Utils::Id id, QWidget *parent)
: QToolButton(parent)
{
setCommandId(id);
}
void CommandButton::setCommandId(Utils::Id id)
{
if (m_command)
disconnect(m_command.data(),
&Command::keySequenceChanged,
this,
&CommandButton::updateToolTip);
m_command = ActionManager::command(id);
QTC_ASSERT(m_command, return);
if (m_toolTipBase.isEmpty())
m_toolTipBase = m_command->description();
updateToolTip();
connect(m_command.data(), &Command::keySequenceChanged, this, &CommandButton::updateToolTip);
}
/*!
The base tool tip that is extended with the command's shortcut.
Defaults to the command's description.
\sa Command::description()
*/
QString CommandButton::toolTipBase() const
{
return m_toolTipBase;
}
/*!
Sets the base tool tip that is extended with the command's shortcut.
\sa toolTipBase()
*/
void CommandButton::setToolTipBase(const QString &toolTipBase)
{
m_toolTipBase = toolTipBase;
updateToolTip();
}
void CommandButton::updateToolTip()
{
if (m_command)
setToolTip(Utils::ProxyAction::stringWithAppendedShortcut(m_toolTipBase,
m_command->keySequence()));
}
|