linux.x86.linphone/Linphone/view/Control/Button/Settings/ComboSetting.qml
data 1c7e9271bf Fix: ComboSetting support for QStringList models and multiple model types
- Add type detection for three different model types:
  - QStringList (video devices): plain strings
  - Audio devices: objects with {id, display_name}
  - Simple entries (language, color): objects with {text, value}
- Set textRole: "" for video devices ComboBox (QStringList)
- Fix ComboBox popup background color for dark mode
- Add window background color to CallsWindow for dark mode
- Update documentation

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-08 07:41:28 +01:00

106 lines
3.4 KiB
QML

import QtQuick
import QtQuick.Controls.Basic
import QtQuick.Layouts
import Linphone
import 'qrc:/qt/qml/Linphone/view/Control/Tool/Helper/utils.js' as Utils
RowLayout {
id: mainItem
property string titleText
property string subTitleText
property string propertyName
property var propertyOwner
property var propertyOwnerGui
property alias entries: comboBox.model
property alias model: comboBox.model
property alias textRole: comboBox.textRole
property alias flagRole: comboBox.flagRole
property alias currentIndex: comboBox.currentIndex
property alias currentValue: comboBox.currentValue
property alias listView: comboBox.listView
spacing: Utils.getSizeWithScreenRatio(20)
ColumnLayout {
Layout.minimumHeight: Utils.getSizeWithScreenRatio(32)
Layout.fillWidth: true
spacing: Utils.getSizeWithScreenRatio(4)
visible: titleText.length > 0
Text {
text: titleText
font: Typography.p2l
wrapMode: Text.WordWrap
color: DefaultStyle.main2_600
Layout.fillWidth: true
}
Text {
text: subTitleText
font: Typography.p1
wrapMode: Text.WordWrap
visible: subTitleText.length > 0
color: DefaultStyle.main2_600
Layout.fillWidth: true
}
}
ComboBox {
id: comboBox
Layout.alignment: titleText.length > 0 ? (Qt.AlignRight | Qt.AlignVCenter) : Qt.AlignLeft
Layout.preferredHeight: Utils.getSizeWithScreenRatio(49)
Layout.preferredWidth: titleText.length > 0 ? Utils.getSizeWithScreenRatio(200) : undefined
Layout.fillWidth: titleText.length === 0
oneLine: true
textRole: "text"
currentIndex: Utils.findIndex(model, function (entry) {
var currentVal = propertyOwnerGui
? propertyOwnerGui.core[mainItem.propertyName]
: propertyOwner[mainItem.propertyName]
// Handle different entry types
if (typeof entry === 'string') {
// QStringList (video devices): compare strings directly
return entry === currentVal
} else if (entry.id !== undefined) {
// Audio devices: compare by id
return currentVal && entry.id === currentVal.id
} else if (entry.value !== undefined) {
// Simple entries (language, color): compare by value
return entry.value === currentVal
}
return false
})
onCurrentIndexChanged: {
if (currentIndex < 0 || !model) return
var entry = model[currentIndex]
if (!entry) return
var storedVal = propertyOwnerGui
? propertyOwnerGui.core[mainItem.propertyName]
: propertyOwner[mainItem.propertyName]
// Determine if values differ based on entry type
if (typeof entry === 'string') {
// QStringList: compare strings directly
binding.when = entry !== storedVal
} else if (entry.id !== undefined) {
// Audio devices: compare by id
binding.when = !storedVal || entry.id !== storedVal.id
} else if (entry.value !== undefined) {
// Simple entries: compare by value
binding.when = entry.value !== storedVal
}
}
Binding {
id: binding
target: propertyOwnerGui ? propertyOwnerGui.core : propertyOwner
property: mainItem.propertyName
value: {
if (comboBox.currentIndex < 0 || !comboBox.model) return undefined
var entry = comboBox.model[comboBox.currentIndex]
if (!entry) return undefined
// Return based on entry type
if (typeof entry === 'string') return entry // QStringList
if (entry.id !== undefined) return entry // Audio devices
if (entry.value !== undefined) return entry.value // Simple entries
return entry
}
when: false
}
}
}