kcms/effects: Fix & modernize QML/JS code style

Key-value mapping is more convenient to use than iterating through array
manually, and Map type is safer to use than plain old ECMAScript Object.
master
ivan tkachenko 1 year ago
parent b91d9a96ae
commit 4d63039b2f
No known key found for this signature in database
GPG Key ID: AF72731B7C654CB3

@ -15,20 +15,22 @@ import org.kde.kcm as KCM
Kirigami.SwipeListItem {
id: listItem
hoverEnabled: true
onClicked: {
if (view.currentIndex == index) {
if (ListView.isCurrentItem) {
// Collapse list item
view.currentIndex = -1;
ListView.view.currentIndex = -1;
} else {
// Expand list item
view.currentIndex = index;
ListView.view.currentIndex = index;
}
}
contentItem: RowLayout {
id: row
QQC2.RadioButton {
property bool _exclusive: model.ExclusiveRole != ""
readonly property bool _exclusive: model.ExclusiveRole != ""
property bool _toggled: false
checked: model.StatusRole
@ -39,6 +41,7 @@ Kirigami.SwipeListItem {
model.StatusRole = checked ? Qt.Checked : Qt.Unchecked;
_toggled = true;
}
onClicked: {
// Uncheck the radio button if it's clicked.
if (checked && !_toggled) {
@ -91,7 +94,7 @@ Kirigami.SwipeListItem {
text: i18n("Author: %1\nLicense: %2", model.AuthorNameRole, model.LicenseRole)
opacity: listItem.hovered ? 0.8 : 0.6
visible: view.currentIndex === index
visible: listItem.ListView.isCurrentItem
wrapMode: Text.Wrap
}
@ -114,6 +117,7 @@ Kirigami.SwipeListItem {
}
}
}
actions: [
Kirigami.Action {
visible: model.VideoRole.toString() !== ""

@ -15,29 +15,32 @@ import QtMultimedia as Multimedia
Multimedia.Video {
id: videoItem
autoPlay: true
source: model.VideoRole
width: 400
height: 400
QQC2.BusyIndicator {
anchors.centerIn: parent
visible: videoItem.status == Multimedia.MediaPlayer.Loading
visible: videoItem.status === Multimedia.MediaPlayer.Loading
running: true
}
QQC2.Button {
id: replayButton
visible: false
anchors.centerIn: parent
icon.name: "media-playback-start"
onClicked: {
replayButton.visible = false;
videoItem.play();
}
Connections {
target: videoItem
function onStopped() {
replayButton.visible = true
}
}
}
onStopped: {
replayButton.visible = true
}
}

@ -73,7 +73,8 @@ ScrollViewKCM {
view: ListView {
id: effectsList
property var _buttonGroups: []
// { string name: QQC2.ButtonGroup group }
property var _buttonGroups: new Map()
clip: true
@ -94,23 +95,18 @@ ScrollViewKCM {
text: section
}
function findButtonGroup(name) {
for (let item of effectsList._buttonGroups) {
if (item.name == name) {
return item.group;
}
}
let group = Qt.createQmlObject(
'import QtQuick 2.5;' +
'import QtQuick.Controls 2.5;' +
'ButtonGroup {}',
effectsList,
"dynamicButtonGroup" + effectsList._buttonGroups.length
);
Component {
id: buttonGroupComponent
effectsList._buttonGroups.push({ name, group });
QQC2.ButtonGroup {}
}
function findButtonGroup(name: string): QQC2.ButtonGroup {
let group = _buttonGroups.get(name);
if (group === undefined) {
group = buttonGroupComponent.createObject(this);
_buttonGroups.set(name, group);
}
return group;
}
}
@ -123,7 +119,7 @@ ScrollViewKCM {
text: i18n("Get New Desktop Effects…")
visible: KAuthorized.authorize(KAuthorized.GHNS)
configFile: "kwineffect.knsrc"
onEntryEvent: function (entry, event) {
onEntryEvent: (entry, event) => {
if (event === NewStuff.Engine.StatusChangedEvent) {
kcm.onGHNSEntriesChanged()
}

Loading…
Cancel
Save