try to fix #LINQT-1906

This commit is contained in:
Gaelle Braud 2025-08-26 17:18:07 +02:00
parent 60ebaf73a9
commit e0286fdc42
4 changed files with 190 additions and 218 deletions

View file

@ -2242,8 +2242,10 @@ QImage Utils::getImage(const QString &pUri) {
}
void Utils::setGlobalCursor(Qt::CursorShape cursor) {
if (!App::getInstance()->overrideCursor() || App::getInstance()->overrideCursor()->shape() != cursor) {
App::getInstance()->setOverrideCursor(QCursor(cursor));
}
}
void Utils::restoreGlobalCursor() {
App::getInstance()->restoreOverrideCursor();

View file

@ -55,7 +55,7 @@ GridLayout {
visible: modelData
height: mainItem.itemWidth
width: mainItem.itemWidth
onIsHoveringChanged: mainItem.isHoveringFile = isHovering
// onIsHoveringChanged: mainItem.isHoveringFile = isHovering
}
}
}

View file

@ -79,7 +79,7 @@ ColumnLayout {
Layout.fillHeight: true
// Layout.preferredHeight: contentHeight
chatMessageGui: mainItem.chatMessageGui
onIsHoveringFileChanged: mainItem.isFileHoveringChanged(isHoveringFile)
// onIsHoveringFileChanged: mainItem.isFileHoveringChanged(isHoveringFile)
// borderWidth: mainItem.fileBorderWidth
// property int availableSection: mainItem.availableWidth / mainItem.filesBestWidth
// property int bestFitSection: mainItem.bestWidth / mainItem.filesBestWidth

View file

@ -30,6 +30,16 @@ Item {
property int overriddenHeight
// property to change default view display
property bool showAsSquare: true
// default image
property var imageSource: mainItem.contentGui
? UtilsCpp.isImage(mainItem.filePath)
? AppIcons.fileImage
: UtilsCpp.isPdf(mainItem.filePath)
? AppIcons.filePdf
: UtilsCpp.isText(mainItem.filePath)
? AppIcons.fileText
: AppIcons.file
: ''
Connections {
enabled: contentGui
@ -40,55 +50,9 @@ Item {
}
}
property bool isHovering: thumbnailProvider.state == 'hovered'
// property bool isHovering: thumbnailProvider.state == 'hovered'
property bool isOutgoing: false
MouseArea {
anchors.fill: parent
hoverEnabled: true
propagateComposedEvents: true
function handleMouseMove (mouse) {
thumbnailProvider.state = Utils.pointIsInItem(this, thumbnailProvider, mouse)
? 'hovered'
: ''
}
onMouseXChanged: (mouse) => handleMouseMove.call(this, mouse)
onMouseYChanged: (mouse) => handleMouseMove.call(this, mouse)
onEntered: {
thumbnailProvider.state = 'hovered'
}
onExited: {
thumbnailProvider.state = ''
}
onClicked: (mouse) => {
mouse.accepted = false
if(mainItem.isTransferring) {
mainItem.contentGui.core.lCancelDownloadFile()
mouse.accepted = true
thumbnailProvider.state = ''
}
else if(!mainItem.contentGui.core.wasDownloaded) {
mouse.accepted = true
thumbnailProvider.state = ''
mainItem.contentGui.core.lDownloadFile()
} else if (Utils.pointIsInItem(this, thumbnailProvider, mouse)) {
mouse.accepted = true
thumbnailProvider.state = ''
// if(SettingsModel.isVfsEncrypted){
// window.attachVirtualWindow(Utils.buildCommonDialogUri('FileViewDialog'), {
// contentGui: mainItem.contentGui,
// }, function (status) {
// })
// }else
mainItem.contentGui.core.lOpenFile()
} else if (mainItem.contentGui) {
mouse.accepted = true
thumbnailProvider.state = ''
mainItem.contentGui.core.lOpenFile(true)// Show directory
}
}
}
// ---------------------------------------------------------------------
// Thumbnail
// ---------------------------------------------------------------------
@ -185,33 +149,8 @@ Item {
}
// ---------------------------------------------------------------------
// Extension
// Default view
// ---------------------------------------------------------------------
Component {
id: defaultFileView
Control.StackView {
id: defaultViewStack
width: childrenRect.width
height: childrenRect.height
initialItem: mainItem.showAsSquare ? defaultSquareView : defaultView
Connections {
target: mainItem
function onShowAsSquareChanged() {
if (mainItem.showAsSquare) defaultViewStack.replace(defaultSquareView)
else defaultViewStack.replace(defaultView)
}
}
property var imageSource: mainItem.contentGui
? UtilsCpp.isImage(mainItem.filePath)
? AppIcons.fileImage
: UtilsCpp.isPdf(mainItem.filePath)
? AppIcons.filePdf
: UtilsCpp.isText(mainItem.filePath)
? AppIcons.fileText
: AppIcons.file
: ''
Component {
id: defaultSquareView
Control.Control {
@ -234,7 +173,7 @@ Item {
height: Math.round(23 * DefaultStyle.dp)
EffectImage {
anchors.centerIn: parent
imageSource: defaultViewStack.imageSource
imageSource: mainItem.imageSource
imageWidth: Math.round(14 * DefaultStyle.dp)
imageHeight: Math.round(14 * DefaultStyle.dp)
colorizationColor: DefaultStyle.main2_600
@ -358,9 +297,6 @@ Item {
}
}
}
}
}
Loader {
id: thumbnailProvider
@ -370,17 +306,51 @@ Item {
? animatedImage
: mainItem.haveThumbnail
? thumbnailImage
: defaultFileView
: mainItem.showAsSquare
? defaultSquareView
: defaultView
: undefined
states: State {
name: 'hovered'
}
MouseArea {
anchors.fill: thumbnailProvider.item
hoverEnabled: true
propagateComposedEvents: true
cursorShape: containsMouse ? Qt.PointingHandCursor : Qt.ArrowCursor
// Changing cursor in MouseArea seems not to work with the Loader
// Use override cursor for this case
onStateChanged: {
if (state === 'hovered') UtilsCpp.setGlobalCursor(Qt.PointingHandCursor)
onContainsMouseChanged: {
console.log("contains mouse", containsMouse)
if (containsMouse) UtilsCpp.setGlobalCursor(Qt.PointingHandCursor)
else UtilsCpp.restoreGlobalCursor()
thumbnailProvider.state = containsMouse ? 'hovered' : ''
}
onPressed: (mouse) => {
mouse.accepted = false
if(mainItem.isTransferring) {
mainItem.contentGui.core.lCancelDownloadFile()
mouse.accepted = true
}
else if(!mainItem.contentGui.core.wasDownloaded) {
mouse.accepted = true
mainItem.contentGui.core.lDownloadFile()
} else if (Utils.pointIsInItem(this, thumbnailProvider, mouse)) {
mouse.accepted = true
// if(SettingsModel.isVfsEncrypted){
// window.attachVirtualWindow(Utils.buildCommonDialogUri('FileViewDialog'), {
// contentGui: mainItem.contentGui,
// }, function (status) {
// })
// }else
mainItem.contentGui.core.lOpenFile()
} else if (mainItem.contentGui) {
mouse.accepted = true
mainItem.contentGui.core.lOpenFile(true)// Show directory
}
}
}
}
}