shift-shell/containments/homescreens/folio/package/contents/ui/HomeScreenPages.qml

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

161 lines
4.6 KiB
QML
Raw Normal View History

2021-03-19 16:30:43 +00:00
/*
* SPDX-FileCopyrightText: 2019 Marco Martin <mart@kde.org>
* SPDX-FileCopyrightText: 2021 Devin Lin <devin@kde.org>
2021-03-19 16:30:43 +00:00
*
* SPDX-License-Identifier: LGPL-2.0-or-later
*/
import QtQuick 2.12
import QtQuick.Window 2.12
import QtQuick.Layouts 1.1
import org.kde.plasma.plasmoid 2.0
import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.plasma.components 3.0 as PlasmaComponents
import org.kde.draganddrop 2.0 as DragDrop
import "private" as Private
2021-03-19 16:30:43 +00:00
import org.kde.plasma.private.containmentlayoutmanager 1.0 as ContainmentLayoutManager
import org.kde.plasma.private.mobileshell 1.0 as MobileShell
MobileShell.Flickable {
2021-03-19 16:30:43 +00:00
id: mainFlickable
required property var homeScreenState
2021-04-08 12:54:06 +00:00
property Item footer
2021-04-08 16:57:20 +00:00
property bool showAddPageIndicator: false
contentX: homeScreenState.xPosition
2021-03-19 16:30:43 +00:00
contentHeight: height
interactive: false
signal cancelEditModeForItemsRequested
onDragStarted: cancelEditModeForItemsRequested()
onDragEnded: cancelEditModeForItemsRequested()
onFlickStarted: cancelEditModeForItemsRequested()
onFlickEnded: cancelEditModeForItemsRequested()
2021-04-08 12:54:06 +00:00
onFooterChanged: {
if (footer) {
footer.parent = mainFlickable;
footer.anchors.left = mainFlickable.left;
footer.anchors.bottom = mainFlickable.bottom;
footer.anchors.right = mainFlickable.right;
}
2021-04-08 12:54:06 +00:00
}
// autoscroll between pages (when holding a delegate to go to a new page)
function scrollLeft() {
if (mainFlickable.atXBeginning) {
return;
}
autoScrollTimer.scrollRight = false;
autoScrollTimer.running = true;
scrollLeftIndicator.opacity = 1;
scrollRightIndicator.opacity = 0;
}
function scrollRight() {
if (mainFlickable.atXEnd) {
return;
}
autoScrollTimer.scrollRight = true;
autoScrollTimer.running = true;
scrollLeftIndicator.opacity = 0;
scrollRightIndicator.opacity = 1;
}
function stopScroll() {
autoScrollTimer.running = false;
scrollLeftIndicator.opacity = 0;
scrollRightIndicator.opacity = 0;
}
Timer {
id: autoScrollTimer
property bool scrollRight: true
repeat: true
interval: 1500
onTriggered: {
homeScreenState.animateGoToPageIndex(Math.max(0, homeScreenState.currentPageIndex + (scrollRight ? 1 : -1)), PlasmaCore.Units.longDuration * 2);
}
}
2021-03-19 16:30:43 +00:00
PlasmaComponents.PageIndicator {
2021-04-08 16:57:20 +00:00
id: pageIndicator
2021-03-19 16:30:43 +00:00
anchors {
bottom: parent.bottom
horizontalCenter: parent.horizontalCenter
2021-04-08 12:54:06 +00:00
bottomMargin: mainFlickable.footer ? mainFlickable.footer.height : 0
2021-03-19 16:30:43 +00:00
}
2021-03-19 16:30:43 +00:00
PlasmaCore.ColorScope.inherit: false
PlasmaCore.ColorScope.colorGroup: PlasmaCore.Theme.ComplementaryColorGroup
2021-03-19 16:30:43 +00:00
parent: mainFlickable
visible: count > 1
count: homeScreenState.pagesCount
currentIndex: homeScreenState.currentPageIndex
2021-04-08 16:57:20 +00:00
delegate: Rectangle {
property bool isAddPageIndicator: index === pageIndicator.count-1 && mainFlickable.showAddPageIndicator
implicitWidth: PlasmaCore.Units.gridUnit/2
implicitHeight: implicitWidth
radius: width
color: isAddPageIndicator ? "transparent" : PlasmaCore.ColorScope.textColor
PlasmaComponents.Label {
anchors.centerIn: parent
visible: parent.isAddPageIndicator
text: "⊕"
}
opacity: index === pageIndicator.currentIndex ? 0.9 : pressed ? 0.7 : 0.5
2021-04-08 16:57:20 +00:00
Behavior on opacity {
OpacityAnimator {
duration: PlasmaCore.Units.longDuration
easing.type: Easing.InOutQuad
}
}
}
2021-03-19 16:30:43 +00:00
}
Item {
z: 9999999
anchors.fill: parent
parent: {
let candidate = mainFlickable;
while (candidate.parent) {
candidate = candidate.parent;
}
return candidate;
}
Private.ScrollIndicator {
id: scrollLeftIndicator
anchors {
left: parent.left
2021-09-13 16:40:56 +00:00
leftMargin: PlasmaCore.Units.smallSpacing
}
elementId: "left-arrow"
}
Private.ScrollIndicator {
id: scrollRightIndicator
anchors {
right: parent.right
2021-09-13 16:40:56 +00:00
rightMargin: PlasmaCore.Units.smallSpacing
}
elementId: "right-arrow"
}
}
2021-03-19 16:30:43 +00:00
}