GridViewItem: Improve the display of label borders

This commit is contained in:
cutefishd 2021-03-30 20:44:50 +08:00
parent 358926370b
commit aac7ca3882
6 changed files with 68 additions and 82 deletions

View file

@ -18,6 +18,7 @@
*/ */
#include "desktopview.h" #include "desktopview.h"
#include "helper/thumbnailer.h"
#include <QQmlEngine> #include <QQmlEngine>
#include <QQmlContext> #include <QQmlContext>
@ -40,6 +41,7 @@ DesktopView::DesktopView(QQuickView *parent)
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());
setScreen(qApp->primaryScreen()); setScreen(qApp->primaryScreen());
setResizeMode(QQuickView::SizeRootObjectToView); setResizeMode(QQuickView::SizeRootObjectToView);

View file

@ -75,6 +75,8 @@ Item {
rightMargin: desktopView.screenRect.width - (desktopView.screenAvailableRect.x + desktopView.screenAvailableRect.width) rightMargin: desktopView.screenRect.width - (desktopView.screenAvailableRect.x + desktopView.screenAvailableRect.width)
bottomMargin: desktopView.screenRect.height - (desktopView.screenAvailableRect.y + desktopView.screenAvailableRect.height) bottomMargin: desktopView.screenRect.height - (desktopView.screenAvailableRect.y + desktopView.screenAvailableRect.height)
flow: GridView.FlowTopToBottom
delegate: FolderGridItem {} delegate: FolderGridItem {}
} }

View file

