repositories / dotfiles

dotfiles

bugabingas dorkfiles

owned by bugabinga

quickshell/nuguland/PopupCard.qml

Raw
import QtQuick

Rectangle {
    id: root

    required property Theme theme
    default property alias content: contentItem.data
    property string role: "normal"
    property bool active: false
    property bool revealed: false
    property bool attention: false
    property bool destructive: false
    property bool interactive: false
    property bool hoverable: interactive
    property bool externallyPressed: false
    property int padding: 12
    signal clicked

    readonly property bool highlighted: active || revealed || attention || destructive
    readonly property color stateColor: destructive ? theme.error : (attention ? theme.warning : theme.ui.accent)

    implicitWidth: contentItem.implicitWidth + padding * 2
    implicitHeight: Math.max(44, contentItem.implicitHeight + padding * 2)
    radius: 12
    color: theme.withAlpha(highlighted ? stateColor : theme.ui.backdrop, tap.pressed || externallyPressed ? 0.34 : (hover.hovered ? 0.24 : (highlighted ? 0.18 : 0.55)))
    border.width: highlighted || activeFocus ? 2 : 1
    border.color: activeFocus ? theme.content.focus : theme.withAlpha(highlighted ? stateColor : theme.ui.minor, highlighted ? 0.8 : 0.42)
    activeFocusOnTab: interactive && enabled
    opacity: enabled ? 1 : 0.48
    Accessible.role: interactive ? Accessible.Button : Accessible.Pane
    Accessible.name: role
    Keys.onPressed: event => {
        if (interactive && enabled && (event.key === Qt.Key_Return || event.key === Qt.Key_Enter || event.key === Qt.Key_Space)) {
            event.accepted = true;
            root.clicked();
        }
    }

    Item {
        id: contentItem

        anchors.fill: parent
        anchors.margins: root.padding
        readonly property Item child: children.length > 0 ? children[0] : null
        implicitWidth: child ? child.implicitWidth : 0
        implicitHeight: child ? child.implicitHeight : 0
    }

    HoverHandler {
        id: hover
        enabled: root.hoverable && root.enabled
    }

    TapHandler {
        id: tap
        enabled: root.interactive && root.enabled
        gesturePolicy: TapHandler.ReleaseWithinBounds
        onTapped: root.clicked()
    }

    Behavior on color {
        ColorAnimation {
            duration: root.theme.lowPowerMode ? 0 : 90
        }
    }
}