ElisaConfigurationDialog.qml 4.36 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
Dialogs.Dialog {
    id: dialog
26 27

    title: i18n("Configure")
28

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

    SystemPalette {
        id: myPalette
        colorGroup: SystemPalette.Active
    }

    Component {
        id: highlightBar

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

    Component {
        id: pathDelegate

        Item {
            id: delegateItem

53
            height: 3 * 30
54

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

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

                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
77
                        icon.name: 'list-remove'
78

79 80
                        Accessible.onPressAction: onClicked

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

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

    RowLayout {
        spacing: 0

99 100 101
        LayoutMirroring.enabled: Qt.application.layoutDirection == Qt.RightToLeft
        LayoutMirroring.childrenInherit: true

102 103 104
        anchors.fill: parent
        anchors.margins: 0

105
        implicitWidth: 600
106
        implicitHeight: 400
107

Alexander Stippich's avatar
Alexander Stippich committed
108 109
        ListView {
            id:pathList
110 111 112

            Layout.fillWidth: true
            Layout.fillHeight: true
Alexander Stippich's avatar
Alexander Stippich committed
113
            boundsBehavior: Flickable.StopAtBounds
114

Alexander Stippich's avatar
Alexander Stippich committed
115
            model: DelegateModel {
116
                model: config.rootPath
117

Alexander Stippich's avatar
Alexander Stippich committed
118 119
                delegate: pathDelegate
            }
120

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

            highlight: highlightBar
126 127 128 129
        }

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

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

137 138
                Accessible.onPressAction: onClicked

139 140
                Layout.alignment: Qt.AlignTop | Qt.AlignLeft

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

                    visible: false

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

            Item {
                Layout.fillHeight: true
            }
        }
    }
162 163 164 165 166 167 168

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

    onApply: config.save()
169
}