Commit 971dc0a2 authored by Nate Graham's avatar Nate Graham Committed by Fushan Wen
Browse files

applets/keyboardlayout: re-introduce "label+flag" display style option

This feature got lost in the QML port and is re-added here.

The old version of the feature drew the label on top of the flag with no
background, thereby making the label appear invisible for certain flags.
To alleviate this, the new implementation draws the label on a badge in
the corner, like the Battery & Brightness widget does.

Because this changes the format of the setting that controls the display
style (going from a bool to an enum), an update script is provided to
migrate people's old settings as needed.

BUG: 444864
FIXED-IN: 5.26
parent 06632f45
Pipeline #230956 passed with stage
in 5 minutes and 12 seconds
......@@ -6,7 +6,15 @@
<kcfgfile name=""/>
<group name="General">
<entry name="showFlag" type="Bool"/>
<entry name="displayStyle" type="Enum">
<label>Whether to show text, a flag, or both on the compact representation.</label>
<choices>
<choice name="Label"/>
<choice name="Flag"/>
<choice name="LabelOverFlag"/>
</choices>
<default>0</default>
</entry>
</group>
</kcfg>
......@@ -4,12 +4,14 @@ import QtQuick.Controls 2.15
import Qt.labs.platform 1.1 as Platform
import org.kde.kirigami 2.5 as Kirigami
import org.kde.kquickcontrolsaddons 2.0 as KQCAddons
import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.plasma.workspace.keyboardlayout 1.0
import org.kde.plasma.workspace.components 2.0 as WorkspaceComponents
Kirigami.FormLayout {
id: root
property alias cfg_showFlag: showFlag.checked
property int cfg_displayStyle
readonly property string layoutShortName: keyboardLayout.layoutsList.length ? keyboardLayout.layoutsList[keyboardLayout.layout].shortName
: ""
readonly property string displayName: keyboardLayout.layoutsList.length ? keyboardLayout.layoutsList[keyboardLayout.layout].displayName
......@@ -19,23 +21,30 @@ Kirigami.FormLayout {
RadioButton {
id: showLabel
Kirigami.FormData.label: i18n("Display style:")
checked: true
text: root.displayName.length > 0 ? root.displayName: root.layoutShortName
checked: cfg_displayStyle === 0
onToggled: cfg_displayStyle = 0;
}
RadioButton {
id: showFlag
checked: cfg_displayStyle === 1
onToggled: cfg_displayStyle = 1;
contentItem: Item {
implicitWidth: childrenRect.width + showFlag.indicator.width
implicitHeight: childrenRect.height
Image {
// Deliberately using this instead of Image to preserve visual fidelity
// with what the widget will show
PlasmaCore.IconItem {
id: flagImage
width: PlasmaCore.Units.iconSizes.medium
height: PlasmaCore.Units.iconSizes.medium
anchors.right: parent.right
anchors.verticalCenter: parent.verticalCenter
source: Platform.StandardPaths.locate(Platform.StandardPaths.GenericDataLocation,
"kf5/locale/countries/" + root.layoutShortName + "/flag.png")
visible: status == Image.Ready
visible: valid
}
RowLayout {
anchors.right: parent.right
......@@ -57,6 +66,36 @@ Kirigami.FormLayout {
}
}
RadioButton {
id: showLabelOverFlag
checked: cfg_displayStyle === 2
onToggled: cfg_displayStyle = 2;
contentItem: Item {
implicitWidth: childrenRect.width + showLabelOverFlag.indicator.width
implicitHeight: childrenRect.height
// Deliberately using this instead of Image to preserve visual fidelity
// with what the widget will show
PlasmaCore.IconItem {
width: PlasmaCore.Units.iconSizes.medium
height: PlasmaCore.Units.iconSizes.medium
anchors.right: parent.right
anchors.verticalCenter: parent.verticalCenter
source: Platform.StandardPaths.locate(Platform.StandardPaths.GenericDataLocation,
"kf5/locale/countries/" + root.layoutShortName + "/flag.png")
visible: valid
WorkspaceComponents.BadgeOverlay {
anchors.bottom: parent.bottom
anchors.right: parent.right
text: showLabel.text
icon: parent
}
}
}
}
Kirigami.Separator {
Kirigami.FormData.isSection: true
}
......
......@@ -54,22 +54,35 @@ Item {
}
PlasmaCore.IconItem {
id: icon
id: flag
anchors.fill: parent
visible: plasmoid.configuration.showFlag && source
visible: valid && (Plasmoid.configuration.displayStyle === 1 || Plasmoid.configuration.displayStyle === 2)
active: containsMouse
source: iconURL(layoutNames.shortName)
BadgeOverlay {
anchors.bottom: parent.bottom
anchors.right: parent.right
visible: !countryCode.visible && Plasmoid.configuration.displayStyle === 2
text: countryCode.text
icon: flag
}
}
PlasmaComponents3.Label {
id: countryCode
anchors.fill: parent
visible: !icon.visible
visible: Plasmoid.configuration.displayStyle === 0 || (!flag.valid && (Plasmoid.configuration.displayStyle === 1 || Plasmoid.configuration.displayStyle === 2))
font.pointSize: height
fontSizeMode: Text.Fit
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
text: layoutNames.displayName || layoutNames.shortName
}
}
......
// Find all Keyboard Layout applets in all containments and change
// showFlag=true
// to
// displayStyle=Flag
// See https://invent.kde.org/plasma/plasma-workspace/-/merge_requests/1131
const containments = desktops().concat(panels());
for (var i in containments) {
forEachWidgetInContainment(containments[i]);
}
function forEachWidgetInContainment(containment) {
const widgets = containment.widgets();
for (var i in widgets) {
const widget = widgets[i];
switch(widget.type) {
case "org.kde.plasma.systemtray":
systemtrayId = widget.readConfig("SystrayContainmentId");
if (systemtrayId) {
forEachWidgetInContainment(desktopById(systemtrayId))
}
break;
case "org.kde.plasma.keyboardlayout":
widget.currentConfigGroup = new Array('General')
if (widget.readConfig("showFlag", false) == true) {
widget.writeConfig("displayStyle", "Flag")
// Work around not being able to delete config file keys using widget interface
widget.writeConfig("showFlag", "")
}
break;
}
}
}
Supports Markdown
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