/*
 * Copyright (c) 2013-2020 Meltytech, LLC
 *
 * This program 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.
 *
 * This program 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.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

import QtQuick 2.2
import QtQuick.Controls 1.0

Rectangle {
    property alias value: slider.value

    SystemPalette { id: activePalette }

    color: activePalette.window
    width: 200
    height: 24

    Slider {
        id: slider
        orientation: Qt.Horizontal
        anchors {
            left: parent.left
            right: parent.right
            bottom: parent.bottom
            leftMargin: 4
            rightMargin: 4
        }
        minimumValue: 0
        maximumValue: 3.0
        value: 1
        function setScaleFactor() {
            multitrack.scaleFactor = Math.pow(value, 3) + 0.01
        }
        onValueChanged: {
            if (!pressed && typeof multitrack.scaleFactor != 'undefined')
                setScaleFactor()
        }
        onPressedChanged: {
            if (!pressed) {
                var targetX = scrollView.flickableItem.contentX + scrollView.width / 2
                var offset = targetX - scrollView.flickableItem.contentX
                var before = multitrack.scaleFactor

                setScaleFactor()

                if (!settings.timelineCenterPlayhead)
                    scrollView.flickableItem.contentX = (targetX * multitrack.scaleFactor / before) - offset

                for (var i = 0; i < tracksRepeater.count; i++)
                    tracksRepeater.itemAt(i).redrawWaveforms(false)
            }
        }
    }
}
