ElisaConfigurationDialog.qml 4.33 KB
Newer Older
1 2 3
/*
 * Copyright 2017 Matthieu Gallien <matthieu_gallien@yahoo.fr>
 *
4 5
 * This program is free software: you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
6 7 8
 * License as published by the Free Software Foundation; either
 * version 3 of the License, or (at your option) any later version.
 *
9
 * This program is distributed in the hope that it will be useful,
10 11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12
 * Lesser General Public License for more details.
13
 *
14 15
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
16 17
 */

18 19
import QtQuick 2.11
import QtQuick.Controls 2.4
20
import QtQuick.Layouts 1.3
21
import QtQuick.Dialogs 1.2 as Dialogs
22 23
import QtQml.Models 2.3

24 25 26
Dialogs.Dialog {
    id: dialog
    title: 'Configure'
27

28 29 30
    visible: true
    modality: Qt.ApplicationModal
    standardButtons: Dialogs.StandardButton.Ok | Dialogs.StandardButton.Apply | Dialogs.StandardButton.Cancel
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51

    SystemPalette {
        id: myPalette
        colorGroup: SystemPalette.Active
    }

    Component {
        id: highlightBar

        Rectangle {
            width: 200; height: 50
            color: myPalette.highlight
        }
    }

    Component {
        id: pathDelegate

        Item {
            id: delegateItem

52
            height: 3 * 30
53

Alexander Stippich's avatar
Alexander Stippich committed
54
            width: scrollBar.visible ? pathList.width - scrollBar.width : pathList.width
55 56 57

            Rectangle {
                anchors.fill: parent
58
                anchors.margins: 0.1 * 30
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75

                color: myPalette.base

                MouseArea {
                    anchors.fill: parent

                    hoverEnabled: true

                    onEntered: pathList.currentIndex = delegateItem.DelegateModel.itemsIndex

                    Label {
                        text: modelData

                        anchors.centerIn: parent
                    }

                    ToolButton {
Alexander Stippich's avatar
Alexander Stippich committed
76
                        icon.name: 'list-remove'
77

78 79
                        Accessible.onPressAction: onClicked

80 81 82 83 84
                        anchors.top: parent.top
                        anchors.right: parent.right

                        onClicked:
                        {
85
                            var oldPaths = config.rootPath
86
                            oldPaths.splice(delegateItem.DelegateModel.itemsIndex, 1)
87
                            config.rootPath = oldPaths
88 89 90 91 92 93 94 95 96 97
                        }
                    }
                }
            }
        }
    }

    RowLayout {
        spacing: 0

98 99 100 101 102 103 104
        LayoutMirroring.enabled: Qt.application.layoutDirection == Qt.RightToLeft
        LayoutMirroring.childrenInherit: true

        height: 400
        width: 600
        implicitHeight: 400
        implicitWidth: 600
105

Alexander Stippich's avatar
Alexander Stippich committed
106 107
        ListView {
            id:pathList
108 109 110

            Layout.fillWidth: true
            Layout.fillHeight: true
Alexander Stippich's avatar
Alexander Stippich committed
111
            boundsBehavior: Flickable.StopAtBounds
112

Alexander Stippich's avatar
Alexander Stippich committed
113
            model: DelegateModel {
114
                model: config.rootPath
115

Alexander Stippich's avatar
Alexander Stippich committed
116 117
                delegate: pathDelegate
            }
118

Alexander Stippich's avatar
Alexander Stippich committed
119 120
            ScrollBar.vertical: ScrollBar {
                id: scrollBar
121
            }
Alexander Stippich's avatar
Alexander Stippich committed
122 123

            highlight: highlightBar
124 125 126 127
        }

        ColumnLayout {
            Layout.fillHeight: true
Safa AlFulaij's avatar
Safa AlFulaij committed
128 129
            Layout.leftMargin: !LayoutMirroring.enabled ? (0.3 * 30) : 0
            Layout.rightMargin: LayoutMirroring.enabled ? (0.3 * 30) : 0
130 131

            Button {
132
                text: i18n("Add new path")
133 134
                onClicked: fileDialog.open()

135 136
                Accessible.onPressAction: onClicked

137 138
                Layout.alignment: Qt.AlignTop | Qt.AlignLeft

139
                Dialogs.FileDialog {
140
                    id: fileDialog
141
                    title: i18n("Choose a Folder")
142 143 144 145 146 147
                    folder: shortcuts.home
                    selectFolder: true

                    visible: false

                    onAccepted: {
148
                        var oldPaths = config.rootPath
149
                        oldPaths.push(fileDialog.fileUrls)
150
                        config.rootPath = oldPaths
151 152 153 154 155 156 157 158 159
                    }
                }
            }

            Item {
                Layout.fillHeight: true
            }
        }
    }
160 161 162 163 164 165 166

    onAccepted: {
        config.save()
        close()
    }

    onApply: config.save()
167
}