mirror of
https://github.com/overte-org/overte.git
synced 2025-06-03 01:33:03 +02:00
Scroll and snap to attachment with focus
This commit is contained in:
parent
c7d1aa8ff4
commit
b539c55c02
5 changed files with 79 additions and 20 deletions
|
@ -25,6 +25,8 @@ Original.CheckBox {
|
|||
readonly property int checkSize: Math.max(boxSize - 8, 10)
|
||||
readonly property int checkRadius: 2
|
||||
|
||||
activeFocusOnPress: true
|
||||
|
||||
style: CheckBoxStyle {
|
||||
indicator: Rectangle {
|
||||
id: box
|
||||
|
|
|
@ -17,10 +17,24 @@ Item {
|
|||
|
||||
HifiConstants { id: hifi }
|
||||
|
||||
signal selectAttachment();
|
||||
signal deleteAttachment(var attachment);
|
||||
signal updateAttachment();
|
||||
property bool completed: false;
|
||||
|
||||
function doSelectAttachment(control, focus) {
|
||||
if (focus) {
|
||||
selectAttachment();
|
||||
|
||||
// Refocus control after possibly changing focus to attachment.
|
||||
if (control.setControlFocus !== undefined) {
|
||||
control.setControlFocus();
|
||||
} else {
|
||||
control.focus = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Rectangle { color: hifi.colors.baseGray; anchors.fill: parent; radius: 4 }
|
||||
|
||||
Component.onCompleted: {
|
||||
|
@ -50,6 +64,7 @@ Item {
|
|||
updateAttachment();
|
||||
}
|
||||
}
|
||||
onFocusChanged: doSelectAttachment(this, focus);
|
||||
}
|
||||
HifiControls.Button {
|
||||
id: modelChooserButton;
|
||||
|
@ -91,6 +106,7 @@ Item {
|
|||
updateAttachment();
|
||||
}
|
||||
}
|
||||
onFocusChanged: doSelectAttachment(this, focus);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -108,6 +124,7 @@ Item {
|
|||
updateAttachment();
|
||||
}
|
||||
}
|
||||
onControlFocusChanged: doSelectAttachment(this, controlFocus);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -125,6 +142,7 @@ Item {
|
|||
updateAttachment();
|
||||
}
|
||||
}
|
||||
onControlFocusChanged: doSelectAttachment(this, controlFocus);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -153,6 +171,7 @@ Item {
|
|||
updateAttachment();
|
||||
}
|
||||
}
|
||||
onFocusChanged: doSelectAttachment(this, focus);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -178,6 +197,7 @@ Item {
|
|||
updateAttachment();
|
||||
}
|
||||
}
|
||||
onFocusChanged: doSelectAttachment(this, focus);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,9 +15,37 @@ Item {
|
|||
property real stepSize: 1
|
||||
property real maximumValue: 99
|
||||
property real minimumValue: 0
|
||||
property bool controlFocus: false; // True if one of the ordinate controls has focus.
|
||||
property var controlFocusControl: undefined
|
||||
|
||||
signal valueChanged();
|
||||
|
||||
function setControlFocus() {
|
||||
if (controlFocusControl) {
|
||||
controlFocusControl.focus = true;
|
||||
// The controlFocus value is updated via onFocusChanged.
|
||||
}
|
||||
}
|
||||
|
||||
function setFocus(control, focus) {
|
||||
if (focus) {
|
||||
controlFocusControl = control;
|
||||
setControlFocusTrue.start(); // After any subsequent false from previous control.
|
||||
} else {
|
||||
controlFocus = false;
|
||||
}
|
||||
}
|
||||
|
||||
Timer {
|
||||
id: setControlFocusTrue
|
||||
interval: 50
|
||||
repeat: false
|
||||
running: false
|
||||
onTriggered: {
|
||||
controlFocus = true;
|
||||
}
|
||||
}
|
||||
|
||||
HifiConstants { id: hifi }
|
||||
|
||||
HifiControls.SpinBox {
|
||||
|
@ -38,6 +66,7 @@ Item {
|
|||
root.valueChanged();
|
||||
}
|
||||
}
|
||||
onFocusChanged: setFocus(this, focus);
|
||||
}
|
||||
|
||||
HifiControls.SpinBox {
|
||||
|
@ -58,6 +87,7 @@ Item {
|
|||
root.valueChanged();
|
||||
}
|
||||
}
|
||||
onFocusChanged: setFocus(this, focus);
|
||||
}
|
||||
|
||||
HifiControls.SpinBox {
|
||||
|
@ -78,6 +108,6 @@ Item {
|
|||
root.valueChanged();
|
||||
}
|
||||
}
|
||||
onFocusChanged: setFocus(this, focus);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -45,17 +45,32 @@ Item {
|
|||
anchors.fill: parent
|
||||
anchors.margins: 4
|
||||
clip: true
|
||||
focus: true
|
||||
snapMode: ListView.SnapToItem
|
||||
|
||||
model: ListModel {}
|
||||
delegate: Item {
|
||||
id: attachmentDelegate
|
||||
implicitHeight: attachmentView.height + 8;
|
||||
implicitWidth: attachmentView.width
|
||||
|
||||
MouseArea {
|
||||
// User can click on whitespace to select item.
|
||||
anchors.fill: parent
|
||||
propagateComposedEvents: true
|
||||
onClicked: {
|
||||
listView.currentIndex = index;
|
||||
attachmentsBackground.forceActiveFocus(); // Unfocus from any control.
|
||||
mouse.accepted = false;
|
||||
}
|
||||
}
|
||||
|
||||
Attachment {
|
||||
id: attachmentView
|
||||
width: listView.width
|
||||
attachment: content.attachments[index]
|
||||
onSelectAttachment: {
|
||||
listView.currentIndex = index;
|
||||
}
|
||||
onDeleteAttachment: {
|
||||
attachments.splice(index, 1);
|
||||
listView.model.remove(index, 1);
|
||||
|
@ -63,11 +78,18 @@ Item {
|
|||
onUpdateAttachment: MyAvatar.setAttachmentsVariant(attachments);
|
||||
}
|
||||
}
|
||||
|
||||
onCountChanged: MyAvatar.setAttachmentsVariant(attachments);
|
||||
|
||||
function scrollBy(delta) {
|
||||
// @@@@@@@
|
||||
//flickableItem.contentY += delta;
|
||||
/* */
|
||||
// DEBUG
|
||||
highlight: Rectangle { color: "#40ffff00" }
|
||||
highlightFollowsCurrentItem: true
|
||||
/* */
|
||||
|
||||
onHeightChanged: {
|
||||
// Keyboard has been raised / lowered.
|
||||
positionViewAtIndex(currentIndex, ListView.SnapPosition);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -145,9 +167,4 @@ Item {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
function scrollBy(delta) {
|
||||
listView.scrollBy(delta);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -107,16 +107,6 @@ Item {
|
|||
}
|
||||
}
|
||||
|
||||
onKeyboardRaisedChanged: {
|
||||
if (keyboardEnabled && keyboardRaised) {
|
||||
var buttonsHeight = 120; // Allow for New Attachment plus Cancel & OK buttons.
|
||||
var delta = activator.mouseY - (root.height - keyboard.raisedHeight - buttonsHeight);
|
||||
if (delta > 0) {
|
||||
attachments.scrollBy(delta);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
MouseArea {
|
||||
id: activator
|
||||
anchors.fill: parent
|
||||
|
|
Loading…
Reference in a new issue