mirror of
https://invent.kde.org/network/falkon.git
synced 2024-12-20 18:56:34 +01:00
enable loading icons from resource in qml
This commit is contained in:
parent
987e4c75ae
commit
a19f23435f
@ -17,6 +17,7 @@
|
||||
* ============================================================ */
|
||||
#include "qmlbrowseraction.h"
|
||||
#include "mainapplication.h"
|
||||
#include "qztools.h"
|
||||
#include <QQuickWindow>
|
||||
|
||||
QmlBrowserAction::QmlBrowserAction(QObject *parent)
|
||||
@ -54,8 +55,8 @@ QString QmlBrowserAction::iconUrl() const
|
||||
void QmlBrowserAction::setIconUrl(const QString &iconUrl)
|
||||
{
|
||||
m_iconUrl = iconUrl;
|
||||
QString fileName = QUrl(m_iconUrl.toUtf8()).toLocalFile();
|
||||
setIcon(QIcon(fileName));
|
||||
QString iconPath = QzTools::getPathFromUrl(QUrl(m_iconUrl));
|
||||
setIcon(QIcon(iconPath));
|
||||
}
|
||||
|
||||
QQmlComponent* QmlBrowserAction::popup() const
|
||||
|
@ -18,6 +18,7 @@
|
||||
#include "qmlnotifications.h"
|
||||
#include "mainapplication.h"
|
||||
#include "desktopnotificationsfactory.h"
|
||||
#include "qztools.h"
|
||||
|
||||
QmlNotifications::QmlNotifications(QObject *parent)
|
||||
: QObject(parent)
|
||||
@ -36,9 +37,9 @@ QmlNotifications::QmlNotifications(QObject *parent)
|
||||
*/
|
||||
void QmlNotifications::create(const QVariantMap &map)
|
||||
{
|
||||
const QString fileUrl = map.value(QSL("icon")).toString();
|
||||
const QString fileName = QUrl::fromEncoded(fileUrl.toUtf8()).toLocalFile();
|
||||
const QPixmap icon(fileName);
|
||||
const QString iconUrl = map.value(QSL("icon")).toString();
|
||||
const QString iconPath = QzTools::getPathFromUrl(QUrl(iconUrl));
|
||||
const QPixmap icon(iconPath);
|
||||
const QString heading = map.value(QSL("heading")).toString();
|
||||
const QString message = map.value(QSL("message")).toString();
|
||||
mApp->desktopNotifications()->showNotification(icon, heading, message);
|
||||
|
@ -17,6 +17,7 @@
|
||||
* ============================================================ */
|
||||
#include "qmlsidebar.h"
|
||||
#include "mainapplication.h"
|
||||
#include "qztools.h"
|
||||
#include <QAction>
|
||||
#include <QQuickWindow>
|
||||
|
||||
@ -92,7 +93,8 @@ QAction *QmlSideBar::createMenuAction()
|
||||
action->setText(m_title);
|
||||
action->setCheckable(m_checkable);
|
||||
action->setShortcut(QKeySequence(m_shortcut));
|
||||
action->setIcon(QIcon(QUrl(m_iconUrl).toLocalFile()));
|
||||
QString iconPath = QzTools::getPathFromUrl(QUrl(m_iconUrl));
|
||||
action->setIcon(QIcon(iconPath));
|
||||
return action;
|
||||
}
|
||||
|
||||
|
@ -1018,3 +1018,16 @@ void QzTools::paintDropIndicator(QWidget *widget, const QRect &r)
|
||||
p.drawLine(x + i, r.top(), x + i, r.bottom());
|
||||
}
|
||||
}
|
||||
|
||||
QString QzTools::getPathFromUrl(const QUrl &url)
|
||||
{
|
||||
if (url.isLocalFile()) {
|
||||
return url.toLocalFile();
|
||||
} else if (url.scheme() == QSL("qrc")) {
|
||||
const QString path = url.toString(QUrl::RemoveScheme);
|
||||
return QSL(":") + path;
|
||||
} else {
|
||||
const QString path = url.toString(QUrl::RemoveScheme);
|
||||
return path;
|
||||
}
|
||||
}
|
||||
|
@ -98,6 +98,7 @@ public:
|
||||
}
|
||||
|
||||
static void paintDropIndicator(QWidget *widget, const QRect &r);
|
||||
static QString getPathFromUrl(const QUrl &url);
|
||||
};
|
||||
|
||||
#endif // QZTOOLS_H
|
||||
|
Loading…
Reference in New Issue
Block a user