Debian Codegraph @

src/GUI/qml/SettingPathChooser.qml

raw
1 import QtQuick 2.4
2 import FlightGear 1.0 as FG
3 import FlightGear 1.0
4
5 SettingControl {
6 id: root
7 implicitHeight: defaultButton.height + Style.margin + description.height
8
9 property alias label: label.text
10 property string path
11 property string defaultPath
12 property alias chooseDirectory: picker.selectFolder
13 property alias dialogPrompt: picker.title
14
15
16 property alias value: root.path // needed for save + restore
17 property string defaultValue: "" // needed for correct save/restore typing
18
19 readonly property bool isDefault: (path.length == 0) || (path == defaultPath)
20
21 readonly property url effectiveUrl: picker.urlFromLocalFilePath(effectivePath());
22
23 function effectivePath()
24 {
25 return root.isDefault ? defaultPath : path;
26 }
27
28 function apply()
29 {
30 if (option != "") {
31 _config.setArg(option, effectivePath())
32 }
33 }
34
35 Text {
36 id: label
37 text: root.label
38 anchors.verticalCenter: chooseButton.verticalCenter
39 color: (root.enabled ? Style.baseTextColor : Style.disabledTextColor)
40 }
41
42 Text {
43 id: currentPath
44 text: root.isDefault ? qsTr("%1 (default)").arg(root.defaultPath) : root.path
45 anchors.verticalCenter: chooseButton.verticalCenter
46 color: (root.enabled ? Style.baseTextColor : Style.disabledTextColor)
47 font.italic: true
48 anchors.left: label.right
49 anchors.leftMargin: Style.margin
50 anchors.right: chooseButton.left
51 anchors.rightMargin: Style.margin
52 elide: Text.ElideRight
53 }
54
55
56
57 Button {
58 id: chooseButton
59 text: qsTr("Change")
60 anchors.right: defaultButton.left
61 anchors.rightMargin: Style.margin
62 enabled: root.enabled
63
64 onClicked: {
65 // set current value as a URL
66 picker.folder = effectiveUrl
67 picker.open();
68 }
69 }
70
71 Button {
72 id: defaultButton
73 text: qsTr("Use default")
74 anchors.right: parent.right
75 anchors.rightMargin: Style.margin
76 enabled: root.enabled && !root.isDefault
77
78 onClicked: {
79 path = defaultPath
80 }
81 }
82
83 SettingDescription {
84 id: description
85 enabled: root.enabled
86 text: root.description
87 anchors.top: chooseButton.bottom
88 anchors.topMargin: Style.margin
89 width: parent.width
90 }
91
92 FG.FileDialog {
93 id: picker
94
95 onAccepted: {
96 path = filePath
97 }
98
99 onRejected: {
100
101 }
102 }
103 }