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 "qmlbrowseraction.h"
|
||||||
#include "mainapplication.h"
|
#include "mainapplication.h"
|
||||||
|
#include "qztools.h"
|
||||||
#include <QQuickWindow>
|
#include <QQuickWindow>
|
||||||
|
|
||||||
QmlBrowserAction::QmlBrowserAction(QObject *parent)
|
QmlBrowserAction::QmlBrowserAction(QObject *parent)
|
||||||
@ -54,8 +55,8 @@ QString QmlBrowserAction::iconUrl() const
|
|||||||
void QmlBrowserAction::setIconUrl(const QString &iconUrl)
|
void QmlBrowserAction::setIconUrl(const QString &iconUrl)
|
||||||
{
|
{
|
||||||
m_iconUrl = iconUrl;
|
m_iconUrl = iconUrl;
|
||||||
QString fileName = QUrl(m_iconUrl.toUtf8()).toLocalFile();
|
QString iconPath = QzTools::getPathFromUrl(QUrl(m_iconUrl));
|
||||||
setIcon(QIcon(fileName));
|
setIcon(QIcon(iconPath));
|
||||||
}
|
}
|
||||||
|
|
||||||
QQmlComponent* QmlBrowserAction::popup() const
|
QQmlComponent* QmlBrowserAction::popup() const
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
#include "qmlnotifications.h"
|
#include "qmlnotifications.h"
|
||||||
#include "mainapplication.h"
|
#include "mainapplication.h"
|
||||||
#include "desktopnotificationsfactory.h"
|
#include "desktopnotificationsfactory.h"
|
||||||
|
#include "qztools.h"
|
||||||
|
|
||||||
QmlNotifications::QmlNotifications(QObject *parent)
|
QmlNotifications::QmlNotifications(QObject *parent)
|
||||||
: QObject(parent)
|
: QObject(parent)
|
||||||
@ -36,9 +37,9 @@ QmlNotifications::QmlNotifications(QObject *parent)
|
|||||||
*/
|
*/
|
||||||
void QmlNotifications::create(const QVariantMap &map)
|
void QmlNotifications::create(const QVariantMap &map)
|
||||||
{
|
{
|
||||||
const QString fileUrl = map.value(QSL("icon")).toString();
|
const QString iconUrl = map.value(QSL("icon")).toString();
|
||||||
const QString fileName = QUrl::fromEncoded(fileUrl.toUtf8()).toLocalFile();
|
const QString iconPath = QzTools::getPathFromUrl(QUrl(iconUrl));
|
||||||
const QPixmap icon(fileName);
|
const QPixmap icon(iconPath);
|
||||||
const QString heading = map.value(QSL("heading")).toString();
|
const QString heading = map.value(QSL("heading")).toString();
|
||||||
const QString message = map.value(QSL("message")).toString();
|
const QString message = map.value(QSL("message")).toString();
|
||||||
mApp->desktopNotifications()->showNotification(icon, heading, message);
|
mApp->desktopNotifications()->showNotification(icon, heading, message);
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
* ============================================================ */
|
* ============================================================ */
|
||||||
#include "qmlsidebar.h"
|
#include "qmlsidebar.h"
|
||||||
#include "mainapplication.h"
|
#include "mainapplication.h"
|
||||||
|
#include "qztools.h"
|
||||||
#include <QAction>
|
#include <QAction>
|
||||||
#include <QQuickWindow>
|
#include <QQuickWindow>
|
||||||
|
|
||||||
@ -92,7 +93,8 @@ QAction *QmlSideBar::createMenuAction()
|
|||||||
action->setText(m_title);
|
action->setText(m_title);
|
||||||
action->setCheckable(m_checkable);
|
action->setCheckable(m_checkable);
|
||||||
action->setShortcut(QKeySequence(m_shortcut));
|
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;
|
return action;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1018,3 +1018,16 @@ void QzTools::paintDropIndicator(QWidget *widget, const QRect &r)
|
|||||||
p.drawLine(x + i, r.top(), x + i, r.bottom());
|
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 void paintDropIndicator(QWidget *widget, const QRect &r);
|
||||||
|
static QString getPathFromUrl(const QUrl &url);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // QZTOOLS_H
|
#endif // QZTOOLS_H
|
||||||
|
Loading…
Reference in New Issue
Block a user