summaryrefslogtreecommitdiffstats
path: root/tools/qqem/qml/EffectPreviewToolbar.qml
blob: 73452481ff82c10273299bfa3331bcfee26cb2f1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
// Copyright (C) 2022 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only

import QtQuick
import QtQuick.Controls

Item {
    id: rootItem

    property real contentScale: 1.0
    property bool smoothScaling: true
    property bool useSmoothContent: true
    property bool showContentBorders: false
    property alias currentSourceImage: sourceImageSelector.currentImage
    property alias currentBackgroundImage: backgroundImageSelector.currentImage

    readonly property real contentMinScale: 0.10
    readonly property real contentMaxScale: 4.0
    readonly property real contentScaleStep: 0.10

    function updateScaleSlider(newScale) {
        scaleSlider.value = newScale;
    }

    function getStepSize(zoomingIn) {
        // Differentiate zooming directions so zoomin 1 step in, then 1
        // step out will end up into starting zoom level.
        var z = zoomingIn ? contentScale + 0.01 : contentScale - 0.01;
        if (z >= 2.0)
            return contentScaleStep * 5.0;
        else if (z >= 1.0)
            return contentScaleStep * 2.0;
        return contentScaleStep;
    }

    function contentZoomIn() {
        var step = getStepSize(true);
        var newScale = scaleSlider.value + step;
        newScale = Math.min(newScale, contentMaxScale);
        scaleSlider.value = newScale;
    }

    function contentZoomOut() {
        var step = getStepSize(false);
        var newScale = scaleSlider.value - step;
        newScale = Math.max(newScale, contentMinScale);
        scaleSlider.value = newScale;
    }

    function selectLastPreviewSource() {
        sourceImageSelector.currentIndex = sourceImageSelector.imagesModel.rowCount - 1;
    }

    height: 50

    Behavior on contentScale {
        enabled: rootItem.smoothScaling
        NumberAnimation {
            duration: 400
            easing.type: Easing.InOutQuad
        }
    }

    Rectangle {
        anchors.fill: parent
        color: mainView.backgroundColor1
        opacity: 0.8
    }
    Row {
        anchors.verticalCenter: parent.verticalCenter
        height: 50
        spacing: 2
        x: 5
        CustomImageSelector {
            id: sourceImageSelector
            anchors.verticalCenter: parent.verticalCenter
            description: "Preview source"
            imagesModel: effectManager.settings.sourceImagesModel
            showAddButton: true
            onAddPressed: {
                applicationSettingsDialog.addPreviewSourceImage();
            }
        }
        CustomImageSelector {
            id: backgroundImageSelector
            anchors.verticalCenter: parent.verticalCenter
            description: "Preview background"
            imagesModel: effectManager.settings.backgroundImagesModel
        }
        Item {
            width: 20
            height: 1
        }
        CustomIconButton {
            id: zoomOutButton
            anchors.verticalCenter: parent.verticalCenter
            height: parent.height * 0.6
            width: height
            icon: "images/icon_zoom_out.png"
            description: "Zoom out"
            onClicked: {
                contentZoomOut();
            }
        }
        Slider {
            id: scaleSlider
            anchors.verticalCenter: parent.verticalCenter
            anchors.verticalCenterOffset: 5
            width: 120
            from: contentMinScale
            to: contentMaxScale
            stepSize: contentScaleStep
            value: 1.0
            onValueChanged: {
                contentScale = value;
            }
            Text {
                anchors.horizontalCenter: parent.horizontalCenter
                anchors.verticalCenter: parent.verticalCenter
                anchors.verticalCenterOffset: -16
                text: (100 * contentScale).toFixed(0) + " %"
                font.pixelSize: 14
                color: mainView.foregroundColor2
                z: 2
            }
        }
        CustomIconButton {
            id: zoomInButton
            anchors.verticalCenter: parent.verticalCenter
            height: parent.height * 0.6
            width: height
            icon: "images/icon_zoom_in.png"
            description: "Zoom in"
            onClicked: {
                contentZoomIn();
            }
        }
        CustomIconButton {
            id: zoomAutoButton
            anchors.verticalCenter: parent.verticalCenter
            height: parent.height * 0.6
            width: height
            icon: "images/icon_zoom_auto.png"
            description: "Zoom to fit"
            onClicked: {
                autoScaleToContent();
            }
        }

        Item {
            width: 20
            height: 1
        }

        CustomIconButton {
            id: softenButton
            anchors.verticalCenter: parent.verticalCenter
            height: parent.height * 0.6
            width: height
            icon: "images/icon_soften.png"
            toggledIcon: "images/icon_soften_on.png"
            toggleButton: true
            toggled: useSmoothContent
            description: "Bilinear scaling"
            onClicked: {
                useSmoothContent = !useSmoothContent;
            }
        }
        CustomIconButton {
            id: showBordersButton
            anchors.verticalCenter: parent.verticalCenter
            height: parent.height * 0.6
            width: height
            icon: "images/icon_borders.png"
            toggledIcon: "images/icon_borders_on.png"
            toggleButton: true
            toggled: showContentBorders
            description: "Show item borders"
            onClicked: {
                showContentBorders = !showContentBorders;
            }
        }
    }
}