Minor improvements on icon selector
This commit is contained in:
@@ -99,6 +99,12 @@ ColumnLayout {
|
|||||||
model: iconsModel
|
model: iconsModel
|
||||||
|
|
||||||
currentIndex: listView.currentData ? iconComboBox.indexOfValue(listView.currentData.iconName) : -1
|
currentIndex: listView.currentData ? iconComboBox.indexOfValue(listView.currentData.iconName) : -1
|
||||||
|
Component.onCompleted: {
|
||||||
|
iconsModel.onRowCountChanged.connect(function(){
|
||||||
|
currentIndex = Qt.binding(function() { return listView.currentData ? iconComboBox.indexOfValue(listView.currentData.iconName) : -1});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
onActivated: {
|
onActivated: {
|
||||||
console.log(currentValue);
|
console.log(currentValue);
|
||||||
if (listView.currentData) listView.currentData.iconName = currentValue; else console.warn('discarded');
|
if (listView.currentData) listView.currentData.iconName = currentValue; else console.warn('discarded');
|
||||||
|
@@ -1,12 +1,24 @@
|
|||||||
import QtQuick
|
import QtQuick
|
||||||
import QtQuick.Controls
|
import QtQuick.Controls
|
||||||
import QtQuick.Controls.Material
|
import QtQuick.Controls.Material
|
||||||
|
import Qt.labs.folderlistmodel 2.4
|
||||||
|
|
||||||
ComboBox {
|
ComboBox {
|
||||||
id: comboBox
|
id: comboBox
|
||||||
|
|
||||||
property string iconSourceRole
|
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 {
|
delegate: ItemDelegate {
|
||||||
height: 64
|
height: 64
|
||||||
anchors.left: parent.left
|
anchors.left: parent.left
|
||||||
@@ -15,18 +27,11 @@ ComboBox {
|
|||||||
anchors.top: parent.top
|
anchors.top: parent.top
|
||||||
anchors.bottom: parent.bottom
|
anchors.bottom: parent.bottom
|
||||||
text: model[comboBox.textRole]
|
text: model[comboBox.textRole]
|
||||||
iconSource: model[comboBox.iconSourceRole]
|
iconSource: comboBox.getIconUrl(index)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
contentItem: IconChooserDelegateLayout {
|
contentItem: IconChooserDelegateLayout {
|
||||||
text: comboBox.currentText
|
text: comboBox.displayText
|
||||||
iconSource: {
|
iconSource: comboBox.currentIndex >= 0 ? comboBox.getIconUrl(comboBox.currentIndex) : ""
|
||||||
if (!comboBox.model)
|
|
||||||
return '';
|
|
||||||
const url = comboBox.model.get(comboBox.currentIndex, "fileUrl");
|
|
||||||
if (!url)
|
|
||||||
return '';
|
|
||||||
return url;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user