aboutsummaryrefslogtreecommitdiffstats
path: root/src/styles
diff options
context:
space:
mode:
authorJarkko Koivikko <jarkko.koivikko@code-q.fi>2018-05-27 12:12:06 +0300
committerMitch Curtis <mitch.curtis@qt.io>2018-08-06 08:20:01 +0000
commit59208edaaf40be982904a6c8cad4eab2d14f938e (patch)
treea613276e1f785e6cd82d019f01dbe478c7cebc5d /src/styles
parent263a16009e8d08004a546954cd7b2671c26fab9e (diff)
Modularize virtual keyboard and add an extension interface
With the extension interface it is possible to add new input method and/or languages without recompiling the Qt Virtual Keyboard plugin itself. The existing input methods are now isolated into plugins. So installing a new input method is a matter of copying the corresponding extension plugin to the plugins/virtualkeyboard directory (and any collateral required by the extension plugin itself). This change also renames the HunspellInputMethod to DefaultInputMethod. This change is necessary because some other extension plugin may want to provide the default input method instead. Implementation plan =================== [x] Create virtualkeyboard-private module [x] Create plugin library [x] Define interface for input method plugin [x] Define interface for keyboard layouts [x] Move existing input methods and layouts to plugins [x] HangulInputMethod [x] HunspellInputMethod [x] Maybe create a private library for sharing between HunspellInputMethod and LipiInputMethod [x] LipiInputMethod [x] OpenWnnInputMethod [x] PinyinInputMethod [x] T9WriteInputMethod [x] TCInputMethod [o] Rename some C++ classes (too generic name?) [x] Think again replacing the QtVirtualKeyboard namespace [x] Update documentation [x] General instructions for creating a plugin [x] For the C++ interfaces too (previously removed) [ChangeLog][Important Behavior Changes] Introduce an extension interface for the virtual keyboard. All the current input methods and some special keyboard layouts (e.g. Hunspell, OpenWnn, etc.) have been moved to extensions. The extension interface allows third party to create a new input method without having to modify or rebuild the virtual keyboard. In addition, this change makes it possible to add features and languages independently by copying the desired extension to the system. [ChangeLog][Important Behavior Changes] Introduce a virtualkeyboard module, which can be linked against an extension plugin. This module provides the C++ API necessary for creating an input method. [ChangeLog][Important Behavior Changes] Wrap the entire virtual keyboard API into Qt namespace (e.g. QT_BEGIN_NAMESPACE/QT_END_NAMESPACE). Task-number: QTBUG-57602 Change-Id: I449f4429109f596a7a1df7517c81f97d4aada27c Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Diffstat (limited to 'src/styles')
-rw-r--r--src/styles/KeyIcon.qml70
-rw-r--r--src/styles/KeyPanel.qml93
-rw-r--r--src/styles/KeyboardStyle.qml527
-rw-r--r--src/styles/SelectionListItem.qml64
-rw-r--r--src/styles/TraceCanvas.qml152
-rw-r--r--src/styles/TraceInputKeyPanel.qml61
-rw-r--r--src/styles/TraceUtils.js89
-rw-r--r--src/styles/plugins.qmltypes4
-rw-r--r--src/styles/qmldir4
-rw-r--r--src/styles/styles.pro23
-rw-r--r--src/styles/styles.qrc11
-rw-r--r--src/styles/styles_plugin.cpp75
-rw-r--r--src/styles/styles_plugin.h47
-rw-r--r--src/styles/svgimageprovider.cpp108
-rw-r--r--src/styles/svgimageprovider.h45
15 files changed, 1373 insertions, 0 deletions
diff --git a/src/styles/KeyIcon.qml b/src/styles/KeyIcon.qml
new file mode 100644
index 00000000..645fe11e
--- /dev/null
+++ b/src/styles/KeyIcon.qml
@@ -0,0 +1,70 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the Qt Virtual Keyboard module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:GPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 or (at your option) any later version
+** approved by the KDE Free Qt Foundation. The licenses are as published by
+** the Free Software Foundation and appearing in the file LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+import QtQuick 2.0
+
+/*!
+ \qmltype KeyIcon
+ \inqmlmodule QtQuick.VirtualKeyboard.Styles
+ \brief Key icon with adjustable color.
+ \ingroup qtvirtualkeyboard-styles-qml
+
+ The KeyIcon item displays an icon with adjustable color.
+*/
+
+Item {
+ /*! The icon color. */
+ property alias color: overlay.color
+ /*! The source image. */
+ property alias source: icon.source
+ Image {
+ id: icon
+ sourceSize.height: parent.height
+ sourceSize.width: parent.width
+ anchors.horizontalCenter: parent.horizontalCenter
+ anchors.verticalCenter: parent.verticalCenter
+ visible: false
+ }
+ ShaderEffect {
+ id: overlay
+ property color color
+ property variant texture: icon
+ anchors.fill: icon
+ fragmentShader: "
+ uniform lowp vec4 color;
+ uniform lowp float qt_Opacity;
+ uniform lowp sampler2D texture;
+ varying highp vec2 qt_TexCoord0;
+ void main() {
+ highp vec4 sample = texture2D(texture, qt_TexCoord0) * qt_Opacity;
+ gl_FragColor = vec4(color.rgb, 1.0) * sample.a;
+ }
+ "
+ }
+}
diff --git a/src/styles/KeyPanel.qml b/src/styles/KeyPanel.qml
new file mode 100644
index 00000000..4e12b9a8
--- /dev/null
+++ b/src/styles/KeyPanel.qml
@@ -0,0 +1,93 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the Qt Virtual Keyboard module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:GPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 or (at your option) any later version
+** approved by the KDE Free Qt Foundation. The licenses are as published by
+** the Free Software Foundation and appearing in the file LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+import QtQuick 2.0
+
+/*!
+ \qmltype KeyPanel
+ \inqmlmodule QtQuick.VirtualKeyboard.Styles
+ \brief A base type of the styled keys.
+ \ingroup qtvirtualkeyboard-styles-qml
+
+ All the key delegates provided by the style should be based on this type.
+*/
+
+Item {
+ /*! Provides access to properties in BaseKey.
+
+ A list of available properties in control:
+ \list
+ \li \c control.key Unicode code of the key.
+ \li \c control.text Unicode text of the key.
+ \li \c control.displayText Display text of the key.
+ \li \c control.smallText Small text of the key, usually rendered in the corner of the key.
+ \li \c control.smallTextVisible Visibility of the small text.
+ \li \c control.alternativeKeys List of alternative key sequences.
+ \li \c control.enabled Set to true when the key is enabled.
+ \li \c control.pressed Set to true when the key is currently pressed.
+ \li \c control.uppercased Set to true when the key is uppercased.
+ \endlist
+ */
+ property Item control
+
+ /*!
+ \since QtQuick.VirtualKeyboard.Styles 1.1
+
+ Sets the sound effect to be played on key press.
+ */
+ property url soundEffect
+
+ // Uncomment the following to reveal the key sizes
+ /*
+ Rectangle {
+ id: root
+ z: 1
+ color: "transparent"
+ border.color: "white"
+ anchors.fill: parent
+ Rectangle {
+ color: "black"
+ opacity: 0.6
+ anchors.top: parent.top
+ anchors.topMargin: 1
+ anchors.left: parent.left
+ anchors.leftMargin: 1
+ implicitWidth: keyPanelInfoText.width + 4
+ implicitHeight: keyPanelInfoText.height + 4
+ Text {
+ id: keyPanelInfoText
+ text: root.parent.width + "x" + root.parent.height
+ font.pixelSize: 12
+ color: "white"
+ anchors.centerIn: parent
+ }
+ }
+ }
+ */
+}
diff --git a/src/styles/KeyboardStyle.qml b/src/styles/KeyboardStyle.qml
new file mode 100644
index 00000000..1d1c8222
--- /dev/null
+++ b/src/styles/KeyboardStyle.qml
@@ -0,0 +1,527 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the Qt Virtual Keyboard module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:GPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 or (at your option) any later version
+** approved by the KDE Free Qt Foundation. The licenses are as published by
+** the Free Software Foundation and appearing in the file LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+import QtQuick 2.0
+
+/*!
+ \qmltype KeyboardStyle
+ \inqmlmodule QtQuick.VirtualKeyboard.Styles
+ \brief Provides a styling interface for the Virtual Keyboard.
+ \ingroup qtvirtualkeyboard-styles-qml
+
+ The style type provides the style definitions that are used by
+ the InputPanel to decorate the virtual keyboard.
+
+ The design size specifies the aspect ratio of the virtual keyboard.
+ Styles are scalable according to \l scaleHint, which is
+ calculated from the keyboard's actual height and design height.
+*/
+
+QtObject {
+ /*! The current height of the keyboard. */
+ property real keyboardHeight
+
+ /*! The design width of the keyboard. */
+ property real keyboardDesignWidth
+
+ /*! The design height of the keyboard. */
+ property real keyboardDesignHeight
+
+ /*! The keyboard style scale hint. This value is determined by dividing
+ \l keyboardHeight by \l keyboardDesignHeight. All pixel
+ dimensions must be proportional to this value.
+ */
+ readonly property real scaleHint: keyboardHeight / keyboardDesignHeight
+
+ /*!
+ The distance between the left-most keys and the left edge of the
+ keyboard, expressed as a percentage (\c 0.0 - \c 1.0) of the keyboard's
+ width.
+ */
+ property real keyboardRelativeLeftMargin: 0
+
+ /*!
+ The distance between the right-most keys and the right edge of the
+ keyboard, expressed as a percentage (\c 0.0 - \c 1.0) of the keyboard's
+ width.
+
+ This value is proportional to the keyboard's width.
+ */
+ property real keyboardRelativeRightMargin: 0
+
+ /*!
+ The distance between the top-most keys and the top edge of the
+ keyboard, expressed as a percentage (\c 0.0 - \c 1.0) of the keyboard's
+ height.
+ */
+ property real keyboardRelativeTopMargin: 0
+
+ /*!
+ The distance between the bottom-most keys and the bottom edge of the
+ keyboard container, expressed as a percentage (\c 0.0 - \c 1.0) of the
+ keyboard's height.
+ */
+ property real keyboardRelativeBottomMargin: 0
+
+ /*! Template for the keyboard background.
+
+ Example:
+ \code
+ keyboardBackground: Rectangle {
+ color: "black"
+ }
+ \endcode
+ */
+ property Component keyboardBackground: null
+
+ /*! Template for the regular keys.
+
+ \note The delegate must be based on the KeyPanel type.
+
+ Example:
+ \code
+ keyPanel: KeyPanel {
+ Rectangle {
+ anchors.fill: parent
+ ...
+ Text {
+ anchors.fill: parent
+ text: control.displayText
+ ...
+ }
+ }
+ }
+ \endcode
+ */
+ property Component keyPanel: null
+
+ /*! Template for the backspace key.
+
+ \note The delegate must be based on the KeyPanel type.
+ */
+ property Component backspaceKeyPanel: null
+
+ /*! Template for the language key.
+
+ \note The delegate must be based on the KeyPanel type.
+ */
+ property Component languageKeyPanel: null
+
+ /*! Template for the enter key.
+
+ \note The delegate must be based on the KeyPanel type.
+ */
+ property Component enterKeyPanel: null
+
+ /*! Template for the hide key.
+
+ \note The delegate must be based on the KeyPanel type.
+ */
+ property Component hideKeyPanel: null
+
+ /*! Template for the shift key.
+
+ \note The delegate must be based on the KeyPanel type.
+ */
+ property Component shiftKeyPanel: null
+
+ /*! Template for the space key.
+
+ \note The delegate must be based on the KeyPanel type.
+ */
+ property Component spaceKeyPanel: null
+
+ /*! Template for the symbol mode key.
+
+ \note The delegate must be based on the KeyPanel type.
+ */
+ property Component symbolKeyPanel: null
+
+ /*! Template for the generic mode key.
+
+ This template provides a visualization of the key in which the state
+ can be on or off. This template is used in situations where the key label
+ will remain the same regardless of status.
+
+ The current state is available in the \c control.mode property.
+
+ \note The delegate must be based on the KeyPanel type.
+ */
+ property Component modeKeyPanel: null
+
+ /*! Template for the handwriting mode key.
+
+ \note The delegate must be based on the KeyPanel type.
+ */
+ property Component handwritingKeyPanel: null
+
+ /*!
+ Number of pixels between the top of each key and the bottom of the
+ characterPreviewDelegate.
+ */
+ property real characterPreviewMargin: 0
+
+ /*! Template for the character preview popup.
+
+ If the delegate contains the \c text property, the property is updated
+ with the display text when the component becomes active.
+
+ \code
+ property string text
+ \endcode
+
+ Example:
+ \code
+ characterPreviewDelegate: Item {
+ property string text
+ id: characterPreview
+ Rectangle {
+ id: characterPreviewBackground
+ anchors.fill: parent
+ ...
+ Text {
+ text: characterPreview.text
+ anchors.fill: parent
+ ...
+ }
+ }
+ }
+ \endcode
+ */
+ property Component characterPreviewDelegate: null
+
+ /*! Width of the alternate keys list item. */
+ property real alternateKeysListItemWidth: 0
+
+ /*! Height of the alternate keys list item. */
+ property real alternateKeysListItemHeight: 0
+
+ /*! Top margin for the alternate keys list panel. */
+ property real alternateKeysListTopMargin: 0
+
+ /*! Bottom margin for the alternate keys list panel. */
+ property real alternateKeysListBottomMargin: 0
+
+ /*! Left margin for the alternate keys list panel. */
+ property real alternateKeysListLeftMargin: 0
+
+ /*! Right margin for the alternate keys list panel. */
+ property real alternateKeysListRightMargin: 0
+
+ /*! Template for the alternative keys list item.
+
+ \note The delegate is used in a \l ListView.
+ */
+ property Component alternateKeysListDelegate: null
+
+ /*! Template for the alternative keys list highlight.
+
+ \note The delegate is used as \c ListView.highlight.
+ */
+ property Component alternateKeysListHighlight: null
+
+ /*! Template for the alternative keys list background. */
+ property Component alternateKeysListBackground: null
+
+ /*! Selection list height. */
+ property real selectionListHeight: 0
+
+ /*! Template for the selection list item.
+
+ \note The delegate is used in a \l ListView.
+ \note The delegate must be based on the \l SelectionListItem type.
+
+ The following properties are available to the item:
+ \list
+ \li \c display Display text for the current item.
+ \li \c wordCompletionLength Word completion length measured from the end of the display text.
+ \endlist
+ */
+ property Component selectionListDelegate: null
+
+ /*! Template for the selection list highlight.
+
+ \note The delegate is used as \c ListView.highlight.
+ */
+ property Component selectionListHighlight: null
+
+ /*! Template for the selection list background. */
+ property Component selectionListBackground: null
+
+ /*! \since QtQuick.VirtualKeyboard.Styles 1.3
+
+ This property holds the transition to apply to items that
+ are added to the selection list view.
+ */
+ property Transition selectionListAdd
+
+ /*! \since QtQuick.VirtualKeyboard.Styles 1.3
+
+ This property holds the transition to apply to items that
+ are removed from the selection list view.
+ */
+ property Transition selectionListRemove
+
+ /*!
+ \since QtQuick.VirtualKeyboard.Styles 1.1
+
+ Template for the navigation highlight item.
+
+ This item is used in \l {Configuration Options}{arrow-key-navigation}
+ mode to highlight the navigation focus on the keyboard.
+
+ The item is typically a transparent rectangle with a
+ high contrast border.
+ */
+ property Component navigationHighlight: null
+
+ /*!
+ \since QtQuick.VirtualKeyboard.Styles 2.1
+
+ Template for the trace input key.
+
+ \note The delegate must be based on the TraceInputKeyPanel type.
+ */
+ property Component traceInputKeyPanelDelegate: null
+
+ /*!
+ \since QtQuick.VirtualKeyboard.Styles 2.1
+
+ Template for rendering a Trace object.
+
+ \note The delegate must be based on the TraceCanvas type.
+ */
+ property Component traceCanvasDelegate: null
+
+ /*! \since QtQuick.VirtualKeyboard.Styles 2.1
+
+ Template for the popup list item.
+
+ \note The delegate is used in a \l ListView.
+ \note The delegate must be based on the \l SelectionListItem type.
+
+ The following properties are available to the item:
+ \list
+ \li \c display Display text for the current item.
+ \li \c wordCompletionLength Word completion length measured from the end of the display text.
+ \endlist
+ */
+ property Component popupListDelegate: null
+
+ /*! \since QtQuick.VirtualKeyboard.Styles 2.1
+
+ Template for the popup list highlight.
+
+ \note The delegate is used as \c ListView.highlight.
+ */
+ property Component popupListHighlight: null
+
+ /*! \since QtQuick.VirtualKeyboard.Styles 2.1
+
+ Template for the popup list background.
+ */
+ property Component popupListBackground: null
+
+ /*! \since QtQuick.VirtualKeyboard.Styles 2.1
+
+ This property holds the transition to apply to items that
+ are added to the popup list view.
+ */
+ property Transition popupListAdd
+
+ /*! \since QtQuick.VirtualKeyboard.Styles 2.1
+
+ This property holds the transition to apply to items that
+ are removed from the popup list view.
+ */
+ property Transition popupListRemove
+
+ /*! \since QtQuick.VirtualKeyboard.Styles 2.1
+
+ This property determines whether a popup list will be shown when the
+ language key is clicked. If this property is \c false, clicking the
+ language key cycles through the available languages one at a time.
+
+ The default value is \c false.
+ */
+ property bool languagePopupListEnabled: false
+
+ /*! \since QtQuick.VirtualKeyboard.Styles 2.1
+
+ Template for the language list item.
+
+ \note The delegate is used in a \l ListView.
+ \note The delegate must be based on the \l SelectionListItem type.
+
+ The following properties are available to the item:
+ \list
+ \li \c display Display text for the current item.
+ \li \c wordCompletionLength Word completion length measured from the end of the display text.
+ \endlist
+ */
+ property Component languageListDelegate: null
+
+ /*! \since QtQuick.VirtualKeyboard.Styles 2.1
+
+ Template for the language list highlight.
+
+ \note The delegate is used as \c ListView.highlight.
+ */
+ property Component languageListHighlight: null
+
+ /*! \since QtQuick.VirtualKeyboard.Styles 2.1
+
+ Template for the language list background.
+ */
+ property Component languageListBackground: null
+
+ /*! \since QtQuick.VirtualKeyboard.Styles 2.1
+
+ This property holds the transition to apply to items that
+ are added to the language list view.
+ */
+ property Transition languageListAdd
+
+ /*! \since QtQuick.VirtualKeyboard.Styles 2.1
+
+ This property holds the transition to apply to items that
+ are removed from the language list view.
+ */
+ property Transition languageListRemove
+
+ /*!
+ \since QtQuick.VirtualKeyboard.Styles 2.1
+
+ This item is used to indicate where the bounds of the text selection is
+ and to be able to interactively move the start or end of the selection.
+ The same item is used for both start and end selection.
+
+ Selection handles are currently only supported for the
+ \l {Integration Method}{application-based integration method}.
+ */
+ property Component selectionHandle: null
+
+ /*!
+ \since QtQuick.VirtualKeyboard.Styles 2.2
+
+ This property holds the delegate for the background of the full screen
+ input container.
+ */
+ property Component fullScreenInputContainerBackground: null
+
+ /*!
+ \since QtQuick.VirtualKeyboard.Styles 2.2
+
+ This property holds the delegate for the background of the full screen
+ input.
+ */
+ property Component fullScreenInputBackground: null
+
+ /*!
+ \since QtQuick.VirtualKeyboard.Styles 2.2
+
+ This property holds the margins around the full screen input field.
+
+ The default value is \c 0.
+ */
+ property real fullScreenInputMargins: 0
+
+ /*!
+ \since QtQuick.VirtualKeyboard.Styles 2.2
+
+ This property holds the padding around the full screen input content.
+
+ The default value is \c 0.
+ */
+ property real fullScreenInputPadding: 0
+
+ /*!
+ \since QtQuick.VirtualKeyboard.Styles 2.2
+
+ This property holds the delegate for the cursor in the full screen input
+ field.
+
+ The delegate should toggle the visibility of the cursor according to
+ the \c {parent.blinkStatus} property defined for the full screen input
+ field. For example:
+
+ \code
+ fullScreenInputCursor: Rectangle {
+ width: 1
+ color: "#000"
+ visible: parent.blinkStatus
+ }
+ \endcode
+ */
+ property Component fullScreenInputCursor: null
+
+ /*!
+ \since QtQuick.VirtualKeyboard.Styles 2.2
+
+ This property holds the \c font for the full screen input field.
+ */
+ property font fullScreenInputFont
+
+ /*!
+ \since QtQuick.VirtualKeyboard.Styles 2.2
+
+ This property holds the password mask character for the full screen
+ input field.
+ */
+ property string fullScreenInputPasswordCharacter: "\u2022"
+
+ /*!
+ \since QtQuick.VirtualKeyboard.Styles 2.2
+
+ This property holds the text color for the full screen input field.
+
+ The default color is black.
+ */
+ property color fullScreenInputColor: "#000"
+
+ /*!
+ \since QtQuick.VirtualKeyboard.Styles 2.2
+
+ This property holds the selection color for the full screen input
+ field.
+
+ The default color is semi-transparent black.
+ */
+ property color fullScreenInputSelectionColor: Qt.rgba(0, 0, 0, 0.15)
+
+ /*!
+ \since QtQuick.VirtualKeyboard.Styles 2.2
+
+ This property holds the selected text color for the full screen input
+ field.
+
+ The default color is set to \c fullScreenInputColor.
+ */
+ property color fullScreenInputSelectedTextColor: fullScreenInputColor
+}
diff --git a/src/styles/SelectionListItem.qml b/src/styles/SelectionListItem.qml
new file mode 100644
index 00000000..f3c9fdc9
--- /dev/null
+++ b/src/styles/SelectionListItem.qml
@@ -0,0 +1,64 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the Qt Virtual Keyboard module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:GPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 or (at your option) any later version
+** approved by the KDE Free Qt Foundation. The licenses are as published by
+** the Free Software Foundation and appearing in the file LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+import QtQuick 2.0
+
+/*!
+ \qmltype SelectionListItem
+ \inqmlmodule QtQuick.VirtualKeyboard.Styles
+ \brief A base type for selection list item delegates.
+ \ingroup qtvirtualkeyboard-styles-qml
+
+ The SelectionListItem enables mouse handling for the selection list item
+ delegates.
+*/
+
+Item {
+ id: selectionListItem
+ height: parent.height
+
+ /*!
+ \since QtQuick.VirtualKeyboard.Styles 1.1
+
+ Sets the sound effect to be played on touch event.
+ */
+ property url soundEffect
+
+ MouseArea {
+ id: mouseArea
+ anchors.fill: parent
+ hoverEnabled: true
+ onClicked: {
+ if (index === -1)
+ return
+ selectionListItem.ListView.view.currentIndex = index
+ selectionListItem.ListView.view.model.selectItem(index)
+ }
+ }
+}
diff --git a/src/styles/TraceCanvas.qml b/src/styles/TraceCanvas.qml
new file mode 100644
index 00000000..ffee8538
--- /dev/null
+++ b/src/styles/TraceCanvas.qml
@@ -0,0 +1,152 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the Qt Virtual Keyboard module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:GPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 or (at your option) any later version
+** approved by the KDE Free Qt Foundation. The licenses are as published by
+** the Free Software Foundation and appearing in the file LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+import QtQuick 2.0
+import "TraceUtils.js" as TraceUtils
+
+/*!
+ \qmltype TraceCanvas
+ \inqmlmodule QtQuick.VirtualKeyboard.Styles
+ \brief A specialized Canvas type for rendering Trace objects.
+ \ingroup qtvirtualkeyboard-styles-qml
+ \inherits Canvas
+ \since QtQuick.VirtualKeyboard 2.0
+
+ This type provides capabilities for rendering Trace objects on the screen.
+
+ To make the Trace rendering available in the keyboard, this type must be
+ declared as the \l {KeyboardStyle::traceCanvasDelegate}
+ {KeyboardStyle.traceCanvasDelegate} component.
+
+ \code
+ traceCanvasDelegate: TraceCanvas {
+ }
+ \endcode
+
+ Custom drawing attributes can be initialized in the Canvas.available
+ signal. For example:
+
+ \code
+ onAvailableChanged: {
+ if (!available)
+ return;
+ var ctx = getContext("2d")
+ ctx.lineWidth = 8 * scaleHint
+ ctx.lineCap = "round"
+ ctx.strokeStyle = Qt.rgba(0xFF, 0xFF, 0xFF)
+ ctx.fillStyle = ctx.strokeStyle
+ }
+ \endcode
+
+ The type offers built-in options for Trace rendering. Currently
+ the following rendering options are available:
+
+ \list
+ \li \c renderSmoothedLine Renders smoothed line with round corners (the default)
+ \endlist
+
+ The rendering function can be changed with the renderFunction property.
+
+ \code
+ renderFunction: renderSmoothedLine
+ \endcode
+
+ Custom rendering function is also supported. Consider the following example:
+
+ \code
+ renderFunction: renderCustomLine
+
+ function renderCustomLine() {
+ getContext("2d")
+ var points = trace.points()
+
+ ...
+ }
+ \endcode
+*/
+
+Canvas {
+ id: canvas
+
+ /*! Provides access to \l Trace object.
+ */
+ property var trace
+
+ /*! Enables auto destruction mode.
+
+ If enabled, this item will be destroyed when the \c trace object is
+ destroyed.
+
+ The default value is false.
+ */
+ property bool autoDestroy
+
+ /*! Specifies the approximate delay in milliseconds, counted from the beginning of the
+ auto destruction, before the object is to be destroyed.
+
+ This delay makes it possible, for example, to animate the item before destruction.
+
+ The default value is 0.
+ */
+ property int autoDestroyDelay
+
+ /*! This property defines the rendering function.
+
+ The default value is \c renderSmoothedLine
+ */
+ property var renderFunction: renderSmoothedLine
+
+ property int __renderPos
+
+ property bool __renderingEnabled
+
+ /*! Renders smoothed line with round corners.
+
+ This function is incremental and renders only the new part added to the Trace.
+
+ This function does not alter any of the canvas attributes (i.e. they can be set elsewhere.)
+ */
+ function renderSmoothedLine() {
+ __renderPos = TraceUtils.renderSmoothedLine(getContext("2d"), trace, __renderPos)
+ }
+
+ onTraceChanged: if (trace === null && autoDestroy) destroy(autoDestroyDelay)
+
+ onAvailableChanged: {
+ __renderingEnabled = available
+ if (__renderingEnabled)
+ requestAnimationFrame(renderFunction)
+ }
+
+ Connections {
+ target: canvas.__renderingEnabled && trace ? trace : null
+ onLengthChanged: if (renderFunction) canvas.requestAnimationFrame(renderFunction)
+ onFinalChanged: if (renderFunction) canvas.requestAnimationFrame(renderFunction)
+ }
+}
diff --git a/src/styles/TraceInputKeyPanel.qml b/src/styles/TraceInputKeyPanel.qml
new file mode 100644
index 00000000..d128a12b
--- /dev/null
+++ b/src/styles/TraceInputKeyPanel.qml
@@ -0,0 +1,61 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the Qt Virtual Keyboard module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:GPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 or (at your option) any later version
+** approved by the KDE Free Qt Foundation. The licenses are as published by
+** the Free Software Foundation and appearing in the file LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+import QtQuick 2.0
+
+/*!
+ \qmltype TraceInputKeyPanel
+ \inqmlmodule QtQuick.VirtualKeyboard.Styles
+ \brief A base type of the trace input key.
+ \ingroup qtvirtualkeyboard-styles-qml
+ \since QtQuick.VirtualKeyboard 2.0
+
+ This type provides panel for decorating TraceInputKey
+ items in the keyboard layout.
+*/
+
+Item {
+ /*! Provides access to properties in TraceInputKey.
+
+ A list of available properties in control:
+ \list
+ \li \c patternRecognitionMode Pattern recognition mode of this input area
+ \li \c horizontalRulers A list of horizontal rulers
+ \li \c verticalRulers A list of vertical rulers
+ \li \c boundingBox Bounding box for the trace input
+ \endlist
+ */
+ property Item control
+
+ /*! Sets margins of the trace input area.
+
+ The margins affect to the bounding box of the trace input area.
+ */
+ property real traceMargins
+}
diff --git a/src/styles/TraceUtils.js b/src/styles/TraceUtils.js
new file mode 100644
index 00000000..f2dd9bbb
--- /dev/null
+++ b/src/styles/TraceUtils.js
@@ -0,0 +1,89 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the Qt Virtual Keyboard module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:GPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 or (at your option) any later version
+** approved by the KDE Free Qt Foundation. The licenses are as published by
+** the Free Software Foundation and appearing in the file LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+.pragma library
+
+function renderSmoothedLine(ctx, trace, renderPos) {
+
+ if (!trace)
+ return renderPos
+
+ if (renderPos >= trace.length)
+ return renderPos
+
+ // Fetch points and draw the initial "dot"
+ var points, tp
+ if (renderPos === 0) {
+ points = trace.points()
+ tp = points[renderPos++]
+ ctx.beginPath()
+ ctx.moveTo(tp.x, tp.y)
+ ctx.lineTo(tp.x, tp.y + 0.000001)
+ ctx.stroke()
+ } else {
+ points = trace.points(renderPos - 1)
+ }
+
+ // Draw smoothed line using quadratic curve
+ var i = 1
+ if (i + 1 < points.length) {
+ var pt1, pt2
+ if (renderPos === 1) {
+ tp = points[i - 1]
+ } else {
+ pt1 = points[i - 1]
+ pt2 = points[i]
+ tp = Qt.point((pt1.x + pt2.x) / 2, (pt1.y + pt2.y) / 2)
+ }
+ ctx.beginPath()
+ ctx.moveTo(tp.x, tp.y)
+ while (i + 1 < points.length) {
+ pt1 = points[i++]
+ pt2 = points[i]
+ tp = Qt.point((pt1.x + pt2.x) / 2, (pt1.y + pt2.y) / 2)
+ ctx.quadraticCurveTo(pt1.x, pt1.y, tp.x, tp.y)
+ ctx.moveTo(tp.x, tp.y)
+ }
+ ctx.stroke()
+ }
+
+ // Draw the remainder of the line
+ if (trace.isFinal) {
+ if (i < points.length) {
+ tp = points[i - 1]
+ ctx.beginPath()
+ ctx.moveTo(tp.x, tp.y)
+ tp = points[i++]
+ ctx.lineTo(tp.x, tp.y)
+ ctx.stroke()
+ }
+ }
+
+ return renderPos + i - 1
+}
diff --git a/src/styles/plugins.qmltypes b/src/styles/plugins.qmltypes
new file mode 100644
index 00000000..3ef80efb
--- /dev/null
+++ b/src/styles/plugins.qmltypes
@@ -0,0 +1,4 @@
+import QtQuick.tooling 1.1
+
+Module {
+}
diff --git a/src/styles/qmldir b/src/styles/qmldir
new file mode 100644
index 00000000..26544a54
--- /dev/null
+++ b/src/styles/qmldir
@@ -0,0 +1,4 @@
+module QtQuick.VirtualKeyboard.Styles
+plugin qtvirtualkeyboardstylesplugin
+classname QtVirtualKeyboardStylesPlugin
+typeinfo plugins.qmltypes
diff --git a/src/styles/styles.pro b/src/styles/styles.pro
new file mode 100644
index 00000000..f5ce051f
--- /dev/null
+++ b/src/styles/styles.pro
@@ -0,0 +1,23 @@
+TARGET = qtvirtualkeyboardstylesplugin
+TARGETPATH = QtQuick/VirtualKeyboard/Styles
+QT += qml quick svg
+
+CONFIG += no_cxx_module
+
+SOURCES += \
+ svgimageprovider.cpp \
+ styles_plugin.cpp
+
+HEADERS += \
+ svgimageprovider.h \
+ styles_plugin.h
+
+RESOURCES += \
+ styles.qrc
+
+win32 {
+ QMAKE_TARGET_PRODUCT = "Qt Virtual Keyboard (Qt $$QT_VERSION)"
+ QMAKE_TARGET_DESCRIPTION = "Virtual Keyboard for Qt."
+}
+
+load(qml_plugin)
diff --git a/src/styles/styles.qrc b/src/styles/styles.qrc
new file mode 100644
index 00000000..819d4771
--- /dev/null
+++ b/src/styles/styles.qrc
@@ -0,0 +1,11 @@
+<RCC>
+ <qresource prefix="/QtQuick/VirtualKeyboard/Styles/content">
+ <file>KeyboardStyle.qml</file>
+ <file>KeyIcon.qml</file>
+ <file>KeyPanel.qml</file>
+ <file>SelectionListItem.qml</file>
+ <file>TraceInputKeyPanel.qml</file>
+ <file>TraceCanvas.qml</file>
+ <file>TraceUtils.js</file>
+ </qresource>
+</RCC>
diff --git a/src/styles/styles_plugin.cpp b/src/styles/styles_plugin.cpp
new file mode 100644
index 00000000..f65ae42d
--- /dev/null
+++ b/src/styles/styles_plugin.cpp
@@ -0,0 +1,75 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the Qt Virtual Keyboard module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:GPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 or (at your option) any later version
+** approved by the KDE Free Qt Foundation. The licenses are as published by
+** the Free Software Foundation and appearing in the file LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "styles_plugin.h"
+#include "svgimageprovider.h"
+
+#include <qqml.h>
+#include <QtCore/QLibraryInfo>
+
+/*!
+ \qmlmodule QtQuick.VirtualKeyboard.Styles 2.2
+ \title Qt Quick Virtual Keyboard Styles QML Types
+ \ingroup qmlmodules
+
+ \brief Provides styling for Qt Virtual Keyboard.
+
+ The QML types can be imported into your application using the following
+ import statements in your .qml file:
+
+ \code
+ import QtQuick.VirtualKeyboard.Styles 2.2
+ \endcode
+*/
+
+void QtVirtualKeyboardStylesPlugin::registerTypes(const char *uri)
+{
+ const QString path(QStringLiteral("qrc:///QtQuick/VirtualKeyboard/Styles/content/"));
+ qmlRegisterType(QUrl(path + QLatin1String("KeyboardStyle.qml")), uri, 1, 0, "KeyboardStyle");
+ qmlRegisterType(QUrl(path + QLatin1String("KeyboardStyle.qml")), uri, 1, 1, "KeyboardStyle");
+ qmlRegisterType(QUrl(path + QLatin1String("KeyboardStyle.qml")), uri, 1, 2, "KeyboardStyle");
+ qmlRegisterType(QUrl(path + QLatin1String("KeyboardStyle.qml")), uri, 1, 3, "KeyboardStyle");
+ qmlRegisterType(QUrl(path + QLatin1String("KeyboardStyle.qml")), uri, 2, 0, "KeyboardStyle");
+ qmlRegisterType(QUrl(path + QLatin1String("KeyboardStyle.qml")), uri, 2, 1, "KeyboardStyle");
+ qmlRegisterType(QUrl(path + QLatin1String("KeyboardStyle.qml")), uri, 2, 2, "KeyboardStyle");
+ qmlRegisterType(QUrl(path + QLatin1String("KeyIcon.qml")), uri, 1, 0, "KeyIcon");
+ qmlRegisterType(QUrl(path + QLatin1String("KeyIcon.qml")), uri, 2, 0, "KeyIcon");
+ qmlRegisterType(QUrl(path + QLatin1String("KeyPanel.qml")), uri, 1, 0, "KeyPanel");
+ qmlRegisterType(QUrl(path + QLatin1String("KeyPanel.qml")), uri, 2, 0, "KeyPanel");
+ qmlRegisterType(QUrl(path + QLatin1String("SelectionListItem.qml")), uri, 1, 0, "SelectionListItem");
+ qmlRegisterType(QUrl(path + QLatin1String("SelectionListItem.qml")), uri, 2, 0, "SelectionListItem");
+ qmlRegisterType(QUrl(path + QLatin1String("TraceInputKeyPanel.qml")), uri, 2, 0, "TraceInputKeyPanel");
+ qmlRegisterType(QUrl(path + QLatin1String("TraceCanvas.qml")), uri, 2, 0, "TraceCanvas");
+}
+
+void QtVirtualKeyboardStylesPlugin::initializeEngine(QQmlEngine *engine, const char *uri)
+{
+ Q_UNUSED(uri)
+ engine->addImageProvider(QStringLiteral("qtvkbsvg"), new SvgImageProvider());
+}
diff --git a/src/styles/styles_plugin.h b/src/styles/styles_plugin.h
new file mode 100644
index 00000000..0eca2e9b
--- /dev/null
+++ b/src/styles/styles_plugin.h
@@ -0,0 +1,47 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the Qt Virtual Keyboard module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:GPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 or (at your option) any later version
+** approved by the KDE Free Qt Foundation. The licenses are as published by
+** the Free Software Foundation and appearing in the file LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef STYLES_PLUGIN_H
+#define STYLES_PLUGIN_H
+
+#include <QQmlExtensionPlugin>
+
+class QtVirtualKeyboardStylesPlugin : public QQmlExtensionPlugin
+{
+ Q_OBJECT
+ Q_PLUGIN_METADATA(IID QQmlExtensionInterface_iid)
+
+public:
+ QtVirtualKeyboardStylesPlugin(QObject *parent = 0) : QQmlExtensionPlugin(parent) { }
+ void registerTypes(const char *uri);
+ void initializeEngine(QQmlEngine *engine, const char *uri);
+};
+
+#endif // STYLES_PLUGIN_H
+
diff --git a/src/styles/svgimageprovider.cpp b/src/styles/svgimageprovider.cpp
new file mode 100644
index 00000000..1dd2930f
--- /dev/null
+++ b/src/styles/svgimageprovider.cpp
@@ -0,0 +1,108 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the Qt Virtual Keyboard module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:GPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 or (at your option) any later version
+** approved by the KDE Free Qt Foundation. The licenses are as published by
+** the Free Software Foundation and appearing in the file LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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;
+ for (const QString &param : paramList) {
+ QStringList keyValue = param.split(QChar('='), QString::SkipEmptyParts);
+ if (keyValue.length() == 2)
+ params[keyValue[0]] = keyValue[1];
+ }
+ const auto widthIt = params.constFind("width");
+ if (widthIt != params.cend()) {
+ bool ok = false;
+ int value = widthIt.value().toInt(&ok);
+ if (ok)
+ imageSize.setWidth(value);
+ }
+ const auto heightIt = params.constFind("height");
+ if (heightIt != params.cend()) {
+ bool ok = false;
+ int value = heightIt.value().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/styles/svgimageprovider.h b/src/styles/svgimageprovider.h
new file mode 100644
index 00000000..476689bf
--- /dev/null
+++ b/src/styles/svgimageprovider.h
@@ -0,0 +1,45 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the Qt Virtual Keyboard module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:GPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 or (at your option) any later version
+** approved by the KDE Free Qt Foundation. The licenses are as published by
+** the Free Software Foundation and appearing in the file LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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
+