File size: 2,890 Bytes
a4cf109 |
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 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
import QtQuick 2.2
import QuickKeyboard 1.0
Item {
id: preview
property bool hasPreview: false
property Item keyboard
property Item btn
property int backgroundBorder: 3
property int padding: 10
property int centeredX: -width / 2 + btn.width / 2 + btn.x
property int minX: - backgroundBorder
property int maxX: btn.parent.width - width + backgroundBorder
property bool initTouch: true
x: Math.max(Math.min(centeredX, maxX), minX)
y: btn.y - height
width: buttonContent.width + backgroundBorder * 2
height: buttonContent.height + backgroundBorder * 2
visible: symbolsItems.count > 0
Rectangle {
id: shadow
x: 10
y: 5
width: background.width - 20
height: background.height
color: "darkgray"
radius: 4
}
Rectangle {
id: background
anchors.fill: parent
color: "white"
border.color: "black"
border.width: backgroundBorder
radius: 4
}
Component {
id: textPreview
Rectangle {
property bool active: (index == currentSymbolIndex)
color: active ? "black" : "transparent"
width: 70
height: 160
Text {
id: labelPreview
anchors.fill: parent
text: modelData
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
color: active ? "white" : "black"
font.family: "Noto Sans"
font.pixelSize: 50
font.weight: Font.Bold
}
}
}
Item {
id: buttonContent
x: backgroundBorder
y: backgroundBorder
height: 160
width: chars.width
Row {
id: chars
Repeater {
id: symbolsItems
model: 0
delegate: textPreview
}
}
MultiPointTouchArea {
id: buttonsArea
anchors.fill: parent
onPressed: {
symbolsItems.visible = true
symbolsItems.model = symbols
}
onReleased: {
if (touchPoints.length == 1) {
btn.triggered();
}
}
onTouchUpdated: {
if (touchPoints.length > 0) {
if (initTouch) {
initTouch = false;
currentSymbolIndex = Math.floor(symbolsItems.count / 2)
return;
}
var touchPoint = touchPoints[0];
var underMouseIndex = Math.floor(touchPoint.x * symbolsItems.count / chars.width);
if (underMouseIndex < 0) {
underMouseIndex = 0;
}
if (underMouseIndex >= symbolsItems.count) {
underMouseIndex = symbolsItems.count - 1;
}
currentSymbolIndex = underMouseIndex;
}
}
}
}
Timer {
interval: 500
running: mouseDown && symbols.length > 1
onTriggered: btn.GridLayout.layout.redirectEventsToItem(buttonsArea)
}
}
|