import QtQuick import "../core" import "../theme" // A popup that grows out of the bar (Caelestia-style drawer). Place it at // y = BarDrawers.bottom in a window whose top is the screen's top edge: the // layer box then starts above the bar, so the join is not a glass edge. // Content slides down with the body as it is revealed. Item { id: root default property alias content: inner.data property bool open: false property bool attached: true property real contentWidth: 300 property real contentHeight: 200 // Registered with the bar so it opens its border over this span. property string drawerId: "" property string screenName: "" property real screenX: 0 readonly property real ear: attached ? BarDrawers.ear : 0 // "slide" unrolls out of the bar; "drop" falls into place and away // downwards; "fade" fades in place; "shrink" grows from / shrinks to nothing. property string style: "slide" // Notch mode has no bar to unroll from: attached drawers use NotchDrop // instead, with the notch's own panel speeds. Opt out with `liquid: false`. property bool liquid: ShellState.notchMode && attached // Screen x of the icon the drawer belongs to; the drop comes out under it. property real sourceScreenX: -1 // Fill and timing; notch mode passes the notch's own. property color fillColor: Qt.alpha(Theme.surface, Theme.glassOpacity) property real openDuration: Theme.duration * 1.8 property real closeDuration: Theme.duration readonly property bool unrolls: style === "slide" && !liquid property real progress: open ? 1 : 0 readonly property real revealed: unrolls ? Math.max(0, contentHeight * progress) : contentHeight // Drop moves down on the way in and on the way out. property real dropFrom: -1 onOpenChanged: dropFrom = open ? -1 : 1 readonly property bool shown: progress > 0.001 // NotchDrop's content fade: in once the panel has its size, out first. readonly property real dropContent: { const t = Math.min(1, Math.max(0, (progress - 0.82) / 0.18)); return t * t * (3 - 2 * t); } readonly property bool settled: !anim.running && open // Input/hover region: the full body as soon as it opens (the pointer may // reach the drawer before the reveal finishes), the visible part while closing. readonly property alias body: area readonly property bool hovered: hover.hovered // Content parent, for items reparented in at runtime. readonly property alias container: inner // Enter: emphasized decelerate; exit: emphasized accelerate (Material 3). Behavior on progress { NumberAnimation { id: anim duration: root.liquid ? (root.open ? Theme.notchPanelOpenDuration : Theme.notchPanelCloseDuration) : root.open ? root.openDuration : root.closeDuration // NotchDrop eases each phase itself. easing.type: root.liquid ? Easing.Linear : Easing.BezierSpline easing.bezierCurve: root.open ? [0.05, 0.7, 0.1, 1, 1, 1] : [0.3, 0, 0.8, 0.15, 1, 1] } } implicitWidth: contentWidth + 2 * ear implicitHeight: contentHeight width: implicitWidth height: implicitHeight // Input/hover region stays put; only the drawn drawer animates. Item { id: area x: root.ear width: root.contentWidth height: root.open ? root.contentHeight : root.revealed } // On the root so it wraps the content: a sibling under the content would // lose hover to the content's own hover areas. HoverHandler { id: hover } Item { id: motion width: root.width height: root.height opacity: root.liquid ? 1 : root.style === "fade" || root.style === "drop" ? root.progress : root.style === "shrink" ? Math.min(1, root.progress * 1.5) : 1 scale: !root.liquid && root.style === "shrink" ? Math.max(0.001, root.progress) : 1 transformOrigin: Item.Center transform: Translate { y: !root.liquid && root.style === "drop" ? (1 - root.progress) * 28 * root.dropFrom * Math.max(0.3, Theme.intensity) : 0 } Loader { active: root.liquid width: root.width sourceComponent: NotchDrop { width: root.width progress: root.progress bodyX: root.ear bodyWidth: root.contentWidth bodyHeight: root.contentHeight sourceX: root.sourceScreenX < 0 ? -1 : root.sourceScreenX - root.screenX topSpace: Math.max(0, root.y) islandBottom: Math.round((BarDrawers.bottom - BarDrawers.height) / 2) + BarDrawers.height - root.y fillColor: root.fillColor screenName: root.screenName screenX: root.screenX } } DrawerShape { id: shape visible: !root.liquid bodyWidth: root.contentWidth bodyHeight: root.revealed ear: BarDrawers.ear attached: root.attached fillColor: root.fillColor } Item { id: hit x: root.ear width: root.contentWidth height: root.revealed clip: true Item { id: inner width: root.contentWidth height: root.contentHeight y: root.revealed - root.contentHeight opacity: root.liquid ? root.dropContent : root.unrolls ? Math.min(1, root.progress * 1.6) : 1 transform: Translate { y: root.liquid ? (1 - root.dropContent) * 6 : 0 } } } } readonly property bool joined: attached && (unrolls ? shown : progress > 0.5) readonly property var gapKey: [joined, screenName, Math.round(screenX), Math.round(width)] onGapKeyChanged: syncGap() Component.onCompleted: syncGap() Component.onDestruction: if (drawerId) BarDrawers.clearGap(drawerId) function syncGap() { if (!drawerId) return; if (joined && screenName) BarDrawers.setGap(drawerId, screenName, screenX, screenX + width); else BarDrawers.clearGap(drawerId); } }