mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-18 23:27:09 +02:00
Moved date and progress text formatting to tg_ui:ui/text/format_values.
This commit is contained in:
parent
b3f6fe1c10
commit
348712059b
4 changed files with 80 additions and 69 deletions
|
@ -606,28 +606,10 @@ void OverlayWidget::updateDocSize() {
|
|||
return;
|
||||
}
|
||||
|
||||
if (_document->loading()) {
|
||||
quint64 ready = _document->loadOffset(), total = _document->size;
|
||||
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");
|
||||
}
|
||||
_docSize = tr::lng_media_save_progress(tr::now, lt_ready, readyStr, lt_total, totalStr, lt_mb, mb);
|
||||
} else {
|
||||
_docSize = Ui::FormatSizeText(_document->size);
|
||||
}
|
||||
const auto size = _document->size;
|
||||
_docSize = _document->loading()
|
||||
? Ui::FormatProgressText(_document->loadOffset(), size)
|
||||
: Ui::FormatSizeText(size);
|
||||
_docSizeWidth = st::mediaviewFont->width(_docSize);
|
||||
int32 maxw = st::mediaviewFileSize.width() - st::mediaviewFileIconSize - st::mediaviewFilePadding * 3;
|
||||
if (_docSizeWidth > maxw) {
|
||||
|
@ -739,13 +721,7 @@ void OverlayWidget::updateControls() {
|
|||
}
|
||||
return dNow;
|
||||
}();
|
||||
if (d.date() == dNow.date()) {
|
||||
_dateText = tr::lng_mediaview_today(tr::now, lt_time, d.time().toString(cTimeFormat()));
|
||||
} else if (d.date().addDays(1) == dNow.date()) {
|
||||
_dateText = tr::lng_mediaview_yesterday(tr::now, lt_time, d.time().toString(cTimeFormat()));
|
||||
} else {
|
||||
_dateText = tr::lng_mediaview_date_time(tr::now, lt_date, d.date().toString(qsl("dd.MM.yy")), lt_time, d.time().toString(cTimeFormat()));
|
||||
}
|
||||
_dateText = Ui::FormatDateTime(d, cTimeFormat());
|
||||
if (!_fromName.isEmpty()) {
|
||||
_fromNameLabel.setText(st::mediaviewTextStyle, _fromName, Ui::NameTextOptions());
|
||||
_nameNav = myrtlrect(st::mediaviewTextLeft, height() - st::mediaviewTextTop, qMin(_fromNameLabel.maxWidth(), width() / 3), st::mediaviewFont->height);
|
||||
|
|
|
@ -18,6 +18,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "ui/toast/toast.h"
|
||||
#include "ui/widgets/input_fields.h"
|
||||
#include "ui/chat/attach/attach_prepare.h"
|
||||
#include "ui/text/format_values.h"
|
||||
#include "ui/text/text_entity.h"
|
||||
#include "ui/text/text_options.h"
|
||||
#include "chat_helpers/message_field.h"
|
||||
|
@ -135,29 +136,6 @@ void EditInfoBox::setInnerFocus() {
|
|||
_field->setFocusFast();
|
||||
}
|
||||
|
||||
QString FormatDateTime(TimeId value) {
|
||||
const auto now = QDateTime::currentDateTime();
|
||||
const auto date = base::unixtime::parse(value);
|
||||
if (date.date() == now.date()) {
|
||||
return tr::lng_mediaview_today(
|
||||
tr::now,
|
||||
lt_time,
|
||||
date.time().toString(cTimeFormat()));
|
||||
} else if (date.date().addDays(1) == now.date()) {
|
||||
return tr::lng_mediaview_yesterday(
|
||||
tr::now,
|
||||
lt_time,
|
||||
date.time().toString(cTimeFormat()));
|
||||
} else {
|
||||
return tr::lng_mediaview_date_time(
|
||||
tr::now,
|
||||
lt_date,
|
||||
date.date().toString(qsl("dd.MM.yy")),
|
||||
lt_time,
|
||||
date.time().toString(cTimeFormat()));
|
||||
}
|
||||
}
|
||||
|
||||
uint32 OccupationTag() {
|
||||
return uint32(Core::Sandbox::Instance().installationTag() & 0xFFFFFFFF);
|
||||
}
|
||||
|
@ -484,7 +462,10 @@ rpl::producer<QString> Helper::infoLabelValue(
|
|||
return infoValue(
|
||||
user
|
||||
) | rpl::map([](const Support::UserInfo &info) {
|
||||
return info.author + ", " + FormatDateTime(info.date);
|
||||
const auto time = Ui::FormatDateTime(
|
||||
base::unixtime::parse(info.date),
|
||||
cTimeFormat());
|
||||
return info.author + ", " + time;
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -13,24 +13,22 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
|
||||
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;
|
||||
}
|
||||
namespace {
|
||||
|
||||
QString FormatDownloadText(qint64 ready, qint64 total) {
|
||||
QString FormatTextWithReadyAndTotal(
|
||||
tr::phrase<lngtag_ready, lngtag_total, lngtag_mb> phrase,
|
||||
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);
|
||||
const qint64 readyTenthMb = (ready * 10 / (1024 * 1024));
|
||||
const qint64 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);
|
||||
|
@ -42,7 +40,61 @@ QString FormatDownloadText(qint64 ready, qint64 total) {
|
|||
totalStr = QString::number(total);
|
||||
mb = u"B"_q;
|
||||
}
|
||||
return tr::lng_save_downloaded(tr::now, lt_ready, readyStr, lt_total, totalStr, lt_mb, mb);
|
||||
return phrase(tr::now, lt_ready, readyStr, lt_total, totalStr, lt_mb, mb);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
QString FormatSizeText(qint64 size) {
|
||||
if (size >= 1024 * 1024) { // more than 1 mb
|
||||
const qint64 sizeTenthMb = (size * 10 / (1024 * 1024));
|
||||
return QString::number(sizeTenthMb / 10)
|
||||
+ '.'
|
||||
+ QString::number(sizeTenthMb % 10) + u" MB"_q;
|
||||
}
|
||||
if (size >= 1024) {
|
||||
const 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) {
|
||||
return FormatTextWithReadyAndTotal(
|
||||
tr::lng_save_downloaded,
|
||||
ready,
|
||||
total);
|
||||
}
|
||||
|
||||
QString FormatProgressText(qint64 ready, qint64 total) {
|
||||
return FormatTextWithReadyAndTotal(
|
||||
tr::lng_media_save_progress,
|
||||
ready,
|
||||
total);
|
||||
}
|
||||
|
||||
QString FormatDateTime(QDateTime date, QString format) {
|
||||
const auto now = QDateTime::currentDateTime();
|
||||
if (date.date() == now.date()) {
|
||||
return tr::lng_mediaview_today(
|
||||
tr::now,
|
||||
lt_time,
|
||||
date.time().toString(format));
|
||||
} else if (date.date().addDays(1) == now.date()) {
|
||||
return tr::lng_mediaview_yesterday(
|
||||
tr::now,
|
||||
lt_time,
|
||||
date.time().toString(format));
|
||||
} else {
|
||||
return tr::lng_mediaview_date_time(
|
||||
tr::now,
|
||||
lt_date,
|
||||
date.date().toString(u"dd.MM.yy"_q),
|
||||
lt_time,
|
||||
date.time().toString(format));
|
||||
}
|
||||
}
|
||||
|
||||
QString FormatDurationText(qint64 duration) {
|
||||
|
|
|
@ -15,6 +15,8 @@ inline constexpr auto FileStatusSizeFailed = 0x7FFFFFF2;
|
|||
|
||||
[[nodiscard]] QString FormatSizeText(qint64 size);
|
||||
[[nodiscard]] QString FormatDownloadText(qint64 ready, qint64 total);
|
||||
[[nodiscard]] QString FormatProgressText(qint64 ready, qint64 total);
|
||||
[[nodiscard]] QString FormatDateTime(QDateTime date, QString format);
|
||||
[[nodiscard]] QString FormatDurationText(qint64 duration);
|
||||
[[nodiscard]] QString FormatDurationWords(qint64 duration);
|
||||
[[nodiscard]] QString FormatDurationAndSizeText(qint64 duration, qint64 size);
|
||||
|
|
Loading…
Add table
Reference in a new issue