/* * 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 . * */ 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 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 } delegate: AppControls2.StyleBackground { id: delegateItem width: ListView.view.width - 18 height: 40 useStyleTransparent: false alpha: itemArea.pressed ? 1 : itemArea.hovered ? 0.65 : 0 radius: 8 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 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) } } } } } } }