Use QVariant for MenuItem::icon
This way, we can cover string and QIcon assignments transparently, another backwards compatibility fix, and easier thing in Plasma2: Now the user doesn't have to worry about creating QIcons, but can just assign the icon name, and it will get loaded from the theme. Models that provide QIcons (such as QStandardItems) now work correctly with PlasmaCore.MenuItems.
This commit is contained in:
parent
cb5f8a3248
commit
b68317e930
@ -45,17 +45,20 @@ void QMenuItem::setAction(QAction* a)
|
||||
}
|
||||
}
|
||||
|
||||
QString QMenuItem::icon() const
|
||||
QVariant QMenuItem::icon() const
|
||||
{
|
||||
return m_icon;
|
||||
}
|
||||
|
||||
void QMenuItem::setIcon(const QString& i)
|
||||
void QMenuItem::setIcon(const QVariant& i)
|
||||
{
|
||||
if (i != m_icon) {
|
||||
m_action->setIcon(QIcon::fromTheme(i));
|
||||
emit iconChanged();
|
||||
m_icon = i;
|
||||
if (i.canConvert<QIcon>()) {
|
||||
m_action->setIcon(i.value<QIcon>());
|
||||
} else if (i.canConvert<QString>()) {
|
||||
m_action->setIcon(QIcon::fromTheme(i.value<QString>()));
|
||||
}
|
||||
emit iconChanged();
|
||||
}
|
||||
|
||||
bool QMenuItem::separator() const
|
||||
|
@ -38,7 +38,7 @@ class QMenuItem : public QQuickItem
|
||||
*/
|
||||
Q_PROPERTY(bool separator READ separator WRITE setSeparator NOTIFY separatorChanged)
|
||||
Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged)
|
||||
Q_PROPERTY(QString icon READ icon WRITE setIcon NOTIFY iconChanged)
|
||||
Q_PROPERTY(QVariant icon READ icon WRITE setIcon NOTIFY iconChanged)
|
||||
Q_PROPERTY(QAction* action READ action WRITE setAction NOTIFY actionChanged)
|
||||
|
||||
public:
|
||||
@ -46,8 +46,8 @@ public:
|
||||
|
||||
QAction* action() const;
|
||||
void setAction(QAction* a);
|
||||
QString icon() const;
|
||||
void setIcon(const QString& i);
|
||||
QVariant icon() const;
|
||||
void setIcon(const QVariant& i);
|
||||
bool separator() const;
|
||||
void setSeparator(bool s);
|
||||
QString text() const;
|
||||
@ -63,7 +63,7 @@ Q_SIGNALS:
|
||||
|
||||
private:
|
||||
QAction* m_action;
|
||||
QString m_icon;
|
||||
QVariant m_icon;
|
||||
};
|
||||
|
||||
#endif // QMENUITEM_H
|
||||
|
Loading…
Reference in New Issue
Block a user