Commit e3bea66e authored by Chupligin Sergey's avatar Chupligin Sergey

[VolumeControl] added repeating of volume change if key stay pressed

parent 4622bc51
...@@ -42,6 +42,8 @@ ProgressBar { ...@@ -42,6 +42,8 @@ ProgressBar {
maximumValue: volumeControl.maximumVolume maximumValue: volumeControl.maximumVolume
property bool shouldbevisible property bool shouldbevisible
property int pressedKey
opacity: volumeSlider.shouldbevisible ? 1 : 0 opacity: volumeSlider.shouldbevisible ? 1 : 0
Behavior on opacity { Behavior on opacity {
NumberAnimation { NumberAnimation {
...@@ -49,6 +51,7 @@ ProgressBar { ...@@ -49,6 +51,7 @@ ProgressBar {
onRunningChanged: if (!running && volumeSlider.opacity == 0) volumeControl.windowVisible = false onRunningChanged: if (!running && volumeSlider.opacity == 0) volumeControl.windowVisible = false
} }
} }
Timer { Timer {
id: voltimer id: voltimer
interval: 2000 interval: 2000
...@@ -58,30 +61,25 @@ ProgressBar { ...@@ -58,30 +61,25 @@ ProgressBar {
Connections { Connections {
target: volumeControl target: volumeControl
onVolumeKeyPressed: { onVolumeKeyPressed: {
if(key == Qt.Key_VolumeUp) volumeSlider.pressedKey = key;
{
//up volume
if(volumeControl.volume < maximumValue)
{
volumeControl.volume = volumeControl.volume+1
}
}
else
{
//down volume
if(volumeControl.volume > 0)
{
volumeControl.volume = volumeControl.volume-1
}
}
volumeControl.windowVisible = true volumeControl.windowVisible = true
volumeSlider.value = volumeControl.volume volumeChange()
keyPressTimer.start()
maxMinTimer.start()
if (volumeControl.windowVisible) { if (volumeControl.windowVisible) {
voltimer.restart() voltimer.restart()
} }
} }
onVolumeKeyReleased: {
keyPressTimer.stop()
maxMinTimer.stop()
volumeSlider.pressedKey = ""
}
onWindowVisibleChanged: { onWindowVisibleChanged: {
if (volumeControl.windowVisible) { if (volumeControl.windowVisible) {
volumeSlider.shouldbevisible = true volumeSlider.shouldbevisible = true
...@@ -89,4 +87,59 @@ ProgressBar { ...@@ -89,4 +87,59 @@ ProgressBar {
} }
} }
} }
PropertyAnimation {
id: volumeChangeAinmation
target: volumeSlider
property: "value"
to: volumeControl.volume
duration: 100
}
Timer{
id: keyPressTimer
interval: 500
onTriggered: {
volumeChange()
voltimer.restart()
}
repeat: true
}
Timer{
id: maxMinTimer
interval: 1900
onTriggered: {
if(volumeSlider.pressedKey == Qt.Key_VolumeUp)
{
volumeControl.volume = volumeSlider.maximumValue
}
else if(volumeSlider.pressedKey == Qt.Key_VolumeDown)
{
volumeControl.volume = 0
}
volumeChangeAinmation.start()
}
}
function volumeChange()
{
if(volumeSlider.pressedKey == Qt.Key_VolumeUp)
{
//up volume
if(volumeControl.volume < maximumValue)
{
volumeControl.volume = volumeControl.volume+1
}
}
else if(volumeSlider.pressedKey == Qt.Key_VolumeDown)
{
//down volume
if(volumeControl.volume > 0)
{
volumeControl.volume = volumeControl.volume-1
}
}
volumeChangeAinmation.start()
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment