@ -110,6 +110,12 @@ MxcImageProvider::download(const QString &id,
return ;
return ;
}
}
bool cropLocally = false ;
if ( crop & & requestedSize . width ( ) > 96 ) {
crop = false ;
cropLocally = true ;
}
std : : optional < mtx : : crypto : : EncryptedFile > encryptionInfo ;
std : : optional < mtx : : crypto : : EncryptedFile > encryptionInfo ;
auto temp = infos . find ( " mxc:// " + id ) ;
auto temp = infos . find ( " mxc:// " + id ) ;
if ( temp ! = infos . end ( ) )
if ( temp ! = infos . end ( ) )
@ -126,7 +132,7 @@ MxcImageProvider::download(const QString &id,
. arg ( requestedSize . width ( ) )
. arg ( requestedSize . width ( ) )
. arg ( requestedSize . height ( ) )
. arg ( requestedSize . height ( ) )
. arg ( crop ? " crop " : " scale " )
. arg ( crop ? " crop " : " scale " )
. arg ( radius ) ;
. arg ( cropLocally ? 0 : radius ) ;
QFileInfo fileInfo ( QStandardPaths : : writableLocation ( QStandardPaths : : CacheLocation ) +
QFileInfo fileInfo ( QStandardPaths : : writableLocation ( QStandardPaths : : CacheLocation ) +
" /media_cache " ,
" /media_cache " ,
fileName ) ;
fileName ) ;
@ -138,8 +144,16 @@ MxcImageProvider::download(const QString &id,
if ( requestedSize . width ( ) < = 0 ) {
if ( requestedSize . width ( ) < = 0 ) {
image = image . scaledToHeight ( requestedSize . height ( ) , Qt : : SmoothTransformation ) ;
image = image . scaledToHeight ( requestedSize . height ( ) , Qt : : SmoothTransformation ) ;
} else {
} else {
image =
image = image . scaled ( requestedSize ,
image . scaled ( requestedSize , Qt : : KeepAspectRatio , Qt : : SmoothTransformation ) ;
cropLocally ? Qt : : KeepAspectRatioByExpanding
: Qt : : KeepAspectRatio ,
Qt : : SmoothTransformation ) ;
if ( cropLocally ) {
image = image . copy ( ( image . width ( ) - requestedSize . width ( ) ) / 2 ,
( image . height ( ) - requestedSize . height ( ) ) / 2 ,
requestedSize . width ( ) ,
requestedSize . height ( ) ) ;
}
}
}
if ( radius ! = 0 ) {
if ( radius ! = 0 ) {
@ -160,8 +174,8 @@ MxcImageProvider::download(const QString &id,
opts . method = crop ? " crop " : " scale " ;
opts . method = crop ? " crop " : " scale " ;
http : : client ( ) - > get_thumbnail (
http : : client ( ) - > get_thumbnail (
opts ,
opts ,
[ fileInfo , requestedSize , radius , then , id , crop ] ( const std : : string & res ,
[ fileInfo , requestedSize , radius , then , id , crop , cropLocally ] (
mtx : : http : : RequestErr err ) {
const std : : string & res , mtx : : http : : RequestErr err ) {
if ( err | | res . empty ( ) ) {
if ( err | | res . empty ( ) ) {
download ( id , QSize ( ) , then , crop , radius ) ;
download ( id , QSize ( ) , then , crop , radius ) ;
return ;
return ;
@ -174,8 +188,16 @@ MxcImageProvider::download(const QString &id,
image =
image =
image . scaledToHeight ( requestedSize . height ( ) , Qt : : SmoothTransformation ) ;
image . scaledToHeight ( requestedSize . height ( ) , Qt : : SmoothTransformation ) ;
} else {
} else {
image =
image = image . scaled ( requestedSize ,
image . scaled ( requestedSize , Qt : : KeepAspectRatio , Qt : : SmoothTransformation ) ;
cropLocally ? Qt : : KeepAspectRatioByExpanding
: Qt : : KeepAspectRatio ,
Qt : : SmoothTransformation ) ;
if ( cropLocally ) {
image = image . copy ( ( image . width ( ) - requestedSize . width ( ) ) / 2 ,
( image . height ( ) - requestedSize . height ( ) ) / 2 ,
requestedSize . width ( ) ,
requestedSize . height ( ) ) ;
}
}
}
if ( radius ! = 0 ) {
if ( radius ! = 0 ) {