summaryrefslogtreecommitdiff
path: root/src/controls/Styles
diff options
context:
space:
mode:
authorFrederik Gladhorn <frederik.gladhorn@theqtcompany.com>2014-11-27 18:04:58 +0100
committerFrederik Gladhorn <frederik.gladhorn@theqtcompany.com>2014-11-27 18:04:58 +0100
commit71314570d03631f50ab2c262011aba6a572d0ced (patch)
tree6d0c663ad313af89efff8e7b0fdafe6a28b19505 /src/controls/Styles
parent3704a616dfabb71ebd3ffc64f8efe32931c82a8b (diff)
parentea099e341b5f8845be56f81b22e44a8b6cb227a2 (diff)
downloadqtquickcontrols-71314570d03631f50ab2c262011aba6a572d0ced.tar.gz
Merge remote-tracking branch 'origin/5.4.0' into 5.4
Change-Id: I4c81a7852e7041328b7cfa320e907cc3cb863f04
Diffstat (limited to 'src/controls/Styles')
-rw-r--r--src/controls/Styles/Android/SwitchStyle.qml19
-rw-r--r--src/controls/Styles/Android/drawables/AnimationDrawable.qml5
-rw-r--r--src/controls/Styles/Android/drawables/ImageDrawable.qml28
-rw-r--r--src/controls/Styles/Android/drawables/StateDrawable.qml76
4 files changed, 118 insertions, 10 deletions
diff --git a/src/controls/Styles/Android/SwitchStyle.qml b/src/controls/Styles/Android/SwitchStyle.qml
index 4c36c918..6e9260c3 100644
--- a/src/controls/Styles/Android/SwitchStyle.qml
+++ b/src/controls/Styles/Android/SwitchStyle.qml
@@ -79,18 +79,26 @@ SwitchStyle {
Item {
id: thumb
+ readonly property bool hideText: AndroidStyle.styleDef.switchStyle.Switch_showText === false
+
x: control.checked ? max : min
- FontMetrics {
- id: metrics
+ TextMetrics {
+ id: onMetrics
+ font: label.font
+ text: panel.styleDef.Switch_textOn
+ }
+
+ TextMetrics {
+ id: offMetrics
font: label.font
+ text: panel.styleDef.Switch_textOff
}
- readonly property real maxTextWidth: Math.max(metrics.boundingRect(panel.styleDef.Switch_textOn).width,
- metrics.boundingRect(panel.styleDef.Switch_textOff).width)
+ readonly property real maxTextWidth: Math.max(onMetrics.width, offMetrics.width)
implicitWidth: Math.max(loader.implicitWidth, maxTextWidth + 2 * panel.styleDef.Switch_thumbTextPadding)
- implicitHeight: Math.max(loader.implicitHeight, metrics.height)
+ implicitHeight: Math.max(loader.implicitHeight, onMetrics.height, offMetrics.height)
anchors.top: parent.top
anchors.bottom: parent.bottom
@@ -120,6 +128,7 @@ SwitchStyle {
LabelStyle {
id: label
+ visible: !thumb.hideText
text: control.checked ? panel.styleDef.Switch_textOn : panel.styleDef.Switch_textOff
pressed: control.pressed
diff --git a/src/controls/Styles/Android/drawables/AnimationDrawable.qml b/src/controls/Styles/Android/drawables/AnimationDrawable.qml
index a522bfa7..12d576ff 100644
--- a/src/controls/Styles/Android/drawables/AnimationDrawable.qml
+++ b/src/controls/Styles/Android/drawables/AnimationDrawable.qml
@@ -49,14 +49,17 @@ Drawable {
property int currentFrame: 0
readonly property int frameCount: styleDef.frames ? styleDef.frames.length : 0
readonly property var frameDef: styleDef.frames ? styleDef.frames[currentFrame] : undefined
+ readonly property alias running: timer.running
+ property bool oneshot: styleDef.oneshot
Timer {
+ id: timer
repeat: true
running: root.frameCount && root.visible && Qt.application.active
interval: root.frameDef ? root.frameDef.duration : 0
onTriggered: {
var frame = root.currentFrame + 1
- repeat = !root.styleDef.oneshot || frame < root.frameCount - 1
+ repeat = !root.oneshot || frame < root.frameCount - 1
root.currentFrame = frame % root.frameCount
}
}
diff --git a/src/controls/Styles/Android/drawables/ImageDrawable.qml b/src/controls/Styles/Android/drawables/ImageDrawable.qml
index 1e71a389..4b41b2f2 100644
--- a/src/controls/Styles/Android/drawables/ImageDrawable.qml
+++ b/src/controls/Styles/Android/drawables/ImageDrawable.qml
@@ -52,5 +52,33 @@ Drawable {
anchors.fill: parent
fillMode: Image.TileHorizontally
source: AndroidStyle.filePath(styleDef.path)
+
+ layer.enabled: !!styleDef && !!styleDef.tintList
+ layer.effect: ShaderEffect {
+ property variant source: image
+ property color color: AndroidStyle.colorValue(styleDef.tintList[state])
+ state: {
+ var states = []
+ if (pressed) states.push("PRESSED")
+ if (enabled) states.push("ENABLED")
+ if (focused) states.push("FOCUSED")
+ if (selected) states.push("SELECTED")
+ if (window_focused) states.push("WINDOW_FOCUSED")
+ if (!states.length)
+ states.push("EMPTY")
+ return states.join("_") + "_STATE_SET"
+ }
+ // QtGraphicalEffects/ColorOverlay:
+ fragmentShader: "
+ varying mediump vec2 qt_TexCoord0;
+ uniform highp float qt_Opacity;
+ uniform lowp sampler2D source;
+ uniform highp vec4 color;
+ void main() {
+ highp vec4 pixelColor = texture2D(source, qt_TexCoord0);
+ gl_FragColor = vec4(mix(pixelColor.rgb/max(pixelColor.a, 0.00390625), color.rgb/max(color.a, 0.00390625), color.a) * pixelColor.a, pixelColor.a) * qt_Opacity;
+ }
+ "
+ }
}
}
diff --git a/src/controls/Styles/Android/drawables/StateDrawable.qml b/src/controls/Styles/Android/drawables/StateDrawable.qml
index d446542d..862ab9ae 100644
--- a/src/controls/Styles/Android/drawables/StateDrawable.qml
+++ b/src/controls/Styles/Android/drawables/StateDrawable.qml
@@ -46,10 +46,12 @@ Drawable {
implicitWidth: Math.max(loader.implicitWidth, styleDef.width || 0)
implicitHeight: Math.max(loader.implicitHeight, styleDef.height || 0)
+ property int prevMatch: 0
+
DrawableLoader {
id: loader
anchors.fill: parent
- styleDef: bestStateMatch()
+ visible: !animation.active
focused: root.focused
pressed: root.pressed
checked: root.checked
@@ -65,17 +67,70 @@ Drawable {
clippables: root.clippables
}
- function bestStateMatch () {
+ Loader {
+ id: animation
+ property var animDef
+ active: false
+ anchors.fill: parent
+ sourceComponent: AnimationDrawable {
+ anchors.fill: parent
+ styleDef: animDef
+ focused: root.focused
+ pressed: root.pressed
+ checked: root.checked
+ selected: root.selected
+ accelerated: root.accelerated
+ window_focused: root.window_focused
+ index: root.index
+ level: root.level
+ levelId: root.levelId
+ orientations: root.orientations
+ duration: root.duration
+ excludes: root.excludes
+ clippables: root.clippables
+
+ oneshot: true
+ onRunningChanged: if (!running) animation.active = false
+ }
+ }
+
+ onStyleDefChanged: resolveState()
+ Component.onCompleted: resolveState()
+
+ // In order to be able to find appropriate transition paths between
+ // various states, the following states must be allowed to change in
+ // batches. For example, button-like controls could have a transition
+ // path from pressed+checked to unpressed+unchecked. We must let both
+ // properties change before we try to find the transition path.
+ onEnabledChanged: resolver.start()
+ onFocusedChanged: resolver.start()
+ onPressedChanged: resolver.start()
+ onCheckedChanged: resolver.start()
+ onSelectedChanged: resolver.start()
+ onAcceleratedChanged: resolver.start()
+ onWindow_focusedChanged: resolver.start()
+
+ Timer {
+ id: resolver
+ interval: 15
+ onTriggered: resolveState()
+ }
+
+ function resolveState () {
if (styleDef && styleDef.stateslist) {
var bestMatch = 0
var highestScore = -1
var stateslist = styleDef.stateslist
+ var transitions = []
for (var i = 0; i < stateslist.length; ++i) {
var score = 0
var state = stateslist[i]
+ if (state.transition)
+ transitions.push(i)
+
for (var s in state.states) {
if (s === "pressed")
score += (pressed === state.states[s]) ? 1 : -10
@@ -98,8 +153,21 @@ Drawable {
highestScore = score
}
}
- return stateslist[bestMatch].drawable
+
+ if (prevMatch != bestMatch) {
+ for (var t = 0; t < transitions.length; ++t) {
+ var transition = stateslist[transitions[t]].transition
+ if ((transition.from == prevMatch && transition.to == bestMatch) ||
+ (transition.reverse && transition.from == bestMatch && transition.to == prevMatch)) {
+ animation.animDef = stateslist[transitions[t]].drawable
+ animation.active = true
+ break
+ }
+ }
+ prevMatch = bestMatch
+ }
+
+ loader.styleDef = stateslist[bestMatch].drawable
}
- return undefined
}
}