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]= Name[zh_CN]=
GenericName=File Manager GenericName=File Manager
Comment=Cutefish File Manager Comment=Cutefish File Manager
Exec=cutefish-filemanager %U Exec=cutefish-filemanager %u
MimeType=inode/directory; MimeType=inode/directory;
Icon=file-system-manager Icon=file-system-manager
Categories=FileManager;Utility;Core;Qt; Categories=Qt;System;FileTools;FileManager;
StartupNotify=true StartupNotify=true

View file

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

View file

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

View file

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

View file

@ -6,7 +6,7 @@ import MeuiKit 1.0 as Meui
Item { Item {
id: _listItem id: _listItem
width: ListView.view.width - ListView.view.leftMargin - ListView.view.rightMargin 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.name: fileName
Accessible.role: Accessible.Canvas Accessible.role: Accessible.Canvas
@ -39,7 +39,7 @@ Item {
id: _background id: _background
anchors.fill: parent anchors.fill: parent
radius: Meui.Theme.smallRadius radius: Meui.Theme.smallRadius
color: selected ? selectedColor : hovered ? hoveredColor : "transparent" color: selected ? Meui.Theme.highlightColor : hovered ? hoveredColor : "transparent"
visible: selected || hovered visible: selected || hovered
} }
@ -88,21 +88,21 @@ Item {
id: _label id: _label
text: model.fileName text: model.fileName
Layout.fillWidth: true Layout.fillWidth: true
color: Meui.Theme.textColor color: selected ? Meui.Theme.highlightedTextColor : Meui.Theme.textColor
elide: Qt.ElideMiddle elide: Qt.ElideMiddle
} }
Label { Label {
id: _label2 id: _label2
text: model.fileSize text: model.fileSize
color: Meui.Theme.disabledTextColor color: selected ? Meui.Theme.highlightedTextColor : Meui.Theme.disabledTextColor
Layout.fillWidth: true Layout.fillWidth: true
} }
} }
Label { Label {
text: model.modified 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 Item editor: null
property int anchorIndex: 0 property int anchorIndex: 0
property var itemHeight: Meui.Units.fontMetrics.height * 2 + Meui.Units.largeSpacing
property variant cachedRectangleSelection: null
signal keyPress(var event) signal keyPress(var event)
currentIndex: -1 currentIndex: -1
@ -58,6 +62,16 @@ ListView {
} }
} }
onCachedRectangleSelectionChanged: {
if (cachedRectangleSelection === null)
return
if (cachedRectangleSelection.length)
control.currentIndex[0]
folderModel.updateSelection(cachedRectangleSelection, control.ctrlPressed)
}
onContentXChanged: { onContentXChanged: {
cancelRename() cancelRename()
} }
@ -266,7 +280,7 @@ ListView {
control.rubberBand = null control.rubberBand = null
control.interactive = true control.interactive = true
// control.cachedRectangleSelection = null control.cachedRectangleSelection = null
folderModel.unpinSelection() folderModel.unpinSelection()
} }
@ -281,7 +295,13 @@ ListView {
} }
function rectangleSelect(x, y, width, height) { 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) { function updateSelection(modifier) {

View file

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