1
mirror of https://invent.kde.org/network/falkon.git synced 2024-11-11 09:32:12 +01:00

enable icon from theme in qml plugins

This commit is contained in:
Anmol Gautam 2018-06-30 07:27:52 +05:30
parent 18ebbc2ade
commit f42049eb12
4 changed files with 24 additions and 6 deletions

View File

@ -210,7 +210,11 @@ void QmlBrowserActionButton::setToolTip(const QString &toolTip)
void QmlBrowserActionButton::setIcon(const QString &icon) void QmlBrowserActionButton::setIcon(const QString &icon)
{ {
m_iconUrl = icon; m_iconUrl = icon;
if (QIcon::hasThemeIcon(m_iconUrl)) {
AbstractButtonInterface::setIcon(QIcon::fromTheme(m_iconUrl));
} else {
AbstractButtonInterface::setIcon(QIcon(QzTools::getPathFromUrl(QUrl(m_iconUrl)))); AbstractButtonInterface::setIcon(QIcon(QzTools::getPathFromUrl(QUrl(m_iconUrl))));
}
} }
void QmlBrowserActionButton::setBadgeText(const QString &badgeText) void QmlBrowserActionButton::setBadgeText(const QString &badgeText)

View File

@ -33,8 +33,13 @@ void QmlAction::setProperties(const QVariantMap &map)
for (const QString &key : map.keys()) { for (const QString &key : map.keys()) {
if (key == QSL("icon")) { if (key == QSL("icon")) {
QUrl url = map.value(key).toUrl(); QString iconPath = map.value(key).toString();
QIcon icon(QzTools::getPathFromUrl(url)); QIcon icon;
if (QIcon::hasThemeIcon(iconPath)) {
icon = QIcon::fromTheme(iconPath);
} else {
icon = QIcon(QzTools::getPathFromUrl(QUrl::fromEncoded(iconPath.toUtf8())));
}
m_action->setIcon(icon); m_action->setIcon(icon);
} else if (key == QSL("shortcut")) { } else if (key == QSL("shortcut")) {
m_action->setShortcut(QKeySequence(map.value(key).toString())); m_action->setShortcut(QKeySequence(map.value(key).toString()));

View File

@ -64,8 +64,13 @@ QmlMenu *QmlMenu::addMenu(const QVariantMap &map)
QMenu *newMenu = new QMenu(); QMenu *newMenu = new QMenu();
for (const QString &key : map.keys()) { for (const QString &key : map.keys()) {
if (key == QSL("icon")) { if (key == QSL("icon")) {
QUrl url = map.value(key).toUrl(); QString iconPath = map.value(key).toString();
QIcon icon(QzTools::getPathFromUrl(url)); QIcon icon;
if (QIcon::hasThemeIcon(iconPath)) {
icon = QIcon::fromTheme(iconPath);
} else {
icon = QIcon(QzTools::getPathFromUrl(QUrl::fromEncoded(iconPath.toUtf8())));
}
newMenu->setIcon(icon); newMenu->setIcon(icon);
continue; continue;
} }

View File

@ -131,7 +131,11 @@ QAction *QmlSideBarHelper::createMenuAction()
{ {
QAction *action = new QAction(m_title); QAction *action = new QAction(m_title);
action->setShortcut(QKeySequence(m_shortcut)); action->setShortcut(QKeySequence(m_shortcut));
if (QIcon::hasThemeIcon(m_iconUrl)) {
action->setIcon(QIcon::fromTheme(m_iconUrl));
} else {
action->setIcon(QIcon(QzTools::getPathFromUrl(QUrl(m_iconUrl)))); action->setIcon(QIcon(QzTools::getPathFromUrl(QUrl(m_iconUrl))));
}
action->setCheckable(m_checkable); action->setCheckable(m_checkable);
return action; return action;
} }