ColorChooser.qml 4.06 KB
Newer Older
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
/* GCompris - ColorChooser.qml
*
* Copyright (C) 2014 Stephane Mankowski <stephane@mankowski.fr>
*
* Authors:
*   Matilda Bernard <serah4291@gmail.com> (GTK+ version)
*   Stephane Mankowski <stephane@mankowski.fr> (Qt Quick port)
*
*   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.0
import QtGraphicalEffects 1.0

import GCompris 1.0

Stephane Mankowski's avatar
Stephane Mankowski committed
27
import "colormix.js" as Activity
28
import "."
29
30

Image {
Stephane Mankowski's avatar
Stephane Mankowski committed
31
    id: chooser
32
    source: Activity.url + (activity.modeRGB ? "flashlight.svg" : "tube.svg")
33
    z: 1
34
35
36

    property int maxSteps: 10
    property int currentStep: 0
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
    property alias hue: color.hue

    Image {
        id: intensity
        source: Activity.url + "flashlight2.svg"
        sourceSize.height: parent.sourceSize.height
        z: 2
        visible: activity.modeRGB ? true : false

        Colorize {
            anchors.fill: parent
            source: parent
            hue: chooser.hue
            lightness: -(maxSteps - currentStep) / maxSteps
            saturation: 1
        }

        Image {
            source: Activity.url + "light.svg"
            sourceSize.height: parent.sourceSize.height / 2
            anchors {
                left: parent.right
                leftMargin: -20 * ApplicationInfo.ratio
                verticalCenter: parent.verticalCenter
            }
            opacity: currentStep / maxSteps

            Colorize {
                anchors.fill: parent
                source: parent
                hue: chooser.hue
                lightness: -(maxSteps - currentStep) / maxSteps
                saturation: 1
            }
        }
    }
73
74
75

    Image {
        id: intensityBrush
76
        source: Activity.url + "brush.svg"
77
78
79
80
        sourceSize.height: parent.sourceSize.height * 0.25 + currentStep / maxSteps * 15
        z: 2
        anchors {
            left: parent.right
81
            leftMargin: activity.modeRGB ? -20 * ApplicationInfo.ratio : 0
82
83
            verticalCenter: parent.verticalCenter
        }
84
        visible: currentStep > 0
85
86
        fillMode: Image.PreserveAspectFit

Stephane Mankowski's avatar
Stephane Mankowski committed
87
88
89
90
        Colorize {
            anchors.fill: parent
            source: parent
            hue: chooser.hue
91
            lightness: 0
Stephane Mankowski's avatar
Stephane Mankowski committed
92
93
94
95
            saturation: 1
        }
    }

96
97
98
99
100
101
102
103
    Colorize {
        id: color
        anchors.fill: parent
        source: parent
        hue: 0.0
        saturation: 1
    }

104
105
    ColorButton {
        text: "+"
Stephane Mankowski's avatar
Stephane Mankowski committed
106
107
108
109
110
        anchors {
            verticalCenter: parent.verticalCenter
            right: parent.right
            rightMargin: parent.width * 0.2
        }
111
112
    }

113
114
    ColorButton {
        text: "-"
Stephane Mankowski's avatar
Stephane Mankowski committed
115
116
117
        anchors {
            verticalCenter: parent.verticalCenter
            left: parent.left
118
            leftMargin: parent.width * 0.3
Stephane Mankowski's avatar
Stephane Mankowski committed
119
        }
120
    }
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141

    MultiPointTouchArea {
        anchors.fill: parent
        touchPoints: [ TouchPoint { id: point1 } ]
        z: 4
        property real startX
        property int initialStep: 0

        onPressed: {
            startX = point1.x
            if(startX > parent.width / 2)
                currentStep = Math.max(currentStep + 1, 0)
            else
                currentStep = Math.max(currentStep - 1, 0)
            initialStep = currentStep
        }

        onTouchUpdated: {
            currentStep = initialStep + (point1.x - startX) / (20 * ApplicationInfo.ratio)
            currentStep = Math.min(currentStep, maxSteps)
            currentStep = Math.max(currentStep, 0)
Bruno Coudoin's avatar
Bruno Coudoin committed
142
            activity.audioEffects.play('qrc:/gcompris/src/activities/redraw/resource/brush.wav')
143
144
145
        }
    }

146
}