Skip to content

Commit

Permalink
qml: Add new Qml element: PingComboSlider
Browse files Browse the repository at this point in the history
This element should be use to pick discrete elements in a range
of options.
  • Loading branch information
tcanabrava authored and patrickelectric committed Jul 29, 2019
1 parent 3f635ce commit 332b880
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 0 deletions.
71 changes: 71 additions & 0 deletions qml/PingComboSlider.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import QtQuick 2.0
import QtQuick.Controls 2.0
import QtQuick.Controls.Material 2.1
import QtQuick.Layouts 1.12

/* Usage:
ComboSlider {
id: slider
// not needed, used if it exists.
model: [strings | numbers]
onOptionChanged: {
console.log("Value " + value + " at key " + key)
}
}
*/

PingSlider {
id: root

property alias model: internalTicks.model
property var startingIndex
signal optionChanged(var key, var value)

valueText: model[value]

control.from: 0
control.to: model.length - 1

control.stepSize: 1

onStartingIndexChanged: {
root.value = startingIndex
}

onValueChanged: {
optionChanged(value, model[value])
}

control.background: Rectangle {
x: control.leftPadding
y: control.topPadding + control.availableHeight/2 - height/2
implicitWidth: 200
implicitHeight: 1
width: control.availableWidth
height: implicitHeight
color: Material.accent

Repeater {
id: internalTicks

delegate: Rectangle {
id: tick
width: 1
height: parent.implicitHeight * 6
x: index*(control.availableWidth - control.handle.width)/control.to + control.handle.width/2
y: parent.implicitHeight
color: Material.accent

Text {
anchors.top: tick.bottom
id: textDelegate
text: modelData
color: Material.accent
x: -width/2
}
}
}
}
}


1 change: 1 addition & 0 deletions resources.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
<file alias="PolarGrid.qml">qml/PolarGrid.qml</file>
<file alias="ValueReadout.qml">qml/ValueReadout.qml</file>
<file alias="PingTextField.qml">qml/PingTextField.qml</file>
<file alias="PingComboSlider.qml">qml/PingComboSlider.qml</file>
</qresource>
<qresource prefix="/icons">
<file alias="arrow.svg">qml/icons/arrow.svg</file>
Expand Down

0 comments on commit 332b880

Please sign in to comment.