2020-06-17 19:31:01 +00:00
|
|
|
import QtQuick 2.13
|
|
|
|
import QtQuick.Controls 2.13
|
|
|
|
import QtQuick.Layouts 1.13
|
|
|
|
import QtGraphicalEffects 1.13
|
2020-06-10 14:11:06 +00:00
|
|
|
import "../imports"
|
|
|
|
|
|
|
|
Item {
|
|
|
|
property string label: ""
|
|
|
|
readonly property bool hasLabel: label !== ""
|
2020-07-02 15:14:31 +00:00
|
|
|
property color bgColor: Style.current.grey
|
2020-06-10 14:11:06 +00:00
|
|
|
readonly property int labelMargin: 7
|
|
|
|
property var selectOptions
|
|
|
|
property int customHeight: 44
|
2020-06-26 17:29:03 +00:00
|
|
|
property string selectedText: ""
|
2020-06-26 20:02:05 +00:00
|
|
|
property url icon: ""
|
|
|
|
property int iconHeight: 24
|
|
|
|
property int iconWidth: 24
|
2020-07-02 15:14:31 +00:00
|
|
|
property color iconColor: Style.current.transparent
|
2020-06-26 20:02:05 +00:00
|
|
|
|
|
|
|
readonly property bool hasIcon: icon.toString() !== ""
|
2020-06-10 14:11:06 +00:00
|
|
|
|
|
|
|
id: inputBox
|
|
|
|
height: inputRectangle.height + (hasLabel ? inputLabel.height + labelMargin : 0)
|
|
|
|
anchors.right: parent.right
|
|
|
|
anchors.left: parent.left
|
|
|
|
|
2020-06-26 19:43:20 +00:00
|
|
|
onSelectOptionsChanged: {
|
|
|
|
selectMenu.setupMenuItems()
|
|
|
|
}
|
|
|
|
|
2020-06-19 18:06:58 +00:00
|
|
|
StyledText {
|
2020-06-10 14:11:06 +00:00
|
|
|
id: inputLabel
|
|
|
|
text: inputBox.label
|
|
|
|
font.weight: Font.Medium
|
|
|
|
anchors.left: parent.left
|
|
|
|
anchors.leftMargin: 0
|
|
|
|
anchors.top: parent.top
|
|
|
|
anchors.topMargin: 0
|
|
|
|
font.pixelSize: 13
|
|
|
|
}
|
|
|
|
|
|
|
|
Rectangle {
|
|
|
|
id: inputRectangle
|
|
|
|
height: customHeight
|
|
|
|
color: bgColor
|
|
|
|
radius: 8
|
|
|
|
anchors.top: inputBox.hasLabel ? inputLabel.bottom : parent.top
|
|
|
|
anchors.topMargin: inputBox.hasLabel ? inputBox.labelMargin : 0
|
|
|
|
anchors.right: parent.right
|
|
|
|
anchors.left: parent.left
|
|
|
|
|
2020-06-26 20:02:05 +00:00
|
|
|
SVGImage {
|
|
|
|
id: iconImg
|
|
|
|
sourceSize.height: iconHeight
|
|
|
|
sourceSize.width: iconWidth
|
|
|
|
anchors.left: parent.left
|
2020-07-02 15:14:31 +00:00
|
|
|
anchors.leftMargin: Style.current.smallPadding
|
2020-06-26 20:02:05 +00:00
|
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
|
|
fillMode: Image.PreserveAspectFit
|
|
|
|
source: inputBox.icon
|
|
|
|
}
|
|
|
|
ColorOverlay {
|
|
|
|
anchors.fill: iconImg
|
|
|
|
source: iconImg
|
2020-06-29 16:37:36 +00:00
|
|
|
color: iconColor
|
2020-06-26 20:02:05 +00:00
|
|
|
}
|
|
|
|
|
2020-06-26 17:29:03 +00:00
|
|
|
StyledText {
|
|
|
|
id: selectedTextField
|
|
|
|
visible: inputBox.selectedText !== ""
|
|
|
|
text: inputBox.selectedText
|
|
|
|
anchors.left: parent.left
|
2020-07-02 15:14:31 +00:00
|
|
|
anchors.leftMargin: inputBox.hasIcon ? iconWidth + 20 : Style.current.padding
|
2020-06-26 17:29:03 +00:00
|
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
|
|
font.pixelSize: 15
|
|
|
|
}
|
|
|
|
|
|
|
|
SVGImage {
|
|
|
|
id: caret
|
|
|
|
width: 11
|
|
|
|
height: 6
|
|
|
|
anchors.right: parent.right
|
2020-07-02 15:14:31 +00:00
|
|
|
anchors.rightMargin: Style.current.padding
|
2020-06-26 17:29:03 +00:00
|
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
|
|
fillMode: Image.PreserveAspectFit
|
|
|
|
source: "../app/img/caret.svg"
|
|
|
|
}
|
|
|
|
ColorOverlay {
|
|
|
|
anchors.fill: caret
|
|
|
|
source: caret
|
2020-07-02 15:14:31 +00:00
|
|
|
color: Style.current.darkGrey
|
2020-06-26 17:29:03 +00:00
|
|
|
}
|
|
|
|
|
2020-06-10 14:11:06 +00:00
|
|
|
Menu {
|
2020-06-26 19:43:20 +00:00
|
|
|
property var items: []
|
|
|
|
|
2020-06-10 14:11:06 +00:00
|
|
|
id: selectMenu
|
|
|
|
width: parent.width
|
|
|
|
padding: 10
|
|
|
|
background: Rectangle {
|
|
|
|
width: parent.width
|
|
|
|
height: parent.height
|
2020-07-02 15:14:31 +00:00
|
|
|
color: Style.current.grey
|
|
|
|
radius: Style.current.radius
|
2020-06-10 14:11:06 +00:00
|
|
|
}
|
2020-06-26 19:43:20 +00:00
|
|
|
|
|
|
|
function setupMenuItems() {
|
|
|
|
if (selectMenu.items.length) {
|
|
|
|
// Remove old items
|
|
|
|
selectMenu.items.forEach(function (item) {
|
|
|
|
selectMenu.removeItem(item)
|
|
|
|
})
|
|
|
|
selectMenu.items = []
|
|
|
|
}
|
2020-06-10 14:11:06 +00:00
|
|
|
if (!selectOptions) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
selectOptions.forEach(function (element) {
|
|
|
|
var item = menuItem.createObject(undefined, element)
|
2020-06-26 19:43:20 +00:00
|
|
|
selectMenu.items.push(item)
|
2020-06-10 14:11:06 +00:00
|
|
|
selectMenu.addItem(item)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-06-26 19:43:20 +00:00
|
|
|
Component.onCompleted: {
|
|
|
|
setupMenuItems()
|
|
|
|
}
|
|
|
|
|
2020-06-10 14:11:06 +00:00
|
|
|
Component {
|
|
|
|
id: menuItem
|
|
|
|
MenuItem {
|
|
|
|
property var onClicked: console.log("Default click function. Override me please")
|
2020-07-02 15:14:31 +00:00
|
|
|
property color bgColor: Style.current.white
|
2020-06-10 14:11:06 +00:00
|
|
|
onTriggered: function () {
|
|
|
|
onClicked()
|
|
|
|
}
|
|
|
|
background: Rectangle {
|
|
|
|
color: bgColor
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
MouseArea {
|
|
|
|
id: mouseArea
|
|
|
|
anchors.fill: parent
|
|
|
|
onClicked: {
|
|
|
|
selectMenu.open()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*##^##
|
|
|
|
Designer {
|
|
|
|
D{i:0;formeditorColor:"#ffffff";formeditorZoom:1.25}
|
|
|
|
}
|
|
|
|
##^##*/
|