mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-16 06:07:06 +02:00
Move some text formatting to tg_ui:ui/text/format_values.
This commit is contained in:
parent
8634c1f7f3
commit
719bed6e85
38 changed files with 307 additions and 262 deletions
|
@ -34,7 +34,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "history/history_item.h"
|
||||
#include "platform/platform_specific.h"
|
||||
#include "lang/lang_keys.h"
|
||||
#include "layout.h"
|
||||
#include "media/streaming/media_streaming_instance.h"
|
||||
#include "media/streaming/media_streaming_player.h"
|
||||
#include "media/streaming/media_streaming_document.h"
|
||||
|
@ -47,6 +46,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "ui/widgets/input_fields.h"
|
||||
#include "ui/widgets/checkbox.h"
|
||||
#include "ui/widgets/checkbox.h"
|
||||
#include "ui/text/format_values.h"
|
||||
#include "ui/special_buttons.h"
|
||||
#include "ui/text_options.h"
|
||||
#include "window/window_session_controller.h"
|
||||
|
@ -1030,7 +1030,7 @@ void EditCaptionBox::setName(QString nameString, qint64 size) {
|
|||
st::semiboldTextStyle,
|
||||
nameString,
|
||||
Ui::NameTextOptions());
|
||||
_status = formatSizeText(size);
|
||||
_status = Ui::FormatSizeText(size);
|
||||
}
|
||||
|
||||
void EditCaptionBox::keyPressEvent(QKeyEvent *e) {
|
||||
|
|
|
@ -14,6 +14,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "ui/widgets/shadow.h"
|
||||
#include "ui/widgets/continuous_sliders.h"
|
||||
#include "ui/effects/radial_animation.h"
|
||||
#include "ui/text/format_values.h"
|
||||
#include "ui/emoji_config.h"
|
||||
#include "storage/storage_account.h"
|
||||
#include "storage/cache/storage_cache_database.h"
|
||||
|
@ -21,7 +22,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "lang/lang_keys.h"
|
||||
#include "mainwindow.h"
|
||||
#include "main/main_session.h"
|
||||
#include "layout.h"
|
||||
#include "styles/style_layers.h"
|
||||
#include "styles/style_boxes.h"
|
||||
|
||||
|
@ -260,7 +260,7 @@ QString LocalStorageBox::Row::titleText(const Database::TaggedSummary &data) con
|
|||
|
||||
QString LocalStorageBox::Row::sizeText(const Database::TaggedSummary &data) const {
|
||||
return data.totalSize
|
||||
? formatSizeText(data.totalSize)
|
||||
? Ui::FormatSizeText(data.totalSize)
|
||||
: tr::lng_local_storage_empty(tr::now);
|
||||
}
|
||||
|
||||
|
|
|
@ -31,6 +31,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "ui/widgets/input_fields.h"
|
||||
#include "ui/widgets/scroll_area.h"
|
||||
#include "ui/wrap/fade_wrap.h"
|
||||
#include "ui/text/format_values.h"
|
||||
#include "ui/grouped_layout.h"
|
||||
#include "ui/text_options.h"
|
||||
#include "ui/special_buttons.h"
|
||||
|
@ -41,7 +42,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "window/window_session_controller.h"
|
||||
#include "core/application.h"
|
||||
#include "core/core_settings.h"
|
||||
#include "layout.h"
|
||||
#include "facades.h" // App::LambdaDelayed.
|
||||
#include "app.h"
|
||||
#include "styles/style_history.h"
|
||||
|
@ -352,7 +352,7 @@ AlbumThumb::AlbumThumb(
|
|||
} else {
|
||||
auto fileinfo = QFileInfo(filepath);
|
||||
_name = fileinfo.fileName();
|
||||
_status = formatSizeText(fileinfo.size());
|
||||
_status = Ui::FormatSizeText(fileinfo.size());
|
||||
}
|
||||
_nameWidth = st::semiboldFont->width(_name);
|
||||
if (_nameWidth > availableFileWidth) {
|
||||
|
@ -1050,7 +1050,7 @@ void SingleFilePreview::preparePreview(const Storage::PreparedFile &file) {
|
|||
st::semiboldTextStyle,
|
||||
nameString,
|
||||
Ui::NameTextOptions());
|
||||
_statusText = formatSizeText(fileinfo.size());
|
||||
_statusText = Ui::FormatSizeText(fileinfo.size());
|
||||
_statusWidth = qMax(
|
||||
_nameText.maxWidth(),
|
||||
st::normalFont->width(_statusText));
|
||||
|
|
|
@ -24,6 +24,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "ui/widgets/window.h"
|
||||
#include "ui/effects/ripple_animation.h"
|
||||
#include "ui/image/image.h"
|
||||
#include "ui/text/format_values.h"
|
||||
#include "ui/wrap/fade_wrap.h"
|
||||
#include "ui/wrap/padding_wrap.h"
|
||||
#include "ui/platform/ui_platform_utility.h"
|
||||
|
@ -38,7 +39,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "platform/platform_specific.h"
|
||||
#include "base/platform/base_platform_info.h"
|
||||
#include "window/main_window.h"
|
||||
#include "layout.h"
|
||||
#include "app.h"
|
||||
#include "webrtc/webrtc_video_track.h"
|
||||
#include "styles/style_calls.h"
|
||||
|
@ -1070,7 +1070,7 @@ void Panel::updateStatusText(State state) {
|
|||
auto durationMs = _call->getDurationMs();
|
||||
auto durationSeconds = durationMs / 1000;
|
||||
startDurationUpdateTimer(durationMs);
|
||||
return formatDurationText(durationSeconds);
|
||||
return Ui::FormatDurationText(durationSeconds);
|
||||
}
|
||||
return tr::lng_call_status_ended(tr::now);
|
||||
} break;
|
||||
|
|
|
@ -10,6 +10,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "ui/widgets/buttons.h"
|
||||
#include "ui/widgets/labels.h"
|
||||
#include "ui/wrap/padding_wrap.h"
|
||||
#include "ui/text/format_values.h"
|
||||
#include "lang/lang_keys.h"
|
||||
#include "core/application.h"
|
||||
#include "calls/calls_call.h"
|
||||
|
@ -20,7 +21,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "main/main_session.h"
|
||||
#include "boxes/abstract_box.h"
|
||||
#include "base/timer.h"
|
||||
#include "layout.h"
|
||||
#include "app.h"
|
||||
#include "styles/style_calls.h"
|
||||
#include "styles/style_layers.h"
|
||||
|
@ -162,7 +162,7 @@ void TopBar::updateDurationText() {
|
|||
auto durationMs = _call->getDurationMs();
|
||||
auto durationSeconds = durationMs / 1000;
|
||||
startDurationUpdateTimer(durationMs);
|
||||
_durationLabel->setText(formatDurationText(durationSeconds));
|
||||
_durationLabel->setText(Ui::FormatDurationText(durationSeconds));
|
||||
if (_durationLabel->width() != wasWidth) {
|
||||
updateControlsGeometry();
|
||||
}
|
||||
|
|
|
@ -25,6 +25,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "history/view/media/history_view_theme_document.h"
|
||||
#include "history/view/media/history_view_dice.h"
|
||||
#include "ui/image/image.h"
|
||||
#include "ui/text/format_values.h"
|
||||
#include "ui/text_options.h"
|
||||
#include "ui/emoji_config.h"
|
||||
#include "storage/storage_shared_media.h"
|
||||
|
@ -39,7 +40,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "data/data_file_origin.h"
|
||||
#include "main/main_session.h"
|
||||
#include "lang/lang_keys.h"
|
||||
#include "layout.h"
|
||||
#include "storage/file_upload.h"
|
||||
#include "app.h"
|
||||
|
||||
|
@ -882,7 +882,7 @@ QString MediaCall::notificationText() const {
|
|||
lt_type,
|
||||
result,
|
||||
lt_duration,
|
||||
formatDurationWords(_call.duration));
|
||||
Ui::FormatDurationWords(_call.duration));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "export/export_settings.h"
|
||||
#include "export/output/export_output_file.h"
|
||||
#include "base/base_file_utilities.h"
|
||||
#include "ui/text/format_values.h"
|
||||
#include "core/mime_type.h"
|
||||
#include "core/utils.h"
|
||||
#include <QtCore/QDateTime>
|
||||
|
@ -23,11 +24,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
namespace App { // Hackish..
|
||||
QString formatPhone(QString phone);
|
||||
} // namespace App
|
||||
namespace HistoryView {
|
||||
QString FillAmountAndCurrency(uint64 amount, const QString ¤cy);
|
||||
} // namespace HistoryView
|
||||
QString formatSizeText(qint64 size);
|
||||
QString formatDurationText(qint64 duration);
|
||||
|
||||
namespace Export {
|
||||
namespace Data {
|
||||
|
@ -1787,17 +1783,17 @@ Utf8String FormatDateTime(
|
|||
}
|
||||
|
||||
Utf8String FormatMoneyAmount(uint64 amount, const Utf8String ¤cy) {
|
||||
return HistoryView::FillAmountAndCurrency(
|
||||
return Ui::FillAmountAndCurrency(
|
||||
amount,
|
||||
QString::fromUtf8(currency)).toUtf8();
|
||||
}
|
||||
|
||||
Utf8String FormatFileSize(int64 size) {
|
||||
return formatSizeText(size).toUtf8();
|
||||
return Ui::FormatSizeText(size).toUtf8();
|
||||
}
|
||||
|
||||
Utf8String FormatDuration(int64 seconds) {
|
||||
return formatDurationText(seconds).toUtf8();
|
||||
return Ui::FormatDurationText(seconds).toUtf8();
|
||||
}
|
||||
|
||||
} // namespace Data
|
||||
|
|
|
@ -9,7 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
|
||||
#include "export/export_settings.h"
|
||||
#include "lang/lang_keys.h"
|
||||
#include "layout.h"
|
||||
#include "ui/text/format_values.h"
|
||||
|
||||
namespace Export {
|
||||
namespace View {
|
||||
|
@ -61,7 +61,7 @@ Content ContentFromState(
|
|||
return;
|
||||
}
|
||||
const auto progress = state.bytesLoaded / float64(state.bytesCount);
|
||||
const auto info = formatDownloadText(
|
||||
const auto info = Ui::FormatDownloadText(
|
||||
state.bytesLoaded,
|
||||
state.bytesCount);
|
||||
push(id, label, info, progress);
|
||||
|
@ -148,7 +148,7 @@ Content ContentFromState(const FinishedState &state) {
|
|||
tr::lng_export_total_size(
|
||||
tr::now,
|
||||
lt_size,
|
||||
formatSizeText(state.bytesCount)),
|
||||
Ui::FormatSizeText(state.bytesCount)),
|
||||
QString(),
|
||||
1. });
|
||||
return result;
|
||||
|
|
|
@ -26,10 +26,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "ui/toast/toast.h"
|
||||
#include "ui/text/text_utilities.h"
|
||||
#include "ui/text/text_isolated_emoji.h"
|
||||
#include "ui/text/format_values.h"
|
||||
#include "ui/text_options.h"
|
||||
#include "core/application.h"
|
||||
#include "core/ui_integration.h"
|
||||
#include "layout.h"
|
||||
#include "window/notifications_manager.h"
|
||||
#include "window/window_session_controller.h"
|
||||
#include "storage/storage_shared_media.h"
|
||||
|
@ -187,7 +187,7 @@ QString GetErrorTextForSending(
|
|||
return tr::lng_slowmode_enabled(
|
||||
tr::now,
|
||||
lt_left,
|
||||
formatDurationWords(left));
|
||||
Ui::FormatDurationWords(left));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -28,6 +28,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "window/notifications_manager.h"
|
||||
#include "window/window_session_controller.h"
|
||||
#include "storage/storage_shared_media.h"
|
||||
#include "ui/text/format_values.h"
|
||||
#include "ui/text_options.h"
|
||||
|
||||
namespace {
|
||||
|
@ -678,7 +679,7 @@ void HistoryService::createFromMtp(const MTPDmessageService &message) {
|
|||
UpdateComponents(HistoryServicePayment::Bit());
|
||||
auto amount = message.vaction().c_messageActionPaymentSent().vtotal_amount().v;
|
||||
auto currency = qs(message.vaction().c_messageActionPaymentSent().vcurrency());
|
||||
Get<HistoryServicePayment>()->amount = HistoryView::FillAmountAndCurrency(amount, currency);
|
||||
Get<HistoryServicePayment>()->amount = Ui::FillAmountAndCurrency(amount, currency);
|
||||
}
|
||||
if (const auto replyTo = message.vreply_to()) {
|
||||
replyTo->match([&](const MTPDmessageReplyHeader &data) {
|
||||
|
|
|
@ -28,6 +28,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "ui/widgets/shadow.h"
|
||||
#include "ui/effects/ripple_animation.h"
|
||||
#include "ui/text/text_utilities.h" // Ui::Text::ToUpper
|
||||
#include "ui/text/format_values.h"
|
||||
#include "ui/image/image.h"
|
||||
#include "ui/special_buttons.h"
|
||||
#include "inline_bots/inline_bot_result.h"
|
||||
|
@ -4092,7 +4093,7 @@ bool HistoryWidget::showSendingFilesError(
|
|||
return tr::lng_slowmode_enabled(
|
||||
tr::now,
|
||||
lt_left,
|
||||
formatDurationWords(left));
|
||||
Ui::FormatDurationWords(left));
|
||||
}
|
||||
using Error = Storage::PreparedList::Error;
|
||||
switch (list.error) {
|
||||
|
@ -5096,7 +5097,7 @@ bool HistoryWidget::showSlowmodeError() {
|
|||
return tr::lng_slowmode_enabled(
|
||||
tr::now,
|
||||
lt_left,
|
||||
formatDurationWords(left));
|
||||
Ui::FormatDurationWords(left));
|
||||
} else if (_peer->slowmodeApplied()) {
|
||||
if (const auto item = _history->latestSendingMessage()) {
|
||||
if (const auto view = item->mainView()) {
|
||||
|
@ -6337,7 +6338,7 @@ void HistoryWidget::drawRecording(Painter &p, float64 recordActive) {
|
|||
p.drawEllipse(_attachToggle->x() + (_tabbedSelectorToggle->width() - d) / 2, _attachToggle->y() + (_attachToggle->height() - d) / 2, d, d);
|
||||
}
|
||||
|
||||
auto duration = formatDurationText(_recordingSamples / Media::Player::kDefaultFrequency);
|
||||
auto duration = Ui::FormatDurationText(_recordingSamples / Media::Player::kDefaultFrequency);
|
||||
p.setFont(st::historyRecordFont);
|
||||
|
||||
p.setPen(st::historyRecordDurationFg);
|
||||
|
|
|
@ -36,6 +36,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "ui/text_options.h"
|
||||
#include "ui/ui_utility.h"
|
||||
#include "ui/widgets/input_fields.h"
|
||||
#include "ui/text/format_values.h"
|
||||
#include "window/window_session_controller.h"
|
||||
#include "mainwindow.h"
|
||||
|
||||
|
@ -937,7 +938,7 @@ void ComposeControls::drawRecording(Painter &p, float64 recordActive) {
|
|||
p.drawEllipse(_attachToggle->x() + (_tabbedSelectorToggle->width() - d) / 2, _attachToggle->y() + (_attachToggle->height() - d) / 2, d, d);
|
||||
}
|
||||
|
||||
auto duration = formatDurationText(_recordingSamples / ::Media::Player::kDefaultFrequency);
|
||||
auto duration = Ui::FormatDurationText(_recordingSamples / ::Media::Player::kDefaultFrequency);
|
||||
p.setFont(st::historyRecordFont);
|
||||
|
||||
p.setPen(st::historyRecordDurationFg);
|
||||
|
|
|
@ -8,7 +8,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "history/view/media/history_view_call.h"
|
||||
|
||||
#include "lang/lang_keys.h"
|
||||
#include "layout.h"
|
||||
#include "ui/text/format_values.h"
|
||||
#include "layout.h" // FullSelection
|
||||
#include "history/history.h"
|
||||
#include "history/history_item.h"
|
||||
#include "history/view/history_view_element.h"
|
||||
|
@ -50,7 +51,7 @@ Call::Call(
|
|||
lt_time,
|
||||
_status,
|
||||
lt_duration,
|
||||
formatDurationWords(_duration));
|
||||
Ui::FormatDurationWords(_duration));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -8,7 +8,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "history/view/media/history_view_document.h"
|
||||
|
||||
#include "lang/lang_keys.h"
|
||||
#include "layout.h"
|
||||
#include "storage/localstorage.h"
|
||||
#include "media/audio/media_audio.h"
|
||||
#include "media/player/media_player_instance.h"
|
||||
|
@ -18,6 +17,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "history/view/history_view_cursor_state.h"
|
||||
#include "history/view/media/history_view_media_common.h"
|
||||
#include "ui/image/image.h"
|
||||
#include "ui/text/format_values.h"
|
||||
#include "layout.h" // FullSelection
|
||||
#include "data/data_session.h"
|
||||
#include "data/data_document.h"
|
||||
#include "data/data_document_media.h"
|
||||
|
@ -77,7 +78,7 @@ Document::Document(
|
|||
|
||||
setDocumentLinks(_data, item);
|
||||
|
||||
setStatusSize(FileStatusSizeReady);
|
||||
setStatusSize(Ui::FileStatusSizeReady);
|
||||
|
||||
if (const auto captioned = Get<HistoryDocumentCaptioned>()) {
|
||||
captioned->_caption = std::move(caption);
|
||||
|
@ -417,7 +418,7 @@ void Document::draw(Painter &p, const QRect &r, TextSelection selection, crl::ti
|
|||
return 0.;
|
||||
})();
|
||||
if (voice->seeking()) {
|
||||
voiceStatusOverride = formatPlayedText(qRound(progress * voice->_lastDurationMs) / 1000, voice->_lastDurationMs / 1000);
|
||||
voiceStatusOverride = Ui::FormatPlayedText(qRound(progress * voice->_lastDurationMs) / 1000, voice->_lastDurationMs / 1000);
|
||||
}
|
||||
|
||||
// rescale waveform by going in waveform.size * bar_count 1D grid
|
||||
|
@ -739,11 +740,11 @@ void Document::setStatusSize(int newSize, qint64 realDuration) const {
|
|||
: -1);
|
||||
File::setStatusSize(newSize, _data->size, duration, realDuration);
|
||||
if (auto thumbed = Get<HistoryDocumentThumbed>()) {
|
||||
if (_statusSize == FileStatusSizeReady) {
|
||||
if (_statusSize == Ui::FileStatusSizeReady) {
|
||||
thumbed->_link = tr::lng_media_download(tr::now).toUpper();
|
||||
} else if (_statusSize == FileStatusSizeLoaded) {
|
||||
} else if (_statusSize == Ui::FileStatusSizeLoaded) {
|
||||
thumbed->_link = tr::lng_media_open_with(tr::now).toUpper();
|
||||
} else if (_statusSize == FileStatusSizeFailed) {
|
||||
} else if (_statusSize == Ui::FileStatusSizeFailed) {
|
||||
thumbed->_link = tr::lng_media_download(tr::now).toUpper();
|
||||
} else if (_statusSize >= 0) {
|
||||
thumbed->_link = tr::lng_media_cancel(tr::now).toUpper();
|
||||
|
@ -759,15 +760,15 @@ bool Document::updateStatusText() const {
|
|||
auto statusSize = 0;
|
||||
auto realDuration = 0;
|
||||
if (_data->status == FileDownloadFailed || _data->status == FileUploadFailed) {
|
||||
statusSize = FileStatusSizeFailed;
|
||||
statusSize = Ui::FileStatusSizeFailed;
|
||||
} else if (_data->uploading()) {
|
||||
statusSize = _data->uploadingData->offset;
|
||||
} else if (_data->loading()) {
|
||||
statusSize = _data->loadOffset();
|
||||
} else if (dataLoaded()) {
|
||||
statusSize = FileStatusSizeLoaded;
|
||||
statusSize = Ui::FileStatusSizeLoaded;
|
||||
} else {
|
||||
statusSize = FileStatusSizeReady;
|
||||
statusSize = Ui::FileStatusSizeReady;
|
||||
}
|
||||
|
||||
if (_data->isVoiceMessage()) {
|
||||
|
|
|
@ -8,7 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "history/view/media/history_view_file.h"
|
||||
|
||||
#include "lang/lang_keys.h"
|
||||
#include "layout.h"
|
||||
#include "ui/text/format_values.h"
|
||||
#include "history/history_item.h"
|
||||
#include "history/history.h"
|
||||
#include "data/data_document.h"
|
||||
|
@ -56,16 +56,16 @@ void File::refreshParentId(not_null<HistoryItem*> realParent) {
|
|||
|
||||
void File::setStatusSize(int newSize, int fullSize, int duration, qint64 realDuration) const {
|
||||
_statusSize = newSize;
|
||||
if (_statusSize == FileStatusSizeReady) {
|
||||
_statusText = (duration >= 0) ? formatDurationAndSizeText(duration, fullSize) : (duration < -1 ? formatGifAndSizeText(fullSize) : formatSizeText(fullSize));
|
||||
} else if (_statusSize == FileStatusSizeLoaded) {
|
||||
_statusText = (duration >= 0) ? formatDurationText(duration) : (duration < -1 ? qsl("GIF") : formatSizeText(fullSize));
|
||||
} else if (_statusSize == FileStatusSizeFailed) {
|
||||
if (_statusSize == Ui::FileStatusSizeReady) {
|
||||
_statusText = (duration >= 0) ? Ui::FormatDurationAndSizeText(duration, fullSize) : (duration < -1 ? Ui::FormatGifAndSizeText(fullSize) : Ui::FormatSizeText(fullSize));
|
||||
} else if (_statusSize == Ui::FileStatusSizeLoaded) {
|
||||
_statusText = (duration >= 0) ? Ui::FormatDurationText(duration) : (duration < -1 ? qsl("GIF") : Ui::FormatSizeText(fullSize));
|
||||
} else if (_statusSize == Ui::FileStatusSizeFailed) {
|
||||
_statusText = tr::lng_attach_failed(tr::now);
|
||||
} else if (_statusSize >= 0) {
|
||||
_statusText = formatDownloadText(_statusSize, fullSize);
|
||||
_statusText = Ui::FormatDownloadText(_statusSize, fullSize);
|
||||
} else {
|
||||
_statusText = formatPlayedText(-_statusSize - 1, realDuration);
|
||||
_statusText = Ui::FormatPlayedText(-_statusSize - 1, realDuration);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -8,7 +8,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "history/view/media/history_view_gif.h"
|
||||
|
||||
#include "lang/lang_keys.h"
|
||||
#include "layout.h"
|
||||
#include "mainwindow.h"
|
||||
#include "main/main_session.h"
|
||||
#include "main/main_session_settings.h"
|
||||
|
@ -28,6 +27,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "window/window_session_controller.h"
|
||||
#include "core/application.h" // Application::showDocument.
|
||||
#include "ui/image/image.h"
|
||||
#include "ui/text/format_values.h"
|
||||
#include "ui/grouped_layout.h"
|
||||
#include "data/data_session.h"
|
||||
#include "data/data_streaming.h"
|
||||
|
@ -35,6 +35,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "data/data_file_origin.h"
|
||||
#include "data/data_document_media.h"
|
||||
#include "app.h"
|
||||
#include "layout.h" // FullSelection
|
||||
#include "styles/style_history.h"
|
||||
|
||||
namespace HistoryView {
|
||||
|
@ -45,8 +46,8 @@ constexpr auto kUseNonBlurredThreshold = 240;
|
|||
constexpr auto kMaxInlineArea = 1920 * 1080;
|
||||
|
||||
int gifMaxStatusWidth(DocumentData *document) {
|
||||
auto result = st::normalFont->width(formatDownloadText(document->size, document->size));
|
||||
accumulate_max(result, st::normalFont->width(formatGifAndSizeText(document->size)));
|
||||
auto result = st::normalFont->width(Ui::FormatDownloadText(document->size, document->size));
|
||||
accumulate_max(result, st::normalFont->width(Ui::FormatGifAndSizeText(document->size)));
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -75,10 +76,10 @@ Gif::Gif(
|
|||
: File(parent, realParent)
|
||||
, _data(document)
|
||||
, _caption(st::minPhotoSize - st::msgPadding.left() - st::msgPadding.right())
|
||||
, _downloadSize(formatSizeText(_data->size)) {
|
||||
, _downloadSize(Ui::FormatSizeText(_data->size)) {
|
||||
setDocumentLinks(_data, realParent);
|
||||
|
||||
setStatusSize(FileStatusSizeReady);
|
||||
setStatusSize(Ui::FileStatusSizeReady);
|
||||
|
||||
refreshCaption();
|
||||
if ((_dataMedia = _data->activeMediaView())) {
|
||||
|
@ -1225,10 +1226,10 @@ void Gif::validateGroupedCache(
|
|||
void Gif::setStatusSize(int newSize) const {
|
||||
if (newSize < 0) {
|
||||
_statusSize = newSize;
|
||||
_statusText = formatDurationText(-newSize - 1);
|
||||
_statusText = Ui::FormatDurationText(-newSize - 1);
|
||||
} else if (_data->isVideoMessage()) {
|
||||
_statusSize = newSize;
|
||||
_statusText = formatDurationText(_data->getDuration());
|
||||
_statusText = Ui::FormatDurationText(_data->getDuration());
|
||||
} else {
|
||||
File::setStatusSize(
|
||||
newSize,
|
||||
|
@ -1244,15 +1245,15 @@ void Gif::updateStatusText() const {
|
|||
auto statusSize = 0;
|
||||
auto realDuration = 0;
|
||||
if (_data->status == FileDownloadFailed || _data->status == FileUploadFailed) {
|
||||
statusSize = FileStatusSizeFailed;
|
||||
statusSize = Ui::FileStatusSizeFailed;
|
||||
} else if (_data->uploading()) {
|
||||
statusSize = _data->uploadingData->offset;
|
||||
} else if (!downloadInCorner() && _data->loading()) {
|
||||
statusSize = _data->loadOffset();
|
||||
} else if (dataLoaded() || _dataMedia->canBePlayed()) {
|
||||
statusSize = FileStatusSizeLoaded;
|
||||
statusSize = Ui::FileStatusSizeLoaded;
|
||||
} else {
|
||||
statusSize = FileStatusSizeReady;
|
||||
statusSize = Ui::FileStatusSizeReady;
|
||||
}
|
||||
const auto round = activeRoundStreamed();
|
||||
const auto own = activeOwnStreamed();
|
||||
|
|
|
@ -14,6 +14,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "history/view/media/history_view_photo.h"
|
||||
#include "history/view/media/history_view_media_common.h"
|
||||
#include "ui/text_options.h"
|
||||
#include "ui/text/format_values.h"
|
||||
#include "data/data_media_types.h"
|
||||
#include "app.h"
|
||||
#include "styles/style_history.h"
|
||||
|
@ -51,7 +52,7 @@ void Invoice::fillFromData(not_null<Data::Invoice*> invoice) {
|
|||
return tr::lng_payments_invoice_label(tr::now);
|
||||
};
|
||||
auto statusText = TextWithEntities {
|
||||
FillAmountAndCurrency(invoice->amount, invoice->currency),
|
||||
Ui::FillAmountAndCurrency(invoice->amount, invoice->currency),
|
||||
EntitiesInText()
|
||||
};
|
||||
statusText.entities.push_back({
|
||||
|
@ -385,59 +386,4 @@ int Invoice::bottomInfoPadding() const {
|
|||
return result;
|
||||
}
|
||||
|
||||
QString FillAmountAndCurrency(uint64 amount, const QString ¤cy) {
|
||||
static const auto ShortCurrencyNames = QMap<QString, QString> {
|
||||
{ qsl("USD"), QString::fromUtf8("\x24") },
|
||||
{ qsl("GBP"), QString::fromUtf8("\xC2\xA3") },
|
||||
{ qsl("EUR"), QString::fromUtf8("\xE2\x82\xAC") },
|
||||
{ qsl("JPY"), QString::fromUtf8("\xC2\xA5") },
|
||||
};
|
||||
static const auto Denominators = QMap<QString, int> {
|
||||
{ qsl("CLF"), 10000 },
|
||||
{ qsl("BHD"), 1000 },
|
||||
{ qsl("IQD"), 1000 },
|
||||
{ qsl("JOD"), 1000 },
|
||||
{ qsl("KWD"), 1000 },
|
||||
{ qsl("LYD"), 1000 },
|
||||
{ qsl("OMR"), 1000 },
|
||||
{ qsl("TND"), 1000 },
|
||||
{ qsl("BIF"), 1 },
|
||||
{ qsl("BYR"), 1 },
|
||||
{ qsl("CLP"), 1 },
|
||||
{ qsl("CVE"), 1 },
|
||||
{ qsl("DJF"), 1 },
|
||||
{ qsl("GNF"), 1 },
|
||||
{ qsl("ISK"), 1 },
|
||||
{ qsl("JPY"), 1 },
|
||||
{ qsl("KMF"), 1 },
|
||||
{ qsl("KRW"), 1 },
|
||||
{ qsl("MGA"), 1 },
|
||||
{ qsl("PYG"), 1 },
|
||||
{ qsl("RWF"), 1 },
|
||||
{ qsl("UGX"), 1 },
|
||||
{ qsl("UYI"), 1 },
|
||||
{ qsl("VND"), 1 },
|
||||
{ qsl("VUV"), 1 },
|
||||
{ qsl("XAF"), 1 },
|
||||
{ qsl("XOF"), 1 },
|
||||
{ qsl("XPF"), 1 },
|
||||
{ qsl("MRO"), 10 },
|
||||
};
|
||||
const auto currencyText = ShortCurrencyNames.value(currency, currency);
|
||||
const auto denominator = Denominators.value(currency, 100);
|
||||
const auto currencyValue = amount / float64(denominator);
|
||||
const auto digits = [&] {
|
||||
auto result = 0;
|
||||
for (auto test = 1; test < denominator; test *= 10) {
|
||||
++result;
|
||||
}
|
||||
return result;
|
||||
}();
|
||||
return QLocale::system().toCurrencyString(currencyValue, currencyText);
|
||||
//auto amountBucks = amount / 100;
|
||||
//auto amountCents = amount % 100;
|
||||
//auto amountText = qsl("%1,%2").arg(amountBucks).arg(amountCents, 2, 10, QChar('0'));
|
||||
//return currencyText + amountText;
|
||||
}
|
||||
|
||||
} // namespace HistoryView
|
||||
|
|
|
@ -102,6 +102,4 @@ private:
|
|||
|
||||
};
|
||||
|
||||
QString FillAmountAndCurrency(uint64 amount, const QString ¤cy);
|
||||
|
||||
} // namespace HistoryView
|
||||
|
|
|
@ -7,7 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
*/
|
||||
#include "history/view/media/history_view_media_common.h"
|
||||
|
||||
#include "layout.h"
|
||||
#include "ui/text/format_values.h"
|
||||
#include "data/data_document.h"
|
||||
#include "history/view/history_view_element.h"
|
||||
#include "history/view/media/history_view_media_grouped.h"
|
||||
|
@ -21,18 +21,18 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
namespace HistoryView {
|
||||
|
||||
int documentMaxStatusWidth(DocumentData *document) {
|
||||
auto result = st::normalFont->width(formatDownloadText(document->size, document->size));
|
||||
auto result = st::normalFont->width(Ui::FormatDownloadText(document->size, document->size));
|
||||
const auto duration = document->getDuration();
|
||||
if (const auto song = document->song()) {
|
||||
accumulate_max(result, st::normalFont->width(formatPlayedText(duration, duration)));
|
||||
accumulate_max(result, st::normalFont->width(formatDurationAndSizeText(duration, document->size)));
|
||||
accumulate_max(result, st::normalFont->width(Ui::FormatPlayedText(duration, duration)));
|
||||
accumulate_max(result, st::normalFont->width(Ui::FormatDurationAndSizeText(duration, document->size)));
|
||||
} else if (const auto voice = document->voice()) {
|
||||
accumulate_max(result, st::normalFont->width(formatPlayedText(duration, duration)));
|
||||
accumulate_max(result, st::normalFont->width(formatDurationAndSizeText(duration, document->size)));
|
||||
accumulate_max(result, st::normalFont->width(Ui::FormatPlayedText(duration, duration)));
|
||||
accumulate_max(result, st::normalFont->width(Ui::FormatDurationAndSizeText(duration, document->size)));
|
||||
} else if (document->isVideoFile()) {
|
||||
accumulate_max(result, st::normalFont->width(formatDurationAndSizeText(duration, document->size)));
|
||||
accumulate_max(result, st::normalFont->width(Ui::FormatDurationAndSizeText(duration, document->size)));
|
||||
} else {
|
||||
accumulate_max(result, st::normalFont->width(formatSizeText(document->size)));
|
||||
accumulate_max(result, st::normalFont->width(Ui::FormatSizeText(document->size)));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "calls/calls_instance.h"
|
||||
#include "ui/text_options.h"
|
||||
#include "ui/text/text_utilities.h"
|
||||
#include "ui/text/format_values.h"
|
||||
#include "ui/effects/animations.h"
|
||||
#include "ui/effects/radial_animation.h"
|
||||
#include "ui/effects/ripple_animation.h"
|
||||
|
@ -26,8 +27,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "data/data_session.h"
|
||||
#include "base/unixtime.h"
|
||||
#include "base/timer.h"
|
||||
#include "layout.h"
|
||||
#include "main/main_session.h"
|
||||
#include "layout.h" // FullSelection
|
||||
#include "apiwrap.h"
|
||||
#include "styles/style_history.h"
|
||||
#include "styles/style_widgets.h"
|
||||
|
@ -931,7 +932,7 @@ void Poll::paintCloseByTimer(
|
|||
} else {
|
||||
_close->radial.stop();
|
||||
}
|
||||
const auto time = formatDurationText(int(std::ceil(left / 1000.)));
|
||||
const auto time = Ui::FormatDurationText(int(std::ceil(left / 1000.)));
|
||||
const auto outbg = _parent->hasOutLayout();
|
||||
const auto selected = (selection == FullSelection);
|
||||
const auto &icon = selected
|
||||
|
|
|
@ -7,7 +7,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
*/
|
||||
#include "history/view/media/history_view_theme_document.h"
|
||||
|
||||
#include "layout.h"
|
||||
#include "history/history.h"
|
||||
#include "history/history_item.h"
|
||||
#include "history/view/history_view_element.h"
|
||||
|
@ -17,7 +16,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "data/data_document_media.h"
|
||||
#include "data/data_file_origin.h"
|
||||
#include "base/qthelp_url.h"
|
||||
#include "ui/text/format_values.h"
|
||||
#include "window/themes/window_theme.h"
|
||||
#include "layout.h" // FullSelection
|
||||
#include "app.h"
|
||||
#include "styles/style_history.h"
|
||||
|
||||
|
@ -37,7 +38,7 @@ ThemeDocument::ThemeDocument(
|
|||
|
||||
_data->loadThumbnail(_parent->data()->fullId());
|
||||
setDocumentLinks(_data, parent->data());
|
||||
setStatusSize(FileStatusSizeReady, _data->size, -1, 0);
|
||||
setStatusSize(Ui::FileStatusSizeReady, _data->size, -1, 0);
|
||||
}
|
||||
|
||||
ThemeDocument::~ThemeDocument() {
|
||||
|
|
|
@ -7,7 +7,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
*/
|
||||
#include "history/view/media/history_view_web_page.h"
|
||||
|
||||
#include "layout.h"
|
||||
#include "core/click_handler_types.h"
|
||||
#include "core/ui_integration.h"
|
||||
#include "lang/lang_keys.h"
|
||||
|
@ -19,6 +18,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "history/view/media/history_view_media_common.h"
|
||||
#include "ui/image/image.h"
|
||||
#include "ui/text_options.h"
|
||||
#include "ui/text/format_values.h"
|
||||
#include "layout.h" // FullSelection
|
||||
#include "data/data_session.h"
|
||||
#include "data/data_media_types.h"
|
||||
#include "data/data_web_page.h"
|
||||
|
@ -286,7 +287,7 @@ QSize WebPage::countOptimalSize() {
|
|||
}
|
||||
}
|
||||
if (_data->type == WebPageType::Video && _data->duration) {
|
||||
_duration = formatDurationText(_data->duration);
|
||||
_duration = Ui::FormatDurationText(_data->duration);
|
||||
_durationWidth = st::msgDateFont->width(_duration);
|
||||
}
|
||||
maxWidth += st::msgPadding.left() + st::webPageLeft + st::msgPadding.right();
|
||||
|
|
|
@ -24,6 +24,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "history/history_location_manager.h"
|
||||
#include "history/view/history_view_cursor_state.h"
|
||||
#include "ui/image/image.h"
|
||||
#include "ui/text/format_values.h"
|
||||
#include "main/main_session.h"
|
||||
#include "lang/lang_keys.h"
|
||||
#include "app.h"
|
||||
|
@ -673,7 +674,7 @@ Video::Video(not_null<Context*> context, not_null<Result*> result)
|
|||
, _title(st::emojiPanWidth - st::emojiScroll.width - st::inlineResultsLeft - st::inlineThumbSize - st::inlineThumbSkip)
|
||||
, _description(st::emojiPanWidth - st::emojiScroll.width - st::inlineResultsLeft - st::inlineThumbSize - st::inlineThumbSkip) {
|
||||
if (int duration = content_duration()) {
|
||||
_duration = formatDurationText(duration);
|
||||
_duration = Ui::FormatDurationText(duration);
|
||||
_durationWidth = st::normalFont->width(_duration);
|
||||
}
|
||||
}
|
||||
|
@ -904,7 +905,9 @@ void File::paint(Painter &p, const QRect &clip, const PaintContext *context) con
|
|||
|
||||
p.setPen(st::inlineDescriptionFg);
|
||||
bool drawStatusSize = true;
|
||||
if (_statusSize == FileStatusSizeReady || _statusSize == FileStatusSizeLoaded || _statusSize == FileStatusSizeFailed) {
|
||||
if (_statusSize == Ui::FileStatusSizeReady
|
||||
|| _statusSize == Ui::FileStatusSizeLoaded
|
||||
|| _statusSize == Ui::FileStatusSizeFailed) {
|
||||
if (!_description.isEmpty()) {
|
||||
_description.drawLeftElided(p, left, descriptionTop, _width - left, _width);
|
||||
drawStatusSize = false;
|
||||
|
@ -1000,15 +1003,15 @@ bool File::updateStatusText() const {
|
|||
bool showPause = false;
|
||||
int32 statusSize = 0, realDuration = 0;
|
||||
if (_document->status == FileDownloadFailed || _document->status == FileUploadFailed) {
|
||||
statusSize = FileStatusSizeFailed;
|
||||
statusSize = Ui::FileStatusSizeFailed;
|
||||
} else if (_document->uploading()) {
|
||||
statusSize = _document->uploadingData->offset;
|
||||
} else if (_document->loading()) {
|
||||
statusSize = _document->loadOffset();
|
||||
} else if (_documentMedia->loaded()) {
|
||||
statusSize = FileStatusSizeLoaded;
|
||||
statusSize = Ui::FileStatusSizeLoaded;
|
||||
} else {
|
||||
statusSize = FileStatusSizeReady;
|
||||
statusSize = Ui::FileStatusSizeReady;
|
||||
}
|
||||
|
||||
if (_document->isVoiceMessage() || _document->isAudioFile()) {
|
||||
|
@ -1037,16 +1040,16 @@ bool File::updateStatusText() const {
|
|||
|
||||
void File::setStatusSize(int32 newSize, int32 fullSize, int32 duration, qint64 realDuration) const {
|
||||
_statusSize = newSize;
|
||||
if (_statusSize == FileStatusSizeReady) {
|
||||
_statusText = (duration >= 0) ? formatDurationAndSizeText(duration, fullSize) : (duration < -1 ? formatGifAndSizeText(fullSize) : formatSizeText(fullSize));
|
||||
} else if (_statusSize == FileStatusSizeLoaded) {
|
||||
_statusText = (duration >= 0) ? formatDurationText(duration) : (duration < -1 ? qsl("GIF") : formatSizeText(fullSize));
|
||||
} else if (_statusSize == FileStatusSizeFailed) {
|
||||
if (_statusSize == Ui::FileStatusSizeReady) {
|
||||
_statusText = (duration >= 0) ? Ui::FormatDurationAndSizeText(duration, fullSize) : (duration < -1 ? Ui::FormatGifAndSizeText(fullSize) : Ui::FormatSizeText(fullSize));
|
||||
} else if (_statusSize == Ui::FileStatusSizeLoaded) {
|
||||
_statusText = (duration >= 0) ? Ui::FormatDurationText(duration) : (duration < -1 ? qsl("GIF") : Ui::FormatSizeText(fullSize));
|
||||
} else if (_statusSize == Ui::FileStatusSizeFailed) {
|
||||
_statusText = tr::lng_attach_failed(tr::now);
|
||||
} else if (_statusSize >= 0) {
|
||||
_statusText = formatDownloadText(_statusSize, fullSize);
|
||||
_statusText = Ui::FormatDownloadText(_statusSize, fullSize);
|
||||
} else {
|
||||
_statusText = formatPlayedText(-_statusSize - 1, realDuration);
|
||||
_statusText = Ui::FormatPlayedText(-_statusSize - 1, realDuration);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -11,6 +11,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "lang/lang_hardcoded.h"
|
||||
#include "lang/lang_text_entity.h"
|
||||
|
||||
#include <QDateTime>
|
||||
|
||||
[[nodiscard]] QString langDayOfMonth(const QDate &date);
|
||||
[[nodiscard]] QString langDayOfMonthFull(const QDate &date);
|
||||
[[nodiscard]] QString langMonthOfYear(int month, int year);
|
||||
|
|
|
@ -20,66 +20,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "history/view/history_view_cursor_state.h"
|
||||
#include "app.h"
|
||||
|
||||
QString formatSizeText(qint64 size) {
|
||||
if (size >= 1024 * 1024) { // more than 1 mb
|
||||
qint64 sizeTenthMb = (size * 10 / (1024 * 1024));
|
||||
return QString::number(sizeTenthMb / 10) + '.' + QString::number(sizeTenthMb % 10) + qsl(" MB");
|
||||
}
|
||||
if (size >= 1024) {
|
||||
qint64 sizeTenthKb = (size * 10 / 1024);
|
||||
return QString::number(sizeTenthKb / 10) + '.' + QString::number(sizeTenthKb % 10) + qsl(" KB");
|
||||
}
|
||||
return QString::number(size) + qsl(" B");
|
||||
}
|
||||
|
||||
QString formatDownloadText(qint64 ready, qint64 total) {
|
||||
QString readyStr, totalStr, mb;
|
||||
if (total >= 1024 * 1024) { // more than 1 mb
|
||||
qint64 readyTenthMb = (ready * 10 / (1024 * 1024)), totalTenthMb = (total * 10 / (1024 * 1024));
|
||||
readyStr = QString::number(readyTenthMb / 10) + '.' + QString::number(readyTenthMb % 10);
|
||||
totalStr = QString::number(totalTenthMb / 10) + '.' + QString::number(totalTenthMb % 10);
|
||||
mb = qsl("MB");
|
||||
} else if (total >= 1024) {
|
||||
qint64 readyKb = (ready / 1024), totalKb = (total / 1024);
|
||||
readyStr = QString::number(readyKb);
|
||||
totalStr = QString::number(totalKb);
|
||||
mb = qsl("KB");
|
||||
} else {
|
||||
readyStr = QString::number(ready);
|
||||
totalStr = QString::number(total);
|
||||
mb = qsl("B");
|
||||
}
|
||||
return tr::lng_save_downloaded(tr::now, lt_ready, readyStr, lt_total, totalStr, lt_mb, mb);
|
||||
}
|
||||
|
||||
QString formatDurationText(qint64 duration) {
|
||||
qint64 hours = (duration / 3600), minutes = (duration % 3600) / 60, seconds = duration % 60;
|
||||
return (hours ? QString::number(hours) + ':' : QString()) + (minutes >= 10 ? QString() : QString('0')) + QString::number(minutes) + ':' + (seconds >= 10 ? QString() : QString('0')) + QString::number(seconds);
|
||||
}
|
||||
|
||||
QString formatDurationWords(qint64 duration) {
|
||||
if (duration > 59) {
|
||||
auto minutes = (duration / 60);
|
||||
auto minutesCount = tr::lng_duration_minsec_minutes(tr::now, lt_count, minutes);
|
||||
auto seconds = (duration % 60);
|
||||
auto secondsCount = tr::lng_duration_minsec_seconds(tr::now, lt_count, seconds);
|
||||
return tr::lng_duration_minutes_seconds(tr::now, lt_minutes_count, minutesCount, lt_seconds_count, secondsCount);
|
||||
}
|
||||
return tr::lng_duration_seconds(tr::now, lt_count, duration);
|
||||
}
|
||||
|
||||
QString formatDurationAndSizeText(qint64 duration, qint64 size) {
|
||||
return tr::lng_duration_and_size(tr::now, lt_duration, formatDurationText(duration), lt_size, formatSizeText(size));
|
||||
}
|
||||
|
||||
QString formatGifAndSizeText(qint64 size) {
|
||||
return tr::lng_duration_and_size(tr::now, lt_duration, qsl("GIF"), lt_size, formatSizeText(size));
|
||||
}
|
||||
|
||||
QString formatPlayedText(qint64 played, qint64 duration) {
|
||||
return tr::lng_duration_played(tr::now, lt_played, formatDurationText(played), lt_duration, formatDurationText(duration));
|
||||
}
|
||||
|
||||
int32 documentColorIndex(DocumentData *document, QString &ext) {
|
||||
auto colorIndex = 0;
|
||||
|
||||
|
|
|
@ -52,18 +52,6 @@ inline bool IsGroupItemSelection(
|
|||
: selection;
|
||||
}
|
||||
|
||||
static const int32 FileStatusSizeReady = 0x7FFFFFF0;
|
||||
static const int32 FileStatusSizeLoaded = 0x7FFFFFF1;
|
||||
static const int32 FileStatusSizeFailed = 0x7FFFFFF2;
|
||||
|
||||
QString formatSizeText(qint64 size);
|
||||
QString formatDownloadText(qint64 ready, qint64 total);
|
||||
QString formatDurationText(qint64 duration);
|
||||
QString formatDurationWords(qint64 duration);
|
||||
QString formatDurationAndSizeText(qint64 duration, qint64 size);
|
||||
QString formatGifAndSizeText(qint64 size);
|
||||
QString formatPlayedText(qint64 played, qint64 duration);
|
||||
|
||||
int32 documentColorIndex(DocumentData *document, QString &ext);
|
||||
style::color documentColor(int colorIndex);
|
||||
style::color documentDarkColor(int colorIndex);
|
||||
|
|
|
@ -18,6 +18,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "ui/widgets/shadow.h"
|
||||
#include "ui/widgets/buttons.h"
|
||||
#include "ui/effects/ripple_animation.h"
|
||||
#include "ui/text/format_values.h"
|
||||
#include "lang/lang_keys.h"
|
||||
#include "media/audio/media_audio.h"
|
||||
#include "media/view/media_view_playback_progress.h"
|
||||
|
@ -28,7 +29,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "styles/style_media_view.h"
|
||||
#include "history/history_item.h"
|
||||
#include "storage/storage_account.h"
|
||||
#include "layout.h"
|
||||
#include "main/main_session.h"
|
||||
#include "facades.h"
|
||||
|
||||
|
@ -496,7 +496,7 @@ void Widget::updateTimeText(const TrackState &state) {
|
|||
_playbackSlider->setDisabled(true);
|
||||
} else {
|
||||
display = display / frequency;
|
||||
_time = formatDurationText(display);
|
||||
_time = Ui::FormatDurationText(display);
|
||||
_playbackSlider->setDisabled(false);
|
||||
}
|
||||
if (_seekPositionMs < 0) {
|
||||
|
@ -508,7 +508,7 @@ void Widget::updateTimeLabel() {
|
|||
auto timeLabelWidth = _timeLabel->width();
|
||||
if (_seekPositionMs >= 0) {
|
||||
auto playAlready = _seekPositionMs / 1000LL;
|
||||
_timeLabel->setText(formatDurationText(playAlready));
|
||||
_timeLabel->setText(Ui::FormatDurationText(playAlready));
|
||||
} else {
|
||||
_timeLabel->setText(_time);
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "ui/text/text_utilities.h"
|
||||
#include "ui/platform/ui_platform_utility.h"
|
||||
#include "ui/toast/toast.h"
|
||||
#include "ui/text/format_values.h"
|
||||
#include "ui/text_options.h"
|
||||
#include "ui/ui_utility.h"
|
||||
#include "boxes/confirm_box.h"
|
||||
|
@ -591,7 +592,7 @@ void OverlayWidget::updateDocSize() {
|
|||
}
|
||||
_docSize = tr::lng_media_save_progress(tr::now, lt_ready, readyStr, lt_total, totalStr, lt_mb, mb);
|
||||
} else {
|
||||
_docSize = formatSizeText(_document->size);
|
||||
_docSize = Ui::FormatSizeText(_document->size);
|
||||
}
|
||||
_docSizeWidth = st::mediaviewFont->width(_docSize);
|
||||
int32 maxw = st::mediaviewFileSize.width() - st::mediaviewFileIconSize - st::mediaviewFilePadding * 3;
|
||||
|
|
|
@ -26,8 +26,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "ui/widgets/buttons.h"
|
||||
#include "ui/wrap/fade_wrap.h"
|
||||
#include "ui/widgets/shadow.h"
|
||||
#include "ui/text/format_values.h"
|
||||
#include "window/window_controller.h"
|
||||
#include "layout.h" // formatDurationText
|
||||
#include "styles/style_window.h"
|
||||
#include "styles/style_media_view.h"
|
||||
#include "styles/style_calls.h" // st::callShadow
|
||||
|
@ -1378,9 +1378,9 @@ void Pip::updatePlaybackTexts(
|
|||
int64 frequency) {
|
||||
const auto playAlready = position / frequency;
|
||||
const auto playLeft = (length / frequency) - playAlready;
|
||||
const auto already = formatDurationText(playAlready);
|
||||
const auto already = Ui::FormatDurationText(playAlready);
|
||||
const auto minus = QChar(8722);
|
||||
const auto left = minus + formatDurationText(playLeft);
|
||||
const auto left = minus + Ui::FormatDurationText(playLeft);
|
||||
if (_timeAlready == already && _timeLeft == left) {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -14,8 +14,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "ui/effects/fade_animation.h"
|
||||
#include "ui/widgets/buttons.h"
|
||||
#include "ui/widgets/popup_menu.h"
|
||||
#include "ui/text/format_values.h"
|
||||
#include "lang/lang_keys.h"
|
||||
#include "layout.h"
|
||||
#include "app.h"
|
||||
#include "styles/style_media_view.h"
|
||||
|
||||
|
@ -333,9 +333,9 @@ void PlaybackControls::updateTimeTexts(const Player::TrackState &state) {
|
|||
|
||||
_lastDurationMs = (state.length * crl::time(1000)) / playFrequency;
|
||||
|
||||
_timeAlready = formatDurationText(playAlready);
|
||||
_timeAlready = Ui::FormatDurationText(playAlready);
|
||||
auto minus = QChar(8722);
|
||||
_timeLeft = minus + formatDurationText(playLeft);
|
||||
_timeLeft = minus + Ui::FormatDurationText(playLeft);
|
||||
|
||||
if (_seekPositionMs < 0) {
|
||||
refreshTimeTexts();
|
||||
|
@ -350,9 +350,9 @@ void PlaybackControls::refreshTimeTexts() {
|
|||
auto playAlready = _seekPositionMs / crl::time(1000);
|
||||
auto playLeft = (_lastDurationMs / crl::time(1000)) - playAlready;
|
||||
|
||||
timeAlready = formatDurationText(playAlready);
|
||||
timeAlready = Ui::FormatDurationText(playAlready);
|
||||
auto minus = QChar(8722);
|
||||
timeLeft = minus + formatDurationText(playLeft);
|
||||
timeLeft = minus + Ui::FormatDurationText(playLeft);
|
||||
}
|
||||
|
||||
_playedAlready->setText(timeAlready, &alreadyChanged);
|
||||
|
|
|
@ -36,6 +36,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "base/unixtime.h"
|
||||
#include "ui/effects/round_checkbox.h"
|
||||
#include "ui/image/image.h"
|
||||
#include "ui/text/format_values.h"
|
||||
#include "ui/text_options.h"
|
||||
#include "app.h"
|
||||
|
||||
|
@ -275,16 +276,16 @@ RadialProgressItem::~RadialProgressItem() = default;
|
|||
|
||||
void StatusText::update(int newSize, int fullSize, int duration, crl::time realDuration) {
|
||||
setSize(newSize);
|
||||
if (_size == FileStatusSizeReady) {
|
||||
_text = (duration >= 0) ? formatDurationAndSizeText(duration, fullSize) : (duration < -1 ? formatGifAndSizeText(fullSize) : formatSizeText(fullSize));
|
||||
} else if (_size == FileStatusSizeLoaded) {
|
||||
_text = (duration >= 0) ? formatDurationText(duration) : (duration < -1 ? qsl("GIF") : formatSizeText(fullSize));
|
||||
} else if (_size == FileStatusSizeFailed) {
|
||||
if (_size == Ui::FileStatusSizeReady) {
|
||||
_text = (duration >= 0) ? Ui::FormatDurationAndSizeText(duration, fullSize) : (duration < -1 ? Ui::FormatGifAndSizeText(fullSize) : Ui::FormatSizeText(fullSize));
|
||||
} else if (_size == Ui::FileStatusSizeLoaded) {
|
||||
_text = (duration >= 0) ? Ui::FormatDurationText(duration) : (duration < -1 ? qsl("GIF") : Ui::FormatSizeText(fullSize));
|
||||
} else if (_size == Ui::FileStatusSizeFailed) {
|
||||
_text = tr::lng_attach_failed(tr::now);
|
||||
} else if (_size >= 0) {
|
||||
_text = formatDownloadText(_size, fullSize);
|
||||
_text = Ui::FormatDownloadText(_size, fullSize);
|
||||
} else {
|
||||
_text = formatPlayedText(-_size - 1, realDuration);
|
||||
_text = Ui::FormatPlayedText(-_size - 1, realDuration);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -416,7 +417,7 @@ Video::Video(
|
|||
not_null<DocumentData*> video)
|
||||
: RadialProgressItem(delegate, parent)
|
||||
, _data(video)
|
||||
, _duration(formatDurationText(_data->getDuration())) {
|
||||
, _duration(Ui::FormatDurationText(_data->getDuration())) {
|
||||
setDocumentLinks(_data);
|
||||
_data->loadThumbnail(parent->fullId());
|
||||
}
|
||||
|
@ -593,19 +594,19 @@ void Video::updateStatusText() {
|
|||
bool showPause = false;
|
||||
int statusSize = 0;
|
||||
if (_data->status == FileDownloadFailed || _data->status == FileUploadFailed) {
|
||||
statusSize = FileStatusSizeFailed;
|
||||
statusSize = Ui::FileStatusSizeFailed;
|
||||
} else if (_data->uploading()) {
|
||||
statusSize = _data->uploadingData->offset;
|
||||
} else if (dataLoaded()) {
|
||||
statusSize = FileStatusSizeLoaded;
|
||||
statusSize = Ui::FileStatusSizeLoaded;
|
||||
} else {
|
||||
statusSize = FileStatusSizeReady;
|
||||
statusSize = Ui::FileStatusSizeReady;
|
||||
}
|
||||
if (statusSize != _status.size()) {
|
||||
int status = statusSize, size = _data->size;
|
||||
if (statusSize >= 0 && statusSize < 0x7F000000) {
|
||||
size = status;
|
||||
status = FileStatusSizeReady;
|
||||
status = Ui::FileStatusSizeReady;
|
||||
}
|
||||
_status.update(status, size, -1, 0);
|
||||
_status.setSize(statusSize);
|
||||
|
@ -639,7 +640,7 @@ Voice::Voice(
|
|||
lt_date,
|
||||
dateText,
|
||||
lt_duration,
|
||||
formatDurationText(duration())),
|
||||
Ui::FormatDurationText(duration())),
|
||||
opts);
|
||||
_details.setLink(1, goToMessageClickHandler(parent));
|
||||
}
|
||||
|
@ -750,7 +751,7 @@ void Voice::paint(Painter &p, const QRect &clip, TextSelection selection, const
|
|||
p.setFont(st::normalFont);
|
||||
p.setPen(selected ? st::mediaInFgSelected : st::mediaInFg);
|
||||
int32 unreadx = nameleft;
|
||||
if (_status.size() == FileStatusSizeLoaded || _status.size() == FileStatusSizeReady) {
|
||||
if (_status.size() == Ui::FileStatusSizeLoaded || _status.size() == Ui::FileStatusSizeReady) {
|
||||
p.setTextPalette(selected ? st::mediaInPaletteSelected : st::mediaInPalette);
|
||||
_details.drawLeftElided(p, nameleft, statustop, namewidth, _width);
|
||||
p.restoreTextPalette();
|
||||
|
@ -815,7 +816,7 @@ TextState Voice::getState(
|
|||
st::normalFont->height,
|
||||
_width);
|
||||
if (statusrect.contains(point)) {
|
||||
if (_status.size() == FileStatusSizeLoaded || _status.size() == FileStatusSizeReady) {
|
||||
if (_status.size() == Ui::FileStatusSizeLoaded || _status.size() == Ui::FileStatusSizeReady) {
|
||||
auto textState = _details.getStateLeft(point - QPoint(nameleft, statustop), _width, _width);
|
||||
result.link = textState.link;
|
||||
result.cursor = textState.uponSymbol
|
||||
|
@ -895,11 +896,11 @@ bool Voice::updateStatusText() {
|
|||
bool showPause = false;
|
||||
int32 statusSize = 0, realDuration = 0;
|
||||
if (_data->status == FileDownloadFailed || _data->status == FileUploadFailed) {
|
||||
statusSize = FileStatusSizeFailed;
|
||||
statusSize = Ui::FileStatusSizeFailed;
|
||||
} else if (dataLoaded()) {
|
||||
statusSize = FileStatusSizeLoaded;
|
||||
statusSize = Ui::FileStatusSizeLoaded;
|
||||
} else {
|
||||
statusSize = FileStatusSizeReady;
|
||||
statusSize = Ui::FileStatusSizeReady;
|
||||
}
|
||||
|
||||
const auto state = Media::Player::instance()->getState(AudioMsgId::Type::Voice);
|
||||
|
@ -935,7 +936,7 @@ Document::Document(
|
|||
|
||||
setDocumentLinks(_data);
|
||||
|
||||
_status.update(FileStatusSizeReady, _data->size, _data->isSong() ? _data->song()->duration : -1, 0);
|
||||
_status.update(Ui::FileStatusSizeReady, _data->size, _data->isSong() ? _data->song()->duration : -1, 0);
|
||||
|
||||
if (withThumb()) {
|
||||
_data->loadThumbnail(parent->fullId());
|
||||
|
@ -1356,15 +1357,15 @@ bool Document::updateStatusText() {
|
|||
int32 statusSize = 0, realDuration = 0;
|
||||
if (_data->status == FileDownloadFailed
|
||||
|| _data->status == FileUploadFailed) {
|
||||
statusSize = FileStatusSizeFailed;
|
||||
statusSize = Ui::FileStatusSizeFailed;
|
||||
} else if (_data->uploading()) {
|
||||
statusSize = _data->uploadingData->offset;
|
||||
} else if (_data->loading()) {
|
||||
statusSize = _data->loadOffset();
|
||||
} else if (dataLoaded()) {
|
||||
statusSize = FileStatusSizeLoaded;
|
||||
statusSize = Ui::FileStatusSizeLoaded;
|
||||
} else {
|
||||
statusSize = FileStatusSizeReady;
|
||||
statusSize = Ui::FileStatusSizeReady;
|
||||
}
|
||||
|
||||
if (_data->isSong()) {
|
||||
|
|
|
@ -21,9 +21,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "ui/toast/toast.h"
|
||||
#include "ui/rp_widget.h"
|
||||
#include "ui/countryinput.h"
|
||||
#include "ui/text/format_values.h"
|
||||
#include "core/update_checker.h"
|
||||
#include "data/data_countries.h"
|
||||
#include "layout.h"
|
||||
#include "app.h"
|
||||
#include "styles/style_layers.h"
|
||||
|
||||
|
@ -44,7 +44,7 @@ ScanInfo CollectScanInfo(const EditFile &file) {
|
|||
if (file.fields.downloadOffset < 0) {
|
||||
return tr::lng_attach_failed(tr::now);
|
||||
} else if (file.fields.downloadOffset < file.fields.size) {
|
||||
return formatDownloadText(
|
||||
return Ui::FormatDownloadText(
|
||||
file.fields.downloadOffset,
|
||||
file.fields.size);
|
||||
} else {
|
||||
|
@ -58,7 +58,7 @@ ScanInfo CollectScanInfo(const EditFile &file) {
|
|||
if (file.uploadData->offset < 0) {
|
||||
return tr::lng_attach_failed(tr::now);
|
||||
} else if (file.uploadData->fullId) {
|
||||
return formatDownloadText(
|
||||
return Ui::FormatDownloadText(
|
||||
file.uploadData->offset,
|
||||
file.uploadData->bytes.size());
|
||||
} else {
|
||||
|
@ -69,7 +69,7 @@ ScanInfo CollectScanInfo(const EditFile &file) {
|
|||
base::unixtime::parse(file.fields.date)));
|
||||
}
|
||||
} else {
|
||||
return formatDownloadText(0, file.fields.size);
|
||||
return Ui::FormatDownloadText(0, file.fields.size);
|
||||
}
|
||||
}();
|
||||
return {
|
||||
|
|
|
@ -15,6 +15,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "ui/widgets/checkbox.h"
|
||||
#include "ui/widgets/buttons.h"
|
||||
#include "ui/text/text_utilities.h" // Ui::Text::ToUpper
|
||||
#include "ui/text/format_values.h"
|
||||
#include "boxes/connection_box.h"
|
||||
#include "boxes/about_box.h"
|
||||
#include "boxes/confirm_box.h"
|
||||
|
@ -30,7 +31,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "main/main_account.h"
|
||||
#include "main/main_session.h"
|
||||
#include "mtproto/facade.h"
|
||||
#include "layout.h"
|
||||
#include "facades.h"
|
||||
#include "app.h"
|
||||
#include "styles/style_settings.h"
|
||||
|
@ -136,7 +136,7 @@ void SetupUpdate(not_null<Ui::VerticalLayout*> container) {
|
|||
texts->fire(tr::lng_settings_downloading_update(
|
||||
tr::now,
|
||||
lt_progress,
|
||||
formatDownloadText(ready, total)));
|
||||
Ui::FormatDownloadText(ready, total)));
|
||||
downloading->fire(true);
|
||||
};
|
||||
const auto setDefaultStatus = [=](const Core::UpdateChecker &checker) {
|
||||
|
|
|
@ -9,7 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
|
||||
#include "base/zlib_help.h"
|
||||
#include "lang/lang_keys.h"
|
||||
#include "layout.h"
|
||||
#include "ui/text/format_values.h"
|
||||
#include "main/main_account.h"
|
||||
#include "main/main_session.h"
|
||||
|
||||
|
@ -73,7 +73,7 @@ QString StateDescription(const BlobState &state, tr::phrase<> activeText) {
|
|||
return tr::lng_emoji_set_download(
|
||||
tr::now,
|
||||
lt_size,
|
||||
formatSizeText(data.size));
|
||||
Ui::FormatSizeText(data.size));
|
||||
}, [](const Ready &data) -> QString {
|
||||
return tr::lng_emoji_set_ready(tr::now);
|
||||
}, [&](const Active &data) -> QString {
|
||||
|
@ -87,7 +87,7 @@ QString StateDescription(const BlobState &state, tr::phrase<> activeText) {
|
|||
lt_percent,
|
||||
QString::number(int(std::round(percent))) + '%',
|
||||
lt_progress,
|
||||
formatDownloadText(data.already, data.size));
|
||||
Ui::FormatDownloadText(data.already, data.size));
|
||||
}, [](const Failed &data) {
|
||||
return tr::lng_attach_failed(tr::now);
|
||||
});
|
||||
|
|
131
Telegram/SourceFiles/ui/text/format_values.cpp
Normal file
131
Telegram/SourceFiles/ui/text/format_values.cpp
Normal file
|
@ -0,0 +1,131 @@
|
|||
/*
|
||||
This file is part of Telegram Desktop,
|
||||
the official desktop application for the Telegram messaging service.
|
||||
|
||||
For license and copyright information please follow this link:
|
||||
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
*/
|
||||
#include "ui/text/format_values.h"
|
||||
|
||||
#include "lang/lang_keys.h"
|
||||
|
||||
#include <QtCore/QLocale>
|
||||
|
||||
namespace Ui {
|
||||
|
||||
QString FormatSizeText(qint64 size) {
|
||||
if (size >= 1024 * 1024) { // more than 1 mb
|
||||
qint64 sizeTenthMb = (size * 10 / (1024 * 1024));
|
||||
return QString::number(sizeTenthMb / 10) + '.' + QString::number(sizeTenthMb % 10) + u" MB"_q;
|
||||
}
|
||||
if (size >= 1024) {
|
||||
qint64 sizeTenthKb = (size * 10 / 1024);
|
||||
return QString::number(sizeTenthKb / 10) + '.' + QString::number(sizeTenthKb % 10) + u" KB"_q;
|
||||
}
|
||||
return QString::number(size) + u" B"_q;
|
||||
}
|
||||
|
||||
QString FormatDownloadText(qint64 ready, qint64 total) {
|
||||
QString readyStr, totalStr, mb;
|
||||
if (total >= 1024 * 1024) { // more than 1 mb
|
||||
qint64 readyTenthMb = (ready * 10 / (1024 * 1024)), totalTenthMb = (total * 10 / (1024 * 1024));
|
||||
readyStr = QString::number(readyTenthMb / 10) + '.' + QString::number(readyTenthMb % 10);
|
||||
totalStr = QString::number(totalTenthMb / 10) + '.' + QString::number(totalTenthMb % 10);
|
||||
mb = u"MB"_q;
|
||||
} else if (total >= 1024) {
|
||||
qint64 readyKb = (ready / 1024), totalKb = (total / 1024);
|
||||
readyStr = QString::number(readyKb);
|
||||
totalStr = QString::number(totalKb);
|
||||
mb = u"KB"_q;
|
||||
} else {
|
||||
readyStr = QString::number(ready);
|
||||
totalStr = QString::number(total);
|
||||
mb = u"B"_q;
|
||||
}
|
||||
return tr::lng_save_downloaded(tr::now, lt_ready, readyStr, lt_total, totalStr, lt_mb, mb);
|
||||
}
|
||||
|
||||
QString FormatDurationText(qint64 duration) {
|
||||
qint64 hours = (duration / 3600), minutes = (duration % 3600) / 60, seconds = duration % 60;
|
||||
return (hours ? QString::number(hours) + ':' : QString()) + (minutes >= 10 ? QString() : QString('0')) + QString::number(minutes) + ':' + (seconds >= 10 ? QString() : QString('0')) + QString::number(seconds);
|
||||
}
|
||||
|
||||
QString FormatDurationWords(qint64 duration) {
|
||||
if (duration > 59) {
|
||||
auto minutes = (duration / 60);
|
||||
auto minutesCount = tr::lng_duration_minsec_minutes(tr::now, lt_count, minutes);
|
||||
auto seconds = (duration % 60);
|
||||
auto secondsCount = tr::lng_duration_minsec_seconds(tr::now, lt_count, seconds);
|
||||
return tr::lng_duration_minutes_seconds(tr::now, lt_minutes_count, minutesCount, lt_seconds_count, secondsCount);
|
||||
}
|
||||
return tr::lng_duration_seconds(tr::now, lt_count, duration);
|
||||
}
|
||||
|
||||
QString FormatDurationAndSizeText(qint64 duration, qint64 size) {
|
||||
return tr::lng_duration_and_size(tr::now, lt_duration, FormatDurationText(duration), lt_size, FormatSizeText(size));
|
||||
}
|
||||
|
||||
QString FormatGifAndSizeText(qint64 size) {
|
||||
return tr::lng_duration_and_size(tr::now, lt_duration, u"GIF"_q, lt_size, FormatSizeText(size));
|
||||
}
|
||||
|
||||
QString FormatPlayedText(qint64 played, qint64 duration) {
|
||||
return tr::lng_duration_played(tr::now, lt_played, FormatDurationText(played), lt_duration, FormatDurationText(duration));
|
||||
}
|
||||
|
||||
QString FillAmountAndCurrency(uint64 amount, const QString ¤cy) {
|
||||
static const auto ShortCurrencyNames = QMap<QString, QString>{
|
||||
{ u"USD"_q, QString::fromUtf8("\x24") },
|
||||
{ u"GBP"_q, QString::fromUtf8("\xC2\xA3") },
|
||||
{ u"EUR"_q, QString::fromUtf8("\xE2\x82\xAC") },
|
||||
{ u"JPY"_q, QString::fromUtf8("\xC2\xA5") },
|
||||
};
|
||||
static const auto Denominators = QMap<QString, int>{
|
||||
{ u"CLF"_q, 10000 },
|
||||
{ u"BHD"_q, 1000 },
|
||||
{ u"IQD"_q, 1000 },
|
||||
{ u"JOD"_q, 1000 },
|
||||
{ u"KWD"_q, 1000 },
|
||||
{ u"LYD"_q, 1000 },
|
||||
{ u"OMR"_q, 1000 },
|
||||
{ u"TND"_q, 1000 },
|
||||
{ u"BIF"_q, 1 },
|
||||
{ u"BYR"_q, 1 },
|
||||
{ u"CLP"_q, 1 },
|
||||
{ u"CVE"_q, 1 },
|
||||
{ u"DJF"_q, 1 },
|
||||
{ u"GNF"_q, 1 },
|
||||
{ u"ISK"_q, 1 },
|
||||
{ u"JPY"_q, 1 },
|
||||
{ u"KMF"_q, 1 },
|
||||
{ u"KRW"_q, 1 },
|
||||
{ u"MGA"_q, 1 },
|
||||
{ u"PYG"_q, 1 },
|
||||
{ u"RWF"_q, 1 },
|
||||
{ u"UGX"_q, 1 },
|
||||
{ u"UYI"_q, 1 },
|
||||
{ u"VND"_q, 1 },
|
||||
{ u"VUV"_q, 1 },
|
||||
{ u"XAF"_q, 1 },
|
||||
{ u"XOF"_q, 1 },
|
||||
{ u"XPF"_q, 1 },
|
||||
{ u"MRO"_q, 10 },
|
||||
};
|
||||
const auto currencyText = ShortCurrencyNames.value(currency, currency);
|
||||
const auto denominator = Denominators.value(currency, 100);
|
||||
const auto currencyValue = amount / float64(denominator);
|
||||
const auto digits = [&] {
|
||||
auto result = 0;
|
||||
for (auto test = 1; test < denominator; test *= 10) {
|
||||
++result;
|
||||
}
|
||||
return result;
|
||||
}();
|
||||
return QLocale::system().toCurrencyString(currencyValue, currencyText);
|
||||
//auto amountBucks = amount / 100;
|
||||
//auto amountCents = amount % 100;
|
||||
//auto amountText = u"%1,%2").arg(amountBucks).arg(amountCents, 2, 10, QChar('0'));
|
||||
//return currencyText + amountText;
|
||||
}
|
||||
|
||||
} // namespace Ui
|
28
Telegram/SourceFiles/ui/text/format_values.h
Normal file
28
Telegram/SourceFiles/ui/text/format_values.h
Normal file
|
@ -0,0 +1,28 @@
|
|||
/*
|
||||
This file is part of Telegram Desktop,
|
||||
the official desktop application for the Telegram messaging service.
|
||||
|
||||
For license and copyright information please follow this link:
|
||||
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
namespace Ui {
|
||||
|
||||
inline constexpr auto FileStatusSizeReady = 0x7FFFFFF0;
|
||||
inline constexpr auto FileStatusSizeLoaded = 0x7FFFFFF1;
|
||||
inline constexpr auto FileStatusSizeFailed = 0x7FFFFFF2;
|
||||
|
||||
[[nodiscard]] QString FormatSizeText(qint64 size);
|
||||
[[nodiscard]] QString FormatDownloadText(qint64 ready, qint64 total);
|
||||
[[nodiscard]] QString FormatDurationText(qint64 duration);
|
||||
[[nodiscard]] QString FormatDurationWords(qint64 duration);
|
||||
[[nodiscard]] QString FormatDurationAndSizeText(qint64 duration, qint64 size);
|
||||
[[nodiscard]] QString FormatGifAndSizeText(qint64 size);
|
||||
[[nodiscard]] QString FormatPlayedText(qint64 played, qint64 duration);
|
||||
|
||||
[[nodiscard]] QString FillAmountAndCurrency(
|
||||
uint64 amount,
|
||||
const QString ¤cy);
|
||||
|
||||
} // namespace Ui
|
|
@ -20,6 +20,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "ui/widgets/labels.h"
|
||||
#include "ui/image/image_prepare.h"
|
||||
#include "ui/toast/toast.h"
|
||||
#include "ui/text/format_values.h"
|
||||
#include "ui/special_fields.h"
|
||||
#include "main/main_account.h"
|
||||
#include "main/main_session.h"
|
||||
|
@ -36,7 +37,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "data/data_cloud_themes.h"
|
||||
#include "storage/file_upload.h"
|
||||
#include "mainwindow.h"
|
||||
#include "layout.h"
|
||||
#include "apiwrap.h"
|
||||
#include "app.h"
|
||||
#include "styles/style_widgets.h"
|
||||
|
@ -119,7 +119,7 @@ BackgroundSelector::BackgroundSelector(
|
|||
_imageText = tr::lng_theme_editor_saved_to_jpg(
|
||||
tr::now,
|
||||
lt_size,
|
||||
formatSizeText(_parsed.background.size()));
|
||||
Ui::FormatSizeText(_parsed.background.size()));
|
||||
_chooseFromFile->setClickedCallback([=] { chooseBackgroundFromFile(); });
|
||||
|
||||
_thumbnailSize = st::boxTextFont->height
|
||||
|
@ -199,7 +199,7 @@ void BackgroundSelector::chooseBackgroundFromFile() {
|
|||
_imageText = phrase(
|
||||
tr::now,
|
||||
lt_size,
|
||||
formatSizeText(_parsed.background.size()));
|
||||
Ui::FormatSizeText(_parsed.background.size()));
|
||||
_tileBackground->setChecked(false);
|
||||
updateThumbnail();
|
||||
}
|
||||
|
|
|
@ -29,6 +29,8 @@ PRIVATE
|
|||
${style_files}
|
||||
|
||||
ui/ui_pch.h
|
||||
ui/text/format_values.cpp
|
||||
ui/text/format_values.h
|
||||
ui/toasts/common_toasts.cpp
|
||||
ui/toasts/common_toasts.h
|
||||
)
|
||||
|
|
Loading…
Add table
Reference in a new issue