diff options
Diffstat (limited to 'src/controls/Styles/Android')
| -rw-r--r-- | src/controls/Styles/Android/ButtonStyle.qml | 2 | ||||
| -rw-r--r-- | src/controls/Styles/Android/CheckBoxStyle.qml | 2 | ||||
| -rw-r--r-- | src/controls/Styles/Android/ComboBoxStyle.qml | 13 | ||||
| -rw-r--r-- | src/controls/Styles/Android/CursorHandleStyle.qml | 75 | ||||
| -rw-r--r-- | src/controls/Styles/Android/GroupBoxStyle.qml | 10 | ||||
| -rw-r--r-- | src/controls/Styles/Android/RadioButtonStyle.qml | 2 | ||||
| -rw-r--r-- | src/controls/Styles/Android/SpinBoxStyle.qml | 13 | ||||
| -rw-r--r-- | src/controls/Styles/Android/SwitchStyle.qml | 19 | ||||
| -rw-r--r-- | src/controls/Styles/Android/TextAreaStyle.qml | 4 | ||||
| -rw-r--r-- | src/controls/Styles/Android/TextFieldStyle.qml | 15 | ||||
| -rw-r--r-- | src/controls/Styles/Android/ToolButtonStyle.qml | 2 | ||||
| -rw-r--r-- | src/controls/Styles/Android/drawables/AnimationDrawable.qml | 5 | ||||
| -rw-r--r-- | src/controls/Styles/Android/drawables/ImageDrawable.qml | 28 | ||||
| -rw-r--r-- | src/controls/Styles/Android/drawables/StateDrawable.qml | 76 |
14 files changed, 188 insertions, 78 deletions
diff --git a/src/controls/Styles/Android/ButtonStyle.qml b/src/controls/Styles/Android/ButtonStyle.qml index 2a1080513..7157affe0 100644 --- a/src/controls/Styles/Android/ButtonStyle.qml +++ b/src/controls/Styles/Android/ButtonStyle.qml @@ -93,7 +93,7 @@ Style { LabelStyle { id: label visible: !!text - text: control.text + text: StyleHelpers.removeMnemonics(control.text) pressed: control.pressed focused: control.activeFocus selected: control.checked diff --git a/src/controls/Styles/Android/CheckBoxStyle.qml b/src/controls/Styles/Android/CheckBoxStyle.qml index 908665d01..3983a868e 100644 --- a/src/controls/Styles/Android/CheckBoxStyle.qml +++ b/src/controls/Styles/Android/CheckBoxStyle.qml @@ -70,7 +70,7 @@ Style { LabelStyle { id: label - text: control.text + text: StyleHelpers.removeMnemonics(control.text) pressed: control.pressed focused: control.activeFocus selected: control.checked diff --git a/src/controls/Styles/Android/ComboBoxStyle.qml b/src/controls/Styles/Android/ComboBoxStyle.qml index 715dd9f69..366deed56 100644 --- a/src/controls/Styles/Android/ComboBoxStyle.qml +++ b/src/controls/Styles/Android/ComboBoxStyle.qml @@ -37,7 +37,7 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ -import QtQuick 2.2 +import QtQuick 2.4 import QtQuick.Window 2.2 import QtQuick.Controls 1.2 import QtQuick.Controls.Private 1.0 @@ -70,7 +70,7 @@ Style { readonly property real minWidth: styleDef.View_minWidth || 0 readonly property real minHeight: styleDef.View_minHeight || 0 - readonly property real labelWidth: label.implicitWidth + paddingStart + paddingEnd + readonly property real labelWidth: Math.max(label.implicitWidth, metrics.width) + paddingStart + paddingEnd readonly property real labelHeight: label.implicitHeight + bg.padding.top + bg.padding.bottom implicitWidth: Math.max(minWidth, Math.max(bg.implicitWidth, labelWidth)) @@ -85,6 +85,11 @@ Style { styleDef: panel.styleDef.View_background } + TextMetrics { + id: metrics + text: "12345678901234567890" + } + LabelStyle { id: label text: control.currentText @@ -105,11 +110,11 @@ Style { property Component __popupStyle: null property Component __dropDownStyle: null - property Component selectionHandle: DrawableLoader { + property Component __selectionHandle: DrawableLoader { styleDef: AndroidStyle.styleDef.textViewStyle.TextView_textSelectHandleLeft x: -width / 4 * 3 y: styleData.lineHeight } - property Component cursorHandle: CursorHandleStyle { } + property Component __cursorHandle: CursorHandleStyle { } } diff --git a/src/controls/Styles/Android/CursorHandleStyle.qml b/src/controls/Styles/Android/CursorHandleStyle.qml index 97b9fe857..e9d08f8e6 100644 --- a/src/controls/Styles/Android/CursorHandleStyle.qml +++ b/src/controls/Styles/Android/CursorHandleStyle.qml @@ -45,66 +45,51 @@ import "drawables" DrawableLoader { id: delegate - property bool active: false + + property bool hasText: !!editor.text || !!editor.displayText + styleDef: styleData.hasSelection ? AndroidStyle.styleDef.textViewStyle.TextView_textSelectHandleRight : AndroidStyle.styleDef.textViewStyle.TextView_textSelectHandle x: styleData.hasSelection ? -width / 4 : -width / 2 y: styleData.lineHeight - opacity: 1.0 pressed: styleData.pressed focused: control.activeFocus window_focused: focused && control.Window.active - Connections { - target: editor - ignoreUnknownSignals: true - onDisplayTextChanged: { - delegate.state = "hidden" - } + opacity: hasText && (styleData.hasSelection || styleData.pressed || idle.running) ? 1.0 : 0.0 + + Timer { + id: idle + repeat: false + interval: 4000 } Connections { target: styleData - onActivated: { - if (editor.text) { - delegate.active = true - delegate.opacity = 1.0 - delegate.state = "" - if (!styleData.hasSelection) - delegate.state = "idle" - } + onActivated: idle.restart() + onPressedChanged: { + if (!styleData.pressed) + idle.restart() } } - state: "hidden" - - states: [ - State { - name: "hidden" - when: editor.inputMethodComposing && !delegate.active && !editor.text - }, - State { - name: "idle" - when: !styleData.hasSelection && !styleData.pressed - } - ] + // Hide the cursor handle on textual changes, unless the signals are + // indirectly triggered by activating/tapping/moving the handle. When + // text prediction is enabled, the textual content may change when the + // cursor moves and the predicted text is committed. + Connections { + target: editor + ignoreUnknownSignals: true + onTextChanged: if (!ignore.running) idle.stop() + onDisplayTextChanged: if (!ignore.running) idle.stop() + onInputMethodComposing: if (!ignore.running) idle.stop() + } - transitions: [ - Transition { - to: "hidden" - SequentialAnimation { - PauseAnimation { duration: 100 } - PropertyAction { target: delegate; property: "opacity"; value: 0.0 } - } - }, - Transition { - to: "idle" - SequentialAnimation { - PauseAnimation { duration: 4000 } - NumberAnimation { target: delegate; property: "opacity"; to: 0.0 } - PropertyAction { target: delegate; property: "active"; value: false } - } - } - ] + Timer { + id: ignore + repeat: false + interval: 250 + running: idle.running + } } diff --git a/src/controls/Styles/Android/GroupBoxStyle.qml b/src/controls/Styles/Android/GroupBoxStyle.qml index b7346ea43..d8f1127b6 100644 --- a/src/controls/Styles/Android/GroupBoxStyle.qml +++ b/src/controls/Styles/Android/GroupBoxStyle.qml @@ -53,7 +53,7 @@ GroupBoxStyle { readonly property var styleDef: AndroidStyle.styleDef.checkboxStyle readonly property real contentMargin: label.implicitHeight / 3 - readonly property real topMargin: indicator.height + readonly property real topMargin: control.checkable ? indicator.height : label.height Binding { target: root; property: "padding.top"; value: topMargin + contentMargin } Binding { target: root; property: "padding.left"; value: contentMargin } Binding { target: root; property: "padding.right"; value: contentMargin } @@ -95,14 +95,15 @@ GroupBoxStyle { DrawableLoader { id: indicator - visible: control.checkable + active: control.checkable checked: control.checked pressed: check.pressed focused: check.activeFocus window_focused: control.Window.active styleDef: AndroidStyle.styleDef.checkboxStyle.CompoundButton_button - anchors.verticalCenter: label.verticalCenter width: control.checkable ? item.implicitWidth : 0 + anchors.verticalCenter: parent.top + anchors.verticalCenterOffset: topMargin / 2 } LabelStyle { @@ -114,9 +115,10 @@ GroupBoxStyle { window_focused: control.Window.active styleDef: AndroidStyle.styleDef.checkboxStyle - anchors.top: parent.top anchors.left: indicator.right anchors.right: parent.right + anchors.verticalCenter: parent.top + anchors.verticalCenterOffset: topMargin / 2 } } } diff --git a/src/controls/Styles/Android/RadioButtonStyle.qml b/src/controls/Styles/Android/RadioButtonStyle.qml index 76b2c9b7c..678fcdc3d 100644 --- a/src/controls/Styles/Android/RadioButtonStyle.qml +++ b/src/controls/Styles/Android/RadioButtonStyle.qml @@ -70,7 +70,7 @@ Style { LabelStyle { id: label - text: control.text + text: StyleHelpers.removeMnemonics(control.text) pressed: control.pressed focused: control.activeFocus selected: control.checked diff --git a/src/controls/Styles/Android/SpinBoxStyle.qml b/src/controls/Styles/Android/SpinBoxStyle.qml index 86fce0349..0e5df3fd0 100644 --- a/src/controls/Styles/Android/SpinBoxStyle.qml +++ b/src/controls/Styles/Android/SpinBoxStyle.qml @@ -37,7 +37,7 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ -import QtQuick 2.2 +import QtQuick 2.4 import QtQuick.Window 2.2 import QtQuick.Controls 1.2 import QtQuick.Controls.Private 1.0 @@ -58,7 +58,7 @@ Style { readonly property real contentWidth: Math.max(styleDef.View_minWidth || 0, styleData.contentWidth) readonly property real contentHeight: Math.max(styleDef.View_minHeight || 0, styleData.contentHeight) - readonly property real labelWidth: label.implicitWidth + bg.padding.left + bg.padding.right + readonly property real labelWidth: Math.max(label.implicitWidth, metrics.width) + bg.padding.left + bg.padding.right readonly property real labelHeight: label.implicitHeight + bg.padding.top + bg.padding.bottom implicitWidth: Math.max(contentWidth, Math.max(bg.implicitWidth, labelWidth)) @@ -88,6 +88,11 @@ Style { readonly property int horizontalAlignment: Qt.AlignLeft readonly property int verticalAlignment: Qt.AlignVCenter + TextMetrics { + id: metrics + text: "12345678901234567890" + } + LabelStyle { id: label visible: false @@ -98,11 +103,11 @@ Style { } } - property Component selectionHandle: DrawableLoader { + property Component __selectionHandle: DrawableLoader { styleDef: AndroidStyle.styleDef.textViewStyle.TextView_textSelectHandleLeft x: -width / 4 * 3 y: styleData.lineHeight } - property Component cursorHandle: CursorHandleStyle { } + property Component __cursorHandle: CursorHandleStyle { } } diff --git a/src/controls/Styles/Android/SwitchStyle.qml b/src/controls/Styles/Android/SwitchStyle.qml index 4c36c918e..6e9260c35 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/TextAreaStyle.qml b/src/controls/Styles/Android/TextAreaStyle.qml index 61ea9fb85..85950efa0 100644 --- a/src/controls/Styles/Android/TextAreaStyle.qml +++ b/src/controls/Styles/Android/TextAreaStyle.qml @@ -72,11 +72,11 @@ ScrollViewStyle { styleDef: style.styleDef } - property Component selectionHandle: DrawableLoader { + property Component __selectionHandle: DrawableLoader { styleDef: AndroidStyle.styleDef.textViewStyle.TextView_textSelectHandleLeft x: -width / 4 * 3 y: styleData.lineHeight } - property Component cursorHandle: CursorHandleStyle { } + property Component __cursorHandle: CursorHandleStyle { } } diff --git a/src/controls/Styles/Android/TextFieldStyle.qml b/src/controls/Styles/Android/TextFieldStyle.qml index e7eec32c6..0edc5c90b 100644 --- a/src/controls/Styles/Android/TextFieldStyle.qml +++ b/src/controls/Styles/Android/TextFieldStyle.qml @@ -37,7 +37,7 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ -import QtQuick 2.2 +import QtQuick 2.4 import QtQuick.Window 2.2 import QtQuick.Controls 1.2 import QtQuick.Controls.Private 1.0 @@ -56,7 +56,7 @@ Style { readonly property real minWidth: styleDef.View_minWidth || 0 readonly property real minHeight: styleDef.View_minHeight || 0 - readonly property real labelWidth: label.implicitWidth + bg.padding.left + bg.padding.right + readonly property real labelWidth: Math.max(label.implicitWidth, metrics.width) + bg.padding.left + bg.padding.right readonly property real labelHeight: label.implicitHeight + bg.padding.top + bg.padding.bottom implicitWidth: Math.max(minWidth, Math.max(bg.implicitWidth, labelWidth)) @@ -81,21 +81,26 @@ Style { readonly property alias selectionColor: label.selectionColor readonly property color selectedTextColor: label.selectedTextColor + TextMetrics { + id: metrics + text: "12345678901234567890" + } + LabelStyle { id: label visible: false - text: control.text + text: control.text || control.placeholderText focused: control.activeFocus window_focused: focused && control.Window.active styleDef: panel.styleDef } } - property Component selectionHandle: DrawableLoader { + property Component __selectionHandle: DrawableLoader { styleDef: AndroidStyle.styleDef.textViewStyle.TextView_textSelectHandleLeft x: -width / 4 * 3 y: styleData.lineHeight } - property Component cursorHandle: CursorHandleStyle { } + property Component __cursorHandle: CursorHandleStyle { } } diff --git a/src/controls/Styles/Android/ToolButtonStyle.qml b/src/controls/Styles/Android/ToolButtonStyle.qml index 33d922207..9dbe60f77 100644 --- a/src/controls/Styles/Android/ToolButtonStyle.qml +++ b/src/controls/Styles/Android/ToolButtonStyle.qml @@ -95,7 +95,7 @@ Style { LabelStyle { id: label visible: !!text - text: control.text + text: StyleHelpers.removeMnemonics(control.text) pressed: control.pressed focused: control.activeFocus selected: control.checked diff --git a/src/controls/Styles/Android/drawables/AnimationDrawable.qml b/src/controls/Styles/Android/drawables/AnimationDrawable.qml index a522bfa7c..12d576ff4 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 1e71a389a..4b41b2f21 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 d446542d9..862ab9ae6 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 } } |
