Localizing theme preview
This commit is contained in:
parent
59c03bb521
commit
4606e5d5bb
6 changed files with 43 additions and 16 deletions
|
|
@ -42,7 +42,8 @@ QImage Prepare(
|
|||
} else if (type == FileType::AnimatedSticker) {
|
||||
return Lottie::ReadThumbnail(Lottie::ReadContent(data, path));
|
||||
} else if (type == FileType::Theme) {
|
||||
return Window::Theme::GeneratePreview(data, path);
|
||||
auto langStrings = Window::Theme::CollectStrings();
|
||||
return Window::Theme::GeneratePreview(data, path, langStrings);
|
||||
}
|
||||
const auto validateSize = [](QSize size) {
|
||||
return (size.width() + size.height()) < 10'000;
|
||||
|
|
|
|||
|
|
@ -2264,13 +2264,15 @@ void OverlayWidget::initThemePreview() {
|
|||
const auto path = _doc->location().name();
|
||||
const auto id = _themePreviewId = rand_value<uint64>();
|
||||
const auto weak = Ui::MakeWeak(this);
|
||||
auto langStrings = CollectStrings();
|
||||
crl::async([=, data = std::move(current)]() mutable {
|
||||
auto preview = GeneratePreview(
|
||||
bytes,
|
||||
path,
|
||||
fields,
|
||||
std::move(data),
|
||||
Window::Theme::PreviewType::Extended);
|
||||
Window::Theme::PreviewType::Extended,
|
||||
langStrings);
|
||||
crl::on_main(weak, [=, result = std::move(preview)]() mutable {
|
||||
if (id != _themePreviewId) {
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -816,7 +816,8 @@ void FileLoadTask::process() {
|
|||
thumbnail = PrepareFileThumbnail(std::move(video->thumbnail));
|
||||
} else if (filemime == qstr("application/x-tdesktop-theme")
|
||||
|| filemime == qstr("application/x-tgtheme-tdesktop")) {
|
||||
goodThumbnail = Window::Theme::GeneratePreview(_content, _filepath);
|
||||
auto langStrings = Window::Theme::CollectStrings();
|
||||
goodThumbnail = Window::Theme::GeneratePreview(_content, _filepath, langStrings);
|
||||
if (!goodThumbnail.isNull()) {
|
||||
QBuffer buffer(&goodThumbnailBytes);
|
||||
goodThumbnail.save(&buffer, "JPG", kThumbnailQuality);
|
||||
|
|
|
|||
|
|
@ -415,7 +415,8 @@ SendMediaReady PrepareThemeMedia(
|
|||
PreparedPhotoThumbs thumbnails;
|
||||
QVector<MTPPhotoSize> sizes;
|
||||
|
||||
auto thumbnail = GeneratePreview(content, QString()).scaled(
|
||||
auto langStrings = CollectStrings();
|
||||
auto thumbnail = GeneratePreview(content, QString(), langStrings).scaled(
|
||||
320,
|
||||
320,
|
||||
Qt::KeepAspectRatio,
|
||||
|
|
|
|||
|
|
@ -86,7 +86,8 @@ public:
|
|||
Generator(
|
||||
const Instance &theme,
|
||||
CurrentData &¤t,
|
||||
PreviewType type);
|
||||
PreviewType type,
|
||||
QMap<QString, QString> lang);
|
||||
|
||||
[[nodiscard]] QImage generate();
|
||||
|
||||
|
|
@ -191,6 +192,8 @@ private:
|
|||
|
||||
style::TextPalette _textPalette;
|
||||
|
||||
QMap<QString, QString> _lang;
|
||||
|
||||
};
|
||||
|
||||
bool Generator::extended() const {
|
||||
|
|
@ -336,7 +339,7 @@ void Generator::generateData() {
|
|||
addRow("Davy Jones", 5, "4:00", textcmdLink(1, "Keynote.pdf"));
|
||||
|
||||
_topBarName.setText(st::msgNameStyle, "Eva Summer", Ui::NameTextOptions());
|
||||
_topBarStatus = "online";
|
||||
_topBarStatus = _lang.value(qsl("lng_status_online"));
|
||||
_topBarStatusActive = true;
|
||||
|
||||
addPhotoBubble(":/gui/art/sunrise.jpg", "Nearly missed this sunrise", "7:00", Status::None);
|
||||
|
|
@ -362,11 +365,13 @@ void Generator::generateData() {
|
|||
Generator::Generator(
|
||||
const Instance &theme,
|
||||
CurrentData &¤t,
|
||||
PreviewType type)
|
||||
PreviewType type,
|
||||
QMap<QString, QString> lang)
|
||||
: _theme(theme)
|
||||
, _palette(_theme.palette)
|
||||
, _current(std::move(current))
|
||||
, _type(type) {
|
||||
, _type(type)
|
||||
, _lang(lang) {
|
||||
}
|
||||
|
||||
QImage Generator::generate() {
|
||||
|
|
@ -542,7 +547,7 @@ void Generator::paintComposeArea() {
|
|||
field.y() + st::historyComposeField.textMargins.top() + st::historyComposeField.placeholderMargins.top(),
|
||||
field.width() - st::historyComposeField.textMargins.left() - st::historyComposeField.textMargins.right(),
|
||||
field.height() - st::historyComposeField.textMargins.top() - st::historyComposeField.textMargins.bottom());
|
||||
_p->drawText(placeholderRect, tr::lng_message_ph(tr::now), QTextOption(st::historyComposeField.placeholderAlign));
|
||||
_p->drawText(placeholderRect, _lang.value(qsl("lng_message_ph")), QTextOption(st::historyComposeField.placeholderAlign));
|
||||
|
||||
_p->restore();
|
||||
_p->setClipping(false);
|
||||
|
|
@ -578,7 +583,7 @@ void Generator::paintDialogs() {
|
|||
auto phRect = QRect(filter.x() + st::dialogsFilter.textMrg.left() + st::dialogsFilter.phPos.x(), filter.y() + st::dialogsFilter.textMrg.top() + st::dialogsFilter.phPos.y(), filter.width() - st::dialogsFilter.textMrg.left() - st::dialogsFilter.textMrg.right(), filter.height() - st::dialogsFilter.textMrg.top() - st::dialogsFilter.textMrg.bottom());;
|
||||
_p->setFont(st::dialogsFilter.font);
|
||||
_p->setPen(st::dialogsFilter.phColor[_palette]);
|
||||
_p->drawText(phRect, tr::lng_dlg_filter(tr::now), QTextOption(st::dialogsFilter.phAlign));
|
||||
_p->drawText(phRect, _lang.value(qsl("lng_dlg_filter")), QTextOption(st::dialogsFilter.phAlign));
|
||||
_p->restore();
|
||||
_p->setClipping(false);
|
||||
|
||||
|
|
@ -972,7 +977,8 @@ std::unique_ptr<Preview> GeneratePreview(
|
|||
const QString &filepath,
|
||||
const Data::CloudTheme &cloud,
|
||||
CurrentData &&data,
|
||||
PreviewType type) {
|
||||
PreviewType type,
|
||||
QMap<QString, QString> lang) {
|
||||
auto result = PreviewFromFile(bytes, filepath, cloud);
|
||||
if (!result) {
|
||||
return nullptr;
|
||||
|
|
@ -980,23 +986,36 @@ std::unique_ptr<Preview> GeneratePreview(
|
|||
result->preview = Generator(
|
||||
result->instance,
|
||||
std::move(data),
|
||||
type
|
||||
type,
|
||||
lang
|
||||
).generate();
|
||||
return result;
|
||||
}
|
||||
|
||||
QImage GeneratePreview(
|
||||
const QByteArray &bytes,
|
||||
const QString &filepath) {
|
||||
const QString &filepath,
|
||||
QMap<QString, QString> lang) {
|
||||
const auto preview = GeneratePreview(
|
||||
bytes,
|
||||
filepath,
|
||||
Data::CloudTheme(),
|
||||
CurrentData{ Data::ThemeWallPaper().id() },
|
||||
PreviewType::Normal);
|
||||
PreviewType::Normal,
|
||||
lang);
|
||||
return preview ? preview->preview : QImage();
|
||||
}
|
||||
|
||||
QMap<QString, QString> CollectStrings() {
|
||||
QMap<QString, QString> result;
|
||||
|
||||
result.insert(qsl("lng_message_ph"), tr::lng_message_ph(tr::now));
|
||||
result.insert(qsl("lng_dlg_filter"), tr::lng_dlg_filter(tr::now));
|
||||
result.insert(qsl("lng_status_online"), tr::lng_status_online(tr::now));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
int DefaultPreviewTitleHeight() {
|
||||
return st::defaultWindowTitle.height;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,10 +38,13 @@ std::unique_ptr<Preview> GeneratePreview(
|
|||
const QString &filepath,
|
||||
const Data::CloudTheme &cloud,
|
||||
CurrentData &&data,
|
||||
PreviewType type);
|
||||
PreviewType type,
|
||||
QMap<QString, QString> lang);
|
||||
QImage GeneratePreview(
|
||||
const QByteArray &bytes,
|
||||
const QString &filepath);
|
||||
const QString &filepath,
|
||||
QMap<QString, QString> lang);
|
||||
QMap<QString, QString> CollectStrings();
|
||||
|
||||
int DefaultPreviewTitleHeight();
|
||||
void DefaultPreviewWindowFramePaint(
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue