ukui-menu/extension/recent-file/qml/RecentFileExtension.qml

169 lines
6.1 KiB
QML
Raw Normal View History

2023-01-17 10:53:00 +08:00
/*
* Copyright (C) 2023, KylinSoft Co., Ltd.
*
* 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
* (at your option) 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 <https://www.gnu.org/licenses/>.
*
*/
import QtQuick 2.0
import QtQuick.Controls 2.5
2023-01-17 10:53:00 +08:00
import org.ukui.menu.extension 1.0
import org.ukui.menu.core 1.0
2023-01-17 10:53:00 +08:00
import AppControls2 1.0 as AppControls2
UkuiMenuExtension {
Component.onCompleted: {
recentFileView.model = extensionData.recentFilesModel
extensionData.recentFilesModel.updateData()
}
Item {
2023-01-17 10:53:00 +08:00
anchors.fill: parent
MouseArea {
anchors.fill: parent
hoverEnabled: true
onContainsMouseChanged: {
if (containsMouse) {
scrollBar.visible = true
2023-01-17 10:53:00 +08:00
}
else {
scrollBar.visible = false
2023-01-17 10:53:00 +08:00
}
}
AppControls2.StyleBackground {
anchors.top: parent.top
width: parent.width; height: 1
useStyleTransparent: false
alpha: 0.15
paletteRole: Palette.Text
visible: recentFileView.contentY > 0
z: 1
}
ListView {
id: recentFileView
2023-01-17 10:53:00 +08:00
anchors.fill: parent
anchors.leftMargin: 12
spacing: 4
2023-05-29 16:22:40 +08:00
focus: true
highlightMoveDuration: 0
onActiveFocusChanged: currentIndex = 0
onCountChanged: currentIndex = 0
keyNavigationWraps: true
ScrollBar.vertical: AppControls2.ScrollBar {
id: scrollBar
visible: false
width: 14
height: recentFileView.height
2023-01-17 10:53:00 +08:00
}
delegate: AppControls2.StyleBackground {
2023-05-29 16:22:40 +08:00
id: delegateItem
2023-03-31 16:20:49 +08:00
width: ListView.view.width - 18
height: 40
useStyleTransparent: false
alpha: itemArea.pressed ? 1 : itemArea.hovered ? 0.65 : 0
radius: 8
2023-05-29 16:22:40 +08:00
focus: true
states: State {
when: delegateItem.activeFocus
PropertyChanges {
target: delegateItem
alpha: 0.65
}
}
Row {
anchors.fill: parent
anchors.leftMargin: 4
spacing: 12
Image {
width: 32
height: 32
anchors.verticalCenter: parent.verticalCenter
source: model.icon
}
AppControls2.StyleText {
id: fileText
width: parent.width - x
height: 20
anchors.verticalCenter: parent.verticalCenter
verticalAlignment: Text.AlignVCenter
text: model.name
elide: Text.ElideRight
}
}
ToolTip {
visible: itemArea.containsMouse
delay: 500
contentItem: Column {
width: childrenRect.width
height: childrenRect.height
Text {
verticalAlignment: Text.AlignVCenter
visible: fileText.truncated
wrapMode: Text.WrapAnywhere
text: model.name
Component.onCompleted: {
if (contentWidth > recentFileView.width) {
width = recentFileView.width;
}
}
}
Text {
verticalAlignment: Text.AlignVCenter
wrapMode: Text.WordWrap
text: qsTr("Path: ") + model.path
Component.onCompleted: {
if (contentWidth > recentFileView.width) {
width = recentFileView.width;
}
}
}
}
}
MouseArea {
id: itemArea
property bool hovered
2023-03-16 14:14:16 +08:00
acceptedButtons: Qt.LeftButton | Qt.RightButton
anchors.fill: parent
hoverEnabled: true
onEntered: {
hovered = true
}
onExited: {
hovered = false
}
onClicked: {
var data = {
2023-03-16 14:14:16 +08:00
"url": model.uri,
"index": model.index
}
2023-03-16 14:14:16 +08:00
data["action"] = mouse.button === Qt.RightButton ? "right" : ""
send(data)
}
2023-01-17 10:53:00 +08:00
}
}
}
}
}
}