Skip to content

Commit

Permalink
Port away from SwipeListItem due to some bug
Browse files Browse the repository at this point in the history
  • Loading branch information
wengxt committed Jan 22, 2025
1 parent 1b91919 commit c79e782
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 100 deletions.
15 changes: 8 additions & 7 deletions src/kcm/ui/AddonPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,9 @@ KCM.ScrollViewKCM {
}
}

delegate: Kirigami.SwipeListItem {
delegate: ItemDelegate {
id: listItem
width: ListView.view ? ListView.view.width : implicitWidth
contentItem: RowLayout {
CheckBox {
id: itemChecked
Expand Down Expand Up @@ -147,16 +148,16 @@ KCM.ScrollViewKCM {
visible: model.comment.length > 0
}
}
}

actions: [
Kirigami.Action {
ToolButton {
icon.name: "configure"
visible: model.configurable
display: AbstractButton.IconOnly
ToolTip.text: text
ToolTip.visible: hovered

onTriggered: kcm.pushConfigPage(model.name, "fcitx://config/addon/" + model.uniqueName)
onClicked: kcm.pushConfigPage(model.name, "fcitx://config/addon/" + model.uniqueName)
}
]
}
}
}
footer: CheckBox {
Expand Down
81 changes: 42 additions & 39 deletions src/kcm/ui/ListOption.qml
Original file line number Diff line number Diff line change
Expand Up @@ -115,50 +115,49 @@ ColumnLayout {
id: delegateComponent

ItemDelegate {
id: listItem
property var model: itemModel
width: ListView.view ? ListView.view.width : implicitWidth
height: listItem.implicitHeight
Kirigami.SwipeListItem {
id: listItem
width: parent.width
contentItem: RowLayout {
Kirigami.ListItemDragHandle {
listItem: listItem
listView: optionView
property var index: itemIndex

contentItem: RowLayout {
Kirigami.ListItemDragHandle {
listItem: listItem
listView: optionView

onMoveRequested: (oldIndex, newIndex) => {
needsSave = true;
listModel.move(oldIndex, newIndex, 1);
}
}
Label {
Layout.fillWidth: true
color: listItem.checked || (listItem.pressed && !listItem.checked && !listItem.sectionDelegate) ? listItem.activeTextColor : listItem.textColor
height: Math.max(implicitHeight, Kirigami.Units.iconSizes.smallMedium)
text: model !== null ? prettify(model.value, subTypeName) : ""
elide: Text.ElideRight
onMoveRequested: (oldIndex, newIndex) => {
needsSave = true;
listModel.move(oldIndex, newIndex, 1);
}
}
Label {
Layout.fillWidth: true
height: Math.max(implicitHeight, Kirigami.Units.iconSizes.smallMedium)
text: model !== null ? prettify(model.value, subTypeName) : ""
elide: Text.ElideRight
}
ToolButton {
icon.name: "document-edit"
text: i18n("edit")
display: AbstractButton.IconOnly
ToolTip.text: text
ToolTip.visible: hovered

actions: [
Kirigami.Action {
icon.name: "document-edit"
text: i18n("edit")

onTriggered: {
sheet.edit(model.index);
}
},
Kirigami.Action {
icon.name: "list-remove-symbolic"
text: i18n("Remove")
onClicked: {
sheet.edit(model.index);
}
}
ToolButton {
icon.name: "list-remove-symbolic"
text: i18n("Remove")
display: AbstractButton.IconOnly
ToolTip.text: text
ToolTip.visible: hovered

onTriggered: {
needsSave = true;
listModel.remove(model.index);
}
onClicked: {
needsSave = true;
listModel.remove(model.index);
}
]
}
}
}
}
Expand All @@ -177,8 +176,12 @@ ColumnLayout {
id: optionView
model: listModel

delegate: delegateComponent
reuseItems: true
delegate: Loader {
width: optionView.width
sourceComponent: delegateComponent
property var itemModel: model
property var itemIndex: index
}
}
}
RowLayout {
Expand Down
105 changes: 51 additions & 54 deletions src/kcm/ui/main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -33,56 +33,60 @@ KCM.ScrollViewKCM {
Component {
id: delegateComponent
ItemDelegate {
id: listItem
width: ListView.view ? ListView.view.width : implicitWidth
height: listItem.implicitHeight
property variant model: itemModel
property variant index: itemIndex

Kirigami.SwipeListItem {
id: listItem
width: parent.width
contentItem: RowLayout {

contentItem: RowLayout {
Kirigami.ListItemDragHandle {
listItem: listItem
listView: imList
Kirigami.ListItemDragHandle {
listItem: listItem
listView: imList
property variant index: itemIndex

onMoveRequested: (oldIndex, newIndex) => {
imList.model.move(oldIndex, newIndex);
checkInputMethod();
}
}
Label {
Layout.fillWidth: true
color: listItem.checked || (listItem.pressed && !listItem.checked && !listItem.sectionDelegate) ? listItem.activeTextColor : listItem.textColor
height: Math.max(implicitHeight, Kirigami.Units.iconSizes.smallMedium)
text: model !== null ? model.name : ""
onMoveRequested: (oldIndex, newIndex) => {
imList.model.move(oldIndex, newIndex);
checkInputMethod();
}
}
Label {
Layout.fillWidth: true
text: model !== null ? model.name : ""
}

ToolButton {
icon.name: "configure"
text: i18n("Configure")
visible: model !== null ? model.configurable : false
display: AbstractButton.IconOnly
ToolTip.text: text
ToolTip.visible: hovered

actions: [
Kirigami.Action {
icon.name: "configure"
text: i18n("Configure")
visible: model !== null ? model.configurable : false

onTriggered: kcm.pushConfigPage(model.name, "fcitx://config/inputmethod/" + model.uniqueName)
},
Kirigami.Action {
icon.name: "input-keyboard"
text: i18n("Select Layout")
visible: model !== null ? !model.uniqueName.startsWith("keyboard-") : false

onTriggered: selectLayoutSheet.selectLayout(i18n("Select layout for %1", model.name), model.uniqueName, (model.layout !== "" ? model.layout : kcm.imConfig.defaultLayout))
},
Kirigami.Action {
icon.name: "list-remove-symbolic"
text: i18n("Remove")

onTriggered: {
imList.model.remove(model.index);
checkInputMethod();
}
onClicked: kcm.pushConfigPage(model.name, "fcitx://config/inputmethod/" + model.uniqueName)
}
ToolButton {
icon.name: "input-keyboard"
text: i18n("Select Layout")
visible: model !== null ? !model.uniqueName.startsWith("keyboard-") : false
display: AbstractButton.IconOnly
ToolTip.text: text
ToolTip.visible: hovered

onClicked: selectLayoutSheet.selectLayout(i18n("Select layout for %1", model.name), model.uniqueName, (model.layout !== "" ? model.layout : kcm.imConfig.defaultLayout))
}
ToolButton {
icon.name: "list-remove-symbolic"
text: i18n("Remove")
display: AbstractButton.IconOnly
ToolTip.text: text
ToolTip.visible: hovered

onClicked: {
imList.model.remove(model.index);
checkInputMethod();
}
]
}
}
}
}
Expand Down Expand Up @@ -354,10 +358,7 @@ KCM.ScrollViewKCM {
}
view: ListView {
id: imList
enabled: kcm.availability
model: kcm.imConfig.currentIMModel
clip: true
activeFocusOnTab: true

section {
property: "active"
Expand All @@ -367,15 +368,11 @@ KCM.ScrollViewKCM {
}
}

reuseItems: true

moveDisplaced: Transition {
YAnimator {
duration: Kirigami.Units.longDuration
easing.type: Easing.InOutQuad
}
delegate: Loader {
width: imList.width
sourceComponent: delegateComponent
property var itemModel: model
property var itemIndex: index
}

delegate: delegateComponent
}
}

0 comments on commit c79e782

Please sign in to comment.