Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Copyright 2015 Canonical Ltd.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; version 3.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
- import QtQuick 2.4
- MultiPointTouchArea {
- id: root
- /// Is true while the area is touched, and the finger did not yet lift
- property bool pressed: false
- /// Cancels the current pressed state of the mouse are
- function cancelPress() {
- pressed = false;
- }
- onPressed: {
- index = 0;
- pressed = true;
- rad = 0
- }
- onReleased: {
- pressed = false;
- }
- property int index: 0 // 0:center, 1:west, 2:northwest, 3:north, 4:northeast, 5:east, 6:southeast, 7:south, 8:southwest
- property int old_index: 0
- property real posX: point.x - parent.width / 2
- property real posY: point.y - parent.height / 2
- property real rad: 0
- property real heading: 0
- property real direction: -157.5
- touchPoints: [
- TouchPoint { id: point }
- ]
- onUpdated: {
- rad = Math.atan2(posY, posX)
- // if the swipe is short it's the center of the key
- if ((posX * posX + posY * posY) < (0.5 * parent.height * 0.5 * parent.height)) {
- index = 0
- } else {
- // calculate swipe angle; -180 < angle < 180 deg
- heading = rad * 180/Math.PI
- index = 1 // If the heading is less than -157.5 deg or greater than 157.5 deg the direction is West
- if (Math.abs(heading) < 157.5) {
- direction = -157.5
- while (direction < heading) {
- index++
- direction += 45
- }
- }
- }
- if (old_index != index) {
- old_index = index
- if (maliit_input_method.useHapticFeedback)
- pressEffect.start();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement