|
| 1 | +/* |
| 2 | + * Copyright (C) Jakub Pavelek <[email protected]> |
| 3 | + * Copyright (C) 2013 Jolla Ltd. |
| 4 | + * |
| 5 | + * Redistribution and use in source and binary forms, with or without modification, |
| 6 | + * are permitted provided that the following conditions are met: |
| 7 | + * |
| 8 | + * Redistributions of source code must retain the above copyright notice, this list |
| 9 | + * of conditions and the following disclaimer. |
| 10 | + * Redistributions in binary form must reproduce the above copyright notice, this list |
| 11 | + * of conditions and the following disclaimer in the documentation and/or other materials |
| 12 | + * provided with the distribution. |
| 13 | + * Neither the name of Nokia Corporation nor the names of its contributors may be |
| 14 | + * used to endorse or promote products derived from this software without specific |
| 15 | + * prior written permission. |
| 16 | + * |
| 17 | + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY |
| 18 | + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 19 | + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL |
| 20 | + * THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 21 | + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 22 | + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 23 | + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
| 24 | + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 25 | + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 26 | + * |
| 27 | + */ |
| 28 | + |
| 29 | +import QtQuick 2.0 |
| 30 | +import com.jolla.keyboard 1.0 |
| 31 | +import Sailfish.Silica 1.0 |
| 32 | +import org.nemomobile.configuration 1.0 |
| 33 | + |
| 34 | +Rectangle { |
| 35 | + id: popper |
| 36 | + |
| 37 | + ConfigurationValue { |
| 38 | + id: flickPopperConfig |
| 39 | + |
| 40 | + key: "/sailfish/text_input/flick_popper_enabled" |
| 41 | + defaultValue: false |
| 42 | + } |
| 43 | + |
| 44 | + opacity: 0 |
| 45 | + color: Qt.darker(Theme.highlightBackgroundColor, 1.2) |
| 46 | + height: portraitMode == false ? geometry.keyHeightLandscape |
| 47 | + : geometry.keyHeightPortrait |
| 48 | + width: portraitMode == false ? geometry.keyboardWidthLandscape / 5 |
| 49 | + : geometry.keyboardWidthPortrait / 5 |
| 50 | + radius: geometry.popperRadius |
| 51 | + visible: flickPopperConfig.value && popperText !== "" ? true : false |
| 52 | + |
| 53 | + property Item target: null |
| 54 | + property int popperIndex |
| 55 | + property string popperText: target !== null |
| 56 | + ? (target.enableFlicker === true |
| 57 | + ? target.currentText.charAt(popperIndex) |
| 58 | + : "") |
| 59 | + : "" |
| 60 | + |
| 61 | + onTargetChanged: { |
| 62 | + if (target && target.enableFlicker) { |
| 63 | + setup() |
| 64 | + } |
| 65 | + } |
| 66 | + |
| 67 | + PopperCell { |
| 68 | + width: parent.width |
| 69 | + height: parent.height |
| 70 | + character: popperText |
| 71 | + active: target === null ? false : target.flickerIndex == popperIndex |
| 72 | + } |
| 73 | + |
| 74 | + states: [ |
| 75 | + State { |
| 76 | + name: "active" |
| 77 | + when: target !== null && target.enableFlicker |
| 78 | + |
| 79 | + PropertyChanges { |
| 80 | + target: popper |
| 81 | + opacity: 1 |
| 82 | + } |
| 83 | + } |
| 84 | + ] |
| 85 | + |
| 86 | + transitions: [ |
| 87 | + Transition { |
| 88 | + from: "active" |
| 89 | + to: "" |
| 90 | + |
| 91 | + SequentialAnimation { |
| 92 | + PauseAnimation { duration: 20 } |
| 93 | + PropertyAction { |
| 94 | + target: popper |
| 95 | + properties: "opacity" |
| 96 | + } |
| 97 | + ScriptAction { |
| 98 | + script: { |
| 99 | + popper.opacity = 0 |
| 100 | + } |
| 101 | + } |
| 102 | + } |
| 103 | + } |
| 104 | + ] |
| 105 | + |
| 106 | + function setup() { |
| 107 | + // set the popper positions depending on the index position |
| 108 | + y = popper.parent.mapFromItem(target, 0, 0).y + (popperIndex == 1 || popperIndex == 3 |
| 109 | + ? 0 |
| 110 | + : (popperIndex == 2 |
| 111 | + ? -popper.height |
| 112 | + : popper.height)) |
| 113 | + x = popper.parent.mapFromItem(target, 0, 0).x + (popperIndex == 2 || popperIndex == 4 |
| 114 | + ? (target.width - popper.width) / 2 |
| 115 | + : (popperIndex == 1 |
| 116 | + ? -target.width + (target.width - popper.width) |
| 117 | + : target.width)) |
| 118 | + } |
| 119 | +} |
0 commit comments