Commit 32870cc9 authored by Ronan's avatar Ronan

feat(ImageProvider): supports images override

parent b21d16a1
......@@ -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));
}
......@@ -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;
};
......
......@@ -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/'
}
......@@ -38,9 +38,7 @@ Item {
}
fillMode: Image.PreserveAspectFit
source: icon
? Constants.imagesPath + icon + Constants.imagesFormat
: ''
source: Utils.resolveImageUri(icon)
// Warning: Perfomance cost.
mipmap: true
......
......@@ -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
......
......@@ -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) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment