Commit 06321a7b authored by Andrey Butirsky's avatar Andrey Butirsky
Browse files

[1/2] impr: no ToolButton in layout switching component

ToolButton should not be used in shared component since it's clints
might have different representation.
Instead, make the component have no visual representation at all,
delegating it to clients themselves.
parent 0e41342c
......@@ -5,42 +5,30 @@
*/
import QtQuick 2.12
import org.kde.plasma.components 3.0 as PlasmaComponents3
import org.kde.plasma.workspace.keyboardlayout 1.0
PlasmaComponents3.ToolButton {
MouseArea {
property alias keyboardLayout: keyboardLayout
readonly property bool hasMultipleKeyboardLayouts: keyboardLayout.layoutsList.length > 1
readonly property var layoutNames: keyboardLayout.layoutsList.length ? keyboardLayout.layoutsList[keyboardLayout.layout]
: { shortName: "", displayName: "", longName: "" }
text: layoutNames.longName
visible: hasMultipleKeyboardLayouts
Accessible.name: i18ndc("plasma_lookandfeel_org.kde.lookandfeel", "Button to change keyboard layout", "Switch layout")
icon.name: "input-keyboard"
onClicked: keyboardLayout.switchToNextLayout()
MouseArea {
anchors.fill: parent
acceptedButtons: Qt.NoButton
property int wheelDelta: 0
property int wheelDelta: 0
onWheel: {
// Magic number 120 for common "one click"
// See: https://qt-project.org/doc/qt-5/qml-qtquick-wheelevent.html#angleDelta-prop
var delta = wheel.angleDelta.y || wheel.angleDelta.x;
wheelDelta += delta;
while (wheelDelta >= 120) {
wheelDelta -= 120;
keyboardLayout.switchToPreviousLayout();
}
while (wheelDelta <= -120) {
wheelDelta += 120;
keyboardLayout.switchToNextLayout();
}
onWheel: {
// Magic number 120 for common "one click"
// See: https://qt-project.org/doc/qt-5/qml-qtquick-wheelevent.html#angleDelta-prop
var delta = wheel.angleDelta.y || wheel.angleDelta.x;
wheelDelta += delta;
while (wheelDelta >= 120) {
wheelDelta -= 120;
keyboardLayout.switchToPreviousLayout();
}
while (wheelDelta <= -120) {
wheelDelta += 120;
keyboardLayout.switchToNextLayout();
}
}
......
module org.kde.plasma.workspace.components
BatteryIcon 2.0 BatteryIcon.qml
KeyboardLayoutButton 2.0 KeyboardLayoutButton.qml
KeyboardLayoutSwitcher 2.0 KeyboardLayoutSwitcher.qml
......@@ -517,7 +517,21 @@ PlasmaCore.ColorScope {
visible: inputPanel.status == Loader.Ready
}
PW.KeyboardLayoutButton {
PlasmaComponents3.ToolButton {
Accessible.description: i18ndc("plasma_lookandfeel_org.kde.lookandfeel", "Button to change keyboard layout", "Switch layout")
icon.name: "input-keyboard"
PW.KeyboardLayoutSwitcher {
id: keyboardLayoutSwitcher
anchors.fill: parent
acceptedButtons: Qt.NoButton
}
text: keyboardLayoutSwitcher.layoutNames.longName
onClicked: keyboardLayoutSwitcher.keyboardLayout.switchToNextLayout()
visible: keyboardLayoutSwitcher.hasMultipleKeyboardLayouts
}
Item {
......
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