Get ComboBox working

This commit is contained in:
David Rowe 2016-03-03 00:04:15 +13:00
parent 829c858b04
commit 98ad785267
2 changed files with 35 additions and 14 deletions

View file

@ -12,18 +12,26 @@ import QtQuick 2.5
import QtQuick.Controls 1.4 import QtQuick.Controls 1.4
import QtQuick.Controls.Styles 1.4 import QtQuick.Controls.Styles 1.4
import "../styles-uit"
import "../controls-uit" as HifiControls
import "." as VrControls import "." as VrControls
FocusScope { FocusScope {
id: root id: root
property alias model: comboBox.model; property alias model: comboBox.model;
property alias comboBox: comboBox
readonly property alias currentText: comboBox.currentText; readonly property alias currentText: comboBox.currentText;
property alias currentIndex: comboBox.currentIndex; property alias currentIndex: comboBox.currentIndex;
property int colorScheme: hifi.colorSchemes.light
readonly property bool isLightColorScheme: colorScheme == hifi.colorSchemes.light
property string label: ""
property real controlHeight: height + (comboBoxLabel.visible ? comboBoxLabel.height + comboBoxLabel.anchors.bottomMargin : 0)
implicitHeight: comboBox.height; implicitHeight: comboBox.height;
focus: true focus: true
readonly property ComboBox control: comboBox
Rectangle { Rectangle {
id: background id: background
gradient: Gradient { gradient: Gradient {
@ -61,9 +69,10 @@ FocusScope {
anchors { right: parent.right; verticalCenter: parent.verticalCenter } anchors { right: parent.right; verticalCenter: parent.verticalCenter }
width: 20 width: 20
height: textField.height height: textField.height
VrControls.FontAwesome { HiFiGlyphs {
anchors.centerIn: parent; size: 16; anchors.centerIn: parent
text: "\uf0d7" size: hifi.dimensions.spinnerSize
text: hifi.glyphs.caratDn
} }
} }
@ -157,4 +166,13 @@ FocusScope {
} }
} }
HifiControls.Label {
id: comboBoxLabel
text: root.label
colorScheme: root.colorScheme
anchors.left: parent.left
anchors.bottom: parent.top
anchors.bottomMargin: 4
visible: label != ""
}
} }

View file

@ -10,30 +10,33 @@
import QtQuick 2.5 import QtQuick 2.5
import "../../controls-uit" import QtQuick.Controls 1.4
import QtQuick.Controls.Styles 1.4
import "../../controls-uit" as HiFiControls
import "../../styles-uit"
Preference { Preference {
id: root id: root
property alias comboBox: comboBox height: dataComboBox.controlHeight
height: comboBox.controlHeight
Component.onCompleted: { Component.onCompleted: {
comboBox.currentIndex = comboBox.find(preference.value); dataComboBox.currentIndex = dataComboBox.comboBox.find(preference.value);
} }
function save() { function save() {
preference.value = comboBox.currentText; preference.value = dataComboBox.currentText;
//preference.value = comboBox.currentText;
preference.save(); preference.save();
} }
Label { HiFiControls.Label {
text: root.label + ":" text: root.label + ":"
colorScheme: hifi.colorSchemes.dark colorScheme: hifi.colorSchemes.dark
anchors.verticalCenter: comboBox.verticalCenter anchors.verticalCenter: dataComboBox.verticalCenter
} }
ComboBox { HiFiControls.ComboBox {
id: comboBox id: dataComboBox
model: preference.items model: preference.items
width: 150 width: 150
anchors { right: parent.right } anchors { right: parent.right }