aboutsummaryrefslogtreecommitdiffstats
path: root/src/virtualkeyboard/styles/TraceUtils.js
diff options
context:
space:
mode:
authorJarkko Koivikko <jarkko.koivikko@code-q.fi>2015-02-12 10:07:00 +0200
committerJarkko Koivikko <jarkko.koivikko@code-q.fi>2015-06-17 12:33:42 +0300
commit28cf4492839f598a3058d40feab37a3274a02771 (patch)
treeb219ffa5c0679f8f99e454d65be5103c900ea14a /src/virtualkeyboard/styles/TraceUtils.js
parentd0ded0ea4a0f322fe1fd54348ad0e0b4ae74a1af (diff)
Add support for pattern recognition based input methods
This change adds generic support for pattern recognition based input methods. Added new API for the input engine and input method to process trace data. The trace data can originate from various input devices, e.g. from touch screen or from a dedicated hardware touch panel. Added new data model type for trace supporting both the C++ and QML interfaces. The new data model is DeclarativeTrace and Trace respectively, and it stores the trace data captured from the input device. The trace object is owned by the input method and is accessible to the UI layer, capture device and the input method. First, when the trace event begins, the capture device invokes the InputEngine.traceBegin(). The input engine forwards this call to the input method, which creates the trace object in response to successful call. Then the capture device receives the trace object and starts collecting the data. Also, in case of touch screen input, there are also the UI layer which renders the data. For this purpose there are new kinds of Style elements available in the Styles plugin. TraceCanvas is a specialized Canvas for rendering the trace object on screen. The TraceCanvas is a normal styling component, and can be customized like any other style element. Finally, the InputMethod.traceEnd() is called when the trace interaction ends. The trace is removed from screen automatically when the trace object is deleted. I.e., the input method has full control on how many traces it wants to collect for single recognition phase. Change-Id: I80ed90032f715726280197d9e94e7f0bd8280ff3 Reviewed-by: Gatis Paeglis <gatis.paeglis@theqtcompany.com>
Diffstat (limited to 'src/virtualkeyboard/styles/TraceUtils.js')
-rw-r--r--src/virtualkeyboard/styles/TraceUtils.js75
1 files changed, 75 insertions, 0 deletions
diff --git a/src/virtualkeyboard/styles/TraceUtils.js b/src/virtualkeyboard/styles/TraceUtils.js
new file mode 100644
index 00000000..b5b6d3bb
--- /dev/null
+++ b/src/virtualkeyboard/styles/TraceUtils.js
@@ -0,0 +1,75 @@
+/****************************************************************************
+**
+** 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
+**
+****************************************************************************/
+
+.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)
+ }
+ }
+
+ // Draw the remainder of the line
+ if (trace.isFinal) {
+ if (i < points.length) {
+ tp = points[i++]
+ ctx.lineTo(tp.x, tp.y)
+ }
+ }
+
+ if (i > 1)
+ ctx.stroke()
+
+ return renderPos + i - 1
+}