Kirigami-addons

FormDelegateBackground.qml
1/*
2 * Copyright 2022 Devin Lin <devin@kde.org>
3 * SPDX-License-Identifier: LGPL-2.0-or-later
4 */
5
6import QtQuick
7import QtQuick.Layouts
8import QtQuick.Templates as T
9import org.kde.kirigami as Kirigami
10
11/**
12 * @brief A background for Form delegates.
13 *
14 * This is a simple background that provides opacity feedback to the user
15 * when the control has focus or is currently being pressed, for example.
16 *
17 * This is used in AbstractFormDelegate so that new delegates provide this
18 * feedback by default, and can be easily overriden with a QtQuick.Item.
19 *
20 * @since KirigamiAddons 0.11.0
21 *
22 * @see AbstractFormDelegate
23 *
24 * @inherit QtQuick.Rectangle
25 */
26Kirigami.ShadowedRectangle {
27 id: root
28
29 /**
30 * @brief The control to which the background will be assigned.
31 */
32 required property T.Control control
33
34 readonly property bool _roundCorners: control.parent._roundCorners === true
35 readonly property bool _isFirst: _roundCorners && control.parent.children[0] === control
36 readonly property bool _isLast: _roundCorners && control.parent.children[control.parent.children.length - 1] === control
37
38 color: {
39 let colorOpacity = 0;
40
41 if (!control.enabled) {
42 colorOpacity = 0;
43 } else if (control.pressed) {
44 colorOpacity = 0.2;
45 } else if (control.visualFocus) {
46 colorOpacity = 0.1;
47 } else if (!Kirigami.Settings.tabletMode && control.hovered) {
48 colorOpacity = 0.07;
49 }
50
51 return Qt.rgba(Kirigami.Theme.textColor.r, Kirigami.Theme.textColor.g, Kirigami.Theme.textColor.b, colorOpacity)
52 }
53
54 corners {
55 topLeftRadius: _isFirst ? Kirigami.Units.smallSpacing : 0
56 topRightRadius: _isFirst ? Kirigami.Units.smallSpacing : 0
57 bottomLeftRadius: _isLast ? Kirigami.Units.smallSpacing : 0
58 bottomRightRadius: _isLast ? Kirigami.Units.smallSpacing : 0
59 }
60
61 Behavior on color {
62 ColorAnimation { duration: Kirigami.Units.shortDuration }
63 }
64}
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Dec 20 2024 11:49:32 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.