CharacterEaseKey.qml 6.67 KB
Newer Older
Jimmy HUGUET's avatar
Jimmy HUGUET committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
/*
 * Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
 * Copyright (C) 2012-2013 Jolla Ltd.
 *
 * Contact: Pekka Vuorela <pekka.vuorela@jollamobile.com>
 *
 * Redistribution and use in source and binary forms, with or without modification,
 * are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice, this list
 * of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright notice, this list
 * of conditions and the following disclaimer in the documentation and/or other materials
 * provided with the distribution.
 * Neither the name of Nokia Corporation nor the names of its contributors may be
 * used to endorse or promote products derived from this software without specific
 * prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
 * THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 */

import QtQuick 2.0
import com.jolla.keyboard 1.0
import Sailfish.Silica 1.0

KeyBase {
    id: aCharKey
    height: width

39 40 41 42 43 44 45 46 47 48 49 50 51
    property var keyValue: {
                                "caption":        "",
                                "captionShifted": "",
                                "swipeCaption":        ["", "", "", "", "", "", "", ""],
                                "swipeCaptionShifted": ["", "", "", "", "", "", "", ""],
                                "swipeSpecial":        ["", "", "", "", "", "", "", ""],
                                "symView": ""
                            }

    caption: keyValue["caption"]
    property string captionShifted: keyValue["captionShifted"]
    property string symView: keyValue["symView"]
    property string symView2: caption
Jimmy HUGUET's avatar
Jimmy HUGUET committed
52 53 54 55 56 57 58 59 60 61 62 63 64
    property int separator: SeparatorState.AutomaticSeparator
    property bool implicitSeparator: true // set by layouting
    property bool showHighlight: true
    property string accents
    property string accentsShifted
    property string nativeAccents // accents considered native to the written language. not rendered.
    property string nativeAccentsShifted
    property bool fixedWidth
    property alias useBoldFont: textItem.font.bold
    property alias pixelSize: textItem.font.pixelSize
    property alias fontSizeMode: textItem.fontSizeMode
    property alias textAnchors: textItem.anchors

65 66 67
    property var swipeCaption: keyValue["swipeCaption"]
    property var swipeCaptionShifted: keyValue["swipeCaptionShifted"]
    property var swipeSpecial: keyValue["swipeSpecial"]
Jimmy HUGUET's avatar
Jimmy HUGUET committed
68 69 70 71
    property int swipeValue: -1
    property point tempPoint: Qt.point(0,0)
    property point startPoint:Qt.point(0,0)
    property point currentPoint:Qt.point(0,0)
72
    property bool swipeHighlightEnable: true
Jimmy HUGUET's avatar
Jimmy HUGUET committed
73 74 75 76 77 78 79 80 81 82 83 84

    property var swipeArray: attributes.isShifted ? swipeCaptionShifted : swipeCaption

    keyType: KeyType.CharacterKey
    text: keyText
    keyText: swipeValue >= 0 ? (swipeArray[swipeValue] === "" ? swipeSpecial[swipeValue] : swipeArray[swipeValue])
                             : (attributes.inSymView && symView.length > 0 ? symView
                                                                           : (attributes.isShifted ? captionShifted : caption))

    Text {
        id: textItem
        anchors.fill: parent
85
        anchors.margins: Math.min(parent.width, parent.height) * 0.1
Jimmy HUGUET's avatar
Jimmy HUGUET committed
86 87 88 89 90 91 92 93 94 95 96
        horizontalAlignment: Text.AlignHCenter
        verticalAlignment: Text.AlignVCenter
        font.family: Theme.fontFamily
        font.pixelSize: Theme.fontSizeExtraLarge
        color: pressed ? Theme.highlightColor : Theme.primaryColor
        text: aCharKey.keyText
    }

    Repeater {
        model: swipeArray
        delegate: Text {
97 98
            width: Math.min(parent.width, parent.height) * 0.5
            height: width
Jimmy HUGUET's avatar
Jimmy HUGUET committed
99 100 101 102 103 104 105 106 107 108 109
            anchors.centerIn: textItem
            anchors.verticalCenterOffset: index < 3 ? -aCharKey.height * 0.4
                                                    : index > 4 ? aCharKey.height * 0.4
                                                                : 0
            anchors.horizontalCenterOffset: index == 0 || index == 3 || index == 5 ? -aCharKey.width * 0.3
                                                    : index == 2 || index == 4 || index == 7 ? aCharKey.width * 0.3
                                                                : 0
            horizontalAlignment: Text.AlignHCenter
            verticalAlignment: Text.AlignVCenter
            font.family: Theme.fontFamily
            font.pixelSize: Theme.fontSizeSmall
110
            fontSizeMode: Text.Fit
Jimmy HUGUET's avatar
Jimmy HUGUET committed
111 112
            color: Theme.primaryColor
            text: modelData === "" ? swipeSpecial[index] : !attributes.inSymView ? modelData : ""
113
            opacity: modelData !== "" ? 0.8 : attributes.inSymView2 || attributes.inSymView  ? 0.5 : 0
Jimmy HUGUET's avatar
Jimmy HUGUET committed
114 115 116 117 118 119 120 121 122 123 124
        }
    }

    Rectangle {
        anchors.centerIn: parent
        width: Math.max(textItem.implicitWidth, textItem.implicitHeight)
        height: width
        radius: width / 2
        z: -1
        color: Theme.highlightBackgroundColor
        opacity: 0.5
125
        visible: pressed && showHighlight && swipeHighlightEnable
Jimmy HUGUET's avatar
Jimmy HUGUET committed
126 127 128 129 130 131 132 133 134 135 136
    }

    Rectangle {
        x: startPoint.x
        y: startPoint.y
        width: Math.sqrt(Math.pow(xDist, 2) + Math.pow(yDist, 2) )
        height: Math.max(textItem.implicitWidth, textItem.implicitHeight) * 0.4
        radius: height / 2
        z: -1
        color: Theme.highlightBackgroundColor
        opacity: 0.3
137
        visible: swipeHighlightEnable
Jimmy HUGUET's avatar
Jimmy HUGUET committed
138 139 140 141 142 143 144 145 146 147 148
        transformOrigin: Item.Left

        property real xDist: startPoint.x - currentPoint.x
        property real yDist: startPoint.y - currentPoint.y
        property real rotValue: Math.atan(Math.abs(yDist) / Math.abs(xDist)) * 180 / Math.PI
        rotation: xDist > 0 && yDist > 0 ? 180 + rotValue
                                         : xDist < 0 && yDist < 0 ? rotValue
                                                                  : xDist < 0 && yDist > 0 ? - rotValue
                                                                                           : 180 - rotValue
    }
}