Flickable toise from Toise
This commit is contained in:
parent
1d14fe935e
commit
a9aada07d8
3 changed files with 68 additions and 3 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
63
qml/ToiseFlickable.qml
Normal file
63
qml/ToiseFlickable.qml
Normal file
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue