Libplasma

Highlight.qml
1/*
2 SPDX-FileCopyrightText: 2011 Daker Fernandes Pinheiro <dakerfp@gmail.com>
3 SPDX-FileCopyrightText: 2022 Carl Schwan <carl@carlschwan.eu>
4 SPDX-FileCopyrightText: 2023 ivan tkachenko <me@ratijas.tk>
5
6 SPDX-License-Identifier: LGPL-2.0-or-later
7*/
8
9import QtQuick
10import org.kde.ksvg as KSvg
11import org.kde.kirigami as Kirigami
12
13/**
14 * @brief Highlight for a list or grid item.
15 *
16 * Highlight provides the highlight used to indicate the active
17 * item in a model view. It is typically used in conjunction with
18 * the @sa QtQuick.ListView::highlight or the
19 * @sa QtQuick.GridView::highlight properties.
20 *
21 * Provides built-in animation of Behavior on opacity Easing.OutQuad for a
22 * duration of 50ms (defined in Kirigami.Units.veryShortDuration).
23 *
24 * @code{.qml}
25 * import QtQuick
26 * import org.kde.plasma.extras as PlasmaExtras
27 *
28 * ListView {
29 * highlightFollowsCurrentItem: true
30 * highlight: PlasmaExtras.Highlight { }
31 * highlightMoveDuration: 0
32 * highlightResizeDuration: 0
33 * currentIndex: -1
34 * }
35 *
36 * @endcode
37 *
38 * @inherit QtQuick.Item
39 */
40Item {
41 id: highlight
42
43 /**
44 * This property holds whether the control is hovered.
45 *
46 * This is set automatically when used in a ListView and GridView.
47 */
48 property bool hovered: ListView.view !== null || GridView.view !== null
50 /**
51 * This property holds whether the highlight has a pressed appearance.
52 */
53 property bool pressed: false
54
55 /**
56 * This property holds the margin hints used by the background.
57 *
58 * @property int marginHints
59 */
60 property alias marginHints: background.margins
62 /**
63 * This property holds whether the item is active. True by default. Set it to
64 * false to visually mark an item that's in the "current item" or "selected"
65 * state but is not currently being hovered.
66 */
67 property bool active: true
68
69 width: {
70 const view = ListView.view;
71 return view ? view.width - view.leftMargin - view.rightMargin : undefined;
72 }
73
75 id: background
76
77 anchors.fill: parent
78
79 opacity: highlight.active ? 1 : 0.6
80
81 imagePath: "widgets/viewitem"
82 prefix: {
83 if (highlight.pressed) {
84 return highlight.hovered ? 'selected+hover' : 'selected';
85 }
86
87 return highlight.hovered ? 'hover' : 'normal';
88 }
89
90 Behavior on opacity {
91 enabled: Kirigami.Units.veryShortDuration > 0
92 NumberAnimation {
93 duration: Kirigami.Units.veryShortDuration
94 easing.type: Easing.OutQuad
95 }
96 }
97 }
98}
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:10:41 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.