diff options
Diffstat (limited to 'src/controls/Styles/Android/SwitchStyle.qml')
-rw-r--r-- | src/controls/Styles/Android/SwitchStyle.qml | 129 |
1 files changed, 68 insertions, 61 deletions
diff --git a/src/controls/Styles/Android/SwitchStyle.qml b/src/controls/Styles/Android/SwitchStyle.qml index 60d8f2ef..13bbd356 100644 --- a/src/controls/Styles/Android/SwitchStyle.qml +++ b/src/controls/Styles/Android/SwitchStyle.qml @@ -41,88 +41,95 @@ import QtQuick 2.4 import QtQuick.Window 2.2 import QtQuick.Controls 1.2 import QtQuick.Controls.Private 1.0 +import QtQuick.Controls.Styles 1.2 import QtQuick.Controls.Styles.Android 1.0 import "drawables" -Style { +SwitchStyle { property Switch control: __control + readonly property bool hasHoloSwitch: !!AndroidStyle.styleDef.switchStyle - property Component panel: Item { - id: panel + Component.onCompleted: if (hasHoloSwitch) panel = holoPanel - // TODO: API level < 14 - readonly property var styleDef: AndroidStyle.styleDef.switchStyle - - implicitWidth: Math.max(styleDef.Switch_switchMinWidth, Math.max(track.implicitWidth, 2 * thumb.implicitWidth)) - implicitHeight: Math.max(track.implicitHeight, thumb.implicitHeight) - - property real min: track.padding.left - property real max: track.width - thumb.width - track.padding.left - property var __handle: thumb - - DrawableLoader { - id: track - anchors.fill: parent - pressed: control.pressed - checked: control.checked - focused: control.activeFocus - window_focused: control.window && control.window.active - styleDef: panel.styleDef.Switch_track - } + Component { + id: holoPanel Item { - id: thumb - - x: control.checked ? max : min - - FontMetrics { - id: metrics - font: label.font - } + id: panel - readonly property real maxTextWidth: Math.max(metrics.boundingRect(panel.styleDef.Switch_textOn).width, - metrics.boundingRect(panel.styleDef.Switch_textOff).width) + readonly property var styleDef: AndroidStyle.styleDef.switchStyle - implicitWidth: Math.max(loader.implicitWidth, maxTextWidth + 2 * panel.styleDef.Switch_thumbTextPadding) - implicitHeight: Math.max(loader.implicitHeight, metrics.height) + implicitWidth: Math.max(styleDef.Switch_switchMinWidth, Math.max(track.implicitWidth, 2 * thumb.implicitWidth)) + implicitHeight: Math.max(track.implicitHeight, thumb.implicitHeight) - anchors.top: parent.top - anchors.bottom: parent.bottom - - Behavior on x { - id: behavior - enabled: thumb.status === Loader.Ready - NumberAnimation { - duration: 150 - easing.type: Easing.OutCubic - } - } + property real min: track.padding.left + property real max: track.width - thumb.width - track.padding.left + property var __handle: thumb DrawableLoader { - id: loader - anchors.left: parent.left - anchors.right: parent.right - anchors.leftMargin: -padding.left - anchors.rightMargin: -padding.right - anchors.verticalCenter: parent.verticalCenter + id: track + anchors.fill: parent pressed: control.pressed checked: control.checked focused: control.activeFocus window_focused: control.window && control.window.active - styleDef: panel.styleDef.Switch_thumb + styleDef: panel.styleDef.Switch_track } - LabelStyle { - id: label - text: control.checked ? panel.styleDef.Switch_textOn : panel.styleDef.Switch_textOff + Item { + id: thumb - pressed: control.pressed - focused: control.activeFocus - selected: control.checked - window_focused: control.window && control.window.active - styleDef: panel.styleDef.Switch_switchTextAppearance + x: control.checked ? max : min - anchors.fill: parent + FontMetrics { + id: metrics + font: label.font + } + + readonly property real maxTextWidth: Math.max(metrics.boundingRect(panel.styleDef.Switch_textOn).width, + metrics.boundingRect(panel.styleDef.Switch_textOff).width) + + implicitWidth: Math.max(loader.implicitWidth, maxTextWidth + 2 * panel.styleDef.Switch_thumbTextPadding) + implicitHeight: Math.max(loader.implicitHeight, metrics.height) + + anchors.top: parent.top + anchors.bottom: parent.bottom + + Behavior on x { + id: behavior + enabled: thumb.status === Loader.Ready + NumberAnimation { + duration: 150 + easing.type: Easing.OutCubic + } + } + + DrawableLoader { + id: loader + anchors.left: parent.left + anchors.right: parent.right + anchors.leftMargin: -padding.left + anchors.rightMargin: -padding.right + anchors.verticalCenter: parent.verticalCenter + pressed: control.pressed + checked: control.checked + focused: control.activeFocus + window_focused: control.window && control.window.active + styleDef: panel.styleDef.Switch_thumb + } + + LabelStyle { + id: label + text: control.checked ? panel.styleDef.Switch_textOn : panel.styleDef.Switch_textOff + + pressed: control.pressed + focused: control.activeFocus + selected: control.checked + window_focused: control.window && control.window.active + styleDef: panel.styleDef.Switch_switchTextAppearance + + anchors.fill: parent + } } } } |