28 #include <QtCore/QDebug>
186 using namespace Core::Internal;
251 return QString(
"%1 <span style=\"color: gray; font-size: small\">%2</span>")
253 .arg(
keySequence().toString(QKeySequence::NativeText));
265 , m_shortcut(nullptr)
274 return m_shortcut->whatsThis();
299 if (m_shortcut->key().isEmpty())
306 m_shortcut->setKey(key);
312 return m_shortcut->key();
317 m_defaultText = text;
322 return m_defaultText;
327 foreach (
int ctxt, m_context) {
328 if (context.contains(ctxt)) {
329 m_shortcut->setEnabled(
true);
333 m_shortcut->setEnabled(
false);
339 return m_shortcut->isEnabled();
422 , m_currentAction(nullptr)
424 , m_contextInitialized(false)
437 QAction *oldAction = m_currentAction;
438 m_currentAction =
nullptr;
439 for (
int i = 0;
i < m_context.size(); ++
i) {
440 if (QAction *
a = m_contextActionMap.value(m_context.at(
i),
nullptr)) {
446 if (m_currentAction == oldAction && m_contextInitialized)
448 m_contextInitialized =
true;
451 disconnect(oldAction, SIGNAL(changed()),
this, SLOT(actionChanged()));
452 disconnect(
m_action, SIGNAL(triggered(
bool)), oldAction, SIGNAL(triggered(
bool)));
453 disconnect(
m_action, SIGNAL(toggled(
bool)), oldAction, SLOT(setChecked(
bool)));
455 if (m_currentAction) {
456 connect(m_currentAction, SIGNAL(changed()),
this, SLOT(actionChanged()));
458 connect(
m_action, SIGNAL(triggered(
bool)), m_currentAction, SIGNAL(triggered(
bool)));
461 connect(
m_action, SIGNAL(toggled(
bool)), m_currentAction, SLOT(setChecked(
bool)));
475 if (context.isEmpty()) {
476 m_contextActionMap.insert(0, action);
478 for (
int i = 0;
i < context.size(); ++
i) {
479 int k = context.at(
i);
480 if (m_contextActionMap.contains(k))
481 qWarning() << QString(
"addOverrideAction: action already registered for context "
482 "when registering '%1'")
483 .arg(action->text());
484 m_contextActionMap.insert(k, action);
489 void OverrideableAction::actionChanged()
492 m_action->setIcon(m_currentAction->icon());
493 m_action->setIconText(m_currentAction->iconText());
496 m_action->setText(m_currentAction->text());
499 m_action->setStatusTip(m_currentAction->statusTip());
500 m_action->setWhatsThis(m_currentAction->whatsThis());
503 m_action->setCheckable(m_currentAction->isCheckable());
504 bool block =
m_action->blockSignals(
true);
505 m_action->setChecked(m_currentAction->isChecked());
508 m_action->setEnabled(m_currentAction->isEnabled());
509 m_action->setVisible(m_currentAction->isVisible());
void addOverrideAction(QAction *action, const QList< int > &context)
void setKeySequence(const QKeySequence &key)
QKeySequence keySequence() const
void keySequenceChanged()
bool setCurrentContext(const QList< int > &context)
QKeySequence keySequence() const
virtual QKeySequence keySequence() const =0
void setAction(QAction *action)
void setKeySequence(const QKeySequence &key)
void setContext(const QList< int > &context)
void setDefaultKeySequence(const QKeySequence &key)
bool setCurrentContext(const QList< int > &context)
QString stringWithAppendedShortcut(const QString &str) const
QList< CommandLocation > locations() const
void setLocations(const QList< CommandLocation > &locations)
virtual void setAction(QAction *action)
void updateToolTipWithKeySequence()
virtual void setDefaultText(const QString &key)
QList< int > context() const
QShortcut * shortcut() const
void setDefaultKeySequence(const QKeySequence &key)
void setDefaultText(const QString &text)
OverrideableAction(int id)
virtual QString defaultText() const
QKeySequence defaultKeySequence() const
bool hasAttribute(CommandAttribute attr) const
void setAttribute(CommandAttribute attr)
QString defaultText() const
void setDefaultKeySequence(const QKeySequence &key)
void removeAttribute(CommandAttribute attr)
QList< CommandLocation > m_locations
void setShortcut(QShortcut *shortcut)
QShortcut * shortcut() const
QKeySequence m_defaultKey