diff --git a/src/app/providers/ImageProvider.cpp b/src/app/providers/ImageProvider.cpp index 5be14e8e8..b52b11543 100644 --- a/src/app/providers/ImageProvider.cpp +++ b/src/app/providers/ImageProvider.cpp @@ -245,7 +245,7 @@ ImageProvider::ImageProvider () : QQuickImageProvider( // ----------------------------------------------------------------------------- QImage ImageProvider::requestImage (const QString &id, QSize *size, const QSize &requestedSize) { - const QString path = QStringLiteral(":/assets/images/%1").arg(id); + const QString path = QStringLiteral(":%1").arg(id); qDebug() << QStringLiteral("Image `%1` requested.").arg(path); QElapsedTimer timer; @@ -302,3 +302,7 @@ QImage ImageProvider::requestImage (const QString &id, QSize *size, const QSize return image; } + +QPixmap ImageProvider::requestPixmap (const QString &id, QSize *size, const QSize &requestedSize) { + return QPixmap::fromImage(requestImage(id, size, requestedSize)); +} diff --git a/src/app/providers/ImageProvider.hpp b/src/app/providers/ImageProvider.hpp index 327dd3a60..b9c450da1 100644 --- a/src/app/providers/ImageProvider.hpp +++ b/src/app/providers/ImageProvider.hpp @@ -32,6 +32,7 @@ public: ImageProvider (); QImage requestImage (const QString &id, QSize *size, const QSize &requestedSize) override; + QPixmap requestPixmap (const QString &id, QSize *size, const QSize &requestedSize) override; static const QString ProviderId; }; diff --git a/ui/modules/Common/Constants/Constants.qml b/ui/modules/Common/Constants/Constants.qml index 59cdba5c0..1156fb8fe 100644 --- a/ui/modules/Common/Constants/Constants.qml +++ b/ui/modules/Common/Constants/Constants.qml @@ -7,8 +7,4 @@ QtObject { property int zPopup: 999 property int zMax: 999999 property int sizeMax: 999999 - - property string imagesFormat: '.svg' - property string imagesPath: 'image://internal/' - // property string imagesPath: 'qrc:/assets/images/' } diff --git a/ui/modules/Common/Image/Icon.qml b/ui/modules/Common/Image/Icon.qml index 6bb0e5965..816cf2a46 100644 --- a/ui/modules/Common/Image/Icon.qml +++ b/ui/modules/Common/Image/Icon.qml @@ -38,9 +38,7 @@ Item { } fillMode: Image.PreserveAspectFit - source: icon - ? Constants.imagesPath + icon + Constants.imagesFormat - : '' + source: Utils.resolveImageUri(icon) // Warning: Perfomance cost. mipmap: true diff --git a/ui/modules/Common/Tooltip/Tooltip.qml b/ui/modules/Common/Tooltip/Tooltip.qml index 335864a15..c1cb800ad 100644 --- a/ui/modules/Common/Tooltip/Tooltip.qml +++ b/ui/modules/Common/Tooltip/Tooltip.qml @@ -103,7 +103,7 @@ ToolTip { fillMode: Image.PreserveAspectFit height: TooltipStyle.arrowSize source: _edge - ? (Constants.imagesPath + 'tooltip_arrow_' + _edge + Constants.imagesFormat) + ? Utils.resolveImageUri('tooltip_arrow_' + _edge) : '' visible: tooltip.visible && _edge width: TooltipStyle.arrowSize diff --git a/ui/scripts/Utils/utils.js b/ui/scripts/Utils/utils.js index 96cc55a60..41b5d6aa2 100644 --- a/ui/scripts/Utils/utils.js +++ b/ui/scripts/Utils/utils.js @@ -16,6 +16,8 @@ var PORT_REGEX = PortTools.PORT_REGEX var PORT_RANGE_REGEX = PortTools.PORT_RANGE_REGEX +var SCHEME_REGEX = new RegExp('^[^:]+:') + // ============================================================================= // QML helpers. // ============================================================================= @@ -112,32 +114,6 @@ function extractFirstUri (str) { // ----------------------------------------------------------------------------- -// Load by default a window in the ui/views folder. -// If options.isString is equals to true, a marshalling component can -// be used. -// -// Supported options: isString, exitHandler, properties. -// -// If exitHandler is used, window must implement exitStatus signal. -function openWindow (window, parent, options) { - var object = createObject(window, parent, options) - - object.closing.connect(object.destroy.bind(object)) - - if (options && options.exitHandler) { - object.exitStatus.connect( - // Bind to access parent properties. - options.exitHandler.bind(parent) - ) - } - - object.show() - - return object -} - -// ----------------------------------------------------------------------------- - function getSystemPathFromUri (uri) { var str = uri.toString() if (startsWith(str, 'file://')) { @@ -183,6 +159,41 @@ function getTopParent (object, useFakeParent) { // ----------------------------------------------------------------------------- +// Load by default a window in the ui/views folder. +// If options.isString is equals to true, a marshalling component can +// be used. +// +// Supported options: isString, exitHandler, properties. +// +// If exitHandler is used, window must implement exitStatus signal. +function openWindow (window, parent, options) { + var object = createObject(window, parent, options) + + object.closing.connect(object.destroy.bind(object)) + + if (options && options.exitHandler) { + object.exitStatus.connect( + // Bind to access parent properties. + options.exitHandler.bind(parent) + ) + } + + object.show() + + return object +} + +// ----------------------------------------------------------------------------- + +function resolveImageUri (name) { + return name + ? 'image://internal/' + removeScheme(Qt.resolvedUrl('/assets/images/' + name + '.svg')) + : '' +} + +// ----------------------------------------------------------------------------- + + function runOnWindows () { var os = Qt.platform.os return os === 'windows' || os === 'winrt' @@ -225,6 +236,12 @@ function qmlTypeof (object, className) { // ----------------------------------------------------------------------------- +function removeScheme (url) { + return url.toString().replace(SCHEME_REGEX, '') +} + +// ----------------------------------------------------------------------------- + // A copy of `Window.setTimeout` from js. // delay is in milliseconds. function setTimeout (parent, delay, cb) {