From f1669674d8f1ff584129cee43fd520bb8ecb24be Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Thu, 8 Jul 2021 22:15:11 +0300 Subject: [PATCH] Moved formatting of image size text to single place. Fixed wrong size display on retina screens. Replaced "x" with special character. --- Telegram/SourceFiles/boxes/edit_caption_box.cpp | 4 +--- Telegram/SourceFiles/export/output/export_output_html.cpp | 6 +++--- .../SourceFiles/ui/chat/attach/attach_album_thumbnail.cpp | 5 ++--- .../ui/chat/attach/attach_single_file_preview.cpp | 3 ++- Telegram/SourceFiles/ui/text/format_values.cpp | 6 ++++++ Telegram/SourceFiles/ui/text/format_values.h | 1 + 6 files changed, 15 insertions(+), 10 deletions(-) diff --git a/Telegram/SourceFiles/boxes/edit_caption_box.cpp b/Telegram/SourceFiles/boxes/edit_caption_box.cpp index deaf91df47..ce13968234 100644 --- a/Telegram/SourceFiles/boxes/edit_caption_box.cpp +++ b/Telegram/SourceFiles/boxes/edit_caption_box.cpp @@ -646,9 +646,7 @@ void EditCaptionBox::updateEditPreview() { : _preparedList.files.front().content.size()); // Show image dimensions if it should be sent as doc. if (_isImage && docPhotoSize.isValid()) { - _status = qsl("%1x%2") - .arg(docPhotoSize.width()) - .arg(docPhotoSize.height()); + _status = Ui::FormatImageSizeText(docPhotoSize); } _doc = true; } diff --git a/Telegram/SourceFiles/export/output/export_output_html.cpp b/Telegram/SourceFiles/export/output/export_output_html.cpp index b05c875c75..d6ba9196d6 100644 --- a/Telegram/SourceFiles/export/output/export_output_html.cpp +++ b/Telegram/SourceFiles/export/output/export_output_html.cpp @@ -10,6 +10,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "export/output/export_output_result.h" #include "export/data/export_data_types.h" #include "core/utils.h" +#include "ui/text/format_values.h" #include #include @@ -1536,9 +1537,8 @@ QByteArray HtmlWriter::Wrap::pushPhotoMedia( if (thumb.isEmpty()) { auto generic = MediaData(); generic.title = "Photo"; - generic.status = NumberToString(data.image.width) - + "x" - + NumberToString(data.image.height); + generic.status = Ui::FormatImageSizeText( + QSize(data.image.width, data.image.height)).toUtf8(); if (data.image.file.relativePath.isEmpty()) { generic.status += ", " + FormatFileSize(data.image.file.size); } else { diff --git a/Telegram/SourceFiles/ui/chat/attach/attach_album_thumbnail.cpp b/Telegram/SourceFiles/ui/chat/attach/attach_album_thumbnail.cpp index 8e636952ac..b4e2d8a23b 100644 --- a/Telegram/SourceFiles/ui/chat/attach/attach_album_thumbnail.cpp +++ b/Telegram/SourceFiles/ui/chat/attach/attach_album_thumbnail.cpp @@ -76,9 +76,8 @@ AlbumThumbnail::AlbumThumbnail( const auto filepath = file.path; if (filepath.isEmpty()) { _name = "image.png"; - _status = u"%1x%2"_q - .arg(_fullPreview.width()) - .arg(_fullPreview.height()); + _status = FormatImageSizeText(_fullPreview.size() + / _fullPreview.devicePixelRatio()); } else { auto fileinfo = QFileInfo(filepath); _name = fileinfo.fileName(); diff --git a/Telegram/SourceFiles/ui/chat/attach/attach_single_file_preview.cpp b/Telegram/SourceFiles/ui/chat/attach/attach_single_file_preview.cpp index 1d04b85784..f4091ef0d8 100644 --- a/Telegram/SourceFiles/ui/chat/attach/attach_single_file_preview.cpp +++ b/Telegram/SourceFiles/ui/chat/attach/attach_single_file_preview.cpp @@ -92,7 +92,8 @@ void SingleFilePreview::preparePreview(const PreparedFile &file) { if (filepath.isEmpty()) { auto filename = "image.png"; _name = filename; - _statusText = u"%1x%2"_q.arg(preview.width()).arg(preview.height()); + _statusText = FormatImageSizeText(preview.size() + / preview.devicePixelRatio()); _fileIsImage = true; } else { auto fileinfo = QFileInfo(filepath); diff --git a/Telegram/SourceFiles/ui/text/format_values.cpp b/Telegram/SourceFiles/ui/text/format_values.cpp index d34d926254..b44d7ebd50 100644 --- a/Telegram/SourceFiles/ui/text/format_values.cpp +++ b/Telegram/SourceFiles/ui/text/format_values.cpp @@ -363,4 +363,10 @@ CurrencyRule LookupCurrencyRule(const QString ¤cy) { return result; } +QString FormatImageSizeText(const QSize &size) { + return QString::number(size.width()) + + QChar(215) + + QString::number(size.height()); +} + } // namespace Ui diff --git a/Telegram/SourceFiles/ui/text/format_values.h b/Telegram/SourceFiles/ui/text/format_values.h index ea443fb986..1d47f2b459 100644 --- a/Telegram/SourceFiles/ui/text/format_values.h +++ b/Telegram/SourceFiles/ui/text/format_values.h @@ -22,6 +22,7 @@ inline constexpr auto FileStatusSizeFailed = 0x7FFFFFF2; [[nodiscard]] QString FormatDurationAndSizeText(qint64 duration, qint64 size); [[nodiscard]] QString FormatGifAndSizeText(qint64 size); [[nodiscard]] QString FormatPlayedText(qint64 played, qint64 duration); +[[nodiscard]] QString FormatImageSizeText(const QSize &size); struct CurrencyRule { const char *international = "";