Minor improvements on icon selector
This commit is contained in:
@@ -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) : ""
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user