aerothemeplasma/plasma/plasmoids/io.gitgud.wackyideas.SevenStart/contents/ui/KickoffListView.qml

219 lines
8.4 KiB
QML
Raw Permalink Normal View History

2023-09-27 17:50:10 +00:00
/*
Copyright (C) 2011 Martin Gräßlin <mgraesslin@kde.org>
Copyright (C) 2012 Gregor Taetzner <gregor@freenet.de>
Copyright (C) 2015-2018 Eike Hein <hein@kde.org>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
import QtQuick 2.0
import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.plasma.extras 2.0 as PlasmaExtras
2024-08-09 01:20:25 +00:00
import org.kde.plasma.components as PlasmaComponents
2023-09-27 17:50:10 +00:00
2024-08-09 01:20:25 +00:00
import org.kde.kirigami as Kirigami
2023-09-27 17:50:10 +00:00
FocusScope {
id: view
property bool appView: false
2024-08-09 01:20:25 +00:00
property alias contentHeight: listView.contentHeight
property alias count: listView.count
2023-09-27 17:50:10 +00:00
property alias currentIndex: listView.currentIndex
property alias currentItem: listView.currentItem
2024-08-09 01:20:25 +00:00
property alias delegate: listView.delegate
2023-09-27 17:50:10 +00:00
property alias interactive: listView.interactive
2024-08-09 01:20:25 +00:00
readonly property Item listView: listView
property alias model: listView.model
2023-09-27 17:50:10 +00:00
property alias move: listView.move
property alias moveDisplaced: listView.moveDisplaced
2024-08-09 01:20:25 +00:00
readonly property Item scrollView: scrollView
property bool showAppsByName: true
property bool small: false
2023-09-27 17:50:10 +00:00
2024-08-09 01:20:25 +00:00
signal addBreadcrumb(var model, string title)
signal reset
2023-09-27 17:50:10 +00:00
function decrementCurrentIndex() {
listView.decrementCurrentIndex();
}
2024-08-09 01:20:25 +00:00
function incrementCurrentIndex() {
listView.incrementCurrentIndex();
}
2023-09-27 17:50:10 +00:00
Connections {
function onExpandedChanged() {
2024-08-09 01:20:25 +00:00
if (!kicker.expanded) {
2023-09-27 17:50:10 +00:00
listView.positionViewAtBeginning();
}
}
2024-08-09 01:20:25 +00:00
target: kicker
}
Timer {
id: toolTipTimer
interval: Kirigami.Units.longDuration*4
onTriggered: {
if(listView.currentItem) listView.currentItem.toolTip.showToolTip();
}
2023-09-27 17:50:10 +00:00
}
2024-08-09 01:20:25 +00:00
PlasmaComponents.ScrollView {
id: scrollView
2023-09-27 17:50:10 +00:00
2024-08-09 01:20:25 +00:00
//frameVisible: false
2023-09-27 17:50:10 +00:00
anchors.fill: parent
ListView {
id: listView
2024-08-09 01:20:25 +00:00
2023-09-27 17:50:10 +00:00
boundsBehavior: Flickable.StopAtBounds
2024-08-09 01:20:25 +00:00
focus: true
highlightMoveDuration: 0
2023-09-27 17:50:10 +00:00
highlightResizeDuration: 0
2024-08-09 01:20:25 +00:00
keyNavigationWraps: true
spacing: small ? 0 : Kirigami.Units.smallSpacing / 2
2023-09-27 17:50:10 +00:00
delegate: KickoffItem {
id: delegateItem
2024-08-09 01:20:25 +00:00
required property var model
required property int index
2023-09-27 17:50:10 +00:00
appView: view.appView
showAppsByName: view.showAppsByName
2024-08-09 01:20:25 +00:00
smallIcon: small
2023-09-27 17:50:10 +00:00
onAddBreadcrumb: view.addBreadcrumb(model, title)
2024-08-09 01:20:25 +00:00
onReset: view.reset()
2023-09-27 17:50:10 +00:00
}
2024-08-09 01:20:25 +00:00
highlight: KickoffHighlight {
2023-09-27 17:50:10 +00:00
}
2024-08-09 01:20:25 +00:00
section.property: "group"
/*section {
criteria: ViewSection.FullString
property: "group"
2023-09-27 17:50:10 +00:00
2024-08-09 01:20:25 +00:00
delegate: SectionDelegate {
}
}*/
2023-09-27 17:50:10 +00:00
2024-08-09 01:20:25 +00:00
MouseArea {
2023-09-27 17:50:10 +00:00
id: mouseArea
2024-08-09 01:20:25 +00:00
// property Item pressed: null
2023-09-27 17:50:10 +00:00
property int pressX: -1
property int pressY: -1
property bool tapAndHold: false
acceptedButtons: Qt.LeftButton | Qt.RightButton
2024-08-09 01:20:25 +00:00
anchors.left: parent.left
height: parent.height
hoverEnabled: true
width: scrollView.width
2023-09-27 17:50:10 +00:00
2024-08-09 01:20:25 +00:00
onContainsMouseChanged: {
if (!containsMouse) {
//pressed = null;
toolTipTimer.stop();
if(listView.currentItem) listView.currentItem.toolTip.hideToolTip();
pressX = -1;
pressY = -1;
tapAndHold = false;
listView.currentIndex = -1;
}
}
onPositionChanged: function(mouse) {
var mapped = listView.mapToItem(listView.contentItem, mouse.x, mouse.y);
var item = listView.itemAt(mapped.x, mapped.y);
if (item) {
toolTipTimer.stop();
if(listView.currentItem) listView.currentItem.toolTip.hideToolTip();
listView.currentIndex = item.itemIndex;
toolTipTimer.start();
//item.toolTip.showToolTip();
} else {
listView.currentIndex = -1;
}
if (mouse.source != Qt.MouseEventSynthesizedByQt || tapAndHold) {
if (pressed && pressX != -1 && pressed.url && dragHelper.isDrag(pressX, pressY, mouse.x, mouse.y)) {
kickoff.dragSource = item;
if (mouse.source == Qt.MouseEventSynthesizedByQt) {
dragHelper.dragIconSize = Kirigami.Units.iconSizes.huge;
dragHelper.startDrag(kickoff, pressed.url, pressed.decoration);
} else {
dragHelper.dragIconSize = Kirigami.Units.iconSizes.medium;
dragHelper.startDrag(kickoff, pressed.url, pressed.decoration);
}
//pressed = null;
pressX = -1;
pressY = -1;
tapAndHold = false;
}
}
}
onPressAndHold: function(mouse) {
if (mouse.source == Qt.MouseEventSynthesizedByQt) {
tapAndHold = true;
positionChanged(mouse);
}
}
onPressed: function(mouse) {
2023-09-27 17:50:10 +00:00
var mapped = listView.mapToItem(listView.contentItem, mouse.x, mouse.y);
var item = listView.itemAt(mapped.x, mapped.y);
if (!item) {
return;
}
if (mouse.buttons & Qt.RightButton) {
if (item.hasActionList) {
mapped = listView.contentItem.mapToItem(item, mapped.x, mapped.y);
listView.currentItem.openActionMenu(mapped.x, mapped.y);
}
} else {
2024-08-09 01:20:25 +00:00
//pressed = item;
//item.activate();
2023-09-27 17:50:10 +00:00
pressX = mouse.x;
pressY = mouse.y;
}
}
2024-08-09 01:20:25 +00:00
onReleased: function(mouse) {
2023-09-27 17:50:10 +00:00
var mapped = listView.mapToItem(listView.contentItem, mouse.x, mouse.y);
var item = listView.itemAt(mapped.x, mapped.y);
2024-08-09 01:20:25 +00:00
if (item && /*pressed === item && */!tapAndHold) {
2023-09-27 17:50:10 +00:00
if (item.appView) {
if (mouse.source == Qt.MouseEventSynthesizedByQt) {
positionChanged(mouse);
}
view.state = "OutgoingLeft";
} else {
item.activate();
root.visible = false;
}
listView.currentIndex = -1;
}
if (tapAndHold && mouse.source == Qt.MouseEventSynthesizedByQt) {
if (item.hasActionList) {
mapped = listView.contentItem.mapToItem(item, mapped.x, mapped.y);
listView.currentItem.openActionMenu(mapped.x, mapped.y);
}
}
2024-08-09 01:20:25 +00:00
//pressed = null;
2023-09-27 17:50:10 +00:00
pressX = -1;
pressY = -1;
tapAndHold = false;
}
}
}
}
}