ColorChooser.qml 3.98 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
    z: 1
33
34
35

    property int maxSteps: 10
    property int currentStep: 0
36
    property real hue
37
38

    Image {
39
        id: intensityScreen
40
41
42
        source: Activity.url + "flashlight2.svg"
        sourceSize.height: parent.sourceSize.height
        z: 2
43
44
        visible: false
    }
45

46
47
48
49
50
51
52
    Colorize {
        anchors.fill: intensityScreen
        source: intensityScreen
        hue: chooser.hue
        lightness: -(maxSteps - currentStep) / maxSteps
        saturation: 1
        visible: activity.modeRGB ? true : false
53
    }
54

55
56
57
58
    Image {
        id: intensityLight
        source: Activity.url + "light.svg"
        sourceSize.height: intensityScreen.sourceSize.height / 2
59
        visible: false
60
61
62
63
64
65
        anchors {
            left: intensityScreen.right
            leftMargin: -20 * ApplicationInfo.ratio
            verticalCenter: intensityScreen.verticalCenter
        }
        opacity: currentStep / maxSteps
66
    }
67

68
69
70
71
72
73
74
    Colorize {
        anchors.fill: intensityLight
        source: intensityLight
        hue: chooser.hue
        lightness: -(maxSteps - currentStep) / maxSteps
        saturation: 1
        visible: intensityScreen.visible
75
    }
76
77
78

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

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

99
    ColorButton {
100
        source: Activity.url + "plus.svg"
Stephane Mankowski's avatar
Stephane Mankowski committed
101
102
103
104
105
        anchors {
            verticalCenter: parent.verticalCenter
            right: parent.right
            rightMargin: parent.width * 0.2
        }
106
107
    }

108
    ColorButton {
109
        source: Activity.url + "minus.svg"
Stephane Mankowski's avatar
Stephane Mankowski committed
110
111
112
        anchors {
            verticalCenter: parent.verticalCenter
            left: parent.left
113
            leftMargin: parent.width * 0.3
Stephane Mankowski's avatar
Stephane Mankowski committed
114
        }
115
    }
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136

    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
137
            activity.audioEffects.play('qrc:/gcompris/src/activities/redraw/resource/brush.wav')
138
139
140
        }
    }

141
}