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

125 lines
4.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: {
2023-01-17 10:53:00 +08:00
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
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-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
Row {
anchors.fill: parent
anchors.leftMargin: 4
spacing: 12
Image {
width: 32
height: 32
anchors.verticalCenter: parent.verticalCenter
source: model.icon
}
AppControls2.StyleText {
width: parent.width - x
height: 20
anchors.verticalCenter: parent.verticalCenter
verticalAlignment: Text.AlignVCenter
text: model.name
elide: Text.ElideRight
}
}
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
}
}
}
}
}
}