Commit a0de3681 authored by Jimmy HUGUET's avatar Jimmy HUGUET

Draw nice curve

parent b0a583ad
......@@ -33,6 +33,7 @@ Item {
property string lastAccentMerge: ""
property var moveSerie: []
property var fullMoveSerie: []
property string lowercase: "abcdefghijklmnopqrstuvwxyz"
property string uppercase: "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
......@@ -115,6 +116,7 @@ Item {
}
}
MultiPointTouchArea {
anchors.fill: parent
maximumTouchPoints: 1
......@@ -124,7 +126,11 @@ Item {
var touchpoint = touchPoints[0]
var pos = getPos(touchpoint.x, touchpoint.y)
moveSerie.push(pos)
fullMoveSerie.push(pos)
evaluateSelection()
updatePaint(touchpoint.x, touchpoint.y)
paint.pathData = "M%1,%2".arg (touchpoint.x).arg (touchpoint.y);
paint.canErase = false
}
onUpdated: {
var touchpoint = touchPoints[0]
......@@ -137,15 +143,22 @@ Item {
processInput()
}
moveSerie.push(pos)
fullMoveSerie.push(pos)
}
}
evaluateSelection()
updatePaint(touchpoint.x, touchpoint.y)
paint.pathData += "L%1,%2".arg (touchpoint.x).arg (touchpoint.y);
}
onReleased: {
processInput()
moveSerie = []
fullMoveSerie = []
evaluateSelection()
updatePaint()
paint.pathData = ""
paint.canErase = true
}
//onCanceled: keyboard.handleCanceled(touchPoints)
}
......@@ -377,13 +390,13 @@ Item {
implicitWidth: shiftKeyWidth
background.visible: true
anchors.centerIn: parent
anchors.verticalCenterOffset: - parent.height / 2 - height * 0.5
anchors.verticalCenterOffset: - parent.height / 2 + height * 2.5
anchors.horizontalCenterOffset: parent.height / 2
property bool pressed: false
MultiPointTouchArea {
anchors.fill: backspaceKey
anchors.fill: specialKey
maximumTouchPoints: 1
onReleased: {
......@@ -399,5 +412,39 @@ Item {
anchors.verticalCenterOffset: parent.height / 2 + height
}
Paint {
id: paint
anchors.fill: parent
lineColor: Theme.primaryColor
lineSize: 5
baseOpacity: 0.5
}
property var angleMap: {"downright": 30 * Math.PI / 180, "down": 90 * Math.PI / 180, "downleft": 150 * Math.PI / 180, "upleft": 210 * Math.PI / 180, "up": 270 * Math.PI / 180, "upright": 330 * Math.PI / 180}
function updatePaint(x,y) {
/*if (x === undefined || y === undefined){
paint.pathData = ""
return
}
var path = ""
if (fullMoveSerie[0] === "center"){
path += "M%1,%2".arg (xCenter).arg (yCenter)
} else {
var angle = angleMap[fullMoveSerie[0]]
path += "M%1,%2".arg (xCenter + Math.cos(angle) * centerDot.width).arg (yCenter + Math.sin(angle) * centerDot.width)
}
for (var i = 1; i < fullMoveSerie.length; i++) {
var sector = fullMoveSerie[i]
if (sector === "center") {
path += "L%1,%2".arg (xCenter).arg (yCenter)
} else {
var angle = angleMap[sector]
path += "L%1,%2".arg (xCenter + Math.cos(angle) * centerDot.width).arg (yCenter + Math.sin(angle) * centerDot.width)
}
}
path += "L%1,%2".arg (x).arg (y)
paint.pathData = path*/
}
}
import QtQuick 2.6;
Item {
onPathDataChanged: {
lastUpdate = Date.now()
if (toggle) {
if (!imgBusy2) {
pathDataCache1 = pathData;
toggle = false;
}
}
else {
if (!imgBusy1) {
pathDataCache2 = pathData;
toggle = true;
}
}
}
Timer {
interval: 50
repeat: true
running: true
onTriggered: {
var now = Date.now()
if (now - lastUpdate > 100 && canErase) {
paint.opacity -= 0.1
} else {
paint.opacity = baseOpacity
}
if (paint.opacity === 0){
pathData = ""
pathDataCache1 = ""
pathDataCache2 = ""
canErase = false
}
}
}
property real baseOpacity: 1
property bool canErase: false
property real lastUpdate: Date.now()
property int lineSize : 2;
property color lineColor : "blue";
property string pathData : "";
property string pathDataCache1 : "";
property string pathDataCache2 : "";
property bool toggle : false;
property bool imgBusy1 : false;
property bool imgBusy2 : false;
Repeater {
model: 2;
delegate: Image {
source: 'data:image/svg+xml,<?xml version="1.0" encoding="utf-8"?><svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="%1" height="%2"><path d="%3" fill="none" stroke="%4" stroke-width="%5" /></svg>'.arg (width).arg (height).arg (parent ["pathDataCache" + num]).arg (lineColor).arg (lineSize);
cache: false;
mipmap: false;
smooth: true;
opacity: (toggle
? (model.index ? 0 : 1)
: (model.index ? 1 : 0));
fillMode: Image.Pad;
antialiasing: true;
asynchronous: false;
anchors.fill: parent;
onStatusChanged: { parent ["imgBusy" + num] = (status === Image.Loading); }
readonly property string num : (model.index +1).toString ();
}
}
}
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