2016-01-11 19:46:08 +03:00
|
|
|
/* Copyright 2016 (C) Louis-Joseph Fournier
|
|
|
|
* louisjoseph.fournier@gmail.com
|
|
|
|
*
|
|
|
|
* This file is part of SailTuner.
|
|
|
|
*
|
|
|
|
* SailTuner is free software: you can redistribute it and/or modify
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* SailTuner 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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
import QtQuick 2.0
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ToiseFlickable
|
|
|
|
*
|
|
|
|
* A toise flickable with the mouse
|
|
|
|
*/
|
|
|
|
|
|
|
|
Toise {
|
2016-01-13 12:15:35 +03:00
|
|
|
id: toise_flickable
|
2016-01-13 01:09:13 +03:00
|
|
|
property bool flik_enable: true
|
|
|
|
|
|
|
|
property int multiple: index % nb_marks
|
|
|
|
|
|
|
|
property double p_min: index2pos(min)
|
|
|
|
property double p_max: index2pos(max)
|
|
|
|
|
2016-01-13 12:15:35 +03:00
|
|
|
signal released()
|
|
|
|
//animation_enabled: false
|
2016-01-13 01:09:13 +03:00
|
|
|
|
2016-01-11 19:46:08 +03:00
|
|
|
MouseArea {
|
|
|
|
property int refX: 0
|
|
|
|
property double refPos: parent.position
|
|
|
|
|
2016-01-13 01:09:13 +03:00
|
|
|
enabled: flik_enable
|
|
|
|
|
2016-01-11 19:46:08 +03:00
|
|
|
anchors.fill: parent
|
|
|
|
|
|
|
|
onPressed: {
|
2016-01-13 12:15:35 +03:00
|
|
|
animation_enabled = false
|
2016-01-11 19:46:08 +03:00
|
|
|
refX = mouseX
|
|
|
|
refPos = position
|
|
|
|
}
|
|
|
|
onMouseXChanged: {
|
|
|
|
if (!pressed) return
|
|
|
|
var d = (refX - mouseX) / parent.cellWidth
|
|
|
|
var p = refPos + d
|
2016-01-13 01:09:13 +03:00
|
|
|
p = Math.max(Math.min(p, p_max), p_min)
|
2016-01-11 19:46:08 +03:00
|
|
|
var i = Math.round(p + (nb_marks_displayed - 1) / 2)
|
2016-01-13 01:09:13 +03:00
|
|
|
index = i
|
2016-01-11 19:46:08 +03:00
|
|
|
position = p
|
|
|
|
delta = position - Math.floor(position)
|
|
|
|
first_mark = Math.floor(position) % nb_marks
|
|
|
|
}
|
|
|
|
onReleased: {
|
2016-01-13 12:15:35 +03:00
|
|
|
updateFlickable()
|
|
|
|
animation_enabled = true
|
|
|
|
toise_flickable.released()
|
2016-01-11 19:46:08 +03:00
|
|
|
}
|
|
|
|
}
|
2016-01-13 12:15:35 +03:00
|
|
|
|
|
|
|
function updateFlickable() {
|
|
|
|
var p = index2pos(index)
|
|
|
|
delta = Qt.binding(function() { return position - Math.floor(position) })
|
|
|
|
first_mark = Qt.binding(function() { return Math.floor(position) % nb_marks })
|
|
|
|
position = p
|
|
|
|
}
|
2016-01-11 19:46:08 +03:00
|
|
|
}
|