Minor improvements on icon selector

This commit is contained in:
2023-02-19 02:59:19 +01:00
parent e627f8ebca
commit 5334a5a46b
2 changed files with 21 additions and 10 deletions

View File

@@ -1,12 +1,24 @@
import QtQuick
import QtQuick.Controls
import QtQuick.Controls.Material
import Qt.labs.folderlistmodel 2.4
ComboBox {
id: comboBox
property string iconSourceRole
property bool hasTwoArgumentGetter: model instanceof FolderListModel
function getIconUrl(index) {
if (!comboBox.model)
return '';
if (hasTwoArgumentGetter)
return model.get(index, iconSourceRole);
else
return model.get(index)[iconSourceRole];
}
delegate: ItemDelegate {
height: 64
anchors.left: parent.left
@@ -15,18 +27,11 @@ ComboBox {
anchors.top: parent.top
anchors.bottom: parent.bottom
text: model[comboBox.textRole]
iconSource: model[comboBox.iconSourceRole]
iconSource: comboBox.getIconUrl(index)
}
}
contentItem: IconChooserDelegateLayout {
text: comboBox.currentText
iconSource: {
if (!comboBox.model)
return '';
const url = comboBox.model.get(comboBox.currentIndex, "fileUrl");
if (!url)
return '';
return url;
}
text: comboBox.displayText
iconSource: comboBox.currentIndex >= 0 ? comboBox.getIconUrl(comboBox.currentIndex) : ""
}
}