Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[vkb] Key shift transition behavior
  • Loading branch information
Thomas Perl committed Sep 27, 2013
1 parent 8f454d0 commit 4f850d2
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 42 deletions.
Binary file modified icons/enter.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
91 changes: 52 additions & 39 deletions qml/Key.qml
Expand Up @@ -25,11 +25,12 @@ Rectangle {
property string label_alt: ""
property int code: 0
property int code_alt: 0
property int currentCode: code
property string currentLabel: keyLabel.text
property int currentCode: (shiftActive && label_alt != '') ? code_alt : code
property string currentLabel: (shiftActive && label_alt != '') ? label_alt : label
property bool sticky: false // can key be stickied?
property bool becomesSticky: false // will this become sticky after release?
property int stickiness: 0 // current stickiness status
property real labelOpacity: keyboard.active ? 1.0 : 0.3

// mouse input handling
property int clickThreshold: 20
Expand All @@ -44,52 +45,64 @@ Rectangle {
border.width: 1
radius: 5

Connections {
target: keyboard
onKeyModifiersChanged: {
if( (keyboard.keyModifiers & Qt.ShiftModifier) && !sticky ) {
if(key.label_alt!="") {
keyLabel.text = key.label_alt
keyAltLabel.text = key.label
key.currentCode = key.code_alt
} else if(key.label.length==1) {
keyLabel.text = key.label.toUpperCase()
}
} else if(!sticky) {
if(key.label.length==1)
keyLabel.text = key.label.toLowerCase()
else
keyLabel.text = key.label

keyAltLabel.text = key.label_alt
key.currentCode = key.code
}
}
}
property bool shiftActive: (keyboard.keyModifiers & Qt.ShiftModifier) && !sticky

Image {
id: keyImage
anchors.centerIn: parent
opacity: 0.4
opacity: key.labelOpacity
source: { if(key.label.length>1 && key.label.charAt(0)==':') return "qrc:/icons/"+key.label.substring(1)+".png"; else return ""; }
}

Text {
Column {
visible: keyImage.source == ""
id: keyLabel
anchors.centerIn: parent
text: key.label
color: keyboard.keyFgColor
font.pointSize: key.label.length>1 ? 18 : 26
}
Text {
id: keyAltLabel
anchors.bottom: parent.bottom
anchors.right: parent.right
text: key.label_alt
color: keyboard.keyFgColor
font.pointSize: key.label.length>1 ? 10 : 13
spacing: -17

Text {
id: keyAltLabel
property bool highlighted: key.shiftActive

anchors.horizontalCenter: parent.horizontalCenter

text: key.label_alt
color: keyboard.keyFgColor

opacity: key.labelOpacity * (highlighted ? 1.0 : 0.2)
Behavior on opacity { NumberAnimation { duration: 100 } }

font.pointSize: (highlighted ? 24 : 14) * (text.length > 1 ? 0.5 : 1.0)
Behavior on font.pointSize { NumberAnimation { duration: 100 } }
}

Text {
id: keyLabel
property bool highlighted: key.label_alt == '' || !key.shiftActive

anchors.horizontalCenter: parent.horizontalCenter

text: {
if (key.label.length == 1 && key.label_alt == '') {
if (key.shiftActive) {
return key.label.toUpperCase();
} else {
return key.label.toLowerCase();
}
}

return key.label;
}

color: keyboard.keyFgColor

opacity: key.labelOpacity * (highlighted ? 1.0 : 0.2)
Behavior on opacity { NumberAnimation { duration: 100 } }

font.pointSize: (highlighted ? 24 : 14) * (text.length > 1 ? 0.5 : 1.0)
Behavior on font.pointSize { NumberAnimation { duration: 100 } }
}
}

Rectangle {
id: stickIndicator
visible: sticky && stickiness>0
Expand Down Expand Up @@ -147,7 +160,7 @@ Rectangle {
key.color = keyboard.keyBgColor;
keyboard.currentKeyPressed = 0;

if (sticky) {
if (sticky && !becomesSticky) {
keyboard.keyModifiers &= ~code
keyboard.currentStickyPressed = null;
}
Expand Down
2 changes: 1 addition & 1 deletion qml/Keyboard.qml
Expand Up @@ -31,7 +31,7 @@ Rectangle {
property variant currentStickyPressed: null
property variant currentKeyPressed: 0

property string keyFgColor: "#565656"
property string keyFgColor: "#ffffff"
property string keyBgColor: "#202020"
property string keyHilightBgColor: "#ffffff"
property string keyBorderColor: "#303030"
Expand Down
2 changes: 0 additions & 2 deletions qml/Main.qml
Expand Up @@ -342,7 +342,6 @@ PageStackWindow {

lineView.duration = window.fadeOutTime;
textrender.duration = window.fadeOutTime;
vkb.keyFgColor = "#cccccc";
fadeTimer.restart();
vkb.active = true;
lineView.setPosition(vkb.active);
Expand All @@ -355,7 +354,6 @@ PageStackWindow {
{
textrender.duration = window.fadeInTime;
lineView.duration = window.fadeInTime;
vkb.keyFgColor = "#565656";
vkb.active = false;
lineView.setPosition(vkb.active);
util.updateSwipeLock(!vkb.active);
Expand Down

0 comments on commit 4f850d2

Please sign in to comment.