Show blur / dimming in wallpaper preview.
This commit is contained in:
parent
ae6d703a44
commit
1b6b0c1732
|
@ -30,6 +30,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "ui/painter.h"
|
#include "ui/painter.h"
|
||||||
#include "ui/ui_utility.h"
|
#include "ui/ui_utility.h"
|
||||||
#include "window/window_session_controller.h"
|
#include "window/window_session_controller.h"
|
||||||
|
#include "window/themes/window_theme.h"
|
||||||
#include "styles/style_chat.h"
|
#include "styles/style_chat.h"
|
||||||
|
|
||||||
namespace HistoryView {
|
namespace HistoryView {
|
||||||
|
@ -54,6 +55,10 @@ ThemeDocument::ThemeDocument(
|
||||||
_background = params->backgroundColors();
|
_background = params->backgroundColors();
|
||||||
_patternOpacity = params->patternOpacity();
|
_patternOpacity = params->patternOpacity();
|
||||||
_gradientRotation = params->gradientRotation();
|
_gradientRotation = params->gradientRotation();
|
||||||
|
_blurredWallPaper = params->isBlurred();
|
||||||
|
_dimmingIntensity = (params->isPattern() || !_serviceWidth)
|
||||||
|
? 0
|
||||||
|
: std::max(params->patternIntensity(), 0);
|
||||||
}
|
}
|
||||||
const auto fullId = _parent->data()->fullId();
|
const auto fullId = _parent->data()->fullId();
|
||||||
if (_data) {
|
if (_data) {
|
||||||
|
@ -267,6 +272,11 @@ bool ThemeDocument::checkGoodThumbnail() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
void ThemeDocument::validateThumbnail() const {
|
void ThemeDocument::validateThumbnail() const {
|
||||||
|
const auto isDark = Window::Theme::IsNightMode();
|
||||||
|
if (_isDark != isDark) {
|
||||||
|
_isDark = isDark;
|
||||||
|
_thumbnailGood = -1;
|
||||||
|
}
|
||||||
if (checkGoodThumbnail()) {
|
if (checkGoodThumbnail()) {
|
||||||
if (_thumbnailGood > 0) {
|
if (_thumbnailGood > 0) {
|
||||||
return;
|
return;
|
||||||
|
@ -294,16 +304,30 @@ void ThemeDocument::validateThumbnail() const {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QImage ThemeDocument::finishServiceThumbnail(QImage image) const {
|
||||||
|
if (!_serviceWidth) {
|
||||||
|
return image;
|
||||||
|
} else if (_isDark && _dimmingIntensity > 0) {
|
||||||
|
image.setDevicePixelRatio(cIntRetinaFactor());
|
||||||
|
auto p = QPainter(&image);
|
||||||
|
const auto alpha = 255 * _dimmingIntensity / 100;
|
||||||
|
p.fillRect(0, 0, _pixw, _pixh, QColor(0, 0, 0, alpha));
|
||||||
|
}
|
||||||
|
if (_blurredWallPaper) {
|
||||||
|
constexpr auto kRadius = 16;
|
||||||
|
image = Images::BlurLargeImage(std::move(image), kRadius);
|
||||||
|
}
|
||||||
|
return Images::Circle(std::move(image));
|
||||||
|
}
|
||||||
|
|
||||||
void ThemeDocument::generateThumbnail() const {
|
void ThemeDocument::generateThumbnail() const {
|
||||||
auto image = Ui::GenerateBackgroundImage(
|
auto image = Ui::GenerateBackgroundImage(
|
||||||
QSize(_pixw, _pixh) * cIntRetinaFactor(),
|
QSize(_pixw, _pixh) * cIntRetinaFactor(),
|
||||||
_background,
|
_background,
|
||||||
_gradientRotation,
|
_gradientRotation,
|
||||||
_patternOpacity);
|
_patternOpacity);
|
||||||
if (_serviceWidth) {
|
_thumbnail = Ui::PixmapFromImage(
|
||||||
image = Images::Circle(std::move(image));
|
finishServiceThumbnail(std::move(image)));
|
||||||
}
|
|
||||||
_thumbnail = Ui::PixmapFromImage(std::move(image));
|
|
||||||
_thumbnail.setDevicePixelRatio(cRetinaFactor());
|
_thumbnail.setDevicePixelRatio(cRetinaFactor());
|
||||||
_thumbnailGood = 1;
|
_thumbnailGood = 1;
|
||||||
}
|
}
|
||||||
|
@ -317,7 +341,6 @@ void ThemeDocument::prepareThumbnailFrom(
|
||||||
const auto isTheme = _data->isTheme();
|
const auto isTheme = _data->isTheme();
|
||||||
const auto isPattern = _data->isPatternWallPaper();
|
const auto isPattern = _data->isPatternWallPaper();
|
||||||
auto options = (good >= 0 ? Images::Option(0) : Images::Option::Blur)
|
auto options = (good >= 0 ? Images::Option(0) : Images::Option::Blur)
|
||||||
| (_serviceWidth ? Images::Option::RoundCircle : Images::Option(0))
|
|
||||||
| (isPattern
|
| (isPattern
|
||||||
? Images::Option::TransparentBackground
|
? Images::Option::TransparentBackground
|
||||||
: Images::Option(0));
|
: Images::Option(0));
|
||||||
|
@ -344,10 +367,8 @@ void ThemeDocument::prepareThumbnailFrom(
|
||||||
_patternOpacity);
|
_patternOpacity);
|
||||||
original.setDevicePixelRatio(ratio);
|
original.setDevicePixelRatio(ratio);
|
||||||
}
|
}
|
||||||
if (_serviceWidth) {
|
_thumbnail = Ui::PixmapFromImage(
|
||||||
original = Images::Circle(std::move(original));
|
finishServiceThumbnail(std::move(original)));
|
||||||
}
|
|
||||||
_thumbnail = Ui::PixmapFromImage(std::move(original));
|
|
||||||
_thumbnailGood = good;
|
_thumbnailGood = good;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -63,12 +63,12 @@ private:
|
||||||
QSize countOptimalSize() override;
|
QSize countOptimalSize() override;
|
||||||
QSize countCurrentSize(int newWidth) override;
|
QSize countCurrentSize(int newWidth) override;
|
||||||
|
|
||||||
void fillPatternFieldsFrom(const QString &url);
|
|
||||||
[[nodiscard]] bool checkGoodThumbnail() const;
|
[[nodiscard]] bool checkGoodThumbnail() const;
|
||||||
void validateThumbnail() const;
|
void validateThumbnail() const;
|
||||||
void prepareThumbnailFrom(not_null<Image*> image, int good) const;
|
void prepareThumbnailFrom(not_null<Image*> image, int good) const;
|
||||||
void generateThumbnail() const;
|
void generateThumbnail() const;
|
||||||
void ensureDataMediaCreated() const;
|
void ensureDataMediaCreated() const;
|
||||||
|
[[nodiscard]] QImage finishServiceThumbnail(QImage image) const;
|
||||||
|
|
||||||
DocumentData *_data = nullptr;
|
DocumentData *_data = nullptr;
|
||||||
int _pixw = 1;
|
int _pixw = 1;
|
||||||
|
@ -83,6 +83,10 @@ private:
|
||||||
float64 _patternOpacity = 0.;
|
float64 _patternOpacity = 0.;
|
||||||
int _gradientRotation = 0;
|
int _gradientRotation = 0;
|
||||||
|
|
||||||
|
mutable bool _isDark = false;
|
||||||
|
int _dimmingIntensity = 0;
|
||||||
|
bool _blurredWallPaper = false;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class ThemeDocumentBox final : public ServiceBoxContent {
|
class ThemeDocumentBox final : public ServiceBoxContent {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user