@ -19,6 +19,10 @@ Item {
property bool hovered: GridView.view.hoveredItem === control property bool hovered: GridView.view.hoveredItem === control
property bool selected: model.selected property bool selected: model.selected
property bool blank: model.blank property bool blank: model.blank
property var fileName: model.fileName
property color hoveredColor: Meui.Theme.darkMode ? Qt.lighter(Meui.Theme.backgroundColor, 1.1)
: Qt.darker(Meui.Theme.backgroundColor, 1.05)
ColumnLayout { ColumnLayout {
anchors.fill: parent anchors.fill: parent
@ -42,9 +46,9 @@ Item {
Image { Image {
id: _image id: _image
anchors.fill: parent anchors.centerIn: parent
anchors.leftMargin: Meui.Units.smallSpacing height: parent.height
anchors.rightMargin: Meui.Units.smallSpacing width: parent.width
fillMode: Image.PreserveAspectFit fillMode: Image.PreserveAspectFit
visible: status === Image.Ready visible: status === Image.Ready
@ -74,22 +78,23 @@ Item {
} }
Item { Item {
id: _labelItem
Layout.fillHeight: true Layout.fillHeight: true
Layout.preferredHeight: Math.min(_label.implicitHeight, height) Layout.preferredHeight: Math.min(_label.implicitHeight, height)
Layout.fillWidth: true Layout.fillWidth: true
Rectangle { Rectangle {
width: Math.min(_label.implicitWidth + Meui.Units.smallSpacing, parent.width) width: _label.paintedWidth + Meui.Units.smallSpacing * 2
height: Math.min(_label.implicitHeight + Meui.Units.smallSpacing, parent.height) height: _label.paintedHeight
anchors.centerIn: parent x: (_labelItem.width - width + Meui.Units.smallSpacing) / 2
color: selected ? Meui.Theme.highlightColor : "transparent" color: selected ? Meui.Theme.highlightColor : hovered ? hoveredColor : "transparent"
radius: Meui.Theme.smallRadius radius: Meui.Theme.smallRadius
} }
Label { Label {
id: _label id: _label
horizontalAlignment: Qt.AlignHCenter horizontalAlignment: Qt.AlignHCenter
verticalAlignment: Qt.AlignVCenter verticalAlignment: Qt.AlignTop
anchors.fill: parent anchors.fill: parent
anchors.margins: 0 anchors.margins: 0
elide: Qt.ElideRight elide: Qt.ElideRight

View file

@ -78,9 +78,7 @@ GridView {
clip: true clip: true
currentIndex: -1 currentIndex: -1
ScrollBar.vertical: ScrollBar { ScrollBar.vertical: ScrollBar { }
bottomPadding: Meui.Theme.mediumRadius
}
onPressXChanged: { onPressXChanged: {
cPress = mapToItem(control.contentItem, pressX, pressY) cPress = mapToItem(control.contentItem, pressX, pressY)
@ -110,53 +108,30 @@ GridView {
enabled: true enabled: true
z: -1 z: -1
onDoubleClicked: {
if (mouse.button === Qt.LeftButton && control.pressedItem)
folderModel.openSelected()
}
onPressed: { onPressed: {
control.forceActiveFocus() control.forceActiveFocus()
// if (mouse.source === Qt.MouseEventSynthesizedByQt) {
// var index = control.indexAt(mouse.x, mouse.y)
// var indexItem = control.itemAtIndex(index)
// if (indexItem && indexItem.iconArea) {
// control.currentIndex = index
// hoveredItem = indexItem
// } else {
// hoveredItem = null
// }
// }
pressX = mouse.x pressX = mouse.x
pressY = mouse.y pressY = mouse.y
if (!hoveredItem || hoveredItem.blank) { // hoveredItem pressedItem
if (!control.ctrlPressed) { if (hoveredItem) {
control.currentIndex = -1
previouslySelectedItemIndex = -1
folderModel.clearSelection()
}
if (mouse.buttons & Qt.RightButton) {
clearPressState()
folderModel.openContextMenu(null, mouse.modifiers)
mouse.accepted = true
}
} else {
pressedItem = hoveredItem pressedItem = hoveredItem
var pos = mapToItem(hoveredItem, mouse.x, mouse.y) // currentIndex
if (!control.shiftPressed)
currentIndex = pressedItem.index
// Shift ,
if (control.shiftPressed && control.currentIndex !== -1) { if (control.shiftPressed && control.currentIndex !== -1) {
folderModel.setRangeSelected(control.anchorIndex, hoveredItem.index) folderModel.setRangeSelected(control.anchorIndex, hoveredItem.index)
} else { } else {
// Ctrl
if (!control.ctrlPressed && !folderModel.isSelected(hoveredItem.index)) { if (!control.ctrlPressed && !folderModel.isSelected(hoveredItem.index)) {
previouslySelectedItemIndex = -1
folderModel.clearSelection() folderModel.clearSelection()
} }
// Item
if (control.ctrlPressed) { if (control.ctrlPressed) {
folderModel.toggleSelected(hoveredItem.index) folderModel.toggleSelected(hoveredItem.index)
} else { } else {
@ -164,8 +139,20 @@ GridView {
} }
} }
control.currentIndex = hoveredItem.index // Item
if (mouse.buttons & Qt.RightButton) {
clearPressState()
folderModel.openContextMenu(null, mouse.modifiers)
mouse.accepted = true
}
} else {
//
if (!control.ctrlPressed) {
control.currentIndex = -1
folderModel.clearSelection()
}
//
if (mouse.buttons & Qt.RightButton) { if (mouse.buttons & Qt.RightButton) {
clearPressState() clearPressState()
folderModel.openContextMenu(null, mouse.modifiers) folderModel.openContextMenu(null, mouse.modifiers)
@ -178,36 +165,30 @@ GridView {
control.ctrlPressed = (mouse.modifiers & Qt.ControlModifier) control.ctrlPressed = (mouse.modifiers & Qt.ControlModifier)
control.shiftPressed = (mouse.modifiers & Qt.ShiftModifier) control.shiftPressed = (mouse.modifiers & Qt.ShiftModifier)
var cPos = mapToItem(control.contentItem, mouse.x, mouse.y) var index = control.indexAt(mouse.x + control.contentX,
var item = control.itemAt(cPos.x, cPos.y) mouse.y + control.contentY)
var leftEdge = Math.min(control.contentX, control.originX) var indexItem = control.itemAtIndex(index)
if (!item || item.blank) { // Set hoveredItem.
if (control.hoveredItem/* && !root.containsDrag*/) { if (indexItem) {
control.hoveredItem = null var iconPos = mapToItem(indexItem.iconArea, mouse.x, mouse.y)
} var textPos = mapToItem(indexItem.textArea, mouse.x, mouse.y)
} else {
var fPos = mapToItem(item.iconArea, mouse.x, mouse.y)
if (fPos.x < 0 || fPos.y < 0 || fPos.x > item.iconArea.width || fPos.y > item.iconArea.height) { if (iconPos.x < 0 || iconPos.y < 0
|| iconPos.x > indexItem.iconArea.paintedWidth
|| iconPos.y > indexItem.iconArea.paintedHeight + indexItem.textArea.paintedHeight) {
control.hoveredItem = null control.hoveredItem = null
} else { } else {
control.hoveredItem = item control.hoveredItem = indexItem
} }
} } else {
control.hoveredItem = null
// Trigger autoscroll.
if (pressX != -1) {
control.scrollLeft = (mouse.x <= 0 && control.contentX > leftEdge);
control.scrollRight = (mouse.x >= control.width
&& control.contentX < control.contentItem.width - control.width);
control.scrollUp = (mouse.y <= 0 && control.contentY > 0);
control.scrollDown = (mouse.y >= control.height
&& control.contentY < control.contentItem.height - control.height);
} }
// Update rubberband geometry. // Update rubberband geometry.
if (control.rubberBand) { if (control.rubberBand) {
var cPos = mapToItem(control.contentItem, mouse.x, mouse.y)
var leftEdge = Math.min(control.contentX, control.originX)
var rB = control.rubberBand var rB = control.rubberBand
if (cPos.x < cPress.x) { if (cPos.x < cPress.x) {
@ -215,7 +196,7 @@ GridView {
rB.width = Math.abs(rB.x - cPress.x) rB.width = Math.abs(rB.x - cPress.x)
} else { } else {
rB.x = cPress.x rB.x = cPress.x
var ceil = Math.max(control.width, control.contentItem.width) + leftEdge const ceil = Math.max(control.width, control.contentItem.width) + leftEdge
rB.width = Math.min(ceil - rB.x, Math.abs(rB.x - cPos.x)) rB.width = Math.min(ceil - rB.x, Math.abs(rB.x - cPos.x))
} }
@ -224,7 +205,7 @@ GridView {
rB.height = Math.abs(rB.y - cPress.y) rB.height = Math.abs(rB.y - cPress.y)
} else { } else {
rB.y = cPress.y rB.y = cPress.y
var ceil = Math.max(control.height, control.contentItem.height) const ceil = Math.max(control.height, control.contentItem.height)
rB.height = Math.min(ceil - rB.y, Math.abs(rB.y - cPos.y)) rB.height = Math.min(ceil - rB.y, Math.abs(rB.y - cPos.y))
} }
@ -258,19 +239,14 @@ GridView {
onClicked: { onClicked: {
clearPressState() clearPressState()
if (mouse.button === Qt.RightButton) if (mouse.buttons & Qt.RightButton) {
return folderModel.openContextMenu(null, mouse.modifiers)
}
}
if (!hoveredItem) onDoubleClicked: {
return; if (mouse.button === Qt.LeftButton && control.pressedItem)
folderModel.openSelected()
// var pos = mapToItem(hoveredItem, mouse.x, mouse.y);
// if (pos.x < 0 || pos.x > hoveredItem.width || pos.y < 0 || pos.y > hoveredItem.height) {
// hoveredItem = null
// previouslySelectedItemIndex = -1
// folderModel.clearSelection()
// return
// }
} }
onReleased: pressCanceled() onReleased: pressCanceled()

View file

@ -32,9 +32,7 @@ ListView {
currentIndex: -1 currentIndex: -1
clip: true clip: true
ScrollBar.vertical: ScrollBar { ScrollBar.vertical: ScrollBar { }
bottomPadding: Meui.Theme.mediumRadius
}
highlightMoveDuration: 0 highlightMoveDuration: 0
keyNavigationEnabled : true keyNavigationEnabled : true

View file

@ -23,6 +23,8 @@ Item {
Rectangle { Rectangle {
id: _background id: _background
anchors.fill: parent anchors.fill: parent
anchors.rightMargin: Meui.Theme.smallRadius
anchors.bottomMargin: Meui.Theme.smallRadius
radius: Meui.Theme.smallRadius radius: Meui.Theme.smallRadius
color: Meui.Theme.backgroundColor color: Meui.Theme.backgroundColor
} }
@ -54,6 +56,7 @@ Item {
ColumnLayout { ColumnLayout {
anchors.fill: parent anchors.fill: parent
anchors.bottomMargin: Meui.Theme.smallRadius
spacing: 0 spacing: 0
Loader { Loader {
@ -129,7 +132,7 @@ Item {
model: folderModel model: folderModel
leftMargin: Meui.Units.largeSpacing leftMargin: Meui.Units.largeSpacing
rightMargin: Meui.Units.largeSpacing rightMargin: Meui.Units.largeSpacing + Meui.Theme.smallRadius
spacing: Meui.Units.largeSpacing spacing: Meui.Units.largeSpacing
onCountChanged: { onCountChanged: {