mirror of https://github.com/procxx/kepka.git
Allow to blur wallpapers from file.
This commit is contained in:
parent
e2f0886950
commit
890aacaeee
|
@ -511,9 +511,6 @@ void BackgroundPreviewBox::paintEvent(QPaintEvent *e) {
|
||||||
void BackgroundPreviewBox::paintImage(Painter &p, TimeMs ms) {
|
void BackgroundPreviewBox::paintImage(Painter &p, TimeMs ms) {
|
||||||
Expects(!_scaled.isNull());
|
Expects(!_scaled.isNull());
|
||||||
|
|
||||||
if (_paper.isPattern() && _paper.document() && _full.isNull()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const auto master = _paper.isPattern()
|
const auto master = _paper.isPattern()
|
||||||
? std::clamp(_paper.patternIntensity() / 100., 0., 1.)
|
? std::clamp(_paper.patternIntensity() / 100., 0., 1.)
|
||||||
: 1.;
|
: 1.;
|
||||||
|
@ -695,7 +692,8 @@ std::optional<QColor> BackgroundPreviewBox::patternBackgroundColor() const {
|
||||||
|
|
||||||
void BackgroundPreviewBox::checkLoadedDocument() {
|
void BackgroundPreviewBox::checkLoadedDocument() {
|
||||||
const auto document = _paper.document();
|
const auto document = _paper.document();
|
||||||
if (!document
|
if (!_full.isNull()
|
||||||
|
|| !document
|
||||||
|| !document->loaded(DocumentData::FilePathResolveChecked)
|
|| !document->loaded(DocumentData::FilePathResolveChecked)
|
||||||
|| _generating) {
|
|| _generating) {
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -13,6 +13,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "core/application.h"
|
#include "core/application.h"
|
||||||
#include "core/crash_reports.h" // for CrashReports::SetAnnotation
|
#include "core/crash_reports.h" // for CrashReports::SetAnnotation
|
||||||
#include "ui/image/image.h"
|
#include "ui/image/image.h"
|
||||||
|
#include "ui/image/image_source.h" // for Images::LocalFileSource
|
||||||
#include "export/export_controller.h"
|
#include "export/export_controller.h"
|
||||||
#include "export/view/export_view_panel_controller.h"
|
#include "export/view/export_view_panel_controller.h"
|
||||||
#include "window/notifications_manager.h"
|
#include "window/notifications_manager.h"
|
||||||
|
@ -3067,10 +3068,11 @@ void Session::setWallpapers(const QVector<MTPWallPaper> &data, int32 hash) {
|
||||||
_wallpapers.reserve(data.size() + 2);
|
_wallpapers.reserve(data.size() + 2);
|
||||||
|
|
||||||
_wallpapers.push_back(Data::Legacy1DefaultWallPaper());
|
_wallpapers.push_back(Data::Legacy1DefaultWallPaper());
|
||||||
_wallpapers.back().setLocalImageAsThumbnail(Images::Create(
|
_wallpapers.back().setLocalImageAsThumbnail(std::make_shared<Image>(
|
||||||
qsl(":/gui/art/bg_initial.jpg"),
|
std::make_unique<Images::LocalFileSource>(
|
||||||
"JPG"
|
qsl(":/gui/art/bg_initial.jpg"),
|
||||||
).get());
|
QByteArray(),
|
||||||
|
"JPG")));
|
||||||
for (const auto &paper : data) {
|
for (const auto &paper : data) {
|
||||||
paper.match([&](const MTPDwallPaper &paper) {
|
paper.match([&](const MTPDwallPaper &paper) {
|
||||||
if (const auto parsed = Data::WallPaper::Create(paper)) {
|
if (const auto parsed = Data::WallPaper::Create(paper)) {
|
||||||
|
@ -3083,10 +3085,11 @@ void Session::setWallpapers(const QVector<MTPWallPaper> &data, int32 hash) {
|
||||||
Data::IsDefaultWallPaper);
|
Data::IsDefaultWallPaper);
|
||||||
if (defaultFound == end(_wallpapers)) {
|
if (defaultFound == end(_wallpapers)) {
|
||||||
_wallpapers.push_back(Data::DefaultWallPaper());
|
_wallpapers.push_back(Data::DefaultWallPaper());
|
||||||
_wallpapers.back().setLocalImageAsThumbnail(Images::Create(
|
_wallpapers.back().setLocalImageAsThumbnail(std::make_shared<Image>(
|
||||||
qsl(":/gui/arg/bg.jpg"),
|
std::make_unique<Images::LocalFileSource>(
|
||||||
"JPG"
|
qsl(":/gui/arg/bg.jpg"),
|
||||||
).get());
|
QByteArray(),
|
||||||
|
"JPG")));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "boxes/auto_download_box.h"
|
#include "boxes/auto_download_box.h"
|
||||||
#include "boxes/stickers_box.h"
|
#include "boxes/stickers_box.h"
|
||||||
#include "boxes/background_box.h"
|
#include "boxes/background_box.h"
|
||||||
|
#include "boxes/background_preview_box.h"
|
||||||
#include "boxes/download_path_box.h"
|
#include "boxes/download_path_box.h"
|
||||||
#include "boxes/local_storage_box.h"
|
#include "boxes/local_storage_box.h"
|
||||||
#include "ui/wrap/vertical_layout.h"
|
#include "ui/wrap/vertical_layout.h"
|
||||||
|
@ -22,6 +23,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "ui/effects/radial_animation.h"
|
#include "ui/effects/radial_animation.h"
|
||||||
#include "ui/toast/toast.h"
|
#include "ui/toast/toast.h"
|
||||||
#include "ui/image/image.h"
|
#include "ui/image/image.h"
|
||||||
|
#include "ui/image/image_source.h"
|
||||||
#include "lang/lang_keys.h"
|
#include "lang/lang_keys.h"
|
||||||
#include "window/themes/window_theme_editor.h"
|
#include "window/themes/window_theme_editor.h"
|
||||||
#include "window/themes/window_theme.h"
|
#include "window/themes/window_theme.h"
|
||||||
|
@ -395,24 +397,13 @@ void ChooseFromFile(not_null<QWidget*> parent) {
|
||||||
: App::readImage(result.remoteContent);
|
: App::readImage(result.remoteContent);
|
||||||
if (image.isNull() || image.width() <= 0 || image.height() <= 0) {
|
if (image.isNull() || image.width() <= 0 || image.height() <= 0) {
|
||||||
return;
|
return;
|
||||||
} else if (image.width() > 4096 * image.height()) {
|
|
||||||
image = image.copy(
|
|
||||||
(image.width() - 4096 * image.height()) / 2,
|
|
||||||
0,
|
|
||||||
4096 * image.height(),
|
|
||||||
image.height());
|
|
||||||
} else if (image.height() > 4096 * image.width()) {
|
|
||||||
image = image.copy(
|
|
||||||
0,
|
|
||||||
(image.height() - 4096 * image.width()) / 2,
|
|
||||||
image.width(),
|
|
||||||
4096 * image.width());
|
|
||||||
}
|
}
|
||||||
|
auto local = Data::CustomWallPaper();
|
||||||
Window::Theme::Background()->set(
|
local.setLocalImageAsThumbnail(std::make_shared<Image>(
|
||||||
Data::CustomWallPaper(),
|
std::make_unique<Images::ImageSource>(
|
||||||
std::move(image));
|
std::move(image),
|
||||||
Window::Theme::Background()->setTile(false);
|
"JPG")));
|
||||||
|
Ui::show(Box<BackgroundPreviewBox>(local));
|
||||||
};
|
};
|
||||||
FileDialog::GetOpenPath(
|
FileDialog::GetOpenPath(
|
||||||
parent.get(),
|
parent.get(),
|
||||||
|
|
|
@ -105,13 +105,13 @@ QString StringFromColor(QColor color) {
|
||||||
WallPaper::WallPaper(WallPaperId id) : _id(id) {
|
WallPaper::WallPaper(WallPaperId id) : _id(id) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void WallPaper::setLocalImageAsThumbnail(not_null<Image*> image) {
|
void WallPaper::setLocalImageAsThumbnail(std::shared_ptr<Image> image) {
|
||||||
Expects(IsDefaultWallPaper(*this)
|
Expects(IsDefaultWallPaper(*this)
|
||||||
|| IsLegacy1DefaultWallPaper(*this)
|
|| IsLegacy1DefaultWallPaper(*this)
|
||||||
|| IsCustomWallPaper(*this));
|
|| IsCustomWallPaper(*this));
|
||||||
Expects(_thumbnail == nullptr);
|
Expects(_thumbnail == nullptr);
|
||||||
|
|
||||||
_thumbnail = image;
|
_thumbnail = std::move(image);
|
||||||
}
|
}
|
||||||
|
|
||||||
WallPaperId WallPaper::id() const {
|
WallPaperId WallPaper::id() const {
|
||||||
|
@ -127,7 +127,11 @@ DocumentData *WallPaper::document() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
Image *WallPaper::thumbnail() const {
|
Image *WallPaper::thumbnail() const {
|
||||||
return _thumbnail;
|
return _thumbnail
|
||||||
|
? _thumbnail.get()
|
||||||
|
: _document
|
||||||
|
? _document->thumbnail()
|
||||||
|
: nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool WallPaper::isPattern() const {
|
bool WallPaper::isPattern() const {
|
||||||
|
@ -195,6 +199,9 @@ void WallPaper::loadThumbnail() const {
|
||||||
if (_thumbnail) {
|
if (_thumbnail) {
|
||||||
_thumbnail->load(fileOrigin());
|
_thumbnail->load(fileOrigin());
|
||||||
}
|
}
|
||||||
|
if (_document) {
|
||||||
|
_document->loadThumbnail(fileOrigin());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void WallPaper::loadDocument() const {
|
void WallPaper::loadDocument() const {
|
||||||
|
@ -288,6 +295,12 @@ WallPaper WallPaper::withParamsFrom(const WallPaper &other) const {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
WallPaper WallPaper::withoutImageData() const {
|
||||||
|
auto result = *this;
|
||||||
|
result._thumbnail = nullptr;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
std::optional<WallPaper> WallPaper::Create(const MTPWallPaper &data) {
|
std::optional<WallPaper> WallPaper::Create(const MTPWallPaper &data) {
|
||||||
return data.match([](const MTPDwallPaper &data) {
|
return data.match([](const MTPDwallPaper &data) {
|
||||||
return Create(data);
|
return Create(data);
|
||||||
|
@ -307,7 +320,6 @@ std::optional<WallPaper> WallPaper::Create(const MTPDwallPaper &data) {
|
||||||
result._flags = data.vflags.v;
|
result._flags = data.vflags.v;
|
||||||
result._slug = qs(data.vslug);
|
result._slug = qs(data.vslug);
|
||||||
result._document = document;
|
result._document = document;
|
||||||
result._thumbnail = document->thumbnail();
|
|
||||||
if (data.has_settings()) {
|
if (data.has_settings()) {
|
||||||
const auto isPattern = ((result._flags & Flag::f_pattern) != 0);
|
const auto isPattern = ((result._flags & Flag::f_pattern) != 0);
|
||||||
data.vsettings.match([&](const MTPDwallPaperSettings &data) {
|
data.vsettings.match([&](const MTPDwallPaperSettings &data) {
|
||||||
|
@ -988,7 +1000,7 @@ void ChatBackground::set(const Data::WallPaper &paper, QImage image) {
|
||||||
}
|
}
|
||||||
} else if (Data::IsDefaultWallPaper(_paper)
|
} else if (Data::IsDefaultWallPaper(_paper)
|
||||||
|| (!_paper.backgroundColor() && image.isNull())) {
|
|| (!_paper.backgroundColor() && image.isNull())) {
|
||||||
setPaper(Data::DefaultWallPaper());
|
setPaper(Data::DefaultWallPaper().withParamsFrom(_paper));
|
||||||
image.load(qsl(":/gui/art/bg.jpg"));
|
image.load(qsl(":/gui/art/bg.jpg"));
|
||||||
}
|
}
|
||||||
Local::writeBackground(
|
Local::writeBackground(
|
||||||
|
@ -1082,7 +1094,7 @@ void ChatBackground::preparePixmaps(QImage image) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChatBackground::setPaper(const Data::WallPaper &paper) {
|
void ChatBackground::setPaper(const Data::WallPaper &paper) {
|
||||||
_paper = paper;
|
_paper = paper.withoutImageData();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ChatBackground::adjustPaletteRequired() {
|
bool ChatBackground::adjustPaletteRequired() {
|
||||||
|
|
|
@ -17,7 +17,7 @@ class WallPaper {
|
||||||
public:
|
public:
|
||||||
explicit WallPaper(WallPaperId id);
|
explicit WallPaper(WallPaperId id);
|
||||||
|
|
||||||
void setLocalImageAsThumbnail(not_null<Image*> image);
|
void setLocalImageAsThumbnail(std::shared_ptr<Image> image);
|
||||||
|
|
||||||
[[nodiscard]] WallPaperId id() const;
|
[[nodiscard]] WallPaperId id() const;
|
||||||
[[nodiscard]] std::optional<QColor> backgroundColor() const;
|
[[nodiscard]] std::optional<QColor> backgroundColor() const;
|
||||||
|
@ -43,6 +43,7 @@ public:
|
||||||
[[nodiscard]] WallPaper withPatternIntensity(int intensity) const;
|
[[nodiscard]] WallPaper withPatternIntensity(int intensity) const;
|
||||||
[[nodiscard]] WallPaper withBackgroundColor(QColor color) const;
|
[[nodiscard]] WallPaper withBackgroundColor(QColor color) const;
|
||||||
[[nodiscard]] WallPaper withParamsFrom(const WallPaper &other) const;
|
[[nodiscard]] WallPaper withParamsFrom(const WallPaper &other) const;
|
||||||
|
[[nodiscard]] WallPaper withoutImageData() const;
|
||||||
|
|
||||||
[[nodiscard]] static std::optional<WallPaper> Create(
|
[[nodiscard]] static std::optional<WallPaper> Create(
|
||||||
const MTPWallPaper &data);
|
const MTPWallPaper &data);
|
||||||
|
@ -75,7 +76,7 @@ private:
|
||||||
int _intensity = kDefaultIntensity;
|
int _intensity = kDefaultIntensity;
|
||||||
|
|
||||||
DocumentData *_document = nullptr;
|
DocumentData *_document = nullptr;
|
||||||
Image *_thumbnail = nullptr;
|
std::shared_ptr<Image> _thumbnail;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue