aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/virtualkeyboard/styles/styles.pro4
-rw-r--r--src/virtualkeyboard/styles/styles_plugin.cpp7
-rw-r--r--src/virtualkeyboard/styles/styles_plugin.h1
-rw-r--r--src/virtualkeyboard/styles/svgimageprovider.cpp95
-rw-r--r--src/virtualkeyboard/styles/svgimageprovider.h34
5 files changed, 140 insertions, 1 deletions
diff --git a/src/virtualkeyboard/styles/styles.pro b/src/virtualkeyboard/styles/styles.pro
index 0f2fb269..03a8141f 100644
--- a/src/virtualkeyboard/styles/styles.pro
+++ b/src/virtualkeyboard/styles/styles.pro
@@ -1,16 +1,18 @@
TEMPLATE = lib
TARGET = qtvirtualkeyboardstylesplugin
INSTALL_PATH = $$[QT_INSTALL_QML]/QtQuick/Enterprise/VirtualKeyboard/Styles
-QT += qml quick
+QT += qml quick svg
CONFIG += plugin
target.path = $$INSTALL_PATH
INSTALLS += target
SOURCES += \
+ svgimageprovider.cpp \
styles_plugin.cpp
HEADERS += \
+ svgimageprovider.h \
styles_plugin.h
OTHER_FILES += \
diff --git a/src/virtualkeyboard/styles/styles_plugin.cpp b/src/virtualkeyboard/styles/styles_plugin.cpp
index 5b522d67..b20c6d01 100644
--- a/src/virtualkeyboard/styles/styles_plugin.cpp
+++ b/src/virtualkeyboard/styles/styles_plugin.cpp
@@ -17,6 +17,7 @@
****************************************************************************/
#include "styles_plugin.h"
+#include "svgimageprovider.h"
#include <qqml.h>
#include <QtCore/QLibraryInfo>
@@ -39,3 +40,9 @@ void StylesPlugin::registerTypes(const char *uri)
qmlRegisterType(QUrl(path + "KeyPanel.qml"), uri, 1, 0, "KeyPanel");
qmlRegisterType(QUrl(path + "SelectionListItem.qml"), uri, 1, 0, "SelectionListItem");
}
+
+void StylesPlugin::initializeEngine(QQmlEngine *engine, const char *uri)
+{
+ Q_UNUSED(uri)
+ engine->addImageProvider(QLatin1String("qtvkbsvg"), new SvgImageProvider());
+}
diff --git a/src/virtualkeyboard/styles/styles_plugin.h b/src/virtualkeyboard/styles/styles_plugin.h
index 97240d2d..733161c5 100644
--- a/src/virtualkeyboard/styles/styles_plugin.h
+++ b/src/virtualkeyboard/styles/styles_plugin.h
@@ -28,6 +28,7 @@ class StylesPlugin : public QQmlExtensionPlugin
public:
void registerTypes(const char *uri);
+ void initializeEngine(QQmlEngine *engine, const char *uri);
};
#endif // STYLES_PLUGIN_H
diff --git a/src/virtualkeyboard/styles/svgimageprovider.cpp b/src/virtualkeyboard/styles/svgimageprovider.cpp
new file mode 100644
index 00000000..665b37a3
--- /dev/null
+++ b/src/virtualkeyboard/styles/svgimageprovider.cpp
@@ -0,0 +1,95 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 Digia Plc
+** All rights reserved.
+** For any questions to Digia, please use contact form at http://www.qt.io
+**
+** This file is part of the Qt Virtual Keyboard add-on for Qt Enterprise.
+**
+** Licensees holding valid Qt Enterprise licenses may use this file in
+** accordance with the Qt Enterprise License Agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia.
+**
+** If you have questions regarding the use of this file, please use
+** contact form at http://www.qt.io
+**
+****************************************************************************/
+
+#include "svgimageprovider.h"
+#include <QImage>
+#include <QPixmap>
+#include <QSvgRenderer>
+#include <QPainter>
+
+SvgImageProvider::SvgImageProvider() :
+ QQuickImageProvider(QQuickImageProvider::Pixmap)
+{
+}
+
+SvgImageProvider::~SvgImageProvider()
+{
+}
+
+QPixmap SvgImageProvider::requestPixmap(const QString &id, QSize *size, const QSize &requestedSize)
+{
+ QSize imageSize(-1, -1);
+ QUrl request(id);
+ QString imagePath = ":/" + request.path();
+ if (request.hasQuery()) {
+ const QString query = request.query();
+ const QStringList paramList = query.split(QChar('&'), QString::SkipEmptyParts);
+ QVariantMap params;
+ foreach (const QString &param, paramList) {
+ QStringList keyValue = param.split(QChar('='), QString::SkipEmptyParts);
+ if (keyValue.length() == 2)
+ params[keyValue[0]] = keyValue[1];
+ }
+ if (params.contains("width")) {
+ bool ok = false;
+ int value = params["width"].toInt(&ok);
+ if (ok)
+ imageSize.setWidth(value);
+ }
+ if (params.contains("height")) {
+ bool ok = false;
+ int value = params["height"].toInt(&ok);
+ if (ok)
+ imageSize.setHeight(value);
+ }
+ } else {
+ imageSize = requestedSize;
+ }
+
+ QPixmap image;
+ if ((imageSize.width() > 0 || imageSize.height() > 0) && imagePath.endsWith(".svg")) {
+ QSvgRenderer renderer(imagePath);
+ QSize defaultSize(renderer.defaultSize());
+ if (defaultSize.isEmpty())
+ return image;
+ if (imageSize.width() <= 0 && imageSize.height() > 0) {
+ double aspectRatio = (double)defaultSize.width() / (double)defaultSize.height();
+ imageSize.setWidth(qRound(imageSize.height() * aspectRatio));
+ } else if (imageSize.width() > 0 && imageSize.height() <= 0) {
+ double aspectRatio = (double)defaultSize.width() / (double)defaultSize.height();
+ imageSize.setHeight(qRound(imageSize.width() / aspectRatio));
+ }
+ image = QPixmap(imageSize);
+ image.fill(Qt::transparent);
+ QPainter painter(&image);
+ renderer.render(&painter, image.rect());
+ } else {
+ image = QPixmap(imagePath);
+ imageSize = image.size();
+ }
+
+ QPixmap result;
+ if (requestedSize.isValid() && requestedSize != imageSize)
+ result = image.scaled(requestedSize, Qt::KeepAspectRatio);
+ else
+ result = image;
+
+ *size = result.size();
+
+ return result;
+}
diff --git a/src/virtualkeyboard/styles/svgimageprovider.h b/src/virtualkeyboard/styles/svgimageprovider.h
new file mode 100644
index 00000000..c0f1a9e3
--- /dev/null
+++ b/src/virtualkeyboard/styles/svgimageprovider.h
@@ -0,0 +1,34 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 Digia Plc
+** All rights reserved.
+** For any questions to Digia, please use contact form at http://www.qt.io
+**
+** This file is part of the Qt Virtual Keyboard add-on for Qt Enterprise.
+**
+** Licensees holding valid Qt Enterprise licenses may use this file in
+** accordance with the Qt Enterprise License Agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia.
+**
+** If you have questions regarding the use of this file, please use
+** contact form at http://www.qt.io
+**
+****************************************************************************/
+
+#ifndef SVGIMAGEPROVIDER_H
+#define SVGIMAGEPROVIDER_H
+
+#include <QQuickImageProvider>
+
+class SvgImageProvider : public QQuickImageProvider
+{
+public:
+ explicit SvgImageProvider();
+ ~SvgImageProvider();
+
+ QPixmap requestPixmap(const QString &id, QSize *size, const QSize &requestedSize);
+};
+
+#endif // SVGIMAGEPROVIDER_H
+