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

125 lines
4.1 KiB
QML

/*
* 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
import org.ukui.menu.extension 1.0
import org.ukui.menu.core 1.0
import AppControls2 1.0 as AppControls2
UkuiMenuExtension {
Component.onCompleted: {
recentFileView.model = extensionData.recentFilesModel
extensionData.recentFilesModel.updateData()
}
Item {
anchors.fill: parent
MouseArea {
anchors.fill: parent
hoverEnabled: true
onContainsMouseChanged: {
if (containsMouse) {
scrollBar.visible = true
}
else {
scrollBar.visible = false
}
}
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
anchors.fill: parent
anchors.leftMargin: 12
spacing: 4
ScrollBar.vertical: AppControls2.ScrollBar {
id: scrollBar
visible: false
width: 14
height: recentFileView.height
}
delegate: AppControls2.StyleBackground {
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
acceptedButtons: Qt.LeftButton | Qt.RightButton
anchors.fill: parent
hoverEnabled: true
onEntered: {
hovered = true
}
onExited: {
hovered = false
}
onClicked: {
var data = {
"url": model.uri,
"index": model.index
}
data["action"] = mouse.button === Qt.RightButton ? "right" : ""
send(data)
}
}
}
}
}
}
}