1
0
Fork 0
mirror of https://git.jami.net/savoirfairelinux/jami-client-qt.git synced 2025-08-02 22:05:45 +02:00
jami-client-qt/src/commoncomponents/SettingParaCombobox.qml
Andreas Traczyk 28aa5aab6d settings: use default audio devices
Refactors audio settings to avoid list model code duplication. This code
could be greatly simplified by using string lists, however the combo-box
component design is highly dependent on QAbstractItemModel based models.

Also translates the handlebarred strings upon presentation, which is
currently used to translate the "Default" prefix for the first device
item.

Gitlab: #346
Change-Id: I5ed282d29cc4ec6a090a9cdf47b0459f0db2a99b
2021-03-22 15:59:24 -04:00

122 lines
3.5 KiB
QML

/*
* Copyright (C) 2019-2020 by Savoir-faire Linux
* Author: Yang Wang <yang.wang@savoirfairelinux.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import QtQuick 2.14
import QtQuick.Controls 2.14
import QtQuick.Controls.Universal 2.14
import QtQuick.Layouts 1.14
import QtGraphicalEffects 1.14
import QtQuick.Controls.Styles 1.4
import net.jami.Constants 1.0
ComboBox {
id: root
property string tooltipText:""
ToolTip.delay: Qt.styleHints.mousePressAndHoldInterval
ToolTip.visible: hovered && (tooltipText.length > 0)
ToolTip.text: tooltipText
delegate: ItemDelegate {
width: root.width
contentItem: Text {
text: {
var currentItem = root.delegateModel.items.get(index)
return currentItem.model[root.textRole].toString()
}
color: JamiTheme.textColor
font: root.font
elide: Text.ElideRight
verticalAlignment: Text.AlignVCenter
}
highlighted: root.highlightedIndex === index
background: Rectangle {
color: highlighted? JamiTheme.selectedColor : JamiTheme.editBackgroundColor
}
}
indicator: Canvas {
id: canvas
x: root.width - width - root.rightPadding
y: root.topPadding + (root.availableHeight - height) / 2
width: 12
height: 8
contextType: "2d"
Connections {
target: root
function onPressedChanged(){
canvas.requestPaint()
}
}
onPaint: {
context.reset();
context.moveTo(0, 0);
context.lineTo(width, 0);
context.lineTo(width / 2, height);
context.closePath();
context.fillStyle = root.pressed ? JamiTheme.pressColor : JamiTheme.textColor;
context.fill();
}
}
contentItem: Text {
leftPadding: 10
rightPadding: root.indicator.width + leftPadding
text: root.displayText
font: root.font
color: JamiTheme.textColor
verticalAlignment: Text.AlignVCenter
elide: Text.ElideRight
}
background: Rectangle {
color: JamiTheme.editBackgroundColor
implicitWidth: 120
implicitHeight: 40
border.color: JamiTheme.editBackgroundColor
border.width: root.visualFocus ? 2 : 1
radius: 2
}
popup: Popup {
y: root.height - 1
width: root.width
implicitHeight: contentItem.implicitHeight
padding: 1
contentItem: ListView {
clip: true
implicitHeight: contentHeight
model: root.delegateModel
currentIndex: root.highlightedIndex
ScrollIndicator.vertical: ScrollIndicator { }
}
background: Rectangle {
color: JamiTheme.editBackgroundColor
border.color: "gray"
radius: 2
}
}
}