ListView supports RubberBand selection

This commit is contained in:
cutefishd 2021-04-04 23:38:01 +08:00
parent 52591d0929
commit 72db8fceb4
7 changed files with 33 additions and 14 deletions

View file

@ -4,8 +4,8 @@ Name=File Manager
Name[zh_CN]=
GenericName=File Manager
Comment=Cutefish File Manager
Exec=cutefish-filemanager %U
Exec=cutefish-filemanager %u
MimeType=inode/directory;
Icon=file-system-manager
Categories=FileManager;Utility;Core;Qt;
Categories=Qt;System;FileTools;FileManager;
StartupNotify=true

View file

@ -35,14 +35,13 @@ DesktopView::DesktopView(QQuickView *parent)
m_screenRect = qApp->primaryScreen()->geometry();
m_screenAvailableRect = qApp->primaryScreen()->availableGeometry();
setTitle(tr("Desktop"));
KWindowSystem::setType(winId(), NET::Desktop);
KWindowSystem::setState(winId(), NET::KeepBelow);
engine()->rootContext()->setContextProperty("desktopView", this);
engine()->addImageProvider("thumbnailer", new Thumbnailer());
setTitle(tr("Desktop"));
setScreen(qApp->primaryScreen());
setResizeMode(QQuickView::SizeRootObjectToView);
setSource(QStringLiteral("qrc:/qml/Desktop/main.qml"));

View file

@ -31,7 +31,7 @@ Item {
color: selected || hovered ? Meui.Theme.highlightColor : "transparent"
radius: Meui.Theme.mediumRadius
visible: selected || hovered
opacity: selected ? 1.0 : 0.4
opacity: selected ? 1.0 : 0.2
}
Item {

View file

@ -316,7 +316,7 @@ GridView {
control.rubberBand = null
control.interactive = true
// control.cachedRectangleSelection = null
control.cachedRectangleSelection = null
folderModel.unpinSelection()
}

View file

@ -6,7 +6,7 @@ import MeuiKit 1.0 as Meui
Item {
id: _listItem
width: ListView.view.width - ListView.view.leftMargin - ListView.view.rightMargin
height: Meui.Units.fontMetrics.height * 2 + Meui.Units.largeSpacing
height: ListView.view.itemHeight
Accessible.name: fileName
Accessible.role: Accessible.Canvas
@ -39,7 +39,7 @@ Item {
id: _background
anchors.fill: parent
radius: Meui.Theme.smallRadius
color: selected ? selectedColor : hovered ? hoveredColor : "transparent"
color: selected ? Meui.Theme.highlightColor : hovered ? hoveredColor : "transparent"
visible: selected || hovered
}
@ -88,21 +88,21 @@ Item {
id: _label
text: model.fileName
Layout.fillWidth: true
color: Meui.Theme.textColor
color: selected ? Meui.Theme.highlightedTextColor : Meui.Theme.textColor
elide: Qt.ElideMiddle
}
Label {
id: _label2
text: model.fileSize
color: Meui.Theme.disabledTextColor
color: selected ? Meui.Theme.highlightedTextColor : Meui.Theme.disabledTextColor
Layout.fillWidth: true
}
}
Label {
text: model.modified
color: Meui.Theme.disabledTextColor
color: selected ? Meui.Theme.highlightedTextColor : Meui.Theme.disabledTextColor
}
}
}

View file

@ -27,6 +27,10 @@ ListView {
property Item editor: null
property int anchorIndex: 0
property var itemHeight: Meui.Units.fontMetrics.height * 2 + Meui.Units.largeSpacing
property variant cachedRectangleSelection: null
signal keyPress(var event)
currentIndex: -1
@ -58,6 +62,16 @@ ListView {
}
}
onCachedRectangleSelectionChanged: {
if (cachedRectangleSelection === null)
return
if (cachedRectangleSelection.length)
control.currentIndex[0]
folderModel.updateSelection(cachedRectangleSelection, control.ctrlPressed)
}
onContentXChanged: {
cancelRename()
}
@ -266,7 +280,7 @@ ListView {
control.rubberBand = null
control.interactive = true
// control.cachedRectangleSelection = null
control.cachedRectangleSelection = null
folderModel.unpinSelection()
}
@ -281,7 +295,13 @@ ListView {
}
function rectangleSelect(x, y, width, height) {
var indexes = []
for (var i = y; i <= y + height; i += 10) {
const index = control.indexAt(x, i)
if(!indexes.includes(index) && index > -1 && index< control.count)
indexes.push(index)
}
cachedRectangleSelection = indexes
}
function updateSelection(modifier) {

View file

@ -21,7 +21,7 @@ ListView {
leftMargin: Meui.Units.smallSpacing
rightMargin: Meui.Units.smallSpacing
bottomMargin: Meui.Units.smallSpacing
spacing: Meui.Units.largeSpacing
spacing: Meui.Units.smallSpacing
ScrollBar.vertical: ScrollBar {
bottomPadding: Meui.Units.smallSpacing