| 1 |
/* |
| 2 |
* Copyright 2016 Canonical Ltd. |
| 3 |
* |
| 4 |
* This program is free software; you can redistribute it and/or modify |
| 5 |
* it under the terms of the GNU Lesser General Public License as published by |
| 6 |
* the Free Software Foundation; version 3. |
| 7 |
* |
| 8 |
* This program is distributed in the hope that it will be useful, |
| 9 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 |
* GNU Lesser General Public License for more details. |
| 12 |
* |
| 13 |
* You should have received a copy of the GNU Lesser General Public License |
| 14 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 15 |
*/ |
| 16 |
|
| 17 |
import QtQuick 2.4 |
| 18 |
import Lomiri.Components |
| 19 |
|
| 20 |
// FIXME : move the API into Lomiri.Components.Style |
| 21 |
Item { |
| 22 |
id: cursorStyle |
| 23 |
/*! |
| 24 |
Property specifying the visible timeout of the cursor. It is not mandatory |
| 25 |
for styles to define values for this property if the cursor blinking is not |
| 26 |
desired. A value of 0 turns off the cursor blinking. |
| 27 |
*/ |
| 28 |
property int cursorVisibleTimeout: 800 |
| 29 |
/*! |
| 30 |
Property specifying the hidden timeout of the cursor. It is not mandatory |
| 31 |
for styles to define values for this property if the cursor blinking is not |
| 32 |
desired. A value of 0 turns off the cursor blinking. |
| 33 |
*/ |
| 34 |
property int cursorHiddenTimeout: 400 |
| 35 |
|
| 36 |
/*! |
| 37 |
Component defining the default cursor visuals. |
| 38 |
*/ |
| 39 |
property Component cursorDelegate: delegate |
| 40 |
|
| 41 |
/*! |
| 42 |
The item pointing to the cursor handler. Styles should set to null if the |
| 43 |
cursor does not have handler at all. |
| 44 |
*/ |
| 45 |
property Item caret: caretItem |
| 46 |
|
| 47 |
/*! |
| 48 |
The width of the cursor. |
| 49 |
*/ |
| 50 |
property int cursorWidth: units.dp(2) |
| 51 |
|
| 52 |
// style body |
| 53 |
Component { |
| 54 |
id: delegate |
| 55 |
Rectangle { |
| 56 |
objectName: "text_cursor_style_" + styledItem.positionProperty |
| 57 |
width: cursorWidth |
| 58 |
|
| 59 |
color: theme.palette.normal.positionText |
| 60 |
visible: blinkTimer.timerShowCursor || !blinkTimer.running |
| 61 |
Timer { |
| 62 |
id: blinkTimer |
| 63 |
interval: cursorStyle.cursorVisibleTimeout |
| 64 |
running: (cursorStyle.cursorVisibleTimeout > 0) && |
| 65 |
(cursorStyle.cursorHiddenTimeout > 0) && |
| 66 |
styledItem.visible && |
| 67 |
shouldBlink |
| 68 |
repeat: true |
| 69 |
property bool shouldBlink: styledItem.positionProperty === "cursorPosition" && !styledItem.readOnly && !styledItem.contextMenuVisible |
| 70 |
property bool timerShowCursor: true |
| 71 |
onTriggered: { |
| 72 |
interval = (interval === cursorStyle.cursorVisibleTimeout) ? |
| 73 |
cursorStyle.cursorHiddenTimeout : cursorStyle.cursorVisibleTimeout; |
| 74 |
timerShowCursor = !timerShowCursor; |
| 75 |
} |
| 76 |
} |
| 77 |
} |
| 78 |
} |
| 79 |
|
| 80 |
// caretItem |
| 81 |
Image { |
| 82 |
id: caretItem |
| 83 |
source: Qt.resolvedUrl("../artwork/[email protected]") |
| 84 |
width: units.gu(1.25) |
| 85 |
height: units.gu(1.25) |
| 86 |
objectName: "text_cursor_style_caret_" + styledItem.positionProperty |
| 87 |
property bool flip: styledItem.positionProperty !== "selectionStart" |
| 88 |
rotation: flip ? 180 : 0 |
| 89 |
anchors { |
| 90 |
top: flip ? parent.bottom : undefined |
| 91 |
bottom: flip ? undefined : parent.top |
| 92 |
horizontalCenter: parent.horizontalCenter |
| 93 |
horizontalCenterOffset: cursorWidth / 2 |
| 94 |
} |
| 95 |
} |
| 96 |
} |