UI improvement of GridView item

This commit is contained in:
cutefishd 2021-03-31 00:20:52 +08:00
parent aac7ca3882
commit 655fff6e7a
5 changed files with 113 additions and 90 deletions

View file

@ -931,7 +931,8 @@ void FolderModel::dragSelectedInternal(int x, int y)
bool FolderModel::isSupportThumbnails(const QString &mimeType) const bool FolderModel::isSupportThumbnails(const QString &mimeType) const
{ {
const QStringList supportsMimetypes = {"image/bmp", "image/png", "image/gif", "image/jpeg", "image/web", const QStringList supportsMimetypes = {"image/bmp", "image/png", "image/gif", "image/jpeg", "image/web",
"application/pdf", "application/rtf", "application/doc", "application/odf"}; "application/pdf", "application/rtf", "application/doc", "application/odf",
"audio/mpeg"};
if (supportsMimetypes.contains(mimeType)) if (supportsMimetypes.contains(mimeType))
return true; return true;

View file

@ -62,8 +62,10 @@ Item {
FolderGridView { FolderGridView {
anchors.fill: parent anchors.fill: parent
cellHeight: globalSettings.desktopIconSize
cellWidth: globalSettings.desktopIconSize isDesktopView: true
iconSize: globalSettings.desktopIconSize
model: FolderModel { model: FolderModel {
id: folderModel id: folderModel
url: desktopPath() url: desktopPath()

View file

@ -14,6 +14,7 @@ Item {
property Item iconArea: _image.visible ? _image : _icon property Item iconArea: _image.visible ? _image : _icon
property Item textArea: _label property Item textArea: _label
property Item background: _background
property int index: model.index property int index: model.index
property bool hovered: GridView.view.hoveredItem === control property bool hovered: GridView.view.hoveredItem === control
@ -21,24 +22,36 @@ Item {
property bool blank: model.blank property bool blank: model.blank
property var fileName: model.fileName property var fileName: model.fileName
property color hoveredColor: Meui.Theme.darkMode ? Qt.lighter(Meui.Theme.backgroundColor, 1.1) Rectangle {
: Qt.darker(Meui.Theme.backgroundColor, 1.05) id: _background
width: Math.max(_iconItem.width + Meui.Units.smallSpacing,
ColumnLayout { _label.paintedWidth + Meui.Units.largeSpacing)
anchors.fill: parent height: _iconItem.height + _label.paintedHeight + Meui.Units.largeSpacing
anchors.margins: Meui.Units.largeSpacing x: (parent.width - width) / 2
spacing: Meui.Units.smallSpacing y: _iconItem.y
color: selected || hovered ? Meui.Theme.highlightColor : "transparent"
radius: Meui.Theme.mediumRadius
visible: selected || hovered
opacity: selected ? 0.9 : 0.4
}
Item { Item {
id: _iconItem id: _iconItem
Layout.preferredHeight: parent.height * 0.6 anchors.top: parent.top
Layout.fillWidth: true anchors.horizontalCenter: parent.horizontalCenter
anchors.topMargin: Meui.Units.largeSpacing
anchors.bottomMargin: Meui.Units.largeSpacing
z: 2
width: parent.width - Meui.Units.largeSpacing * 2
height: control.GridView.view.iconSize
opacity: selected || !hovered ? 1.0 : 0.95
Image { Image {
id: _icon id: _icon
width: control.GridView.view.iconSize
height: control.GridView.view.iconSize
anchors.centerIn: parent anchors.centerIn: parent
width: parent.height
height: width
sourceSize: Qt.size(width, height) sourceSize: Qt.size(width, height)
source: "image://icontheme/" + model.iconName source: "image://icontheme/" + model.iconName
visible: !_image.visible visible: !_image.visible
@ -46,10 +59,10 @@ Item {
Image { Image {
id: _image id: _image
anchors.centerIn: parent anchors.fill: parent
height: parent.height anchors.topMargin: Meui.Units.smallSpacing
width: parent.width anchors.leftMargin: Meui.Units.smallSpacing
anchors.rightMargin: Meui.Units.smallSpacing
fillMode: Image.PreserveAspectFit fillMode: Image.PreserveAspectFit
visible: status === Image.Ready visible: status === Image.Ready
horizontalAlignment: Qt.AlignHCenter horizontalAlignment: Qt.AlignHCenter
@ -70,38 +83,42 @@ Item {
anchors.centerIn: parent anchors.centerIn: parent
width: Math.min(parent.width, _image.paintedWidth) width: Math.min(parent.width, _image.paintedWidth)
height: Math.min(parent.height, _image.paintedHeight) height: Math.min(parent.height, _image.paintedHeight)
radius: Meui.Theme.smallRadius radius: Meui.Theme.smallRadius / 2
} }
} }
} }
} }
} }
Item {
id: _labelItem
Layout.fillHeight: true
Layout.preferredHeight: Math.min(_label.implicitHeight, height)
Layout.fillWidth: true
Rectangle {
width: _label.paintedWidth + Meui.Units.smallSpacing * 2
height: _label.paintedHeight
x: (_labelItem.width - width + Meui.Units.smallSpacing) / 2
color: selected ? Meui.Theme.highlightColor : hovered ? hoveredColor : "transparent"
radius: Meui.Theme.smallRadius
}
Label { Label {
id: _label id: _label
horizontalAlignment: Qt.AlignHCenter z: 2
verticalAlignment: Qt.AlignTop anchors.top: _iconItem.bottom
anchors.fill: parent anchors.horizontalCenter: parent.horizontalCenter
anchors.margins: 0 anchors.topMargin: Meui.Units.smallSpacing
maximumLineCount: 2
horizontalAlignment: Text.AlignHCenter
width: Math.round(Math.min(_label.implicitWidth + Meui.Units.smallSpacing,
parent.width - Meui.Units.largeSpacing * 2))
textFormat: Text.PlainText
elide: Qt.ElideRight elide: Qt.ElideRight
wrapMode: Text.Wrap wrapMode: Text.Wrap
text: model.fileName text: model.fileName
color: selected ? Meui.Theme.highlightedTextColor : Meui.Theme.textColor color: control.GridView.view.isDesktopView ? "white"
} : selected ? Meui.Theme.highlightedTextColor : Meui.Theme.textColor
} }
DropShadow {
anchors.fill: _label
source: _label
z: 1
horizontalOffset: 1
verticalOffset: 1
radius: Math.round(4 * Meui.Units.devicePixelRatio)
samples: radius * 2 + 1
spread: 0.35
color: Qt.rgba(0, 0, 0, 0.3)
opacity: model.isHidden ? 0.6 : 1
visible: control.GridView.view.isDesktopView
} }
} }

View file

@ -8,6 +8,8 @@ import MeuiKit 1.0 as Meui
GridView { GridView {
id: control id: control
property bool isDesktopView: false
property Item rubberBand: null property Item rubberBand: null
property Item hoveredItem: null property Item hoveredItem: null
property Item pressedItem: null property Item pressedItem: null
@ -28,10 +30,7 @@ GridView {
property Item editor: null property Item editor: null
property int anchorIndex: 0 property int anchorIndex: 0
property var itemSize: settings.gridIconSize property var iconSize: settings.gridIconSize
property var itemWidth: itemSize + Meui.Units.largeSpacing
property var itemHeight: itemSize + Meui.Units.fontMetrics.height * 2
property variant cachedRectangleSelection: null property variant cachedRectangleSelection: null
@ -67,13 +66,18 @@ GridView {
} }
cellHeight: { cellHeight: {
// var extraHeight = calcExtraSpacing(itemHeight, control.height - topMargin - bottomMargin) var iconHeight = iconSize + (Meui.Units.fontMetrics.height * 2) + Meui.Units.largeSpacing * 2
return itemHeight // + extraHeight if (isDesktopView) {
var extraHeight = calcExtraSpacing(iconHeight, control.height - topMargin - bottomMargin)
return iconHeight + extraHeight
}
return iconHeight
} }
cellWidth: { cellWidth: {
var extraWidth = calcExtraSpacing(itemWidth, control.width - leftMargin - rightMargin) var iconWidth = iconSize + Meui.Units.largeSpacing * 4
return itemWidth + extraWidth var extraWidth = calcExtraSpacing(iconWidth, control.width - leftMargin - rightMargin)
return iconWidth + extraWidth
} }
clip: true clip: true
@ -171,12 +175,11 @@ GridView {
// Set hoveredItem. // Set hoveredItem.
if (indexItem) { if (indexItem) {
var iconPos = mapToItem(indexItem.iconArea, mouse.x, mouse.y) var fPos = mapToItem(indexItem.background, mouse.x, mouse.y)
var textPos = mapToItem(indexItem.textArea, mouse.x, mouse.y)
if (iconPos.x < 0 || iconPos.y < 0 if (fPos.x < 0 || fPos.y < 0
|| iconPos.x > indexItem.iconArea.paintedWidth || fPos.x > indexItem.background.width
|| iconPos.y > indexItem.iconArea.paintedHeight + indexItem.textArea.paintedHeight) { || fPos.y > indexItem.background.height) {
control.hoveredItem = null control.hoveredItem = null
} else { } else {
control.hoveredItem = indexItem control.hoveredItem = indexItem
@ -345,7 +348,7 @@ GridView {
var extraSpacing = 0 var extraSpacing = 0
if (availableColumns > 0) { if (availableColumns > 0) {
var allColumnSize = availableColumns * cellSize var allColumnSize = availableColumns * cellSize
var extraSpace = Math.max(containerSize - allColumnSize, Meui.Units.smallSpacing) var extraSpace = Math.max(containerSize - allColumnSize, Meui.Units.largeSpacing)
extraSpacing = extraSpace / availableColumns extraSpacing = extraSpace / availableColumns
} }
return Math.floor(extraSpacing) return Math.floor(extraSpacing)

View file

@ -6,9 +6,9 @@ Settings {
property bool showHidden: false property bool showHidden: false
property int width: 900 property int width: 900
property int height: 580 property int height: 580
property int desktopIconSize: 128 property int desktopIconSize: 72
property int maximumIconSize: 256 property int maximumIconSize: 256
property int minimumIconSize: 128 property int minimumIconSize: 72
property int gridIconSize: 128 property int gridIconSize: 72
} }