2
0
mirror of https://github.com/telegramdesktop/tdesktop synced 2025-08-31 14:38:15 +00:00

Use QImage instead of QPixmap for theme preview.

Working with QPixmap from non-main thread is not defined.
This commit is contained in:
John Preston
2018-01-02 22:10:49 +03:00
parent e89350d4b7
commit 0ef3e19bc2
6 changed files with 113 additions and 77 deletions

View File

@@ -1710,14 +1710,16 @@ void MediaView::initThemePreview() {
Window::Theme::CurrentData current;
current.backgroundId = Window::Theme::Background()->id();
current.backgroundImage = Window::Theme::Background()->pixmap();
current.backgroundImage = Window::Theme::Background()->pixmap().toImage();
current.backgroundTiled = Window::Theme::Background()->tile();
const auto path = _doc->location().name();
const auto id = _themePreviewId = rand_value<uint64>();
const auto weak = make_weak(this);
crl::async([=] {
auto preview = Window::Theme::GeneratePreview(path, current);
crl::async([=, data = std::move(current)]() mutable {
auto preview = Window::Theme::GeneratePreview(
path,
std::move(data));
crl::on_main(weak, [=, result = std::move(preview)]() mutable {
if (id != _themePreviewId) {
return;
@@ -2261,12 +2263,19 @@ void MediaView::paintThemePreview(Painter &p, QRect clip) {
auto fill = _themePreviewRect.intersected(clip);
if (!fill.isEmpty()) {
if (_themePreview) {
p.drawPixmapLeft(_themePreviewRect.x(), _themePreviewRect.y(), width(), _themePreview->preview);
p.drawImage(
myrtlrect(_themePreviewRect).topLeft(),
_themePreview->preview);
} else {
p.fillRect(fill, st::themePreviewBg);
p.setFont(st::themePreviewLoadingFont);
p.setPen(st::themePreviewLoadingFg);
p.drawText(_themePreviewRect, lang(_themePreviewId ? lng_theme_preview_generating : lng_theme_preview_invalid), QTextOption(style::al_center));
p.drawText(
_themePreviewRect,
lang(_themePreviewId
? lng_theme_preview_generating
: lng_theme_preview_invalid),
QTextOption(style::al_center));
}
}