1/* 2 KWin - the KDE window manager 3 This file is part of the KDE project. 4 5 SPDX-FileCopyrightText: 2011 Martin Gräßlin <mgraesslin@kde.org> 6 7 SPDX-License-Identifier: GPL-2.0-or-later 8 */ 9import QtQuick 2.0 10import org.kde.plasma.core 2.0 as PlasmaCore 11import org.kde.kquickcontrolsaddons 2.0 12 13Item { 14 id: iconsTabBox 15 function decrementCurrentIndex() { 16 iconsListView.decrementCurrentIndex(); 17 } 18 function incrementCurrentIndex() { 19 iconsListView.incrementCurrentIndex(); 20 } 21 property int iconSize 22 property alias count: iconsListView.count 23 property alias margins: hoverItem.margins 24 property alias currentItem: iconsListView.currentItem 25 property alias model: iconsListView.model 26 property alias currentIndex: iconsListView.currentIndex 27 focus: true 28 clip: true 29 30 // just to get the margin sizes 31 PlasmaCore.FrameSvgItem { 32 id: hoverItem 33 imagePath: "widgets/viewitem" 34 prefix: "hover" 35 visible: false 36 } 37 38 // delegate 39 Component { 40 id: listDelegate 41 Item { 42 property alias caption: iconItem.caption 43 id: delegateItem 44 width: iconSize + hoverItem.margins.left + hoverItem.margins.right 45 height: iconSize + hoverItem.margins.top + hoverItem.margins.bottom 46 QIconItem { 47 property variant caption: model.caption 48 id: iconItem 49 icon: model.icon 50 width: iconSize 51 height: iconSize 52 state: index == iconsListView.currentIndex ? QIconItem.ActiveState : QIconItem.DefaultState 53 anchors { 54 fill: parent 55 leftMargin: hoverItem.margins.left 56 rightMargin: hoverItem.margins.right 57 topMargin: hoverItem.margins.top 58 bottomMargin: hoverItem.margins.bottom 59 } 60 } 61 MouseArea { 62 anchors.fill: parent 63 onClicked: { 64 iconsListView.currentIndex = index; 65 } 66 } 67 } 68 } 69 ListView { 70 id: iconsListView 71 orientation: ListView.Horizontal 72 width: Math.min(parent.width, (iconSize + margins.left + margins.right) * count) 73 height: iconSize + margins.top + margins.bottom 74 anchors { 75 top: parent.top 76 horizontalCenter: parent.horizontalCenter 77 } 78 clip: true 79 delegate: listDelegate 80 highlight: PlasmaCore.FrameSvgItem { 81 id: highlightItem 82 imagePath: "widgets/viewitem" 83 prefix: "hover" 84 width: iconSize + margins.left + margins.right 85 height: iconSize + margins.top + margins.bottom 86 } 87 highlightMoveDuration: 0 88 highlightResizeDuration: 0 89 boundsBehavior: Flickable.StopAtBounds 90 } 91} 92