2019-12-19 22:46:16 +11:00
|
|
|
// SPDX-License-Identifier: LGPL-3.0-or-later
|
|
|
|
|
2019-08-18 03:01:43 +10:00
|
|
|
import QtQuick 2.12
|
|
|
|
import QtQuick.Controls 2.12
|
2019-11-08 00:50:59 +11:00
|
|
|
import QtQuick.Layouts 1.12
|
2019-08-18 03:01:43 +10:00
|
|
|
|
|
|
|
CheckBox {
|
|
|
|
id: box
|
2020-07-12 14:25:57 +10:00
|
|
|
|
|
|
|
property alias mainText: mainText
|
|
|
|
property alias subtitle: subtitleText
|
|
|
|
property bool defaultChecked: false
|
|
|
|
readonly property bool changed: checked !== defaultChecked
|
|
|
|
|
|
|
|
function reset() { checked = defaultChecked }
|
|
|
|
|
|
|
|
|
2019-12-14 00:56:52 +11:00
|
|
|
checked: defaultChecked
|
2020-06-25 22:32:08 +10:00
|
|
|
spacing: contentItem.visible ? theme.spacing : 0
|
2019-12-08 18:49:07 +11:00
|
|
|
padding: 0
|
2019-08-21 08:31:20 +10:00
|
|
|
|
2019-08-18 03:01:43 +10:00
|
|
|
indicator: Rectangle {
|
2019-12-13 21:21:30 +11:00
|
|
|
opacity: box.enabled ? 1 : theme.disabledElementsOpacity + 0.2
|
2019-12-08 00:38:36 +11:00
|
|
|
implicitWidth: theme.controls.checkBox.boxSize
|
|
|
|
implicitHeight: implicitWidth
|
2019-08-18 03:01:43 +10:00
|
|
|
x: box.leftPadding
|
|
|
|
y: box.topPadding + box.availableHeight / 2 - height / 2
|
2020-03-16 05:27:10 +11:00
|
|
|
radius: theme.radius
|
2019-08-18 03:01:43 +10:00
|
|
|
|
2019-08-21 08:31:20 +10:00
|
|
|
color: theme.controls.checkBox.boxBackground
|
|
|
|
border.color:
|
|
|
|
box.enabled && box.pressed ?
|
|
|
|
theme.controls.checkBox.boxPressedBorder :
|
|
|
|
|
2019-09-09 21:19:06 +10:00
|
|
|
(box.enabled && box.hovered) || box.activeFocus ?
|
2019-08-21 08:31:20 +10:00
|
|
|
theme.controls.checkBox.boxHoveredBorder :
|
|
|
|
|
|
|
|
theme.controls.checkBox.boxBorder
|
2019-08-18 03:01:43 +10:00
|
|
|
|
|
|
|
Behavior on border.color { HColorAnimation { factor: 0.5 } }
|
|
|
|
|
|
|
|
HIcon {
|
|
|
|
anchors.centerIn: parent
|
|
|
|
dimension: parent.width - 2
|
2019-08-29 06:30:48 +10:00
|
|
|
colorize: theme.controls.checkBox.checkIconColorize
|
2020-06-25 22:32:08 +10:00
|
|
|
svgName:
|
|
|
|
box.checkState === Qt.PartiallyChecked ?
|
|
|
|
"check-mark-partial" :
|
|
|
|
"check-mark"
|
2019-08-18 03:01:43 +10:00
|
|
|
|
2020-06-25 22:32:08 +10:00
|
|
|
scale: box.checkState === Qt.Unchecked ? 0 : 1
|
2019-12-01 05:59:48 +11:00
|
|
|
|
2019-08-18 03:35:43 +10:00
|
|
|
Behavior on scale {
|
|
|
|
HNumberAnimation {
|
|
|
|
overshoot: 4
|
|
|
|
easing.type: Easing.InOutBack
|
2020-06-25 22:32:08 +10:00
|
|
|
factor: 0.5
|
2019-08-18 03:35:43 +10:00
|
|
|
}
|
|
|
|
}
|
2019-08-18 03:01:43 +10:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-08 00:50:59 +11:00
|
|
|
contentItem: HColumnLayout {
|
2020-06-25 22:32:08 +10:00
|
|
|
visible: mainText.text || subtitleText.text
|
2019-12-13 21:21:30 +11:00
|
|
|
opacity: box.enabled ? 1 : theme.disabledElementsOpacity
|
|
|
|
|
2019-11-08 00:50:59 +11:00
|
|
|
HLabel {
|
|
|
|
id: mainText
|
|
|
|
text: box.text
|
|
|
|
color: theme.controls.checkBox.text
|
|
|
|
|
|
|
|
// Set a width on CheckBox for wrapping to work,
|
|
|
|
// e.g. by using Layout.fillWidth
|
|
|
|
wrapMode: Text.Wrap
|
|
|
|
leftPadding: box.indicator.width + box.spacing
|
|
|
|
verticalAlignment: Text.AlignVCenter
|
|
|
|
|
|
|
|
Layout.fillWidth: true
|
|
|
|
}
|
|
|
|
|
|
|
|
HLabel {
|
|
|
|
id: subtitleText
|
|
|
|
visible: Boolean(text)
|
|
|
|
color: theme.controls.checkBox.subtitle
|
|
|
|
font.pixelSize: theme.fontSize.small
|
2019-08-18 03:01:43 +10:00
|
|
|
|
2019-11-08 00:50:59 +11:00
|
|
|
wrapMode: mainText.wrapMode
|
|
|
|
leftPadding: mainText.leftPadding
|
|
|
|
verticalAlignment: mainText.verticalAlignment
|
|
|
|
|
|
|
|
Layout.fillWidth: true
|
|
|
|
}
|
2019-08-18 03:01:43 +10:00
|
|
|
}
|
2019-12-14 00:56:52 +11:00
|
|
|
|
2019-12-16 19:42:41 +11:00
|
|
|
Behavior on opacity { HNumberAnimation { factor: 2 } }
|
2019-08-18 03:01:43 +10:00
|
|
|
}
|