maemo.org - Talk

maemo.org - Talk (https://talk.maemo.org/index.php)
-   SailfishOS (https://talk.maemo.org/forumdisplay.php?f=52)
-   -   Changing color gamma in the slider ? (qml edit). (https://talk.maemo.org/showthread.php?t=99569)

Schturman 2017-07-04 10:50

Changing color gamma in the slider ? (qml edit).
 
1 Attachment(s)
Hi to all.
I use this slider (thanks to Ancelad) to get color code (see image below) and for visual effects in the setting. And I want to change this color gamma to darker colors. This code I use, maybe someone can help me and edit this code (if it possible at all) ?
Thanks

Code:

            Slider {
                id: slider
                Rectangle {
            id: background
            x: slider.leftMargin
            z: -1
            width: slider._grooveWidth
            height: Theme.paddingMedium
            anchors.top: parent.verticalCenter
            anchors.topMargin: -Theme.paddingLarge*2
           
                    ShaderEffect {
                        id: rainbow
                        property variant src: background
                        property real saturation: 1.0
                        property real lightness: 0.5
                        property real alpha: 1.0
           
                        width: parent.width
                        height: parent.height
           
                        // Fragment shader to create hue color wheel background
                        fragmentShader: "
                            varying highp vec2 coord;
                            varying highp vec2 qt_TexCoord0;
                            uniform sampler2D src;
                            uniform lowp float qt_Opacity;
                            uniform lowp float saturation;
                            uniform lowp float lightness;
                            uniform lowp float alpha;
           
                            void main() {
                                float r, g, b;
           
                                float h = qt_TexCoord0.x * 360.0;
                                float s = saturation;
                                float l = lightness;
           
                                float c = (1.0 - abs(2.0 * l - 1.0)) * s;
                                float hh = h / 60.0;
                                float x = c * (1.0 - abs(mod(hh, 2.0) - 1.0));
           
                                int i = int( hh );
           
                                if (i == 0) {
                                    r = c; g = x; b = 0.0;
                                } else if (i == 1) {
                                    r = x; g = c; b = 0.0;
                                } else if (i == 2) {
                                    r = 0.0; g = c; b = x;
                                } else if (i == 3) {
                                    r = 0.0; g = x; b = c;
                                } else if (i == 4) {
                                    r = x; g = 0.0; b = c;
                                } else if (i == 5) {
                                    r = c; g = 0.0; b = x;
                                } else {
                                    r = 0.0; g = 0.0; b = 0.0;
                                }
           
                                float m = l - 0.5 * c;
           
                                lowp vec4 tex = texture2D(src, qt_TexCoord0);
                                gl_FragColor = vec4(r+m,g+m,b+m,alpha) * qt_Opacity;
                            }"
                    }
                }   
               
                width: parent.width
                minimumValue: 0
                maximumValue: 100
                stepSize: 1
                value: customFASTdialicon.framecolor
                valueText: "◭"
                onValueChanged: customFASTdialicon.framecolor = value
                onPressAndHold: cancel()

        Label {
                    width: parent.width
                    wrapMode: Text.Wrap
                    font.pixelSize: Theme.fontSizeSmall
                    horizontalAlignment: Text.AlignHCenter
                    anchors.top: parent.verticalCenter
                    anchors.topMargin: Theme.paddingMedium*2.8
                    //color: Color.toHighlight(Color.fromHsva(customFASTdialicon.framecolor/100, 1.0, 0.5, 1.0))
                    text: qsTr("Choose frame color")
                }                       
            }


coderus 2017-07-04 12:44

Re: Changing color gamma in the slider ? (qml edit).
 
color = Qt.darker(oldColor) ?

Schturman 2017-07-04 14:34

Re: Changing color gamma in the slider ? (qml edit).
 
Quote:

Originally Posted by coderus (Post 1530100)
color = Qt.darker(oldColor) ?

Coderus thanks, but I don't understand where to put this line inside the code above...
I tried different variations, but nothing work... Of course I do something wrong...
Please, can you edit the code above ?
Thanks

dcaliste 2017-07-04 15:10

Re: Changing color gamma in the slider ? (qml edit).
 
Have you tried to play with the lightness value ? I guess a value of 0. should make all the range black, while a value of 1. will make the range white.

The saturation will make the colour be less coloured… I mean with a value of 0 and a lightness at 0.5, all the range will be grey.

(I did try but I guess so)

Schturman 2017-07-04 15:30

Re: Changing color gamma in the slider ? (qml edit).
 
Quote:

Originally Posted by dcaliste (Post 1530105)
Have you tried to play with the lightness value ? I guess a value of 0. should make all the range black, while a value of 1. will make the range white.

The saturation will make the colour be less coloured… I mean with a value of 0 and a lightness at 0.5, all the range will be grey.

(I did try but I guess so)

Yes, I tried to play with this values, but I didn't get the desired result...

coderus 2017-07-04 16:57

Re: Changing color gamma in the slider ? (qml edit).
 
Quote:

Originally Posted by Schturman (Post 1530101)
Coderus thanks, but I don't understand where to put this line inside the code above...
I tried different variations, but nothing work... Of course I do something wrong...
Please, can you edit the code above ?
Thanks

customFASTdialicon.framecolor = Qt.darker(value)

Schturman 2017-07-04 17:45

Re: Changing color gamma in the slider ? (qml edit).
 
Quote:

Originally Posted by coderus (Post 1530110)
customFASTdialicon.framecolor = Qt.darker(value)

Ohhh, I got it, thanks ! But not where you put it. It should be like this:
Qt.darker(Color.toHighlight(Color.fromHsva(customF ASTdialicon.framecolor/100, 1.0, 0.5, 1.0)))

Now I see visual darker effect on the rectangle color and can get the darker color code (for next usage), but I still can't see the darker rainbow above the slider itself.
It also ok if it not possible :)


All times are GMT. The time now is 10:43.

vBulletin® Version 3.8.8