Libplasma

CheckBox.qml
1/*
2 SPDX-FileCopyrightText: 2016 Marco Martin <mart@kde.org>
3 SPDX-FileCopyrightText: 2022 ivan (@ratijas) tkachenko <me@ratijas.tk>
4
5 SPDX-License-Identifier: LGPL-2.0-or-later
6*/
7
8import QtQuick
9import QtQuick.Templates as T
10import org.kde.kirigami as Kirigami
11import "private" as Private
12
13T.CheckBox {
14 id: control
15
16 implicitWidth: Math.max(implicitBackgroundWidth + leftInset + rightInset,
17 implicitContentWidth + leftPadding + rightPadding,
18 implicitIndicatorWidth + leftPadding + rightPadding)
19 implicitHeight: Math.max(implicitBackgroundHeight + topInset + bottomInset,
20 implicitContentHeight + topPadding + bottomPadding,
21 implicitIndicatorHeight + topPadding + bottomPadding)
22
23 baselineOffset: contentItem.y + contentItem.baselineOffset
24 spacing: Kirigami.Units.smallSpacing
25 hoverEnabled: true
26
27 // Keeping old default smallMedium size for compatibility
28 // with UIs that currently expect that as the default size
29 icon.width: Kirigami.Units.iconSizes.smallMedium
30 icon.height: Kirigami.Units.iconSizes.smallMedium
31
32 indicator: CheckIndicator {
33 x: (control.text || control.icon.name || control.icon.source)
34 ? (control.mirrored ? control.width - width - control.rightPadding : control.leftPadding)
35 : control.leftPadding + Math.round((control.availableWidth - width) / 2)
36 y: control.topPadding + Math.round((control.availableHeight - height) / 2)
37
38 control: control
39 }
40
41 contentItem: Private.IconLabel {
42 readonly property int effectiveIndicatorWidth: control.indicator && control.indicator.visible && control.indicator.width > 0
43 ? control.indicator.width + control.spacing : 0
44
45 mirrored: control.mirrored
46 leftPadding: !control.mirrored ? effectiveIndicatorWidth : 0
47 rightPadding: control.mirrored ? effectiveIndicatorWidth : 0
48
49 font: control.font
50 alignment: Qt.AlignLeft | Qt.AlignVCenter
51 display: control.display
52 spacing: control.spacing
53 iconItem.implicitWidth: control.icon.width
54 iconItem.implicitHeight: control.icon.height
55 iconItem.source: control.icon.name || control.icon.source
56 label.text: control.text
57
58 Rectangle { // As long as we don't enable antialiasing, not rounding should be fine
59 parent: control.contentItem.label
60 width: Math.min(parent.width, parent.contentWidth)
61 height: 1
62 anchors.left: parent.left
63 anchors.top: parent.bottom
64 color: Kirigami.Theme.highlightColor
65 visible: control.visualFocus
66 }
67 }
68}
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 4 2024 16:34:35 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.