cool-retro-term/app/qml/CheckableSlider.qml

73 lines
2.1 KiB
QML
Raw Normal View History

2013-12-28 14:52:10 +01:00
/*******************************************************************************
* Copyright (c) 2013-2021 "Filippo Scognamiglio"
* https://github.com/Swordfish90/cool-retro-term
2013-12-28 14:52:10 +01:00
*
* This file is part of cool-retro-term.
2013-12-28 14:52:10 +01:00
*
* cool-retro-term is free software: you can redistribute it and/or modify
2013-12-28 14:52:10 +01:00
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*******************************************************************************/
import QtQuick 2.2
import QtQuick.Controls 2.0
2013-12-22 23:08:16 +01:00
import QtQuick.Layouts 1.1
2015-01-08 03:55:19 +01:00
import "Components"
2013-12-22 23:08:16 +01:00
RowLayout {
property alias name: check.text
property double value
property alias min_value: slider.from
property alias max_value: slider.to
property alias stepSize: slider.stepSize
2013-12-22 23:08:16 +01:00
signal newValue(real newValue)
2013-12-22 23:08:16 +01:00
id: setting_component
2018-10-28 01:08:21 +02:00
Layout.fillWidth: true
2013-12-22 23:08:16 +01:00
onValueChanged: {
check.checked = !(value == 0)
if (check.checked)
slider.value = value
}
CheckBox {
2013-12-22 23:08:16 +01:00
id: check
2015-01-08 03:55:19 +01:00
implicitWidth: 160
onClicked: {
if (!checked) {
checked = false
slider.enabled = false
newValue(0)
} else {
checked = true
newValue(slider.value)
slider.enabled = true
}
}
2013-12-22 23:08:16 +01:00
}
Slider {
2013-12-22 23:08:16 +01:00
id: slider
stepSize: parent.stepSize
2013-12-22 23:08:16 +01:00
Layout.fillWidth: true
onValueChanged: {
newValue(value)
}
2013-12-22 23:08:16 +01:00
}
2015-01-08 03:55:19 +01:00
SizedLabel {
text: Math.round(
((value - min_value) / (max_value - min_value)) * 100) + "%"
2013-12-22 23:08:16 +01:00
}
}