Commit 116f3a5b authored by Nate Graham's avatar Nate Graham 💤 Committed by Jan Grulich
Browse files

[applet] Port to checkbox with internally-defined icon property

With frameworks/plasma-framework!46,
checkboxes will be able to have an icon property defined internally, no
need for a separate SVG. So if and when that lands, we can use that and
discard the bespoke SwitchButton component.

This is an alternative to
!13.
parent acfde3ea
......@@ -6,7 +6,7 @@ set(PROJECT_VERSION "5.19.80")
set(PROJECT_VERSION_MAJOR 5)
set(QT_MIN_VERSION "5.14.0")
set(KF5_MIN_VERSION "5.71.0")
set(KF5_MIN_VERSION "5.73.0")
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED On)
......
/*
Copyright 2013-2017 Jan Grulich <jgrulich@redhat.com>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) version 3, or any
later version accepted by the membership of KDE e.V. (or its
successor approved by the membership of KDE e.V.), which shall
act as a proxy defined in Section 6 of version 3 of the license.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
import QtQuick 2.2
import org.kde.plasma.components 3.0 as PlasmaComponents3
import org.kde.plasma.core 2.0 as PlasmaCore
Item {
id: switchButton
property alias icon: switchButtonIcon.source
property alias checked: switchButtonCheckbox.checked
property alias enabled: switchButtonCheckbox.enabled
property alias tooltip: itemTooltip.text
signal clicked
height: Math.max(switchButtonCheckbox.height, switchButtonIcon.height)
width: switchButtonCheckbox.width + switchButtonIcon.width + units.smallSpacing * 3
PlasmaComponents3.CheckBox {
id: switchButtonCheckbox
anchors {
left: parent.left
leftMargin: units.smallSpacing
}
onClicked: {
switchButton.clicked()
}
}
PlasmaCore.IconItem {
id: switchButtonIcon
anchors {
left: switchButtonCheckbox.right
// Checkbox bug adds internally a smallSpacing on the right. Doubling the effective spacing here.
leftMargin: units.smallSpacing
verticalCenter: parent.verticalCenter
}
width: units.iconSizes.smallMedium
height: units.iconSizes.smallMedium
}
PlasmaComponents3.ToolTip {
id: itemTooltip
}
}
......@@ -69,31 +69,35 @@ ColumnLayout {
RowLayout {
spacing: units.smallSpacing
SwitchButton {
PlasmaComponents3.CheckBox {
id: wifiSwitchButton
checked: enabled && enabledConnections.wirelessEnabled
enabled: enabledConnections.wirelessHwEnabled && availableDevices.wirelessDeviceAvailable && !planeModeSwitchButton.airplaneModeEnabled
tooltip: i18n("Enable Wi-Fi")
icon: enabled ? "network-wireless-on" : "network-wireless-off"
icon.name: enabled ? "network-wireless-on" : "network-wireless-off"
visible: availableDevices.wirelessDeviceAvailable
onClicked: {
handler.enableWireless(checked);
onToggled: handler.enableWireless(checked);
PlasmaComponents3.ToolTip {
text: i18n("Enable Wi-Fi")
}
}
SwitchButton {
PlasmaComponents3.CheckBox {
id: wwanSwitchButton
checked: enabled && enabledConnections.wwanEnabled
enabled: enabledConnections.wwanHwEnabled && availableDevices.modemDeviceAvailable && !planeModeSwitchButton.airplaneModeEnabled
tooltip: i18n("Enable mobile network")
icon: enabled ? "network-mobile-on" : "network-mobile-off"
icon.name: enabled ? "network-mobile-on" : "network-mobile-off"
visible: availableDevices.modemDeviceAvailable
onClicked: {
handler.enableWwan(checked);
onToggled: handler.enableWwan(checked);
PlasmaComponents3.ToolTip {
text: i18n("Enable mobile network")
}
}
......@@ -102,20 +106,19 @@ ColumnLayout {
Layout.preferredWidth: units.smallSpacing * 2
}
SwitchButton {
PlasmaComponents3.CheckBox {
id: planeModeSwitchButton
property bool initialized: false
property bool airplaneModeEnabled: false
checked: airplaneModeEnabled
tooltip: airplaneModeEnabled ?
xi18nc("@info", "Disable airplane mode<nl/><nl/>This will enable Wi-Fi and Bluetooth") :
xi18nc("@info", "Enable airplane mode<nl/><nl/>This will disable Wi-Fi and Bluetooth")
icon: airplaneModeEnabled ? "network-flightmode-on" : "network-flightmode-off"
icon.name: airplaneModeEnabled ? "network-flightmode-on" : "network-flightmode-off"
visible: availableDevices.modemDeviceAvailable || availableDevices.wirelessDeviceAvailable
onClicked: {
onToggled: {
handler.enableAirplaneMode(checked);
airplaneModeEnabled = !airplaneModeEnabled;
}
......@@ -131,6 +134,12 @@ ColumnLayout {
airplaneModeEnabled = configuration.airplaneModeEnabled
initialized = true
}
PlasmaComponents3.ToolTip {
text: airplaneModeEnabled ?
xi18nc("@info", "Disable airplane mode<nl/><nl/>This will enable Wi-Fi and Bluetooth") :
xi18nc("@info", "Enable airplane mode<nl/><nl/>This will disable Wi-Fi and Bluetooth")
}
}
Item {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment