[Improvement] Allow to localize theme preview
This commit is contained in:
parent
d84686c8b6
commit
a23dd642a6
6 changed files with 41 additions and 16 deletions
|
|
@ -68,7 +68,8 @@ enum class FileType {
|
||||||
} else if (type == FileType::AnimatedSticker) {
|
} else if (type == FileType::AnimatedSticker) {
|
||||||
return Lottie::ReadThumbnail(Lottie::ReadContent(data, path));
|
return Lottie::ReadThumbnail(Lottie::ReadContent(data, path));
|
||||||
} else if (type == FileType::Theme) {
|
} else if (type == FileType::Theme) {
|
||||||
return Window::Theme::GeneratePreview(data, path);
|
auto langStrings = Window::Theme::CollectStrings();
|
||||||
|
return Window::Theme::GeneratePreview(data, path, langStrings);
|
||||||
} else if (type == FileType::WallPatternSVG) {
|
} else if (type == FileType::WallPatternSVG) {
|
||||||
return Images::Read({
|
return Images::Read({
|
||||||
.path = path,
|
.path = path,
|
||||||
|
|
|
||||||
|
|
@ -3933,13 +3933,15 @@ void OverlayWidget::initThemePreview() {
|
||||||
const auto path = _document->location().name();
|
const auto path = _document->location().name();
|
||||||
const auto id = _themePreviewId = base::RandomValue<uint64>();
|
const auto id = _themePreviewId = base::RandomValue<uint64>();
|
||||||
const auto weak = Ui::MakeWeak(_widget);
|
const auto weak = Ui::MakeWeak(_widget);
|
||||||
|
auto langStrings = CollectStrings();
|
||||||
crl::async([=, data = std::move(current)]() mutable {
|
crl::async([=, data = std::move(current)]() mutable {
|
||||||
auto preview = GeneratePreview(
|
auto preview = GeneratePreview(
|
||||||
bytes,
|
bytes,
|
||||||
path,
|
path,
|
||||||
fields,
|
fields,
|
||||||
std::move(data),
|
std::move(data),
|
||||||
Window::Theme::PreviewType::Extended);
|
Window::Theme::PreviewType::Extended,
|
||||||
|
langStrings);
|
||||||
crl::on_main(weak, [=, result = std::move(preview)]() mutable {
|
crl::on_main(weak, [=, result = std::move(preview)]() mutable {
|
||||||
const auto session = weakSession.get();
|
const auto session = weakSession.get();
|
||||||
if (id != _themePreviewId || !session) {
|
if (id != _themePreviewId || !session) {
|
||||||
|
|
|
||||||
|
|
@ -856,7 +856,8 @@ void FileLoadTask::process(Args &&args) {
|
||||||
thumbnail = PrepareFileThumbnail(std::move(video->thumbnail));
|
thumbnail = PrepareFileThumbnail(std::move(video->thumbnail));
|
||||||
} else if (filemime == u"application/x-tdesktop-theme"_q
|
} else if (filemime == u"application/x-tdesktop-theme"_q
|
||||||
|| filemime == u"application/x-tgtheme-tdesktop"_q) {
|
|| filemime == u"application/x-tgtheme-tdesktop"_q) {
|
||||||
goodThumbnail = Window::Theme::GeneratePreview(_content, _filepath);
|
auto langStrings = Window::Theme::CollectStrings();
|
||||||
|
goodThumbnail = Window::Theme::GeneratePreview(_content, _filepath, langStrings);
|
||||||
if (!goodThumbnail.isNull()) {
|
if (!goodThumbnail.isNull()) {
|
||||||
QBuffer buffer(&goodThumbnailBytes);
|
QBuffer buffer(&goodThumbnailBytes);
|
||||||
goodThumbnail.save(&buffer, "JPG", kThumbnailQuality);
|
goodThumbnail.save(&buffer, "JPG", kThumbnailQuality);
|
||||||
|
|
|
||||||
|
|
@ -392,7 +392,8 @@ std::shared_ptr<FilePrepareResult> PrepareThemeMedia(
|
||||||
PreparedPhotoThumbs thumbnails;
|
PreparedPhotoThumbs thumbnails;
|
||||||
QVector<MTPPhotoSize> sizes;
|
QVector<MTPPhotoSize> sizes;
|
||||||
|
|
||||||
auto thumbnail = GeneratePreview(content, QString()).scaled(
|
auto langStrings = CollectStrings();
|
||||||
|
auto thumbnail = GeneratePreview(content, QString(), langStrings).scaled(
|
||||||
320,
|
320,
|
||||||
320,
|
320,
|
||||||
Qt::KeepAspectRatio,
|
Qt::KeepAspectRatio,
|
||||||
|
|
|
||||||
|
|
@ -94,7 +94,8 @@ public:
|
||||||
Generator(
|
Generator(
|
||||||
const Instance &theme,
|
const Instance &theme,
|
||||||
CurrentData &¤t,
|
CurrentData &¤t,
|
||||||
PreviewType type);
|
PreviewType type,
|
||||||
|
QMap<QString, QString> lang);
|
||||||
|
|
||||||
[[nodiscard]] QImage generate();
|
[[nodiscard]] QImage generate();
|
||||||
|
|
||||||
|
|
@ -205,6 +206,8 @@ private:
|
||||||
|
|
||||||
style::TextPalette _textPalette;
|
style::TextPalette _textPalette;
|
||||||
|
|
||||||
|
QMap<QString, QString> _lang;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
bool Generator::extended() const {
|
bool Generator::extended() const {
|
||||||
|
|
@ -382,7 +385,7 @@ void Generator::generateData() {
|
||||||
addRow("Davy Jones", 5, "4:00", Ui::Text::Colorized("Keynote.pdf"));
|
addRow("Davy Jones", 5, "4:00", Ui::Text::Colorized("Keynote.pdf"));
|
||||||
|
|
||||||
_topBarName.setText(st::msgNameStyle, "Eva Summer", Ui::NameTextOptions());
|
_topBarName.setText(st::msgNameStyle, "Eva Summer", Ui::NameTextOptions());
|
||||||
_topBarStatus = "online";
|
_topBarStatus = _lang.value(qsl("lng_status_online"));
|
||||||
_topBarStatusActive = true;
|
_topBarStatusActive = true;
|
||||||
|
|
||||||
addPhotoBubble(":/gui/art/themeimage.jpg", "To reach a port, we must sail. " + QString::fromUtf8("\xf0\x9f\xa5\xb8"), "7:00", Status::None);
|
addPhotoBubble(":/gui/art/themeimage.jpg", "To reach a port, we must sail. " + QString::fromUtf8("\xf0\x9f\xa5\xb8"), "7:00", Status::None);
|
||||||
|
|
@ -409,12 +412,14 @@ void Generator::generateData() {
|
||||||
Generator::Generator(
|
Generator::Generator(
|
||||||
const Instance &theme,
|
const Instance &theme,
|
||||||
CurrentData &¤t,
|
CurrentData &¤t,
|
||||||
PreviewType type)
|
PreviewType type,
|
||||||
|
QMap<QString, QString> lang)
|
||||||
: _theme(theme)
|
: _theme(theme)
|
||||||
, _palette(_theme.palette)
|
, _palette(_theme.palette)
|
||||||
, _current(std::move(current))
|
, _current(std::move(current))
|
||||||
, _type(type)
|
, _type(type)
|
||||||
, _st(&_palette) {
|
, _st(&_palette)
|
||||||
|
, _lang(lang) {
|
||||||
}
|
}
|
||||||
|
|
||||||
QImage Generator::generate() {
|
QImage Generator::generate() {
|
||||||
|
|
@ -619,7 +624,7 @@ void Generator::paintComposeArea() {
|
||||||
field.y() + st::historyComposeField.textMargins.top() + st::historyComposeField.placeholderMargins.top(),
|
field.y() + st::historyComposeField.textMargins.top() + st::historyComposeField.placeholderMargins.top(),
|
||||||
field.width() - st::historyComposeField.textMargins.left() - st::historyComposeField.textMargins.right(),
|
field.width() - st::historyComposeField.textMargins.left() - st::historyComposeField.textMargins.right(),
|
||||||
field.height() - st::historyComposeField.textMargins.top() - st::historyComposeField.textMargins.bottom());
|
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->restore();
|
||||||
_p->setClipping(false);
|
_p->setClipping(false);
|
||||||
|
|
@ -667,7 +672,7 @@ void Generator::paintDialogs() {
|
||||||
auto phRect = QRect(filter.x() + st::dialogsFilter.textMargins.left() + st::dialogsFilter.placeholderMargins.left(), filter.y() + st::dialogsFilter.textMargins.top() + st::dialogsFilter.placeholderMargins.top(), filter.width() - st::dialogsFilter.textMargins.left() - st::dialogsFilter.textMargins.right(), filter.height() - st::dialogsFilter.textMargins.top() - st::dialogsFilter.textMargins.bottom());
|
auto phRect = QRect(filter.x() + st::dialogsFilter.textMargins.left() + st::dialogsFilter.placeholderMargins.left(), filter.y() + st::dialogsFilter.textMargins.top() + st::dialogsFilter.placeholderMargins.top(), filter.width() - st::dialogsFilter.textMargins.left() - st::dialogsFilter.textMargins.right(), filter.height() - st::dialogsFilter.textMargins.top() - st::dialogsFilter.textMargins.bottom());
|
||||||
_p->setFont(st::dialogsFilter.font);
|
_p->setFont(st::dialogsFilter.font);
|
||||||
_p->setPen(st::dialogsFilter.placeholderFg[_palette]);
|
_p->setPen(st::dialogsFilter.placeholderFg[_palette]);
|
||||||
_p->drawText(phRect, tr::lng_dlg_filter(tr::now), QTextOption(st::dialogsFilter.placeholderAlign));
|
_p->drawText(phRect, _lang.value(qsl("lng_dlg_filter")), QTextOption(st::dialogsFilter.placeholderAlign));
|
||||||
_p->restore();
|
_p->restore();
|
||||||
_p->setClipping(false);
|
_p->setClipping(false);
|
||||||
|
|
||||||
|
|
@ -1112,7 +1117,8 @@ std::unique_ptr<Preview> GeneratePreview(
|
||||||
const QString &filepath,
|
const QString &filepath,
|
||||||
const Data::CloudTheme &cloud,
|
const Data::CloudTheme &cloud,
|
||||||
CurrentData &&data,
|
CurrentData &&data,
|
||||||
PreviewType type) {
|
PreviewType type,
|
||||||
|
QMap<QString, QString> lang) {
|
||||||
auto result = PreviewFromFile(bytes, filepath, cloud);
|
auto result = PreviewFromFile(bytes, filepath, cloud);
|
||||||
if (!result) {
|
if (!result) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
@ -1120,23 +1126,34 @@ std::unique_ptr<Preview> GeneratePreview(
|
||||||
result->preview = Generator(
|
result->preview = Generator(
|
||||||
result->instance,
|
result->instance,
|
||||||
std::move(data),
|
std::move(data),
|
||||||
type
|
type,
|
||||||
|
lang
|
||||||
).generate();
|
).generate();
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
QImage GeneratePreview(
|
QImage GeneratePreview(
|
||||||
const QByteArray &bytes,
|
const QByteArray &bytes,
|
||||||
const QString &filepath) {
|
const QString &filepath,
|
||||||
|
QMap<QString, QString> lang) {
|
||||||
const auto preview = GeneratePreview(
|
const auto preview = GeneratePreview(
|
||||||
bytes,
|
bytes,
|
||||||
filepath,
|
filepath,
|
||||||
Data::CloudTheme(),
|
Data::CloudTheme(),
|
||||||
CurrentData{ Data::ThemeWallPaper().id() },
|
CurrentData{ Data::ThemeWallPaper().id() },
|
||||||
PreviewType::Normal);
|
PreviewType::Normal,
|
||||||
|
lang);
|
||||||
return preview ? preview->preview : QImage();
|
return preview ? preview->preview : QImage();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QMap<QString, QString> CollectStrings() {
|
||||||
|
return {
|
||||||
|
{ "lng_message_ph", tr::lng_message_ph(tr::now) },
|
||||||
|
{ "lng_dlg_filter", tr::lng_dlg_filter(tr::now) },
|
||||||
|
{ "lng_status_online", tr::lng_status_online(tr::now) },
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
int DefaultPreviewTitleHeight() {
|
int DefaultPreviewTitleHeight() {
|
||||||
return st::defaultWindowTitle.height;
|
return st::defaultWindowTitle.height;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -38,10 +38,13 @@ std::unique_ptr<Preview> GeneratePreview(
|
||||||
const QString &filepath,
|
const QString &filepath,
|
||||||
const Data::CloudTheme &cloud,
|
const Data::CloudTheme &cloud,
|
||||||
CurrentData &&data,
|
CurrentData &&data,
|
||||||
PreviewType type);
|
PreviewType type,
|
||||||
|
QMap<QString, QString> lang);
|
||||||
QImage GeneratePreview(
|
QImage GeneratePreview(
|
||||||
const QByteArray &bytes,
|
const QByteArray &bytes,
|
||||||
const QString &filepath);
|
const QString &filepath,
|
||||||
|
QMap<QString, QString> lang);
|
||||||
|
QMap<QString, QString> CollectStrings();
|
||||||
|
|
||||||
int DefaultPreviewTitleHeight();
|
int DefaultPreviewTitleHeight();
|
||||||
void DefaultPreviewWindowFramePaint(
|
void DefaultPreviewWindowFramePaint(
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue