Utils: Add a ProxyAction factory which overrides an action icon

There are several places where we want to override an icon when adding
an action to a toolbar and to a menu, because we need to different
icon variations.

Change-Id: I0bed4d002b8f83c9ce3278137aa463c20d1dc7be
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
Alessandro Portale
2016-04-25 12:25:10 +02:00
parent a3880c4916
commit eea27bc82d
2 changed files with 10 additions and 0 deletions

View File

@@ -175,3 +175,12 @@ QString ProxyAction::stringWithAppendedShortcut(const QString &str, const QKeySe
return QString::fromLatin1("%1 <span style=\"color: gray; font-size: small\">%2</span>").
arg(s, shortcut.toString(QKeySequence::NativeText));
}
ProxyAction *ProxyAction::proxyActionWithIcon(QAction *original, const QIcon &newIcon)
{
ProxyAction *proxyAction = new ProxyAction(original);
proxyAction->setAction(original);
proxyAction->setIcon(newIcon);
proxyAction->setAttribute(UpdateText);
return proxyAction;
}

View File

@@ -58,6 +58,7 @@ public:
bool hasAttribute(Attribute attribute);
static QString stringWithAppendedShortcut(const QString &str, const QKeySequence &shortcut);
static ProxyAction *proxyActionWithIcon(QAction *original, const QIcon &newIcon);
private slots:
void actionChanged();