diff --git a/qml/PlayerScreen.qml b/qml/PlayerScreen.qml index fb59f45..c76c094 100644 --- a/qml/PlayerScreen.qml +++ b/qml/PlayerScreen.qml @@ -129,7 +129,7 @@ Item { } // octave toise - Toise { + ToiseFlickable { anchors.top: main.is_portrait ? title_octave.bottom : toise.bottom anchors.topMargin: parent.margin_h @@ -138,7 +138,7 @@ Item { theme: main.theme - marks: [1, 2, 3, 4, 5, 6, 7, 9] + marks: [1, 2, 3, 4, 5, 6, 7, 8, 9] //nb_marks_displayed: is_portrait ? 4 : 3 width: parent.width * 0.6 diff --git a/qml/Toise.qml b/qml/Toise.qml index e52dbc3..58fbe6d 100644 --- a/qml/Toise.qml +++ b/qml/Toise.qml @@ -49,6 +49,8 @@ Item { property double delta: position - Math.floor(position) property int idx_modulo: index % nb_marks + property alias cellWidth: toise.cellWidth + Behavior on position { NumberAnimation { duration: 200 @@ -60,7 +62,7 @@ Item { id: toise anchors.top: parent.top anchors.left: parent.left - anchors.leftMargin: is_pair ? - cellWidth * delta : 0 + anchors.leftMargin: - cellWidth * delta anchors.bottom: parent.bottom anchors.right: parent.right anchors.topMargin: h_margin diff --git a/qml/ToiseFlickable.qml b/qml/ToiseFlickable.qml new file mode 100644 index 0000000..88e6e39 --- /dev/null +++ b/qml/ToiseFlickable.qml @@ -0,0 +1,63 @@ +/* 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 { + MouseArea { + property int refX: 0 + property double refPos: parent.position + + anchors.fill: parent + + onPressed: { + refX = mouseX + refPos = position + } + onMouseXChanged: { + if (!pressed) return + var d = (refX - mouseX) / parent.cellWidth + var p = refPos + d + var i = Math.round(p + (nb_marks_displayed - 1) / 2) + index = i % nb_marks + position = p + delta = position - Math.floor(position) + first_mark = Math.floor(position) % nb_marks + } + onReleased: { + var p = 0 + var d = position - Math.floor(position) + if (d < 0.5) { + p = Math.floor(position) + } + else { + p = Math.ceil(position) + } + var i = Math.floor(p + (nb_marks_displayed - 1) / 2) + index = i % nb_marks + first_mark = p % nb_marks + position = p + delta = 0 + } + } +}