mirror of
https://github.com/lubosz/overte.git
synced 2025-04-23 23:33:48 +02:00
Add ComboBox preference
This commit is contained in:
parent
5eeaa9a33e
commit
66e1d9668c
4 changed files with 61 additions and 2 deletions
|
@ -49,7 +49,7 @@ Preference {
|
|||
Button {
|
||||
id: button
|
||||
anchors { right: parent.right; verticalCenter: dataTextField.verticalCenter }
|
||||
text: "Browse"
|
||||
text: preference.browseLabel
|
||||
onClicked: {
|
||||
var browser = fileBrowserBuilder.createObject(desktop, { selectDirectory: true, folder: fileDialogHelper.pathToUrl(preference.value) });
|
||||
browser.selectedFile.connect(function(fileUrl){
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
import QtQuick 2.5
|
||||
import QtQuick.Controls 1.4
|
||||
import QtQuick.Controls.Styles 1.4
|
||||
|
||||
Preference {
|
||||
id: root
|
||||
property real spacing: 8
|
||||
height: labelText.height + dataComboBox.height + spacing
|
||||
|
||||
Component.onCompleted: {
|
||||
dataComboBox.currentIndex = dataComboBox.find(preference.value);
|
||||
}
|
||||
|
||||
function save() {
|
||||
preference.value = dataComboBox.currentText;
|
||||
preference.save();
|
||||
}
|
||||
|
||||
Text {
|
||||
id: labelText
|
||||
color: enabled ? "black" : "gray"
|
||||
text: root.label
|
||||
}
|
||||
|
||||
ComboBox {
|
||||
id: dataComboBox
|
||||
model: preference.items
|
||||
style: ComboBoxStyle { renderType: Text.QtRendering }
|
||||
anchors {
|
||||
top: labelText.bottom
|
||||
left: parent.left
|
||||
right: parent.right
|
||||
topMargin: root.spacing
|
||||
rightMargin: root.spacing
|
||||
}
|
||||
}
|
||||
}
|
|
@ -81,6 +81,7 @@ Preference {
|
|||
property var sliderBuilder: Component { SliderPreference { } }
|
||||
property var avatarBuilder: Component { AvatarPreference { } }
|
||||
property var buttonBuilder: Component { ButtonPreference { } }
|
||||
property var comboBoxBuilder: Component { ComboBoxPreference { } }
|
||||
property var preferences: []
|
||||
|
||||
function buildPreferences() {
|
||||
|
@ -123,7 +124,11 @@ Preference {
|
|||
|
||||
case Preference.Button:
|
||||
builder = buttonBuilder;
|
||||
break
|
||||
break;
|
||||
|
||||
case Preference.ComboBox:
|
||||
builder = comboBoxBuilder;
|
||||
break;
|
||||
};
|
||||
|
||||
if (builder) {
|
||||
|
|
|
@ -54,6 +54,7 @@ public:
|
|||
Spinner,
|
||||
Checkbox,
|
||||
Button,
|
||||
ComboBox,
|
||||
// Special casing for an unusual preference
|
||||
Avatar
|
||||
};
|
||||
|
@ -236,6 +237,22 @@ protected:
|
|||
QString _placeholderText;
|
||||
};
|
||||
|
||||
class ComboBoxPreference : public EditPreference {
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QStringList items READ getItems CONSTANT)
|
||||
|
||||
public:
|
||||
ComboBoxPreference(const QString& category, const QString& name, Getter getter, Setter setter)
|
||||
: EditPreference(category, name, getter, setter) { }
|
||||
Type getType() { return ComboBox; }
|
||||
|
||||
const QStringList& getItems() { return _items; }
|
||||
void setItems(const QStringList& items) { _items = items; }
|
||||
|
||||
protected:
|
||||
QStringList _items;
|
||||
};
|
||||
|
||||
class BrowsePreference : public EditPreference {
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QString browseLabel READ getBrowseLabel CONSTANT)
|
||||
|
|
Loading…
Reference in a new issue