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;
|
return m_icon;
|
||||||
}
|
}
|
||||||
|
|
||||||
void QMenuItem::setIcon(const QString& i)
|
void QMenuItem::setIcon(const QVariant& i)
|
||||||
{
|
{
|
||||||
if (i != m_icon) {
|
m_icon = i;
|
||||||
m_action->setIcon(QIcon::fromTheme(i));
|
if (i.canConvert<QIcon>()) {
|
||||||
emit iconChanged();
|
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
|
bool QMenuItem::separator() const
|
||||||
|
@ -38,7 +38,7 @@ class QMenuItem : public QQuickItem
|
|||||||
*/
|
*/
|
||||||
Q_PROPERTY(bool separator READ separator WRITE setSeparator NOTIFY separatorChanged)
|
Q_PROPERTY(bool separator READ separator WRITE setSeparator NOTIFY separatorChanged)
|
||||||
Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged)
|
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)
|
Q_PROPERTY(QAction* action READ action WRITE setAction NOTIFY actionChanged)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@ -46,8 +46,8 @@ public:
|
|||||||
|
|
||||||
QAction* action() const;
|
QAction* action() const;
|
||||||
void setAction(QAction* a);
|
void setAction(QAction* a);
|
||||||
QString icon() const;
|
QVariant icon() const;
|
||||||
void setIcon(const QString& i);
|
void setIcon(const QVariant& i);
|
||||||
bool separator() const;
|
bool separator() const;
|
||||||
void setSeparator(bool s);
|
void setSeparator(bool s);
|
||||||
QString text() const;
|
QString text() const;
|
||||||
@ -63,7 +63,7 @@ Q_SIGNALS:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
QAction* m_action;
|
QAction* m_action;
|
||||||
QString m_icon;
|
QVariant m_icon;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // QMENUITEM_H
|
#endif // QMENUITEM_H
|
||||||
|
Loading…
Reference in New Issue
Block a user