Libplasma

FlatButtonBackground.qml
1/*
2 * SPDX-FileCopyrightText: 2020 Noah Davis <noahadvs@gmail.com>
3 * SPDX-License-Identifier: LGPL-2.0-or-later
4 */
5
6import QtQuick
7import org.kde.ksvg as KSvg
8import org.kde.kirigami as Kirigami
9
10Item {
11 id: root
12 required property bool hovered
13 required property bool pressed
14 required property bool checked
15 required property bool focused
16
17 property real leftMargin: surfaceHover.margins.left
18 property real topMargin: surfaceHover.margins.top
19 property real rightMargin: surfaceHover.margins.right
20 property real bottomMargin: surfaceHover.margins.bottom
21 property string usedPrefix: surfaceHover.usedPrefix
22
23 ButtonShadow {
24 anchors.fill: parent
25 showShadow: !(root.checked || root.pressed) && root.usedPrefix === "normal"
26 }
27
29 anchors.fill: parent
30 showFocus: root.focused && !root.pressed
31 flat: true
32 }
33
34 // TODO: Maybe add a way to customize the look of normal state flat buttons with "toolbutton-normal"?
35 // TODO: Maybe add a way to customize the background of focused flat buttons with "toolbutton-focus-background"?
36 // TODO KF6: "flat" would be a more logical name than "toolbutton" since toolbuttons can be non-flat.
38 id: surfaceHover
39 anchors.fill: parent
40 imagePath: "widgets/button"
41 /* TODO KF6: making "toolbutton-hover" margins work like "hover"
42 * and using "hover" as a fallback would make more sense.
43 * If that is done, make ButtonHover handle flat button hover effects.
44 */
45 // The fallback is "normal" to match PC2 behavior. Some 3rd party themes depend on this.
46 prefix: ["toolbutton-hover", "normal"]
47 visible: root.hovered
48 }
49
51 id: surfacePressed
52 anchors.fill: parent
53 imagePath: "widgets/button"
54 prefix: ["toolbutton-pressed", "pressed"]
55 opacity: root.checked || root.pressed ? 1 : 0
56 Behavior on opacity {
57 enabled: Kirigami.Units.shortDuration > 0
58 NumberAnimation { duration: Kirigami.Units.shortDuration; easing.type: Easing.OutQuad }
59 }
60 }
61}
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 29 2024 11:52:43 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.