2020-08-03 13:27:42 -04:00
|
|
|
/*
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
2021-09-08 10:31:38 -04:00
|
|
|
import QtQuick
|
|
|
|
import QtQuick.Controls
|
2021-03-18 16:10:09 -04:00
|
|
|
|
2021-08-23 13:24:08 -04:00
|
|
|
import net.jami.Constants 1.1
|
2020-08-03 13:27:42 -04:00
|
|
|
|
|
|
|
ComboBox {
|
2020-09-03 21:19:10 -04:00
|
|
|
id: root
|
2020-08-03 13:27:42 -04:00
|
|
|
|
2021-08-31 10:37:11 -04:00
|
|
|
property alias tooltipText: toolTip.text
|
2021-06-02 12:11:49 -04:00
|
|
|
property string placeholderText
|
2021-08-31 10:37:11 -04:00
|
|
|
property string currentSelectionText: currentText
|
|
|
|
property string comboBoxBackgroundColor: JamiTheme.editBackgroundColor
|
2021-06-02 12:11:49 -04:00
|
|
|
|
2021-08-31 10:37:11 -04:00
|
|
|
MaterialToolTip {
|
|
|
|
id: toolTip
|
2020-08-07 11:24:18 -04:00
|
|
|
|
2021-08-31 10:37:11 -04:00
|
|
|
parent: root
|
|
|
|
visible: hovered && (text.length > 0)
|
|
|
|
delay: Qt.styleHints.mousePressAndHoldInterval
|
|
|
|
}
|
|
|
|
|
|
|
|
displayText: currentIndex !== -1 ?
|
|
|
|
currentSelectionText : (placeholderText !== "" ?
|
|
|
|
placeholderText :
|
|
|
|
JamiStrings.notAvailable)
|
2020-08-07 11:24:18 -04:00
|
|
|
|
2020-08-03 13:27:42 -04:00
|
|
|
delegate: ItemDelegate {
|
2020-09-03 21:19:10 -04:00
|
|
|
width: root.width
|
2020-08-03 13:27:42 -04:00
|
|
|
contentItem: Text {
|
|
|
|
text: {
|
2021-06-02 12:11:49 -04:00
|
|
|
if (index >= 0) {
|
|
|
|
var currentItem = root.delegateModel.items.get(index)
|
|
|
|
return currentItem.model[root.textRole].toString()
|
|
|
|
}
|
|
|
|
return ""
|
2020-08-03 13:27:42 -04:00
|
|
|
}
|
2020-11-28 16:14:25 -05:00
|
|
|
color: JamiTheme.textColor
|
2020-09-03 21:19:10 -04:00
|
|
|
font: root.font
|
2020-08-03 13:27:42 -04:00
|
|
|
elide: Text.ElideRight
|
|
|
|
verticalAlignment: Text.AlignVCenter
|
|
|
|
}
|
2020-11-28 16:14:25 -05:00
|
|
|
background: Rectangle {
|
|
|
|
color: highlighted? JamiTheme.selectedColor : JamiTheme.editBackgroundColor
|
|
|
|
}
|
2020-08-03 13:27:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
indicator: Canvas {
|
|
|
|
id: canvas
|
2021-08-31 10:37:11 -04:00
|
|
|
|
2020-09-03 21:19:10 -04:00
|
|
|
x: root.width - width - root.rightPadding
|
|
|
|
y: root.topPadding + (root.availableHeight - height) / 2
|
2021-08-31 10:37:11 -04:00
|
|
|
|
2020-08-03 13:27:42 -04:00
|
|
|
width: 12
|
|
|
|
height: 8
|
|
|
|
contextType: "2d"
|
|
|
|
|
|
|
|
Connections {
|
2020-09-03 21:19:10 -04:00
|
|
|
target: root
|
2020-08-03 13:27:42 -04:00
|
|
|
function onPressedChanged(){
|
|
|
|
canvas.requestPaint()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
onPaint: {
|
|
|
|
context.reset();
|
|
|
|
context.moveTo(0, 0);
|
|
|
|
context.lineTo(width, 0);
|
|
|
|
context.lineTo(width / 2, height);
|
|
|
|
context.closePath();
|
2020-11-28 16:14:25 -05:00
|
|
|
context.fillStyle = root.pressed ? JamiTheme.pressColor : JamiTheme.textColor;
|
2020-08-03 13:27:42 -04:00
|
|
|
context.fill();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
contentItem: Text {
|
2020-12-09 11:00:29 -05:00
|
|
|
leftPadding: 10
|
|
|
|
rightPadding: root.indicator.width + leftPadding
|
2020-08-03 13:27:42 -04:00
|
|
|
|
2020-09-03 21:19:10 -04:00
|
|
|
text: root.displayText
|
|
|
|
font: root.font
|
2020-11-28 16:14:25 -05:00
|
|
|
color: JamiTheme.textColor
|
2020-08-03 13:27:42 -04:00
|
|
|
verticalAlignment: Text.AlignVCenter
|
|
|
|
elide: Text.ElideRight
|
|
|
|
}
|
|
|
|
|
|
|
|
background: Rectangle {
|
2021-03-23 17:46:13 -04:00
|
|
|
color: root.comboBoxBackgroundColor
|
2020-08-03 13:27:42 -04:00
|
|
|
implicitWidth: 120
|
|
|
|
implicitHeight: 40
|
2021-03-23 17:46:13 -04:00
|
|
|
border.color: root.comboBoxBackgroundColor
|
2020-09-03 21:19:10 -04:00
|
|
|
border.width: root.visualFocus ? 2 : 1
|
2020-08-03 13:27:42 -04:00
|
|
|
radius: 2
|
|
|
|
}
|
|
|
|
|
|
|
|
popup: Popup {
|
2021-09-08 10:31:38 -04:00
|
|
|
id: popup
|
|
|
|
|
2020-09-03 21:19:10 -04:00
|
|
|
y: root.height - 1
|
|
|
|
width: root.width
|
2020-08-03 13:27:42 -04:00
|
|
|
implicitHeight: contentItem.implicitHeight
|
|
|
|
padding: 1
|
|
|
|
|
2021-09-08 10:31:38 -04:00
|
|
|
contentItem: JamiListView {
|
2021-06-02 12:11:49 -04:00
|
|
|
id: listView
|
2021-08-31 10:37:11 -04:00
|
|
|
|
2021-09-08 10:31:38 -04:00
|
|
|
implicitHeight: popup.contentHeight
|
2021-06-02 12:11:49 -04:00
|
|
|
model: root.delegateModel
|
2020-08-03 13:27:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
background: Rectangle {
|
2020-11-28 16:14:25 -05:00
|
|
|
color: JamiTheme.editBackgroundColor
|
2021-08-31 10:37:11 -04:00
|
|
|
border.color: JamiTheme.greyBorderColor
|
2020-08-03 13:27:42 -04:00
|
|
|
radius: 2
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|