aboutsummaryrefslogtreecommitdiffstats
path: root/src/quicknativestyle/util/MacFocusFrame.qml
blob: 42d92335b54e7d13c90e82082d52f27b5f6525f6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// Copyright (C) 2020 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
// Qt-Security score:significant reason:default

import QtQuick
import QtQuick.Controls
import QtQuick.Layouts


Rectangle {
    id: root

    function moveToItem(item, margins, radius) {
        if (!item) {
            targetItem = null;
            parent = null;
            return;
        }
        parent = item.parent
        targetItem = item
        leftOffset = margins.left
        rightOffset = margins.right
        topOffset = margins.top
        bottomOffset = margins.bottom
        frameRadius = radius
        animation.restart()
    }

    property Item targetItem
    property real leftOffset: 0
    property real rightOffset: 0
    property real topOffset: 0
    property real bottomOffset: 0
    property real frameOpacity: 0
    property real frameSize: 0
    property real frameRadius: 0

    // systemFrameColor is set to NSColor.keyboardFocusIndicatorColor from cpp
    property color systemFrameColor

    x: targetItem ? targetItem.x + leftOffset - frameSize : 0
    y: targetItem ? targetItem.y + topOffset - frameSize : 0
    // Stack on top of all siblings of the targetItem
    z: 100

    width: targetItem ? targetItem.width - leftOffset - rightOffset + (frameSize * 2) : 0
    height: targetItem ? targetItem.height - topOffset - bottomOffset + (frameSize * 2) : 0
    radius: frameRadius + frameSize
    visible: targetItem && targetItem.visible
    color: "transparent"

    border.color: systemFrameColor
    border.width: frameSize

    ParallelAnimation {
        id: animation
        NumberAnimation {
            target: root
            property: "frameSize"
            duration: 300
            from: 15
            to: 3
            easing.type: Easing.OutCubic
        }
        NumberAnimation {
            target: root
            property: "opacity"
            duration: 300
            from: 0
            to: 0.55
            easing.type: Easing.OutCubic
        }
    }
}