filemanager/qml/Dialogs/OpenWithDialog.qml

200 lines
6.4 KiB
QML
Raw Normal View History

2021-07-29 02:38:47 -07:00
/*
* Copyright (C) 2021 CutefishOS Team.
*
* Author: Reion Wong <reionwong@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import QtQuick 2.12
import QtQuick.Controls 2.4
import QtQuick.Layouts 1.3
import QtGraphicalEffects 1.0
import FishUI 1.0 as FishUI
Item {
id: control
property string url: main.url
2022-01-25 20:25:59 -08:00
width: 400 + FishUI.Units.largeSpacing * 2
2021-07-29 02:38:47 -07:00
height: _mainLayout.implicitHeight + FishUI.Units.largeSpacing * 2
Rectangle {
anchors.fill: parent
color: FishUI.Theme.secondBackgroundColor
}
Component.onCompleted: {
var items = mimeAppManager.recommendedApps(control.url)
for (var i in items) {
listView.model.append(items[i])
}
defaultCheckBox.checked = false
doneButton.focus = true
}
2021-07-29 02:45:04 -07:00
function openApp() {
if (defaultCheckBox.checked)
mimeAppManager.setDefaultAppForFile(control.url, listView.model.get(listView.currentIndex).desktopFile)
launcher.launchApp(listView.model.get(listView.currentIndex).desktopFile, control.url)
main.close()
}
2021-07-29 02:38:47 -07:00
Keys.enabled: true
Keys.onEscapePressed: main.close()
ColumnLayout {
id: _mainLayout
anchors.fill: parent
2021-11-10 19:30:54 -08:00
spacing: 0
2021-07-29 02:38:47 -07:00
2022-01-25 20:25:59 -08:00
GridView {
2021-07-29 02:38:47 -07:00
id: listView
Layout.fillWidth: true
2021-11-10 19:30:54 -08:00
Layout.preferredHeight: 250
2021-07-29 02:38:47 -07:00
model: ListModel {}
2021-08-07 18:29:04 -07:00
clip: true
2022-01-25 20:25:59 -08:00
ScrollBar.vertical: ScrollBar {}
leftMargin: FishUI.Units.smallSpacing
rightMargin: FishUI.Units.smallSpacing
cellHeight: {
var extraHeight = calcExtraSpacing(80, listView.Layout.preferredHeight - topMargin - bottomMargin)
return 80 + extraHeight
}
2021-07-29 02:38:47 -07:00
2022-01-25 20:25:59 -08:00
cellWidth: {
var extraWidth = calcExtraSpacing(120, listView.width - leftMargin - rightMargin)
return 120 + extraWidth
}
2021-11-10 19:30:54 -08:00
2021-07-29 02:38:47 -07:00
Label {
anchors.centerIn: parent
text: qsTr("No applications")
visible: listView.count === 0
}
delegate: Item {
id: item
2022-01-25 20:25:59 -08:00
width: GridView.view.cellWidth
height: GridView.view.cellHeight
2021-07-29 02:38:47 -07:00
scale: mouseArea.pressed ? 0.95 : 1.0
Behavior on scale {
NumberAnimation {
duration: 100
}
}
property bool isSelected: listView.currentIndex === index
MouseArea {
id: mouseArea
anchors.fill: parent
hoverEnabled: true
2021-07-29 02:45:04 -07:00
acceptedButtons: Qt.LeftButton
onDoubleClicked: control.openApp()
onClicked: listView.currentIndex = index
2021-07-29 02:38:47 -07:00
}
Rectangle {
anchors.fill: parent
2022-01-25 20:25:59 -08:00
anchors.margins: FishUI.Units.smallSpacing
radius: FishUI.Theme.mediumRadius
2021-07-29 02:38:47 -07:00
color: isSelected ? FishUI.Theme.highlightColor
: mouseArea.containsMouse ? Qt.rgba(FishUI.Theme.textColor.r,
FishUI.Theme.textColor.g,
FishUI.Theme.textColor.b,
0.1) : "transparent"
smooth: true
}
2022-01-25 20:25:59 -08:00
ColumnLayout {
2021-07-29 02:38:47 -07:00
anchors.fill: parent
anchors.margins: FishUI.Units.smallSpacing
2021-08-07 18:29:04 -07:00
spacing: FishUI.Units.smallSpacing
2021-07-29 02:38:47 -07:00
2021-08-17 14:35:23 -07:00
FishUI.IconItem {
2021-07-29 02:38:47 -07:00
id: icon
2022-01-25 20:25:59 -08:00
Layout.preferredHeight: 36
2021-08-17 14:35:23 -07:00
Layout.preferredWidth: height
source: model.icon
2022-01-25 20:25:59 -08:00
Layout.alignment: Qt.AlignHCenter
2021-07-29 02:38:47 -07:00
}
Label {
text: model.name
Layout.fillWidth: true
2022-01-25 20:25:59 -08:00
elide: Text.ElideMiddle
Layout.alignment: Qt.AlignHCenter
horizontalAlignment: Qt.AlignHCenter
2021-07-29 02:38:47 -07:00
color: isSelected ? FishUI.Theme.highlightedTextColor : FishUI.Theme.textColor
}
}
}
}
CheckBox {
id: defaultCheckBox
focusPolicy: Qt.NoFocus
text: qsTr("Set as default")
enabled: listView.count >= 1
padding: 0
2021-11-10 19:30:54 -08:00
Layout.leftMargin: FishUI.Units.largeSpacing
Layout.bottomMargin: FishUI.Units.largeSpacing
2021-07-29 02:38:47 -07:00
}
RowLayout {
spacing: FishUI.Units.largeSpacing
2021-11-10 19:30:54 -08:00
Layout.leftMargin: FishUI.Units.largeSpacing
Layout.rightMargin: FishUI.Units.largeSpacing
Layout.bottomMargin: FishUI.Units.largeSpacing
2021-07-29 02:38:47 -07:00
Button {
text: qsTr("Cancel")
Layout.fillWidth: true
onClicked: main.close()
}
Button {
id: doneButton
focus: true
flat: true
text: qsTr("Open")
2021-08-31 14:31:38 -07:00
enabled: listView.count > 0
2021-07-29 02:38:47 -07:00
Layout.fillWidth: true
2021-07-29 02:45:04 -07:00
onClicked: control.openApp()
2021-07-29 02:38:47 -07:00
}
}
}
2022-01-25 20:25:59 -08:00
function calcExtraSpacing(cellSize, containerSize) {
var availableColumns = Math.floor(containerSize / cellSize)
var extraSpacing = 0
if (availableColumns > 0) {
var allColumnSize = availableColumns * cellSize
var extraSpace = Math.max(containerSize - allColumnSize, 0)
extraSpacing = extraSpace / availableColumns
}
return Math.floor(extraSpacing)
}
2021-07-29 02:38:47 -07:00
}