for #58,support plasma theme switch svg

work/spdx
Michail Vourlakos 4 years ago
parent d82faa359c
commit f242bdf3bd

@ -24,47 +24,144 @@ import org.kde.plasma.core 2.0 as PlasmaCore
QtQuickControlStyle.SwitchStyle { QtQuickControlStyle.SwitchStyle {
id: styleRoot id: styleRoot
padding { top: 0 ; left: 0 ; right: 0 ; bottom: 0 }
handle: PlasmaCore.FrameSvgItem { PlasmaCore.Svg {
opacity: control.enabled ? 1.0 : 0.6 id: switchSvg
width: height imagePath: "widgets/switch"
imagePath: "widgets/button" colorGroup: PlasmaCore.ColorScope.colorGroup
prefix: "shadow" }
property bool themeHasSwitch: false
handle: Item {
implicitWidth: {
if (fallbackHandle.visible) {
return height;
}
return switchSvg.hasElement("hint-handle-size") ? switchSvg.elementSize("hint-handle-size").width : themeHandleItem.width;
}
implicitHeight: {
if (fallbackHandle.visible) {
return theme.mSize(theme.defaultFont).height
}
PlasmaCore.FrameSvgItem { return switchSvg.hasElement("hint-handle-size") ? switchSvg.elementSize("hint-handle-size").height : themeHandleItem.height
id: button }
Item {
id: fallbackHandle
anchors.fill: parent anchors.fill: parent
imagePath: "widgets/button" visible: !themeHandleItem.visible
prefix: "normal"
PlasmaCore.FrameSvgItem {
anchors.fill: parent
opacity: control.enabled ? 1.0 : 0.6
imagePath: "widgets/button"
prefix: "shadow"
}
PlasmaCore.FrameSvgItem {
id: button
anchors.fill: parent
imagePath: "widgets/button"
prefix: "normal"
}
}
PlasmaCore.SvgItem {
id: themeHandleShadow
anchors.fill: themeHandleItem
opacity: control.enabled ? 1.0 : 0.6
svg: switchSvg
elementId: control.activeFocus ? "handle-focus" : (control.hovered ? "handle-hover" : "handle-shadow")
visible: styleRoot.themeHasSwitch
}
PlasmaCore.SvgItem {
id: themeHandleItem
anchors.centerIn: parent
width: naturalSize.width
height: naturalSize.height
svg: switchSvg
elementId: "handle"
visible: styleRoot.themeHasSwitch
} }
} }
groove: Item { groove: Item {
implicitHeight: theme.mSize(theme.defaultFont).height width: theme.mSize(theme.defaultFont).height * 2
implicitWidth: height * 2 height: themeGroove.visible ? themeGrooveItem.implicitHeight : theme.mSize(theme.defaultFont).height
PlasmaCore.FrameSvgItem { Item{
id: fallbackGroove
anchors.fill: parent anchors.fill: parent
imagePath: "widgets/slider" visible: !themeGroove.visible
prefix: "groove"
opacity: control.checked ? 0 : 1 PlasmaCore.FrameSvgItem {
visible: opacity > 0 id: fallbackGrooveItem
Behavior on opacity { anchors.fill: parent
PropertyAnimation { duration: units.shortDuration * 2 } imagePath: "widgets/slider"
prefix: "groove"
opacity: control.checked ? 0 : 1
colorGroup: PlasmaCore.ColorScope.colorGroup
visible: opacity > 0
Behavior on opacity {
PropertyAnimation { duration: units.shortDuration * 2 }
}
}
PlasmaCore.FrameSvgItem {
id: fallbackHighlight
anchors.fill: fallbackGrooveItem
imagePath: "widgets/slider"
prefix: "groove-highlight"
opacity: control.checked ? 1 : 0
colorGroup: PlasmaCore.ColorScope.colorGroup
visible: opacity > 0
Behavior on opacity {
PropertyAnimation { duration: units.shortDuration * 2 }
}
} }
} }
PlasmaCore.FrameSvgItem { Item {
id: highlight id: themeGroove
anchors.fill: parent anchors.fill: parent
imagePath: "widgets/slider" visible: styleRoot.themeHasSwitch
prefix: "groove-highlight"
PlasmaCore.FrameSvgItem {
id: themeGrooveItem
anchors.fill: parent
imagePath: "widgets/switch"
prefix: "groove"
opacity: control.checked ? 0 : 1
colorGroup: PlasmaCore.ColorScope.colorGroup
visible: opacity > 0
Component.onCompleted: styleRoot.themeHasSwitch = fromCurrentTheme;
onFromCurrentThemeChanged: styleRoot.themeHasSwitch = fromCurrentTheme;
Behavior on opacity {
PropertyAnimation { duration: units.shortDuration * 2 }
}
}
opacity: control.checked ? 1 : 0 PlasmaCore.FrameSvgItem {
visible: opacity > 0 id: themeGrooveHighlight
anchors.fill: parent
imagePath: "widgets/switch"
prefix: "groove-highlight"
opacity: control.checked ? 1 : 0
colorGroup: PlasmaCore.ColorScope.colorGroup
visible: opacity > 0
Behavior on opacity { Behavior on opacity {
PropertyAnimation { duration: units.shortDuration * 2 } PropertyAnimation { duration: units.shortDuration * 2 }
}
} }
} }
} }

Loading…
Cancel
Save