/*SPDX-FileCopyrightText: 2013-2014 Eike Hein <hein@kde.org>SPDX-License-Identifier: GPL-2.0-or-later*/pragma ComponentBehavior: Boundimport QtQuickimport org.kde.kirigami as KirigamiDropArea {id: rootimplicitWidth: repeater.count ? repeater.itemAt(0).implicitWidth : (Kirigami.Units.iconSizes.medium + Kirigami.Units.smallSpacing * 2)implicitHeight: contentHeightenum FavoriteType {Simple,KAStats}property int contentHeight: model ? (model.count * implicitWidth) + ((model.count - 1) * flow.spacing) : 0property /*FavoriteType*/ int favoriteTypeproperty alias model: repeater.modelreadonly property SideBarItem bottomSideBarItem: repeater.itemAt(repeater.count - 1) as SideBarItemreadonly property string favoriteTypeMimeType: favoriteType === SideBarSection.FavoriteType.Simple ? "text/xx-kicker-simplefavorite-id" : "text/xx-kicker-kastatsfavorite-id"signal interactionConcludedsignal itemFocused(Item item)onActiveFocusChanged: (repeater.itemAt(0) ?? KeyNavigation.down).forceActiveFocus(Qt.TabFocusReason)onPositionChanged: event => {if (flow.animating) {return;}const above = flow.childAt(event.x, event.y) as SideBarItemconst eventSource = event.source as SideBarItemif (above && eventSource && above !== eventSource && eventSource.parent === flow) {repeater.model.moveRow(eventSource.itemIndex, above.itemIndex);event.accept(Qt.MoveAction)} else if (eventSource && eventSource.favoritesModel.isFavorite(eventSource.favoriteId)) {event.accept(Qt.MoveAction)} else if (event.formats.includes(root.favoriteTypeMimeType) && !model.isFavorite(event.getDataAsString(root.favoriteTypeMimeType))) {model.dropPlaceholderIndex = above?.itemIndex ?? 0;event.accept(Qt.CopyAction)} else {model.dropPlaceholderIndex = -1;event.accepted = false}}onExited: {if ("dropPlaceholderIndex" in model) {model.dropPlaceholderIndex = -1;}}onDropped: event => {let draggedItem = drag.source as SideBarItemif (event.formats.includes(root.favoriteTypeMimeType)) {model.addFavorite(event.getDataAsString(root.favoriteTypeMimeType), model.dropPlaceholderIndex)event.accept(Qt.CopyAction)} else if (draggedItem && draggedItem.favoritesModel.isFavorite(draggedItem.favoriteId) && draggedItem.favoritesModel !== root.model) {draggedItem.showUnfavoritePlaceholder = truedraggedItem.favoritesModel.removeFavorite(draggedItem.favoriteId)event.accept(Qt.MoveAction)}}Flow {id: flowanchors.fill: parentproperty bool animating: falseproperty int animationDuration: resetAnimationDurationTimer.intervalmove: Transition {SequentialAnimation {PropertyAction { target: flow; property: "animating"; value: true }NumberAnimation {duration: flow.animationDurationproperties: "x, y"easing.type: Easing.OutQuad}PropertyAction { target: flow; property: "animating"; value: false }}}spacing: 0Repeater {id: repeaterdelegate: SideBarItem {favoritesModel: repeater.modelbaseModel: repeater.modelshowUnfavoritePlaceholder: Drag.active && !root.containsDragKeys.onUpPressed: event => {if (index > 0) {repeater.itemAt(index - 1).forceActiveFocus(Qt.TabFocusReason)} else {event.accepted = false}}Keys.onDownPressed: event => {if (index + 1 < repeater.count) {repeater.itemAt(index + 1).forceActiveFocus(Qt.TabFocusReason)} else {event.accepted = false}}onInteractionConcluded: root.interactionConcluded()onActiveFocusChanged: if (activeFocus) root.itemFocused(this)}onCountChanged: {flow.animationDuration = 0;resetAnimationDurationTimer.start();}}}Timer {id: resetAnimationDurationTimerinterval: 150repeat: falseonTriggered: {flow.animationDuration = interval - 20;}}}